Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print 'ref:', item
menu_item_refs.append(weakref.ref(item))
if item.get_submenu():
connect_weakref(item.get_submenu())
class FileNewAction(Action):
id = 'FileNew'
stock_id = 'gtk-new'
def execute(self):
print 'New'
register_action(FileNewAction)
class FileQuitAction(Action):
id = 'FileQuit'
stock_id = 'gtk-quit'
tooltip = 'Quit the application'
def execute(self):
window.destroy()
#gtk.main_quit()
register_action(FileQuitAction)
class FileCheckAction(CheckAction):
id = 'FileCheck'
label = '_Check'
#stock_id = 'gtk-save'
tooltip = 'Check the checkbox'
accel = 'C-a'
def init(self, window):
self._window = window
def update(self):
diagram_tab = self._window.get_current_diagram_tab()
self.sensitive = bool(diagram_tab)
def execute(self):
self._window.get_current_diagram_view().select_all()
register_action(SelectAllAction)
class DeselectAllAction(Action):
id = 'EditDeselectAll'
label = 'Des_elect All'
accel = 'C-S-a'
def init(self, window):
self._window = window
def update(self):
diagram_tab = self._window.get_current_diagram_tab()
self.sensitive = diagram_tab and len(diagram_tab.get_view().selected_items) > 0
def execute(self):
self._window.get_current_diagram_view().unselect_all()
register_action(DeselectAllAction, 'ItemSelect', 'EditDelete')
for item in self._new_items.values():
item.move(10, 10)
for item in self._new_items.values():
item.postload()
view.unselect_all()
for item in self._new_items.values():
view.select(view.find_view_item(item))
register_action(PasteAction, 'EditCopy')
class ZoomInAction(Action):
id = 'ViewZoomIn'
label = 'Zoom _In'
accel = 'C-+'
stock_id = 'gtk-zoom-in'
tooltip = 'Zoom in'
def init(self, window):
self._window = window
def update(self):
diagram_tab = self._window.get_current_diagram_tab()
self.sensitive = bool(diagram_tab)
def execute(self):
view = self._window.get_current_diagram_view()
view.zoom(1.2)
class CloseAction(Action):
id = 'FileClose'
stock_id = 'gtk-close'
tooltip='Close the diagram window'
def init(self, window):
self._window = window
def execute(self):
self._window.close()
register_action(CloseAction)
class QuitAction(Action):
id = 'FileQuit'
stock_id = 'gtk-quit'
tooltip='Quit Gaphor'
def init(self, window):
self._window = window
def execute(self):
if self._window.ask_to_close():
log.debug('Quiting gaphor...')
self._window.close()
del self._window
gc.collect()
register_action(QuitAction)
def execute(self):
element = self._window.get_tree_view().get_selected_element()
diagram = self.element_factory.create(UML.Diagram)
diagram.package = element
diagram.name = '%s diagram' % element.name
self._window.select_element(diagram)
self.action_manager.execute('OpenModelElement')
self.action_manager.execute('RenameModelElement')
register_action(CreateDiagramAction, 'SelectRow')
class DeleteDiagramAction(Action):
id = 'DeleteDiagram'
label = _('_Delete diagram')
stock_id = 'gtk-delete'
def init(self, window):
self._window = window
def update(self):
element = self._window.get_tree_view().get_selected_element()
self.sensitive = isinstance(element, UML.Diagram)
def execute(self):
diagram = self._window.get_tree_view().get_selected_element()
assert isinstance(diagram, UML.Diagram)
m = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION,
gtk.BUTTONS_YES_NO,
tooltip='Quit Gaphor'
def init(self, window):
self._window = window
def execute(self):
if self._window.ask_to_close():
log.debug('Quiting gaphor...')
self._window.close()
del self._window
gc.collect()
register_action(QuitAction)
class OpenEditorWindowAction(Action):
id = 'OpenEditorWindow'
label = _('_Editor')
tooltip = 'Open the Gaphor Editor'
def init(self, window):
self._window = window
def execute(self):
from gaphor.ui.editorwindow import EditorWindow
ew = EditorWindow()
ew.construct()
self._window.add_transient_window(ew)
#self._window.set_message('Editor launched')
register_action(OpenEditorWindowAction)
register_action(SelectAction)
class FocusAction(Action):
"""Dummy action that is "called" when the selected items on the canvas
change.
"""
id = 'ItemFocus'
def init(self, window):
pass
register_action(FocusAction)
class DiagramDropAction(Action):
"""Dummy action that is "called" when a new item is placed on the canvas
by means of Drag-and-drop.
"""
id = 'ItemDiagramDrop'
action_manager = inject('action_manager')
def init(self, window):
self._window = window
def execute(self):
self.action_manager.execute('CreateLinks')
register_action(DiagramDropAction)
register_action(TabChangeAction)
class UndoStackAction(Action):
"""
Dummy action that triggers the undo and redo actions to update
themselves.
"""
id = 'UndoStack'
def init(self, window):
pass
register_action(UndoStackAction)
class UndoAction(Action):
id = 'Undo'
stock_id = 'gtk-undo'
label = _('_Undo')
tooltip = 'Undo the most recent changes'
accel = 'C-z'
# TODO: check if the diagram can undo.
action_manager = inject('action_manager')
def init(self, window):
self._window = window
def update(self):
self.sensitive = get_undo_manager().can_undo()
def execute(self):
def update(self):
diagram_tab = self._window.get_current_diagram_tab()
self.sensitive = bool(diagram_tab)
self.active = diagram_tab and diagram_tab.get_canvas().get_property('grid_color') != diagram_tab.get_canvas().get_property('grid_bg')
def execute(self):
tab = self._window.get_current_diagram_tab()
if tab:
canvas = tab.get_canvas()
#canvas.set_property('grid_color', self.active and 255 or canvas.get_property('grid_bg'))
#register_action(ShowGridAction)
class ShowElementInTreeViewAction(Action):
id = 'ShowElementInTreeView'
label = 'S_how Element in Tree View'
def init(self, window):
self._window = window
def update(self):
diagram_tab = self._window.get_current_diagram_tab()
self.sensitive = diagram_tab and diagram_tab.get_view().focused_item and \
diagram_tab.get_view().focused_item.subject
def execute(self):
tab = self._window.get_current_diagram_tab()
if tab:
view = tab.get_view()
fi = view.focused_item
elif pspec.name == 'sensitive':
return self._sensitive
else:
raise AttributeError, 'Unknown property %s' % pspec.name
def update(self):
"""update() is called by the ActionBroker after an other action
has been changed.
"""
pass
def execute(self):
pass
class CheckAction(Action):
"""CheckActions can be turned on and off.
"""
__gproperties__ = {
'active': (gobject.TYPE_BOOLEAN, 'active',
'', True,
gobject.PARAM_READWRITE)
}
def __init__(self):
Action.__init__(self)
self._active = False
active = property(lambda self: self._active,
lambda self, v: self.set_property('active', v))