Skip to content

Commit

Permalink
add functions to menus
Browse files Browse the repository at this point in the history
  • Loading branch information
socketteer committed Feb 26, 2021
1 parent 5b310e3 commit da56deb
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 33 deletions.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,31 @@ Child edit: `c`

### Navigate

Go to checkpoint: `t`
Next: `period`, `Return`, `Control-period`

Go to child: `Right`, `Control-Right`
Prev: `comma`, `Control-comma`

Go to next bookmark: `d`, `Control-d`
Go to child: `Right`, `Control-Right`

Go to next sibling: `Down`, `Control-Down`

Go to parent: `Left`, `Control-Left`

Go to prev bookmark: `a`, `Control-a`

Go to previous Sibling: `Up`, `Control-Up`

Next: `period`, `Return`, `Control-period`

Prev: `comma`, `Control-comma`

Return to root: `r`, `Control-r`

Walk: `w`, `Control-w`

Go to checkpoint: `t`

Save checkpoint: `Control-t`

Toggle bookmark: `b`, `Control-b`
Go to next bookmark: `d`, `Control-d`

Go to prev bookmark: `a`, `Control-a`

Toggle bookmark: `b`, `Control-b`


### Edit topology
Expand Down Expand Up @@ -148,14 +147,14 @@ Collapse node: `Control-question`

Collapse subtree: `Control-minus`

Expand children: `Control-quotedbl`

### View
Expand subtree: `Control-plus`

Center view: `l`, `Control-l`

Expand children: `Control-quotedbl`
### View

Expand subtree: `Control-plus`
Center view: `l`, `Control-l`

Reset zoom: `Control-0`

Expand Down
11 changes: 4 additions & 7 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
* icons sometimes do not zoom
* edit text box position wrong after zooming (and?)

# features

### Tree visualization
# Tree visualization


- don't calc tree structure when refreshing
Expand All @@ -42,7 +40,7 @@
- editing:
global edit mode, where all nodes turn into textboxes, but no zooming?


# Display

* show / hide navtrees
Expand All @@ -54,6 +52,7 @@ global edit mode, where all nodes turn into textboxes, but no zooming?
* sidebar adjustable
* display hotkeys window
* scroll at top of chapter by default and hotkey to go to top of chapter
* change darkmode in program

# Modifications

Expand All @@ -63,9 +62,7 @@ global edit mode, where all nodes turn into textboxes, but no zooming?
* create parent for root node
* multiple root nodes
* add ghostchildren/ghostparents (using hotkey)
* change parent
- visual indication that change parent mode has been toggled
- check if new parent in subtree
* visual indication that change parent mode has been toggled

* change order of children

