예제 #1
0
 def create_item(self,
                 component,
                 coords=(),
                 item=None,
                 canvas=None,
                 silently=False,
                 **kwargs):
     canvas = canvas or self.canvas
     if item is None:
         opts = dict(**component.defaults)
         opts.update(kwargs)
         item = component(canvas, *coords, **opts)
         # generate a unique id
         item.name = self.generator.generate(component, self._ids)
     canvas._cv_items.append(item)
     item._prev_index = canvas._cv_items.index(item)
     node = canvas._cv_tree.add_as_node(item=item)
     item.bind("<ButtonRelease-1>", lambda e: self._handle_select(item, e),
               True)
     item.bind("<ButtonRelease-1>", lambda e: self._handle_end(item, e),
               True)
     item.bind("<Motion>", lambda e: self._handle_move(item, e), True)
     MenuUtils.bind_context(item, self._show_item_menu(item))
     MenuUtils.bind_all_context(node, self._show_item_menu(item))
     if not silently:
         self.studio.new_action(
             Action(lambda _: self.remove_items([item], silently=True),
                    lambda _: self.restore_items([item])))
     return item
예제 #2
0
    def on_widget_add(self, widget: PseudoWidget, parent=None):
        if parent is None:
            node = self._tree.add_as_node(widget=widget)
        else:
            parent = parent.node
            node = parent.add_as_node(widget=widget)

        # let the designer render the menu for us
        MenuUtils.bind_all_context(
            node, lambda e: self.studio.designer.show_menu(e, widget)
            if self.studio.designer else None)
예제 #3
0
 def _attach(self, obj):
     # bind events for context menu and object selection
     # all widget additions call this method so clear empty message
     self._show_empty(False)
     MenuUtils.bind_all_context(obj,
                                lambda e: self.show_menu(e, obj),
                                add='+')
     obj.bind_all(
         '<Shift-ButtonPress-1>',
         lambda e: self.highlight.set_function(self.highlight.move, e),
         add='+')
     obj.bind_all('<Motion>', self.on_motion, '+')
     obj.bind_all('<ButtonRelease>', self.highlight.clear_resize, '+')
     if "text" in obj.keys():
         obj.bind_all("<Double-Button-1>",
                      lambda _: self._show_text_editor(obj))
     self.objects.append(obj)
     if self.root_obj is None:
         self.root_obj = obj
     obj.bind_all("<Button-1>",
                  lambda e: self._handle_select(obj, e),
                  add='+')
     # bind shortcuts
     self._shortcut_mgr.bind_widget(obj)