Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key mapping feature #39

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ dist/
notes/
markdoc/
npdoc2md/
*.*~
ecui/
*~
epy_cui/
activate.bat
*.swp
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Primary Author(s):

Contributor(s):
Maciej Wlodek
telday
Ellis Wright (telday)
Aaron Pierce
Caleb Reese (cptbldbrd)
30 changes: 15 additions & 15 deletions examples/autogit.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ def __init__(self, root, dir):
self.root.set_title('Autogit v{} - {}'.format(__version__, os.path.basename(self.dir)))

# Keybindings when in overview mode, and set info bar
self.root.add_key_command(py_cui.keys.KEY_R_LOWER, self.refresh_git_status)
self.root.add_key_command(py_cui.keys.KEY_L_LOWER, self.show_log)
self.root.add_key_command(py_cui.keys.KEY_A_LOWER, self.add_all)
self.root.add_key_command(py_cui.keys.KEY_E_LOWER, self.open_editor)
self.root.add_key_command(py_cui.keys.KEY_F_LOWER, self.fetch_branch)
self.root.add_key_command(py_cui.keys.KEY_P_LOWER, self.push_branch)
self.root.add_key_command(py_cui.keys.KEY_M_LOWER, self.show_menu)
self.root.add_key_command(py_cui.keys.Key.R_LOWER, self.refresh_git_status)
self.root.add_key_command(py_cui.keys.Key.L_LOWER, self.show_log)
self.root.add_key_command(py_cui.keys.Key.A_LOWER, self.add_all)
self.root.add_key_command(py_cui.keys.Key.E_LOWER, self.open_editor)
self.root.add_key_command(py_cui.keys.Key.F_LOWER, self.fetch_branch)
self.root.add_key_command(py_cui.keys.Key.P_LOWER, self.push_branch)
self.root.add_key_command(py_cui.keys.Key.M_LOWER, self.show_menu)
self.root.set_status_bar_text('Quit - q | Refresh - r | Add all - a | Git log - l | Open Editor - e | Pull Branch - f | Push Branch - p')

# Create the add files menu. Add color rules to color first characters based on git status
Expand Down Expand Up @@ -77,24 +77,24 @@ def __init__(self, root, dir):
self.commit_message_box = self.root.add_text_box('Commit Message', 8, 2, column_span=6)

# 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.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'

# Enter will show remote info
self.git_remotes_menu.add_key_command(py_cui.keys.KEY_ENTER, self.show_remote_info)
self.git_remotes_menu.add_key_command(py_cui.keys.Key.ENTER, self.show_remote_info)

# Enter will show commit diff
self.git_commits_menu.add_key_command(py_cui.keys.KEY_ENTER, self.show_git_commit_diff)
self.git_commits_menu.add_key_command(py_cui.keys.Key.ENTER, self.show_git_commit_diff)
self.git_commits_menu.add_text_color_rule(' ', py_cui.GREEN_ON_BLACK, 'notstartswith', match_type='region', region=[0,7], include_whitespace=True)

# Enter will checkout
self.branch_menu.add_key_command(py_cui.keys.KEY_ENTER, self.checkout_branch)
self.branch_menu.add_key_command(py_cui.keys.KEY_SPACE, self.show_log)
self.branch_menu.add_key_command(py_cui.keys.Key.ENTER, self.checkout_branch)
self.branch_menu.add_key_command(py_cui.keys.Key.SPACE, self.show_log)

# Add commands for committing and branch checkout.
self.new_branch_textbox.add_key_command(py_cui.keys.KEY_ENTER, self.create_new_branch)
self.commit_message_box.add_key_command(py_cui.keys.KEY_ENTER, self.ask_to_commit)
self.new_branch_textbox.add_key_command(py_cui.keys.Key.ENTER, self.create_new_branch)
self.commit_message_box.add_key_command(py_cui.keys.Key.ENTER, self.ask_to_commit)


