Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Diagrams to Open in Gtk.Notebook Pages #65

Merged
merged 15 commits into from Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions gaphor/plugins/checkmetamodel/checkmodelgui.py
Expand Up @@ -3,20 +3,27 @@
"""
from __future__ import print_function

import logging
from builtins import object

import gi

gi.require_version("Gtk", "3.0")
from gi.repository import GObject
from gi.repository import Gtk
from zope.interface import implementer

from gaphor.core import inject, action, build_action_group
from gaphor.ui.diagrampage import DiagramPage
from gaphor.interfaces import IService, IActionProvider
from gaphor.plugins.checkmetamodel import checkmodel

PYELEMENT_COLUMN = 0
ELEMENT_COLUMN = 1
REASON_COLUMN = 2

log = logging.getLogger(__name__)


@implementer(IService, IActionProvider)
class CheckModelWindow(object):
Expand Down Expand Up @@ -110,15 +117,14 @@ def on_row_activated(self, treeview, row, column):
element = self.model.get_value(iter, PYELEMENT_COLUMN)
print("Looking for element", element)
if element.presentation:
main_window = self.main_window
presentation = element.presentation[0]
try:
diagram = presentation.canvas.diagram
except AttributeError:
presentation = element.namespace.presentation[0]
diagram = presentation.canvas.diagram
diagram_tab = main_window.show_diagram(diagram)
diagram_tab.view.focused_item = presentation
diagram_page = DiagramPage(diagram)
diagram_page.view.focused_item = presentation

def on_destroy(self, window):
self.window = None
Expand Down
2 changes: 1 addition & 1 deletion gaphor/services/diagramexportmanager.py
Expand Up @@ -56,7 +56,7 @@ def update(self):

self.logger.info("Updating")

tab = self.get_window().get_current_diagram_tab()
tab = self.get_window().get_current_diagram_page()
self.sensitive = tab and True or False

def save_dialog(self, diagram, title, ext):
Expand Down
18 changes: 7 additions & 11 deletions gaphor/ui/diagramtab.py → gaphor/ui/diagrampage.py
Expand Up @@ -34,7 +34,7 @@
log = logging.getLogger(__name__)


class DiagramTab(object):
class DiagramPage(object):

component_registry = inject("component_registry")
element_factory = inject("element_factory")
Expand Down Expand Up @@ -84,7 +84,7 @@ class DiagramTab(object):
def __init__(self, diagram):
self.diagram = diagram
self.view = None
# self.owning_window = owning_window
self.widget = None
self.action_group = build_action_group(self)
self.toolbox = None
self.component_registry.register_handler(self._on_element_change)
Expand Down Expand Up @@ -112,7 +112,7 @@ def construct(self):
view = GtkView(canvas=self.diagram.canvas)
view.drag_dest_set(
Gtk.DestDefaults.MOTION,
DiagramTab.VIEW_DND_TARGETS,
DiagramPage.VIEW_DND_TARGETS,
Gdk.DragAction.MOVE | Gdk.DragAction.COPY | Gdk.DragAction.LINK,
)

Expand All @@ -121,6 +121,7 @@ def construct(self):
scrolled_window.set_shadow_type(Gtk.ShadowType.IN)
scrolled_window.add(view)
scrolled_window.show_all()
self.widget = scrolled_window

view.connect("focus-changed", self._on_view_selection_changed)
view.connect("selection-changed", self._on_view_selection_changed)
Expand All @@ -132,12 +133,7 @@ def construct(self):

self.toolbox = DiagramToolbox(self.diagram, view)

# item = DockItem(title=self.title, stock_id='gaphor-diagram')
# item.add(scrolled_window)
item = scrolled_window
self.widget = item

return item
return self.widget

@component.adapter(IAttributeChangeEvent)
def _on_element_change(self, event):
Expand Down Expand Up @@ -325,15 +321,15 @@ def _on_drag_data_received(self, view, context, x, y, data, info, time):
if (
data
and data.get_format() == 8
and info == DiagramTab.VIEW_TARGET_TOOLBOX_ACTION
and info == DiagramPage.VIEW_TARGET_TOOLBOX_ACTION
):
tool = self.toolbox.get_tool(data.get_data().decode())
tool.create_item((x, y))
context.finish(True, False, time)
elif (
data
and data.get_format() == 8
and info == DiagramTab.VIEW_TARGET_ELEMENT_ID
and info == DiagramPage.VIEW_TARGET_ELEMENT_ID
):
# print('drag_data_received:', data.data, info)
n, p = data.data.split("#")
Expand Down
2 changes: 1 addition & 1 deletion gaphor/ui/diagramtoolbox.py
Expand Up @@ -172,7 +172,7 @@ def itemiter(toolbox_actions):

class DiagramToolbox(object):
"""
Composite class for DiagramTab (diagramtab.py).
Composite class for DiagramPage (diagrampage.py).
"""

element_factory = inject("element_factory")
Expand Down
8 changes: 4 additions & 4 deletions gaphor/ui/event.py
Expand Up @@ -4,7 +4,7 @@

from gaphor.ui.interfaces import (
IDiagramSelectionChange,
IDiagramTabChange,
IDiagramPageChange,
IDiagramShow,
)

Expand All @@ -15,11 +15,11 @@ def __init__(self, diagram):
self.diagram = diagram


@implementer(IDiagramTabChange)
class DiagramTabChange(object):
@implementer(IDiagramPageChange)
class DiagramPageChange(object):
def __init__(self, item):
self.item = item
self.diagram_tab = item.diagram_tab
self.diagram_page = item.diagram_page


@implementer(IDiagramSelectionChange)
Expand Down
4 changes: 2 additions & 2 deletions gaphor/ui/interfaces.py
Expand Up @@ -13,14 +13,14 @@ class IDiagramShow(interface.Interface):
diagram = interface.Attribute("The newly selected Diagram")


class IDiagramTabChange(interface.Interface):
class IDiagramPageChange(interface.Interface):
"""
The selected diagram changes.
"""

item = interface.Attribute("The newly selected Notebook pane")

diagram_tab = interface.Attribute("The newly selected diagram tab")
diagram_page = interface.Attribute("The newly selected diagram page")


class IDiagramSelectionChange(interface.Interface):
Expand Down