def get_context_menu(self, node): """ Returns the context menu for a node. """ sat = Group(id='SystemActionsTop') nsa = Group(id='NodeSpecificActions') sab = Group(id='SystemActionsBottom') # The 'New' menu. new_actions = self.get_new_actions(node) if new_actions is not None and len(new_actions) > 0: sat.append( MenuManager( name = 'New', *new_actions ), ) # Node-specific actions. actions = self.get_actions(node) if actions is not None and len(actions) > 0: for item in actions: nsa.append(item) # System actions (actions available on ALL nodes). system_actions = self.node_manager.system_actions if len(system_actions) > 0: for item in system_actions: sab.append(item) context_menu = MenuManager(sat, nsa, sab) context_menu.dump() return context_menu
def _create_menu_manager(self, menu_definition): """ Create a menu manager implementation from a definition. """ menu_manager = MenuManager(id=menu_definition.id) for group_definition in menu_definition.groups: menu_manager.insert(-1, Group(id=group_definition.id)) return menu_manager
def _selected_menu_default(self): root = MenuManager(name="selected_menu") actions = [ Action(name="Delete point", on_perform=self.do_delete_selected_point), ] for a in actions: root.append(a) return root
def _create_window(self): box = Box(bounds=[100.0, 100.0], position=[50.0, 50.0]) menu=MenuManager() menu.append(Action(name="Hello World", on_perform=self.hello)) context_menu = ContextMenuTool(component=box, menu_manager=menu) box.tools.append(context_menu) container = Container(bounds=[500,500]) container.add(box) return Window(self, -1, component=container)
def get_context_menu(self, pos): """ Returns a context menu containing split/collapse actions pos : position (in global coordinates) where the context menu was requested """ menu = MenuManager() splitter = None splitter = None for tabwidget in self.tabwidgets(): # obtain tabwidget's bounding rectangle in global coordinates global_rect = QtCore.QRect(tabwidget.mapToGlobal(QtCore.QPoint(0, 0)), tabwidget.size()) if global_rect.contains(pos): splitter = tabwidget.parent() # no split/collapse context menu for positions outside any tabwidget # region if not splitter: return # add split actions (only show for non-empty tabwidgets) if not splitter.is_empty(): actions = [Action(id='split_hor', name='Create new pane to the right', on_perform=lambda : splitter.split(orientation= QtCore.Qt.Horizontal)), Action(id='split_ver', name='Create new pane to the bottom', on_perform=lambda : splitter.split(orientation= QtCore.Qt.Vertical))] splitgroup = Group(*actions, id='split') menu.append(splitgroup) # add collapse action (only show for collapsible splitters) if splitter.is_collapsible(): if splitter is splitter.parent().leftchild: if splitter.parent().orientation() is QtCore.Qt.Horizontal: text = 'Merge with right pane' else: text = 'Merge with bottom pane' else: if splitter.parent().orientation() is QtCore.Qt.Horizontal: text = 'Merge with left pane' else: text = 'Merge with top pane' actions = [Action(id='merge', name=text, on_perform=lambda : splitter.collapse())] collapsegroup = Group(*actions, id='collapse') menu.append(collapsegroup) # return QMenu object return menu
def make_menu(self): self.edit_group = Group( AddSuffixAction(), ChangeSuffixAction(), ) self.menu = MenuManager(self.edit_group)
def _menu_bar_manager_default(self): # Create an action that exits the application. exit_action = Action(name='E&xit', on_perform=self.close) self.exit_action = exit_action file_menu = MenuManager(name='&File') file_menu.append(Group(exit_action)) self.undo = UndoAction(undo_manager=self.undo_manager, accelerator='Ctrl+Z') self.redo = RedoAction(undo_manager=self.undo_manager, accelerator='Ctrl+Shift+Z') menu_bar_manager = MenuBarManager( file_menu, MenuManager( self.undo, self.redo, name='&Edit') ) return menu_bar_manager
def test_extra_menu(self): """ Test contributing a whole new menu to the menu bar. """ # Initial menu. schema = MenuBarSchema( MenuSchema(GroupSchema(self.action1, id='FileGroup'), id='FileMenu') ) # Contributed menu. extra_menu = MenuSchema( GroupSchema(self.action2, id='BarGroup'), id= 'DummyActionsMenu', ) extra_actions = [ SchemaAddition(path='MenuBar', factory=lambda : extra_menu, id='DummyActionsSMenu'), ] # Build the final menu. builder = TaskActionManagerBuilder( task=Task(menu_bar=schema, extra_actions=extra_actions) ) actual = builder.create_menu_bar_manager() desired = MenuBarManager( MenuManager(Group(self.action1, id='FileGroup'), id='FileMenu'), MenuManager(Group(self.action2, id='BarGroup'), id='DummyActionsMenu'), id='MenuBar' ) self.assertActionElementsEqual(actual, desired)
def __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super(MainWindow, self).__init__(**traits) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager( Action(name='E&xit', on_perform=self.close), name = '&File', ) ) return
def test_unwanted_merge(self): """ Test that we don't have automatic merges due to forgetting to set a schema ID. """ # Initial menu. schema = MenuBarSchema( MenuSchema(GroupSchema(self.action1, id='FileGroup'), name='File 1')) # Contributed menus. extra_menu = MenuSchema(GroupSchema(self.action2, id='FileGroup'), name='File 2') extra_actions = [ SchemaAddition(path='MenuBar', factory=lambda: extra_menu, id='DummyActionsSMenu'), ] # Build the final menu. builder = TaskActionManagerBuilder( task=Task(menu_bar=schema, extra_actions=extra_actions)) actual = builder.create_menu_bar_manager() # Note that we expect the name of the menu to be inherited from # the menu in the menu bar schema that is defined first. desired = MenuBarManager(MenuManager(Group(self.action1, id='FileGroup'), name='File 1', id='MenuSchema_1'), MenuManager(Group(self.action2, id='FileGroup'), name='File 2', id='MenuSchema_2'), id='MenuBar') self.assertActionElementsEqual(actual, desired)
def __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super().__init__(**traits) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager( Action(name="E&xit", on_perform=self.close), Action(name="DoIt", on_perform=_main), name="&File", )) return
def __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super(MainWindow, self).__init__(**traits) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager( Action(name="Start Timer", on_perform=self._start_timer), Action(name="Stop Timer", on_perform=self._stop_timer), Action(name="E&xit", on_perform=self.close), name="&File", )) return
def __label_menu_default(self): """ Trait initialiser. """ size_group = Group(LabelIncrementSizeAction(window=self), LabelDecrementSizeAction(window=self)) normal = LabelNormalFontAction(window=self, id='normal', style='radio', checked=True) bold = LabelBoldFontAction(window=self, id='bold', style='radio') italic = LabelItalicFontAction(window=self, id='italic', style='radio') style_group = Group(normal, bold, italic, id='style') return MenuManager(size_group, style_group, name="&Label")
def __label_menu_default(self): """ Trait initialiser. """ size_group = Group(CommandAction(command=LabelIncrementSizeCommand), CommandAction(command=LabelDecrementSizeCommand)) normal = CommandAction(id='normal', command=LabelNormalFontCommand, style='radio', checked=True) bold = CommandAction(id='bold', command=LabelBoldFontCommand, style='radio') italic = CommandAction(id='italic', command=LabelItalicFontCommand, style='radio') style_group = Group(normal, bold, italic, id='style') return MenuManager(size_group, style_group, name="&Label")
def test_widget_context_menu_cleanup(self): widget = self._create_widget() with patch.object(widget, '_context_menu_updated', return_value=None) as updated: widget._create() try: widget.show(True) self.gui.process_events() finally: widget.destroy() self.gui.process_events() widget.context_menu = MenuManager(Action(name="Test"), name="Test") updated.assert_not_called() widget = None
def __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super(MainWindow, self).__init__(**traits) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager(Action(name="E&xit", on_perform=self.close), name="&File"), MDIWindowMenu(self), ) # Set the size of the window self.size = (640, 480) return
def test_absolute_ordering(self): """ Does specifying absolute_position work? """ schema = MenuBarSchema( MenuSchema( GroupSchema(self.action1, self.action2, id="FileGroup"), id="File", )) extras = [ SchemaAddition( factory=lambda: self.action3, absolute_position="last", path="MenuBar/File/FileGroup", ), SchemaAddition( factory=lambda: self.action4, absolute_position="first", path="MenuBar/File/FileGroup", ), SchemaAddition( factory=lambda: self.action5, absolute_position="first", path="MenuBar/File/FileGroup", ), ] builder = TaskActionManagerBuilder( task=Task(menu_bar=schema, extra_actions=extras)) actual = builder.create_menu_bar_manager() desired = MenuBarManager( MenuManager( Group( self.action4, self.action5, self.action1, self.action2, self.action3, id="FileGroup", ), id="File", ), id="MenuBar", ) self.assertActionElementsEqual(actual, desired)
def _create_action_bars(self): """ Creates the window's menu, tool and status bars. """ # Common actions. highest = Action(name="Highest", style="radio") higher = Action(name="Higher", style="radio", checked=True) lower = Action(name="Lower", style="radio") lowest = Action(name="Lowest", style="radio") self._actions = [highest, higher, lower, lowest] # Menu bar. self.menu_bar_manager = MenuBarManager( MenuManager( ExampleAction(name="Foogle"), Separator(), highest, higher, lower, lowest, Separator(), Action(name="E&xit", on_perform=self.close), name="&File", )) # Tool bar. self.tool_bar_manager = ToolBarManager( ExampleAction(name="Foo"), Separator(), ExampleAction(name="Bar"), Separator(), ExampleAction(name="Baz"), Separator(), highest, higher, lower, lowest, ) # Status bar. self.status_bar_manager = StatusBarManager() return
def test_merging_redundant_items(self): """ Menus and groups with matching path are merged together. """ # Initial menu. schema = MenuBarSchema( MenuSchema( GroupSchema(self.action1, id="FileGroup"), name="File menu number one", id="FileMenu", )) # Contributed menus. extra_menu = MenuSchema( GroupSchema(self.action2, id="FileGroup"), name="File menu number two", id="FileMenu", ) extra_actions = [ SchemaAddition( path="MenuBar", factory=lambda: extra_menu, id="DummyActionsSMenu", ) ] # Build the final menu. builder = TaskActionManagerBuilder( task=Task(menu_bar=schema, extra_actions=extra_actions)) actual = builder.create_menu_bar_manager() # Note that we expect the name of the menu to be inherited from # the menu in the menu bar schema that is defined first. desired = MenuBarManager( MenuManager( Group(self.action1, self.action2, id="FileGroup"), name="File menu number one", id="FileMenu", ), id="MenuBar", ) self.assertActionElementsEqual(actual, desired)
def test_absolute_and_before_after(self): """ Does specifying absolute_position along with before, after work? """ schema = MenuBarSchema( MenuSchema( GroupSchema( self.action1, self.action2, id='FileGroup'), id='File')) extras = [ SchemaAddition( factory=lambda: self.action3, id='action3', after='action2', path='MenuBar/File/FileGroup'), SchemaAddition( factory=lambda: self.action4, after='action3', path='MenuBar/File/FileGroup'), SchemaAddition( factory=lambda: self.action5, id='action5', absolute_position='last', path='MenuBar/File/FileGroup'), SchemaAddition( factory=lambda: self.action6, absolute_position='last', before='action5', path='MenuBar/File/FileGroup') ] builder = TaskActionManagerBuilder(task=Task( menu_bar=schema, extra_actions=extras)) actual = builder.create_menu_bar_manager() desired = MenuBarManager( MenuManager( Group( self.action1, self.action2, self.action3, self.action4, self.action6, self.action5, id='FileGroup'), id='File'), id='MenuBar') self.assertActionElementsEqual(actual, desired)
def __file_menu_default(self): """ Initialize the File Menus. """ new_group = Group( # Create a new python script. #NewScriptAction(), # New Experiement. Ctrl-N should map here. #NewExperimentAction(), # Open an entirely new Project, closing the current one # if necessary. self._new_project_action) file_group = Group( new_group, # OpenAction() # CloseAction() ) exit_group = Group(self._exit_action) return MenuManager(new_group, exit_group, name="&File", id='FileMenu')
def __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super(MainWindow, self).__init__(**traits) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager(Group( Action(name='&Open...', accelerator='Ctrl+O', on_perform=self.on_open_file), Action(name='&Save', accelerator='Ctrl+S', on_perform=self.on_save_file), id='document_group', ), Action(name='&Close', accelerator='Ctrl+W', on_perform=self.close), name='&File'))
def _get_no_selection_context_menu_manager(self): """ Generates a menu manager representing the context menu shown when nothing is selected within the project view. That is, when the user right clicks on any empty space within our associated UI. """ # Retrieve all contributions for the no-selection context menu. extensions = self.get_extensions(ProjectActionSet) # Populate a menu manager from the extensions. menu_manager = MenuManager() if len(extensions) > 0: action_set_manager = ActionSetManager(action_sets=extensions) menu_builder = DefaultMenuBuilder(application=self.application) menu_builder.initialize_menu_manager(menu_manager, action_set_manager, NO_SELECTION_MENU_ID) return menu_manager
def test_additions_menu_bar(self): """ Does constructing a menu with a few additions work? """ schema = MenuBarSchema( MenuSchema( GroupSchema(self.action1, self.action2, id="FileGroup"), id="File", )) extras = [ SchemaAddition( factory=lambda: self.action3, before="action1", path="MenuBar/File/FileGroup", ), SchemaAddition( factory=lambda: self.action4, before="action1", path="MenuBar/File/FileGroup", ), SchemaAddition(factory=lambda: self.action5, path="MenuBar/File/FileGroup"), ] builder = TaskActionManagerBuilder( task=Task(menu_bar=schema, extra_actions=extras)) actual = builder.create_menu_bar_manager() desired = MenuBarManager( MenuManager( Group( self.action3, self.action4, self.action1, self.action2, self.action5, id="FileGroup", ), id="File", ), id="MenuBar", ) self.assertActionElementsEqual(actual, desired)
def __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super().__init__(**traits) # Create an action that exits the application. exit_action = Action(name="E&xit", on_perform=self.close) self.exit_action = exit_action # Test action to toggle visibility of exit action and some action groups test_action = Action(name="&Toggle", on_perform=self.toggle) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager(exit_action, name="&File") ) # Add some tool bars, with the first one subdivided into action groups self.tool_bar_managers = [ ToolBarManager( Group(exit_action, exit_action, id="a"), Group(id="b"), # empty, so will remain hidden Group(exit_action, exit_action, id="c"), Group(exit_action, test_action, exit_action, id="d"), name="Tool Bar 1", show_tool_names=True, ), ToolBarManager( exit_action, name="Tool Bar 2", show_tool_names=True ), ToolBarManager( test_action, name="Tool Bar 3", show_tool_names=True ), ] # Add a status bar. self.status_bar_manager = StatusBarManager() self.status_bar_manager.message = "Example application window"
def __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super(MainWindow, self).__init__(**traits) # Create an action that exits the application. exit_action = Action(name='E&xit', on_perform=self.close) self.exit_action = exit_action # Test action to toggle visibility of exit action and some action groups test_action = Action(name='&Toggle', on_perform=self.toggle) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager(exit_action, name='&File')) # Add some tool bars, with the first one subdivided into action groups self.tool_bar_managers = [ ToolBarManager( Group(exit_action, exit_action, id='a'), Group(id='b'), # empty, so will remain hidden Group(exit_action, exit_action, id='c'), Group(exit_action, test_action, exit_action, id='d'), name='Tool Bar 1', show_tool_names=False), ToolBarManager(exit_action, name='Tool Bar 2', show_tool_names=False), ToolBarManager(test_action, name='Tool Bar 3', show_tool_names=False), ] # Add a status bar. self.status_bar_manager = StatusBarManager() self.status_bar_manager.message = 'Example application window' return
def _create_action_bars(self): """ Creates the window's menu, tool and status bars. """ # Common actions. highest = Action(name='Highest', style='radio') higher = Action(name='Higher', style='radio', checked=True) lower = Action(name='Lower', style='radio') lowest = Action(name='Lowest', style='radio') self._actions = [highest, higher, lower, lowest] # Menu bar. self.menu_bar_manager = MenuBarManager( MenuManager( ExampleAction(name='Foogle'), Separator(), highest, higher, lower, lowest, Separator(), Action(name='E&xit', on_perform=self.close), name='&File', )) # Tool bar. self.tool_bar_manager = ToolBarManager(ExampleAction(name='Foo'), Separator(), ExampleAction(name='Bar'), Separator(), ExampleAction(name='Baz'), Separator(), highest, higher, lower, lowest) # Status bar. self.status_bar_manager = StatusBarManager() return
def test_merging_items_with_same_id_but_different_class(self): """ Schemas with the same path but different types (menus, groups) are not merged together. Having a group and a menu with the same path is of course bad practice, but we need a predictable outcome. """ # Initial menu. schema = MenuBarSchema( MenuSchema( GroupSchema( self.action1, id='FileGroup'), id='FileSchema')) # Contributed menus. extra_group = GroupSchema(self.action2, id='FileSchema') extra_actions = [ SchemaAddition( path='MenuBar', factory=(lambda: extra_group), id='DummyActionsSMenu'), ] # Build the final menu. builder = TaskActionManagerBuilder(task=Task( menu_bar=schema, extra_actions=extra_actions)) actual = builder.create_menu_bar_manager() desired = MenuBarManager( MenuManager( Group( self.action1, id='FileGroup'), id='FileSchema'), Group( self.action2, id='FileSchema'), id='MenuBar') self.assertActionElementsEqual(actual, desired)
def get_context_menu(self, pos): """ Return a context menu containing split/collapse actions. Parameters ---------- pos : QtCore.QPoint Mouse position in global coordinates for which the context menu was requested. Returns ------- menu : pyface.action.menu_manager.MenuManager or None Context menu, or None if the given position doesn't correspond to any of the tab widgets. """ menu = MenuManager() for tabwidget in self.tabwidgets(): widget_pos = tabwidget.mapFromGlobal(pos) if tabwidget.rect().contains(widget_pos): splitter = tabwidget.parent() break else: # no split/collapse context menu for positions outside any # tabwidget region return None # add split actions (only show for non-empty tabwidgets) if not splitter.is_empty(): split_group = Group( Action( id="split_hor", name="Create new pane to the right", on_perform=lambda: splitter.split(orientation=QtCore.Qt. Horizontal), ), Action( id="split_ver", name="Create new pane below", on_perform=lambda: splitter.split(orientation=QtCore.Qt. Vertical), ), id="split", ) menu.append(split_group) # add collapse action (only show for collapsible splitters) if splitter.is_collapsible(): if splitter is splitter.parent().leftchild: if splitter.parent().orientation() == QtCore.Qt.Horizontal: text = "Merge with right pane" else: text = "Merge with bottom pane" else: if splitter.parent().orientation() == QtCore.Qt.Horizontal: text = "Merge with left pane" else: text = "Merge with top pane" collapse_group = Group( Action( id="merge", name=text, on_perform=lambda: splitter.collapse(), ), id="collapse", ) menu.append(collapse_group) return menu
def _menu_manager_default(self): return MenuManager(Group(*self.actions))
def test_field_menu(self): self._create_widget_control() self.widget.menu = MenuManager(Action(name="Test"), name="Test") self.gui.process_events()
class WiringTool(AbstractOverlay, DragTool): """ A tool that enables the user to wire inputs and outputs on the canvas. """ #--------------------------------------------------------------------- # WiringTool traits #--------------------------------------------------------------------- # The width of the line being drawn line_width = Int(2) # The color of the line line_color = RGBAColor((0.5, 0.5, 0.5, 0.8)) # Should we draw the line and icon? draw_line = Bool(False) # (x,y) coordinates for the start of line. _start_pos = Tuple # (x,y) coordinates for the end of line. _end_pos = Tuple # References to the beginning and ending of the Input/Output Fields # that are being hooked up. _start_field = Instance(IOField) _end_field = Instance(IOField) # The selected fields input_selected_fields = List(IOField) output_selected_fields = List(IOField) # The Context Menu - brought up by right clicking on selected fields menu = Instance(MenuManager) edit_group = Any def __init__(self, *args, **kwargs): self.make_menu() super(WiringTool, self).__init__(*args, **kwargs) self.input_selected_fields = [] self.output_selected_fields = [] return def make_menu(self): self.edit_group = Group( AddSuffixAction(), ChangeSuffixAction(), ) self.menu = MenuManager(self.edit_group) #--------------------------------------------------------------------- # Interactor traits #--------------------------------------------------------------------- def normal_left_down(self, event): """ Add this box_field to the selection. """ field = self._get_underlying_box_field(event.x, event.y) if field: # Toggle selection - if already selected, then un-select if field.selected: self.remove_from_selection(field) else: self.add_to_selection(field) else: self.clear_selection() event.window.focus_owner = self.component event.handled = True self.request_redraw() def normal_left_dclick(self, event): """ Edit the name of this input/output. """ field = self._get_underlying_box_field(event.x, event.y) if not field: return text_field = field.value self.event_state = "edit" text_field.normal_left_dclick(event) try: self.remove_from_selection(field) except: pass event.handled = True def edit_left_up(self, event): """ FIXME? This is just to capture the event and pass it down into the EditField. """ field = self._get_underlying_box_field(event.x, event.y) if not field or field is None: event.window.focus_owner = self.component field.value.edit_left_up(event) self.event_state = "normal" event.handled = True def normal_right_down(self, event): """ Right click will bring up a dialog to edit the prefix/suffix of the selected variables. """ field = self._get_underlying_box_field(event.x, event.y) if field: selected_fields = self.input_selected_fields + self.output_selected_fields if field in selected_fields: for group in self.menu.groups: for action_item in group.items: action = action_item.action action.container = self.component action.selected_fields = selected_fields menu = self.menu.create_menu(event.window.control) if len(event._pos_stack) > 0: real_x, real_y = event._pos_stack[0] else: real_x, real_y = event.x, event.y from pyface.api import GUI GUI.invoke_later(menu.show, real_x - 10, event.window._flip_y(real_y)) self.component.request_redraw() event.handled = True def add_to_selection(self, field): if not field.selected: field.set_selected() if field.type == 'input': self.input_selected_fields.append(field) else: self.output_selected_fields.append(field) def remove_from_selection(self, field): if field.selected: field.clear_selected() if field.type == 'input': self.input_selected_fields.remove(field) else: self.output_selected_fields.remove(field) #--------------------------------------------------------------------- # DragTool interface #--------------------------------------------------------------------- def drag_start(self, event): field = self._get_underlying_box_field(event.x, event.y) if not field: return self.add_to_selection(field) self._start_field = field event.window.set_mouse_owner(self, event.net_transform(), history=event.dispatch_history) self._start_pos = self._get_anchor_point(field) event.handled = True def drag_cancel(self, event): event.window.set_mouse_owner(None) self.clear_selection() self.draw_line = False event.handled = True self.component.request_redraw() def drag_end(self, event): import pprint field = self._get_underlying_box_field(event.x, event.y) if field is self._start_field: return if field and self._start_field: self._end_field = field start_type = self._start_field.type end_type = self._end_field.type field.icon.bullet_state = 'up' if ((start_type == 'output' and end_type == 'input') or (start_type == 'input' and end_type == 'output')): self.add_to_selection(self._end_field) if len(self.input_selected_fields) == len(self.output_selected_fields): matches = self.match_inputs2outputs() for input, pairs in matches.items(): for pair in pairs: from blockcanvas.app.scripting import app # Set the input (pair[0]) binding to output(pair[1]) app.update_function_variable_binding(field.box.graph_node, pair[0], pair[1].binding) #***************************************************************************************************# # This code that update a connection dict in the canvas_box is no more necessary # #***************************************************************************************************# # # If the updated of the binding were successful, add this connection # # to the canvas_box that holds the input field (an input can receive # # just one connection rather than an output that could be connected # # with different blocks) # if self._start_field.type == 'input': # update_conn_field = self._start_field # ref_field = self._end_field # else: # update_conn_field = self._end_field # ref_field = self._start_field # # # UUID of the referenced graph_node # ref_uuid = ref_field.box.graph_node.uuid # # # Check if there exist an entry for this referenced graph_node in the # # current "source" graph_node # if ref_uuid in update_conn_field.box.connections: # # Check if there is a tuple for the current variables that are to # # be connected. # conn_list = update_conn_field.box.connections[ref_uuid] # is_in = False # for connection in conn_list: # if connection == (update_conn_field.variable,ref_field.variable): # is_in = True # if not is_in: # conn_list.append((update_conn_field.variable,ref_field.variable)) # else: # update_conn_field.box.connections[ref_uuid] = [(update_conn_field.variable,ref_field.variable)] #***************************************************************************************************# self.drag_cancel(event) def dragging(self, event): field = self._get_underlying_box_field(event.x, event.y) if field is self._start_field: if self.draw_line: self.draw_line = False self.request_redraw() return self.draw_line = True pos = (event.x, event.y) self.clear_end_field() if field and self._start_field: start_type = self._start_field.type if ((start_type == 'input' and field.type == 'output') or (start_type == 'output' and field.type == 'input')): pos = self._get_anchor_point(field) field.icon.bullet_state = "dropping" self._end_field = field self._end_pos = pos event.handled = True self.component.request_redraw() def match_inputs2outputs(self): if len(self.input_selected_fields) == 1: input = self.input_selected_fields[0].variable output = self.output_selected_fields[0].variable return {self.input_selected_fields[0]: [(input, output)]} # FIXME: Need better way to match inputs and outputs. matches = {} for infield in self.input_selected_fields: for outfield in self.output_selected_fields: input = infield.variable.binding output = outfield.variable.binding if input.find(output) >= 0 or output.find(input) >= 0: if matches.has_key(infield): matches[infield].append((input, output)) else: matches[infield] = [(input, output)] return matches def clear_end_field(self): if self._end_field: self._end_field.clear_selected() self._end_field = None def clear_selection(self): selected = self.input_selected_fields + self.output_selected_fields for field in selected: field.clear_selected() self.input_selected_fields = [] self.output_selected_fields = [] self._start_field = None self._end_field = None self.request_redraw() #--------------------------------------------------------------------- # private interface #--------------------------------------------------------------------- def _get_anchor_point(self, field): x_pos = field.box.x + field.x + field.icon.x + field.icon.width/2 y_pos = field.box.y + field.y + field.icon.y + field.icon.height/2 return (x_pos, y_pos) def _get_underlying_box_field(self, x, y): """ Returns either the underlying input or output field under the mouse or None. BlockCanvas -> CanvasBox -> IOField -> EnableBoxField """ canvas_components = self.component.components_at( x, y ) for c in canvas_components: if isinstance(c, CanvasBox): box_components = c.components_at( x, y ) for b in box_components: if isinstance(b, IOField): return b break return None #--------------------------------------------------------------------- # AbstractOverlay interface #--------------------------------------------------------------------- def overlay(self, component, gc, view_bounds=None, mode="normal"): if not self.draw_line: return gc.save_state() # Set up the styles gc.set_stroke_color(self.line_color_) gc.set_line_width(self.line_width) gc.begin_path() gc.move_to(self._start_pos[0], self._start_pos[1]) gc.line_to(self._end_pos[0], self._end_pos[1]) gc.draw_path() # FIXME: not sure whether this is the way to copy this. # Suggestions welcome. if self._start_field is not None: icon = copy.deepcopy(self._start_field.icon) icon.event_state = 'normal' icon.position = [self._end_pos[0] - icon.width*0.5, self._end_pos[1] - icon.height*0.5] icon.bullet_state = "dragging" icon._draw_mainlayer(gc, view_bounds=view_bounds) gc.restore_state() return
def __file_menu_default(self): """ Trait initialiser. """ return MenuManager(self._exit_action, name="&File")
# # Thanks for using Enthought open source! """ Menu Manager example. """ from pyface.action.api import Action from pyface.action.api import Group, MenuManager, Separator file_menu = MenuManager( Group( Action(name="New Project..."), Action(name="Open Project..."), id="OpenGroup", ), Group( Action(name="Close Project"), Action(name="Close Active Editor"), id="CloseGroup", ), Group( Action(name="Export to HTML..."), Action(name="Print..."), id="ExportGroup", ), Group(Action(name="Exit"), id="ExitGroup"), ) file_menu.dump() # ---------------------------------------------------------------------------- file_menu = MenuManager( Action(name="New Project..."), Action(name="Open Project..."),
def __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super(MainWindow, self).__init__(**traits) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager( Group( Action( name="&Open...", accelerator="Ctrl+O", on_perform=self.on_open_file, ), Action( name="&Save", accelerator="Ctrl+S", on_perform=self.on_save_file, ), id="document_group", ), Action( name="&Close", accelerator="Ctrl+W", on_perform=self.close ), name="&File", ) ) # Add a tool bar if we are using qt4 - wx has layout issues if toolkit_object.toolkit == "qt4": from pygments.styles import STYLE_MAP styles = list(STYLE_MAP) self.tool_bar_manager = ToolBarManager( Group( Action(name="Open...", on_perform=self.on_open_file), Action(name="Save", on_perform=self.on_save_file), Action(name="Close", on_perform=self.close), id="document_group", ), Group( Action( name="Lines", style="toggle", on_perform=self.on_show_line_numbers, checked=True, ), FieldAction( name="Style", field_type=ComboField, field_defaults={ "values": styles, "value": "default", "tooltip": "Style", }, on_perform=self.on_style_changed, ), ), )
file_menu = MenuManager( Group( Action(name='New Project...'), Action(name='Open Project...'), id = 'OpenGroup', ), Group( Action(name='Close Project'), Action(name='Close Active Editor'), id = 'CloseGroup' ), Group( Action(name='Export to HTML...'), Action(name='Print...'), id = 'ExportGroup' ), Group( Action(name='Exit'), id = 'ExitGroup' ), ) file_menu.dump()
import os, sys # Put the Enthought library on the Python path. sys.path.append(os.path.abspath(r'..\..\..')) # Local imports. from pyface.action.api import Action from pyface.action.api import Group, MenuManager, Separator file_menu = MenuManager( Group( Action(name='New Project...'), Action(name='Open Project...'), id='OpenGroup', ), Group(Action(name='Close Project'), Action(name='Close Active Editor'), id='CloseGroup'), Group(Action(name='Export to HTML...'), Action(name='Print...'), id='ExportGroup'), Group(Action(name='Exit'), id='ExitGroup'), ) file_menu.dump() ############################################################################### file_menu = MenuManager( Action(name='New Project...'), Action(name='Open Project...'), Separator(), Action(name='Close Project'),
def get_context_menu(self, pos): """ Returns a context menu containing split/collapse actions pos : position (in global coordinates) where the context menu was requested """ menu = MenuManager() splitter = None splitter = None for tabwidget in self.tabwidgets(): # obtain tabwidget's bounding rectangle in global coordinates global_rect = QtCore.QRect( tabwidget.mapToGlobal(QtCore.QPoint(0, 0)), tabwidget.size()) if global_rect.contains(pos): splitter = tabwidget.parent() # no split/collapse context menu for positions outside any tabwidget # region if not splitter: return # add split actions (only show for non-empty tabwidgets) if not splitter.is_empty(): actions = [ Action(id='split_hor', name='Create new pane to the right', on_perform=lambda: splitter.split(orientation=QtCore.Qt. Horizontal)), Action(id='split_ver', name='Create new pane to the bottom', on_perform=lambda: splitter.split(orientation=QtCore.Qt. Vertical)) ] splitgroup = Group(*actions, id='split') menu.append(splitgroup) # add collapse action (only show for collapsible splitters) if splitter.is_collapsible(): if splitter is splitter.parent().leftchild: if splitter.parent().orientation() is QtCore.Qt.Horizontal: text = 'Merge with right pane' else: text = 'Merge with bottom pane' else: if splitter.parent().orientation() is QtCore.Qt.Horizontal: text = 'Merge with left pane' else: text = 'Merge with top pane' actions = [ Action(id='merge', name=text, on_perform=lambda: splitter.collapse()) ] collapsegroup = Group(*actions, id='collapse') menu.append(collapsegroup) # return QMenu object return menu