Skip to content

Commit

Permalink
Implement multiselect foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
ObaraEmmanuel committed Aug 5, 2023
1 parent a7a6349 commit 4946780
Show file tree
Hide file tree
Showing 10 changed files with 862 additions and 357 deletions.
10 changes: 6 additions & 4 deletions hoverset/ui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2558,6 +2558,10 @@ def _load_images(self):
cls.BLANK = get_icon_image("blank", 14, 14)
cls.__icons_loaded = True

@property
def selected(self):
return self._selected

@property
def depth(self):
return self._depth
Expand Down Expand Up @@ -2718,8 +2722,7 @@ def remove(self, node=None):
self._set_expander(self.BLANK)

def expand(self):
if len(self.nodes) == 0:
# There is nothing to expand
if self._expanded:
return
self.pack_propagate(True)
for node in filter(lambda n: n._visible, self.nodes):
Expand All @@ -2728,8 +2731,7 @@ def expand(self):
self._expanded = True

def collapse(self):
if len(self.nodes) == 0:
# There is nothing to collapse
if not self._expanded:
return
for node in self.nodes:
node.pack_forget()
Expand Down
6 changes: 3 additions & 3 deletions studio/feature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
FEATURES = (
ComponentPane,
ComponentTree,
StylePane,
EventPane,
VariablePane,
#StylePane,
#EventPane,
#VariablePane,
)


75 changes: 45 additions & 30 deletions studio/feature/component_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def __init__(self, master, studio=None, **cnf):
self.body = Frame(self, **self.style.surface)
self.body.pack(side="top", fill="both", expand=True)
self._empty_label = Label(self.body, **self.style.text_passive)
self.studio.bind("<<SelectionChanged>>", self._select, "+")

self._selected = None
self._expanded = False
self._tree = None

Expand All @@ -92,6 +92,7 @@ def on_context_switch(self):
self._tree = self.studio.designer.node
else:
self._tree = ComponentTreeView(self.body)
self._tree.allow_multi_select(True)
self._tree.on_select(self._trigger_select)
self.studio.designer.node = self._tree
self._tree.pack(fill="both", expand=True)
Expand Down Expand Up @@ -142,38 +143,52 @@ def on_widget_add(self, widget: PseudoWidget, parent=None):
)

def _trigger_select(self):
if self._selected and self._selected.widget == self._tree.get().widget:
if self.studio.selection == self.selection():
return
self.studio.select(self._tree.get().widget, self)
self._selected = self._tree.get()

def select(self, widget):
if widget:
self.studio.selection.set(self.selection())

def _select(self, _):
if self.studio.selection == self.selection():
return

if not self._tree:
return
nodes = self.studio_selection()

for node in list(self._tree.get()):
if node not in nodes:
self._tree.deselect(node)

for node in nodes:
if not node.selected:
node.select(silently=True)

def selection(self):
if not self._tree:
return []
return [i.widget for i in self._tree.get()]

def studio_selection(self):
return [i.node for i in self.studio.selection]

def on_widget_delete(self, widgets, silently=False):
for widget in widgets:
widget.node.remove()

def on_widget_restore(self, widgets):
for widget in widgets:
widget.layout.node.add(widget.node)

def on_widget_layout_change(self, widgets):
for widget in widgets:
node = widget.node
self._selected = node
node.select(None, True) # Select node silently to avoid triggering a duplicate selection event
elif widget is None:
if self._selected:
self._selected.deselect()
self._selected = None

def on_select(self, widget):
self.select(widget)

def on_widget_delete(self, widget, silently=False):
widget.node.remove()

def on_widget_restore(self, widget):
widget.layout.node.add(widget.node)

def on_widget_layout_change(self, widget):
node = widget.node
if widget.layout == self.studio.designer:
parent = self._tree
else:
parent = widget.layout.node
if node.parent_node != parent:
parent.insert(None, node)
if widget.layout == self.studio.designer:
parent = self._tree
else:
parent = widget.layout.node
if node.parent_node != parent:
parent.insert(None, node)

def on_context_close(self, context):
if hasattr(context, "designer"):
Expand Down
Loading

0 comments on commit 4946780

Please sign in to comment.