def get_logo(self):
Expand Down
4 changes: 2 additions & 2 deletions examples/multi_window_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, root):

# 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)
self.text_box_B.add_key_command(py_cui.keys.KEY_ENTER, self.open_set_A)
self.text_box_B.add_key_command(py_cui.keys.Key.ENTER, self.open_set_A)


def open_set_A(self):
Expand All @@ -41,4 +41,4 @@ def open_set_B(self):
# Create CUI object, pass to wrapper class, and start the CUI
root = py_cui.PyCUI(3, 3)
wrapper = MultiWindowDemo(root)
root.start()
root.start()
8 changes: 4 additions & 4 deletions examples/simple_todo_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def __init__(self, master):
self.save_todo_button = self.master.add_button('Save', 7, 4, column_span=2, command=self.save_todo_file)

# add some custom keybindings
self.new_todo_textbox.add_key_command( py_cui.keys.KEY_ENTER, self.push_and_reset)
self.todo_scroll_cell.add_key_command( py_cui.keys.KEY_ENTER, self.mark_as_in_progress)
self.in_progress_scroll_cell.add_key_command( py_cui.keys.KEY_ENTER, self.mark_as_done)
self.new_todo_textbox.add_key_command( py_cui.keys.Key.ENTER, self.push_and_reset)
self.todo_scroll_cell.add_key_command( py_cui.keys.Key.ENTER, self.mark_as_in_progress)
self.in_progress_scroll_cell.add_key_command( py_cui.keys.Key.ENTER, self.mark_as_done)
self.read_todo_file()


Expand Down Expand Up @@ -134,4 +134,4 @@ def save_todo_file(self):
root = py_cui.PyCUI(8, 6)
root.set_title('CUI TODO List')
s = SimpleTodoList(root)
root.start()
root.start()
10 changes: 5 additions & 5 deletions examples/snano.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def __init__(self, root, dir):
self.dir = dir

# If we press 's' we want to save the opened file
self.root.add_key_command(py_cui.keys.KEY_S_LOWER, self.save_opened_file)
self.root.add_key_command(py_cui.keys.Key.S_LOWER, self.save_opened_file)

# Add a file selection menu
self.file_menu = self.root.add_scroll_menu('Directory Files', 0, 0, row_span=5, column_span=2)

# With ENTER key press, we open the selected file or directory, DELETE will delete the selected file or directory
# See the callback functions for how these operations are performed
self.file_menu.add_key_command(py_cui.keys.KEY_ENTER, self.open_file_dir)
self.file_menu.add_key_command(py_cui.keys.KEY_DELETE, self.delete_selected_file)
self.file_menu.add_key_command(py_cui.keys.Key.ENTER, self.open_file_dir)
self.file_menu.add_key_command(py_cui.keys.Key.DELETE, self.delete_selected_file)

# To better distingusish directories, add a color rule that is used to color directory names green
# First parameter is a regex, second is color, third is how the rule should check the regex against the line.
Expand All @@ -46,7 +46,7 @@ def __init__(self, root, dir):
self.current_dir_box.set_text(self.dir)

# You can manually enter directory path, and ENTER will try to open it
self.current_dir_box.add_key_command(py_cui.keys.KEY_ENTER, self.open_new_directory)
self.current_dir_box.add_key_command(py_cui.keys.Key.ENTER, self.open_new_directory)

# Function that opens initial directory
self.open_new_directory()
Expand All @@ -56,7 +56,7 @@ def __init__(self, root, dir):

# Add a textbox for adding new files on ENTER key
self.new_file_textbox = self.root.add_text_box('Add New File', 5, 0, column_span=2)
self.new_file_textbox.add_key_command(py_cui.keys.KEY_ENTER, self.add_new_file)
self.new_file_textbox.add_key_command(py_cui.keys.Key.ENTER, self.add_new_file)


def open_new_directory(self):
Expand Down
Loading