How to use the gaphor.core.inject function in gaphor

To help you get started, we’ve selected a few gaphor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gaphor / gaphor / gaphor / actions / placementactions.py View on Github external
action.sensitive = True
    tool = None #view.tool
    if tool:
        id = tool.action_id
    else:
        id = 'Pointer'
    if id == action.id:
        action.active = True


class ResetToolAfterCreateAction(CheckAction):
    id = 'ResetToolAfterCreate'
    label = 'Reset _Tool'
    tooltip = 'Reset the tool to the pointer tool after creation of an item'

    properties = inject('properties')
    def init(self, window):
        self._window = window
        self.active = self.properties('reset-tool-after-create', True)

    def execute(self):
        self.properties.set('reset-tool-after-create', self.active)

register_action(ResetToolAfterCreateAction)


class PointerAction(RadioAction):
    id = 'Pointer'
    label = '_Pointer'
    stock_id = 'gaphor-pointer'
    group = 'placementtools'
    accel = 'C-p'
github gaphor / gaphor / gaphor / actions / diagramactions.py View on Github external
'copy-buffer'.

      - in order to make copy/paste work, the load/save functions should be
        generatlised to allow a subset to be saved/loaded (which is needed
        anyway for exporting/importing stereotype Profiles).
      - How many data should be saved? (e.g. we copy a diagram item, remove it
        (the underlaying UML element is removed) and the paste the copied item.
        The diagram should act as if we have placed a copy of the removed item
        on the canvas and make the uml element visible again.
    """
    id = 'EditPaste'
    label = '_Paste'
    accel = 'C-v'
    stock_id = 'gtk-paste'

    element_factory = inject('element_factory')

    def init(self, window):
        self._window = window

    def update(self):
        global copy_buffer
        diagram_tab = self._window.get_current_diagram_tab()
        self.sensitive = diagram_tab and copy_buffer

    def _load_element(self, name, value):
        """Copy an element, preferbly from the list of new items,
        otherwise from the element factory.
        If it does not exist there, do not copy it!
        """
        item = self._new_items.get(value.id)
        if item:
github gaphor / gaphor / gaphor / plugins / xmiexport / __init__.py View on Github external
from __future__ import absolute_import
import gtk
from zope import interface, component
from gaphor.core import _, inject, action, build_action_group
from gaphor.interfaces import IService, IActionProvider
from gaphor.ui.filedialog import FileDialog

from . import exportmodel

class XMIExport(object):

    interface.implements(IService, IActionProvider)

    element_factory = inject('element_factory')
    main_window = inject('main_window')

    menu_xml = """
      
        
          <menu action="file">
            <menu action="file-export">
              <menuitem action="file-export-xmi">
            </menuitem></menu>
          </menu>
        
      """
    
    def __init__(self):
        self.action_group = build_action_group(self)

    def init(self, app):
github gaphor / gaphor / gaphor / plugins / liveobjectbrowser / __init__.py View on Github external
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/300304).
It shows the state of the data model at the time the browser is activated.
"""

from __future__ import absolute_import
from zope import interface
from gaphor.core import _, inject, action, build_action_group
from gaphor.interfaces import IService, IActionProvider
from .browser import Browser


class LiveObjectBrowser(object):

    interface.implements(IService, IActionProvider)

    element_factory = inject('element_factory')

    menu_xml = """
      
        
          <menu action="tools">
            <menuitem action="tools-life-object-browser">
          </menuitem></menu>
        
      """

    def __init__(self):
        self.action_group = build_action_group(self)

    def init(self, app):
        pass
github gaphor / gaphor / gaphor / plugins / diagramlayout / __init__.py View on Github external
from __future__ import absolute_import

import random
from zope import interface

from gaphor.core import inject, action, build_action_group, transactional
from gaphor.diagram import items
from gaphor.interfaces import IService, IActionProvider
from . import toposort


class DiagramLayout(object):
    interface.implements(IService, IActionProvider)

    main_window = inject('main_window')

    menu_xml = """
      
        
          <menu action="diagram">
            <menuitem action="diagram-layout">
          </menuitem></menu>
        
      """

    def __init__(self):
        self.action_group = build_action_group(self)

    def init(self, app):
        pass
github gaphor / gaphor / gaphor / services / backupservice.py View on Github external
"""
    Customize the pickler to only delay instantiations of Element objects.
    """

    def delay(self, obj):
        return isinstance(obj, Element)


class BackupService(object):
    """
    This service makes backups every *x* minutes.
    """

    interface.implements(IService)

    element_factory = inject('element_factory')

    def __init__(self):
        self.tempname = '.backup.gaphor.tmp'


    def init(self, app):
        pass


    def shutdown(self):
        pass


    def backup(self):
        f = open(self.tempname, 'w')
        try:
github gaphor / gaphor / gaphor / ui / elementeditor.py View on Github external
from __future__ import absolute_import
from zope import interface
from gaphor.interfaces import IService, IActionProvider
from gaphor.core import _, inject, open_action, build_action_group
from gaphor.ui.propertyeditor import PropertyEditor
from gaphor.ui.interfaces import IUIComponent

class ElementEditor(object):
    """The ElementEditor class is a utility window used to edit UML elements.
    It will display the properties of the currently selected element in the
    diagram."""

    interface.implements(IUIComponent, IActionProvider)

    element_factory = inject('element_factory')
    properties = inject('properties')

    title = _("Element Editor")
    size = (275, -1)
    resizable = True
    placement = 'floating'
    menu_xml = """
      
        
          <menu action="edit">
            
            <menuitem>
          </menuitem></menu>
        
      
    """
github gaphor / gaphor / gaphor / plugins / xmiexport / __init__.py View on Github external
"""

from __future__ import absolute_import
import gtk
from zope import interface, component
from gaphor.core import _, inject, action, build_action_group
from gaphor.interfaces import IService, IActionProvider
from gaphor.ui.filedialog import FileDialog

from . import exportmodel

class XMIExport(object):

    interface.implements(IService, IActionProvider)

    element_factory = inject('element_factory')
    main_window = inject('main_window')

    menu_xml = """
      
        
          <menu action="file">
            <menu action="file-export">
              <menuitem action="file-export-xmi">
            </menuitem></menu>
          </menu>
        
      """
    
    def __init__(self):
        self.action_group = build_action_group(self)
github gaphor / gaphor / gaphor / plugins / checkmetamodel / checkmodelgui.py View on Github external
from gaphor.core import inject, action, build_action_group
from gaphor.ui.diagrampage import DiagramPage
from gaphor.abc import Service, ActionProvider
from gaphor.plugins.checkmetamodel import checkmodel

PYELEMENT_COLUMN = 0
ELEMENT_COLUMN = 1
REASON_COLUMN = 2

log = logging.getLogger(__name__)


class CheckModelWindow(Service, ActionProvider):

    element_factory = inject("element_factory")
    main_window = inject("main_window")

    menu_xml = """
      
        
          <menu action="tools">
            <menuitem action="tools-open-check-model">
          </menuitem></menu>
        
      """

    def __init__(self):
        # Override the report method
        checkmodel.report = self.on_report
        self.action_group = build_action_group(self)

    def shutdown(self):
github gaphor / gaphor / gaphor / ui / elementeditor.py View on Github external
from __future__ import absolute_import
from zope import interface
from gaphor.interfaces import IService, IActionProvider
from gaphor.core import _, inject, open_action, build_action_group
from gaphor.ui.propertyeditor import PropertyEditor
from gaphor.ui.interfaces import IUIComponent

class ElementEditor(object):
    """The ElementEditor class is a utility window used to edit UML elements.
    It will display the properties of the currently selected element in the
    diagram."""

    interface.implements(IUIComponent, IActionProvider)

    element_factory = inject('element_factory')
    properties = inject('properties')

    title = _("Element Editor")
    size = (275, -1)
    resizable = True
    placement = 'floating'
    menu_xml = """
      
        
          <menu action="edit">
            
            <menuitem>
          </menuitem></menu>
        
      
    """