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 all 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
3 changes: 2 additions & 1 deletion gaphor/misc/console.py
Expand Up @@ -149,6 +149,8 @@ class GTKInterpreterConsole(Gtk.ScrolledWindow):

def __init__(self, locals=None):
Gtk.ScrolledWindow.__init__(self)
self.set_min_content_width(640)
self.set_min_content_height(480)
self.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)

self.text = Gtk.TextView()
Expand Down Expand Up @@ -360,7 +362,6 @@ def do_unrealize(self):
def main():
w = Gtk.Window()
console = GTKInterpreterConsole()
console.set_size_request(640, 480)
w.add(console)

def destroy(arg=None):
Expand Down
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
12 changes: 8 additions & 4 deletions gaphor/plugins/diagramlayout/__init__.py
@@ -1,15 +1,17 @@
"""
This module provides a means to automatocally layout diagrams.
This module provides a means to automatically layout diagrams.

The layout is done like this:
- First all nodes (Classes, packages, comments) on a digram are determined
- First all nodes (Classes, packages, comments) on a diagram are determined
- A vertical ordering is determined based on the inheritance
- A horizontal ordering is determined based on associations and dependencies
- The nodes are moved to their place
- Lines are reconnected to the nodes, so everything looks pretty.

"""
from __future__ import division

import logging
import random
from builtins import object

Expand All @@ -21,6 +23,8 @@
from gaphor.interfaces import IService, IActionProvider
from gaphor.plugins.diagramlayout import toposort

log = logging.getLogger(__name__)


@implementer(IService, IActionProvider)
class DiagramLayout(object):
Expand Down Expand Up @@ -49,10 +53,10 @@ def update(self):
self.sensitive = bool(self.get_window().get_current_diagram())

@action(
name="diagram-layout", label="Layout diagram", tooltip="simple diagram layout"
name="diagram-layout", label="La_yout diagram", tooltip="simple diagram layout"
)
def execute(self):
d = self.main_window.get_current_diagram()
d = self.diagram.get_current_diagram()
self.layout_diagram(d)

@transactional
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
28 changes: 21 additions & 7 deletions gaphor/services/helpservice.py
Expand Up @@ -81,9 +81,15 @@ def add_label(text, padding_x=0, padding_y=0):
tab_vbox.pack_start(label, True, True, 0)

add_label('<span weight="bold">version %s</span>' % version)
add_label('<span variant="smallcaps">UML Modeling tool for GNOME</span>', 8, 8)
add_label(
'<span size="small">Copyright (c) 2001-2007 Arjan J. Molenaar</span>', 8, 8
'<span variant="smallcaps">Gaphor is the simple modeling tool written in Python</span>',
8,
8,
)
add_label(
'<span size="small">Copyright (c) 2001-2019 Arjan J. Molenaar and Dan Yeaw</span>',
8,
8,
)

notebook.append_page(tab_vbox, Gtk.Label(label=_("About")))
Expand All @@ -93,8 +99,8 @@ def add_label(text, padding_x=0, padding_y=0):
add_label(
"This software is published\n"
"under the terms of the\n"
'<span weight="bold">GNU General Public License v2</span>.\n'
"See the COPYING file for details.",
'<span weight="bold">GNU Library General Public License v2</span>.\n'
"See the LICENSE.txt file for details.",
0,
8,
)
Expand All @@ -103,13 +109,21 @@ def add_label(text, padding_x=0, padding_y=0):
tab_vbox = Gtk.VBox()

add_label(
"Gaphor is written by:\n"
"Thanks to all the wonderful people that have contributed:\n\n"
"Arjan Molenaar\n"
"Artur Wroblewski\n"
"Jeroen Vloothuis"
"Jeroen Vloothuis\n"
"Dan Yeaw\n"
"Enno Groeper\n"
"Adam Boduch\n"
"Jordi Mallach\n"
"Ygor Mutti\n"
"Alexis Howells\n"
"Encolpe Degoute\n"
"Melis Dogan"
)
add_label("")
notebook.append_page(tab_vbox, Gtk.Label(label=_("Authors")))
notebook.append_page(tab_vbox, Gtk.Label(label=_("Contributors")))

vbox.show_all()
about.run()
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
2 changes: 1 addition & 1 deletion gaphor/ui/elementeditor.py
Expand Up @@ -48,7 +48,7 @@ def __init__(self):

@open_action(
name="ElementEditor:open",
label=_("Editor"),
label=_("_Editor"),
stock_id="gtk-edit",
accel="<Control>e",
)
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
8 changes: 5 additions & 3 deletions gaphor/ui/layout.py
Expand Up @@ -73,9 +73,9 @@ def _des(element, index, parent_widget=None):
def add(widget, index, parent_widget):
if isinstance(parent_widget, Gtk.Paned):
if index == 0:
parent_widget.add1(widget)
parent_widget.pack1(child=widget, resize=False, shrink=False)
elif index == 1:
parent_widget.add2(widget)
parent_widget.pack2(child=widget, resize=True, shrink=False)
else:
parent_widget.add(widget)

Expand All @@ -93,12 +93,14 @@ def _factory(func):


@factory("paned")
def paned(parent, index, orientation, weight=None):
def paned(parent, index, orientation, position=None):
paned = Gtk.Paned.new(
Gtk.Orientation.HORIZONTAL
if orientation == "horizontal"
else Gtk.Orientation.VERTICAL
)
add(paned, index, parent)
if position:
paned.set_position(int(position))
paned.show()
return paned
6 changes: 3 additions & 3 deletions gaphor/ui/layout.xml
@@ -1,10 +1,10 @@
<?xml version="1.0"?>
<layout>
<paned orientation="horizontal">
<paned orientation="vertical" weight="20">
<paned orientation="horizontal" position="200">
<paned orientation="vertical" position="200">
<component name="namespace"/>
<component name="toolbox"/>
</paned>
<component name="diagrams" weight="80"/>
<component name="diagrams"/>
</paned>
</layout>