Expand Down
38 changes: 28 additions & 10 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,43 @@ def build_menus(self):
# Tuple of 4 things: Name, Hotkey display text, tkinter key to bind to, function to call (without arguments)
menu_list = {
"View": [
('Toggle visualize mode', None, None, no_junk_args(self.toggle_visualization_mode)),
('Change visualization settings', None, None, no_junk_args(self.visualization_settings_dialog)),
('Toggle visualize mode', 'J', None, no_junk_args(self.toggle_visualization_mode)),
('Visualization settings', 'Ctrl+U', None, no_junk_args(self.visualization_settings_dialog)),
('Multimedia', 'U', None, no_junk_args(self.multimedia_dialog)),
('Collapse node', 'Ctrl-?', None, no_junk_args(self.collapse_node)),
('Collapse subtree', 'Ctrl-minus', None, no_junk_args(self.collapse_subtree)),
('Collapse all except subtree', 'Ctrl-:', None, no_junk_args(self.collapse_all_except_subtree)),
('Expand children', 'Ctrl-\"', None, no_junk_args(self.expand_children)),
('Expand subtree', 'Ctrl-+', None, no_junk_args(self.expand_subtree)),
('Center view', 'L, Ctrl-L', None, no_junk_args(self.center_view)),
('Reset zoom', 'Ctrl-0', None, no_junk_args(self.reset_zoom)),
],
"Edit": [
('Edit mode', 'Ctrl+E', None, no_junk_args(self.toggle_edit_mode)),
("Create parent", None, None, no_junk_args(self.create_parent)),
("Merge with parent", None, None, no_junk_args(self.merge_with_parent)),
("Merge with children", None, None, no_junk_args(self.merge_with_children)),
("Create parent", 'Alt-Left', None, no_junk_args(self.create_parent)),
("Change parent", 'Shift-P', None, no_junk_args(self.change_parent)),
("New Child", 'H, Ctrl+H, Alt+Right', None, no_junk_args(self.create_child)),
("New Sibling", 'Alt+Down', None, no_junk_args(self.create_sibling)),
("Merge with parent", 'Shift+Left', None, no_junk_args(self.merge_with_parent)),
("Merge with children", 'Shift+Right', None, no_junk_args(self.merge_with_children)),
('Prepend newline', 'N', None, no_junk_args(self.prepend_newline)),
('Prepend space', 'M', None, no_junk_args(self.prepend_space)),
('Copy', 'Ctrl+C', None, no_junk_args(self.copy_text)),
('Delete', 'Backspace', None, no_junk_args(self.delete_node)),
('Delete and reassign children', '', None, no_junk_args(self.delete_node_reassign_children)),
],
"Generation": [
('Change generation settings', None, None, no_junk_args(self.generation_settings_dialog)),
],
"Bookmarks": [
"Navigate": [
('Return to root', 'R', None, no_junk_args(self.return_to_root)),
('Save checkpoint', 'Ctrl+T', None, no_junk_args(self.save_checkpoint)),
('Go to checkpoint', 'T', None, no_junk_args(self.goto_checkpoint)),
("Bookmark", "B", None, no_junk_args(self.bookmark)),
("Next Bookmark", "D", None, no_junk_args(self.next_bookmark)),
("Prev Bookmark", "A", None, no_junk_args(self.prev_bookmark)),
("Stochastic walk", "W", None, no_junk_args(self.walk)),
],
"Generation": [
('Generation settings', 'Ctrl+P', None, no_junk_args(self.generation_settings_dialog)),
('Generate', 'G, Ctrl+G', None, no_junk_args(self.generate)),
],
"Visited": [
("Mark visited", None, None, lambda: self.set_visited(True)),
Expand All @@ -138,7 +154,7 @@ def build_menus(self):
("Mark all unvisited", None, None, lambda: self.set_all_visited(False)),
],
"Info": [
("Tree statistics", None, None, no_junk_args(self.info_dialog)),
("Tree statistics", "I", None, no_junk_args(self.info_dialog)),
],
}
return menu_list
Expand Down Expand Up @@ -259,8 +275,10 @@ def create_parent(self):
@metadata(name="Change Parent", keys=["<Shift-P>"], display_key="shift-p", selected_node=None)
def change_parent(self):
if self.change_parent.meta["selected_node"] is None:
print('copied node id')
self.change_parent.meta["selected_node"] = self.state.selected_node
else:
print('changing parent')
self.state.change_parent(node=self.change_parent.meta["selected_node"], new_parent_id=self.state.selected_node_id)
self.change_parent.meta["selected_node"] = None

Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def build_menus(self):
"File": [
('New Tab', 'Ctrl+N', '<Control-n>', self.create_tab),
('Open', 'O', None, lambda event=None: self.forward_command(Controller.open_tree)),
('Import subtree', 'Ctrl+Shift+O', None, lambda event=None: self.forward_command(Controller.import_tree)),
('Save', 'S', None, lambda event=None: self.forward_command(Controller.save_tree)),
('Save As...', 'Ctrl+S', '<Control-s>', lambda event=None: self.forward_command(Controller.save_tree_as)),
('Close Tab', None, None, self.close_tab),
Expand Down
8 changes: 6 additions & 2 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from gpt import api_generate, janus_generate
from util.util import json_create, timestamp, json_open, clip_num, index_clip
from util.util_tree import fix_miro_tree, flatten_tree, node_ancestry, overwrite_subtree
from util.util_tree import fix_miro_tree, flatten_tree, node_ancestry, in_ancestry


# Calls any callbacks associated with the wrapped function
Expand Down Expand Up @@ -338,10 +338,14 @@ def change_parent(self, node=None, new_parent_id=None):
return
elif new_parent_id == node["parent_id"]:
return
new_parent = self.tree_node_dict[new_parent_id]
if in_ancestry(node, new_parent, self.tree_node_dict):
print('error: node is ancestor of new parent')
return
old_siblings = self.tree_node_dict[node["parent_id"]]["children"]
old_siblings.remove(node)
node["parent_id"] = new_parent_id
self.tree_node_dict[new_parent_id]["children"].append(node)
new_parent["children"].append(node)
self.tree_updated()

def add_parent(self, node=None, new_ghostparent=None):
Expand Down
6 changes: 6 additions & 0 deletions util/util_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def node_ancestry(node, node_dict):
return ancestry


# Returns True if a is ancestor of b
def in_ancestry(a, b, node_dict):
ancestry = node_ancestry(b, node_dict)
return a in ancestry


# recursively called on subtree
def overwrite_subtree(node, attribute, new_value, old_value=None, force_overwrite=False):
if force_overwrite or (attribute not in node) or old_value is None or (node[attribute] == old_value) \
Expand Down

0 comments on commit da56deb

Please sign in to comment.