Skip to content

Commit

Permalink
Update example programs to work with 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jwlodek committed Mar 30, 2020
1 parent cc1a3c2 commit c676592
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
48 changes: 24 additions & 24 deletions examples/autogit.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, root, dir):
# Key commands for our file menus. Enter will git add, Space will show diff
self.add_files_menu.add_key_command(py_cui.keys.KEY_ENTER, self.add_revert_file)
self.add_files_menu.add_key_command(py_cui.keys.KEY_SPACE, self.open_git_diff)
self.add_files_menu.help_text = 'Enter - git add, Space - see diff, Arrows - scroll, Esc - exit'
self.add_files_menu.set_help_text('Enter - git add, Space - see diff, Arrows - scroll, Esc - exit')

# Enter will show remote info
self.git_remotes_menu.add_key_command(py_cui.keys.KEY_ENTER, self.show_remote_info)
Expand Down Expand Up @@ -127,17 +127,17 @@ def show_git_commit_diff(self):
try:
commit_val = self.git_commits_menu.get()[:7]
proc = Popen(['git', 'diff', commit_val], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
out, _ = proc.communicate()
out = out.decode()
self.diff_text_block.title = 'Git Diff for {}'.format(commit_val)
self.diff_text_block.set_title('Git Diff for {}'.format(commit_val))
self.diff_text_block.set_text(out)
except:
self.root.show_warning_popup('Git Failed', 'Unable to read commit diff information')

def add_all(self):
try:
proc = Popen(['git', 'add', '-A'], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
_, _ = proc.communicate()
self.refresh_git_status(preserve_selected=True)
except:
self.root.show_warning_popup('Git Failed', 'Unable to reset file, please check git installation')
Expand All @@ -147,27 +147,27 @@ def show_remote_info(self):
try:
remote = self.git_remotes_menu.get()
proc = Popen(['git', 'remote', 'show', '-n', remote], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
out, _ = proc.communicate()
out = out.decode()
self.diff_text_block.title = 'Git Remote Info'
self.diff_text_block.set_title('Git Remote Info')
self.diff_text_block.set_text(out)
except:
self.root.show_warning_popup('Git Error', 'Unable to open git remote info, please check git installation')


def open_editor(self):
try:
proc = Popen(['code', '.'], stdout=PIPE, stderr=PIPE)
_ = Popen(['code', '.'], stdout=PIPE, stderr=PIPE)
except:
self.root.show_warning_popup('Open Failed', 'Please install VSCode')

def show_log(self):
try:
branch = self.branch_menu.get()[2:]
proc = Popen(['git', '--no-pager', 'log', branch], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
out, _ = proc.communicate()
out = out.decode()
self.diff_text_block.title='Git Log'
self.diff_text_block.set_title('Git Log')
self.diff_text_block.set_text(out)
except:
self.root.show_warning_popup('Git Error', 'Unable to open git log, please check git installation')
Expand All @@ -180,7 +180,7 @@ def create_new_branch(self):
return
try:
proc = Popen(['git', 'checkout', '-b', new_branch_name])
out, err = proc.communicate()
_, err = proc.communicate()
res = proc.returncode
if res != 0:
self.root.show_error_popup('Create Branch Failed Failed', '{}'.format(err))
Expand All @@ -203,7 +203,7 @@ def commit_changes(self, commit):
self.root.show_error_popup('Invalid Commit Message', 'Please enter a commit message')
return
proc = Popen(['git', 'commit', '-m', message])
out, err = proc.communicate()
_, err = proc.communicate()
res = proc.returncode
if res != 0:
self.root.show_error_popup('Create Branch Failed Failed', '{}'.format(err))
Expand All @@ -219,7 +219,7 @@ def checkout_branch(self):
try:
target = self.branch_menu.get()[2:]
proc = Popen(['git', 'checkout', target])
out, err = proc.communicate()
out, _ = proc.communicate()
res = proc.returncode
if res != 0:
self.root.show_error_popup('Checkout Failed', '{}'.format(out))
Expand All @@ -233,7 +233,7 @@ def checkout_branch(self):
def revert_changes(self):
try:
target = self.add_files_menu.get()[3:]
proc = Popen(['git', 'reset', 'HEAD', target])
_ = Popen(['git', 'reset', 'HEAD', target])
self.refresh_git_status(preserve_selected=True)
except:
self.root.show_warning_popup('Git Failed', 'Unable to reset file, please check git installation')
Expand All @@ -243,7 +243,7 @@ def open_git_diff(self):
target = self.add_files_menu.get()[3:]
self.diff_text_block.title = '{} File Diff'.format(target)
proc = Popen(['git', 'diff', target], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
out, _ = proc.communicate()
out = out.decode()
self.diff_text_block.set_text(out)

Expand All @@ -253,7 +253,7 @@ def add_revert_file(self):
target = self.add_files_menu.get()
if target.startswith(' ') or target.startswith('?'):
target = target[3:]
proc = Popen(['git', 'add', target], stdout=PIPE, stderr=PIPE)
_ = Popen(['git', 'add', target], stdout=PIPE, stderr=PIPE)
self.refresh_git_status(preserve_selected=True)
else:
self.revert_changes()
Expand All @@ -265,7 +265,7 @@ def refresh_git_status(self, preserve_selected=False):

try:
proc = Popen(['git', 'branch'], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
out, _ = proc.communicate()
out = out.decode().splitlines()
self.branch_menu.clear()
self.branch_menu.add_item_list(out)
Expand All @@ -275,33 +275,33 @@ def refresh_git_status(self, preserve_selected=False):
break
selected_branch = selected_branch + 1

remote = self.git_remotes_menu.selected_item
remote = self.git_remotes_menu.get_selected_item()
proc = Popen(['git', 'remote'], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
out, _ = proc.communicate()
out = out.decode().splitlines()
self.git_remotes_menu.clear()
self.git_remotes_menu.add_item_list(out)

proc = Popen(['git', '--no-pager', 'log', self.branch_menu.get()[2:], '--oneline'], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
out, _ = proc.communicate()
out = out.decode().splitlines()
self.git_commits_menu.clear()
self.git_commits_menu.add_item_list(out)

selected_file = self.add_files_menu.selected_item
selected_file = self.add_files_menu.get_selected_item()
proc = Popen(['git', 'status', '-s'], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
out, _ = proc.communicate()
out = out.decode().splitlines()
self.add_files_menu.clear()
self.add_files_menu.add_item_list(out)

if preserve_selected:
if len(self.branch_menu.get_item_list()) > selected_branch:
self.branch_menu.selected_item = selected_branch
self.branch_menu.set_selected_item(selected_branch)
if len(self.git_remotes_menu.get_item_list()) > remote:
self.git_remotes_menu.selected_item = remote
if len(self.add_files_menu.get_item_list()) > selected_file:
self.add_files_menu.selected_item = selected_file
self.add_files_menu.set_selected_item(selected_file)

except:
self.root.show_warning_popup('Git Failed', 'Unable to get git status, please check git installation')
Expand All @@ -312,7 +312,7 @@ def fetch_branch(self):
target = self.branch_menu.get()[2:]
remote = self.remote_menu.get()
proc = Popen(['git', 'pull', remote, target, target])
out, err = proc.communicate()
out, _ = proc.communicate()
res = proc.returncode
if res != 0:
self.root.show_error_popup('Checkout Failed', '{}'.format(out))
Expand Down
2 changes: 1 addition & 1 deletion examples/multi_window_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, root):
self.widget_set_A = self.root.get_widget_set()

# Create a second widget set (window). This one will have a 5x5 grid, not 3x3 like the original CUI
self.widget_set_B = py_cui.widget_set.WidgetSet(5, 5)
self.widget_set_B = self.root.create_new_widget_set(5, 5)

# Add a text box to the second widget set
self.text_box_B = self.widget_set_B.add_text_box('Enter something', 0, 0, column_span=2)
Expand Down
6 changes: 3 additions & 3 deletions examples/popups_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def change_button_color(self, new_color):
elif new_color == "MAGENTA":
color = py_cui.MAGENTA_ON_BLACK
for key in self.master.widgets.keys():
if isinstance(self.master.widgets[key], py_cui.widgets.Button):
self.master.widgets[key].color = color
if isinstance(self.master.get_widgets()[key], py_cui.widgets.Button):
self.master.get_widgets()[key].set_color(color)


# -------------------------------------------------------------------------------
Expand Down Expand Up @@ -132,7 +132,7 @@ def long_operation(self):
"""

counter = 0
for i in range(0, 100):
for _ in range(0, 100):
time.sleep(0.1)
counter= counter +1
self.master.status_bar.set_text(str(counter))
Expand Down
18 changes: 9 additions & 9 deletions examples/snano.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def add_new_file(self):
# Add item to file menu, and refresh. File not saved to disk until 's' pressed.
self.file_menu.add_item(self.new_file_textbox.get())
self.file_menu.selected_item = len(self.file_menu.get_item_list()) - 1
self.new_file_textbox.selected = False
self.root.set_selected_widget(self.edit_text_block.id)
self.new_file_textbox.set_selected(False)
self.root.set_selected_widget(self.edit_text_block.get_id())
self.edit_text_block.title = self.new_file_textbox.get()
self.edit_text_block.clear()
self.new_file_textbox.clear()
Expand All @@ -116,30 +116,30 @@ def open_file_dir(self):
text = fp.read()
fp.close()
self.edit_text_block.set_text(text)
self.edit_text_block.title = filename
self.edit_text_block.set_title(filename)
except:
# if we get an error, it wasn't a text file, so show warning poup
self.root.show_warning_popup('Not a text file', 'The selected file could not be opened - not a text file')


def save_opened_file(self):
# If we have an opened file, save it to the disk
if self.edit_text_block.title != 'Open file':
fp = open(os.path.join(self.dir, self.edit_text_block.title), 'w')
if self.edit_text_block.get_title() != 'Open file':
fp = open(os.path.join(self.dir, self.edit_text_block.get_title()), 'w')
fp.write(self.edit_text_block.get())
fp.close()
self.root.show_message_popup('Saved', 'Your file has been saved as {}'.format(self.edit_text_block.title))
self.root.show_message_popup('Saved', 'Your file has been saved as {}'.format(self.edit_text_block.get_title()))
else:
self.root.show_error_popup('No File Opened', 'Please open a file before saving it.')


def delete_selected_file(self):
# If we have an opened file, delete it from the disk
if self.edit_text_block.title != 'Open file':
if self.edit_text_block.get_title() != 'Open file':
try:
os.remove(os.path.join(self.dir, self.edit_text_block.title))
os.remove(os.path.join(self.dir, self.edit_text_block.get_title()))
self.edit_text_block.clear()
self.edit_text_block.title = 'Open file'
self.edit_text_block.set_title('Open file')
self.file_menu.remove_selected_item()
except OSError:
self.root.show_error_popup('OS Error', 'Operation could not be completed due to an OS error.')
Expand Down

0 comments on commit c676592

Please sign in to comment.