Skip to content

Commit

Permalink
Updated drawing of items.
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/arjan/backup/gaphor/gaphor/trunk@1201 a8418922-720d-0410-834f-a69b97ada669
  • Loading branch information
amolenaar committed Apr 10, 2007
1 parent d80881c commit 1bc568e
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 55 deletions.
8 changes: 4 additions & 4 deletions gaphor/actions/itemactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,15 +1077,15 @@ def update(self):
try:
item = get_parent_focus_item(self._window)
if isinstance(item, items.ObjectNodeItem):
self.active = (item.get_ordering() == self.ordering)
self.active = (item.ordering == self.ordering)
except NoFocusItemError:
pass

@transactional
def execute(self):
if self.active:
item = get_parent_focus_item(self._window)
item.set_ordering(self.ordering)
item.ordering = self.ordering


class ObjectNodeOrderingUnorderedAction(ObjectNodeOrderingAction):
Expand Down Expand Up @@ -1139,12 +1139,12 @@ def update(self):
pass
else:
if isinstance(item, items.ObjectNodeItem):
self.active = item.props.show_ordering
self.active = item.show_ordering

@transactional
def execute(self):
item = get_parent_focus_item(self._window)
item.props.show_ordering = self.active
item.show_ordering = self.active

register_action(ObjectNodeOrderingVisibiltyAction, 'ItemFocus')

Expand Down
6 changes: 5 additions & 1 deletion gaphor/diagram/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class ActionItem(NamedItem):
'name-align': (ALIGN_CENTER, ALIGN_MIDDLE),
}

def pre_update(self, context):
self.update_name_size(context)
self.min_width, self.min_height = self.get_name_size()
super(ActionItem, self).pre_update(context)

def draw(self, context):
"""
Draw action symbol.
Expand All @@ -39,5 +44,4 @@ def draw(self, context):
super(ActionItem, self).draw(context)



# vim:sw=4:et
13 changes: 12 additions & 1 deletion gaphor/diagram/activitynodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,18 @@ class ForkDecisionNodeItem(ActivityNodeItem):
def __init__(self, id=None):
ActivityNodeItem.__init__(self, id)
self._combined = None
self.set_prop_persistent('combined')
#self.set_prop_persistent('combined')

def save(self, save_func):
if self._combined:
save_func('combined', self._combined, reference=True)
super(ForkDecisionNodeItem, self).save(save_func)

def load(self, name, value):
if name == 'combined':
self._combined = value
else:
super(ForkDecisionNodeItem, self).load(name, value)

@observed
def _set_combined(self, value):
Expand Down
1 change: 0 additions & 1 deletion gaphor/diagram/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ def get_icon_pos(self):


def draw_compartment(self, context):
#if not self.subject: return
cr = context.cairo
cr.rectangle(0, 0, self.width, self.height)
cr.stroke()
Expand Down
2 changes: 1 addition & 1 deletion gaphor/diagram/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def draw(self, context):
c.stroke()
if self.subject.body:
# Do not print empty string, since cairo-win32 can't handle it.
text_multiline(c, 5, 15, self.subject.body, padding=2)
text_multiline(c, 5, 5, self.subject.body, padding=2)
#c.move_to(10, 15)
#c.show_text(self.subject.body)

Expand Down
1 change: 1 addition & 0 deletions gaphor/diagram/elementitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ def pre_update(self, context):
super(ElementItem, self).pre_update(context)
self.update_stereotype()


# vim:sw=4
26 changes: 2 additions & 24 deletions gaphor/diagram/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from gaphor.diagram.diagramline import DiagramLine

class ExtensionItem(DiagramLine):
"""ExtensionItem represents associations.
"""
ExtensionItem represents associations.
An ExtensionItem has two ExtensionEnd items. Each ExtensionEnd item
represents a Property (with Property.association == my association).
"""
Expand All @@ -24,29 +25,6 @@ class ExtensionItem(DiagramLine):
def __init__(self, id=None):
DiagramLine.__init__(self, id)

def save (self, save_func):
DiagramLine.save(self, save_func)
if self._head_end.subject:
save_func('head_subject', self._head_end.subject)
if self._tail_end.subject:
save_func('tail_subject', self._tail_end.subject)

def load (self, name, value):
# end_head and end_tail were used in an older Gaphor version
if name in ( 'head_end', 'head_subject' ):
#type(self._head_end).subject.load(self._head_end, value)
self._head_end.load('subject', value)
elif name in ( 'tail_end', 'tail_subject' ):
#type(self._tail_end).subject.load(self._tail_end, value)
self._tail_end.load('subject', value)
else:
DiagramLine.load(self, name, value)

def postload(self):
DiagramLine.postload(self)
self._head_end.postload()
self._tail_end.postload()

def on_subject_notify(self, pspec, notifiers=()):
DiagramLine.on_subject_notify(self, pspec,
notifiers + ('ownedEnd',))
Expand Down
12 changes: 1 addition & 11 deletions gaphor/diagram/nameditem.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ def update_name_size(self, context):
width, height = text_extents(cr, text)
padding = self.style.name_padding
self._name_size = width + padding[0] + padding[2], height + padding[1] + padding[3]
# if self.min_width < self._name_size[0]:
# self.min_width = self._name_size[0]
# if self.min_height < self._name_size[1]:
# self.min_height = self._name_size[1]
# self.min_width, self.min_height = get_min_size(width, height,
# self.style.min_size,
# self.style.name_padding)
#
# super(NamedItem, self).pre_update(context)


def update(self, context):
"""
Expand Down Expand Up @@ -92,5 +82,5 @@ def draw(self, context):
if text:
#cr.move_to(self.name_x, self.name_y)
#cr.show_text(text)
text_align(cr, self.name_x, self.name_y, text, *self.style.name_align)
text_align(cr, self.name_x, self.name_y, text, 1, -1)
super(NamedItem, self).draw(context)
13 changes: 4 additions & 9 deletions gaphor/diagram/objectnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,17 @@ def on_subject_notify(self, pspec, notifiers = ()):
element subject.
"""
NamedItem.on_subject_notify(self, pspec, notifiers)
if self.subject:
if not self.subject.upperBound:
self.subject.upperBound = UML.create(UML.LiteralSpecification)
self.subject.upperBound.value = '*'
#self._upper_bound.subject = self.subject.upperBound
#else:
# self._upper_bound.subject = None
if self.subject and not self.subject.upperBound:
self.subject.upperBound = UML.create(UML.LiteralSpecification)
self.subject.upperBound.value = '*'
self.request_update()

def pre_update(self, context):
"""
Update object node, its ordering and upper bound specification.
"""
NamedItem.update(self, context)
NamedItem.pre_update(self, context)

# TODO: format tag properly:
if self.subject.upperBound:
self._tag = '{ upperBound = %s }\n' % self.subject.upperBound.value

Expand Down
8 changes: 5 additions & 3 deletions gaphor/diagram/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def pre_update(self, context):

super(PackageItem, self).pre_update(context)


def draw(self, context):
cr = context.cairo
o = 0.0
Expand All @@ -48,9 +47,12 @@ def draw(self, context):
cr.line_to(o, y)
cr.stroke()
if self.stereotype:
text_align(cr, w / 2, y + 10, self.stereotype)
y += 10
text_align(cr, w / 2, y, self.stereotype)
y += 10

super(PackageItem, self).draw(context)
if self.subject and self.subject.name:
text_align(cr, w / 2, y + 10, self.subject.name)


# vim:sw=4:et
30 changes: 30 additions & 0 deletions gaphor/event.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
"""
Application wide events are managed here.
"""

from zope import interface
from gaphor.interfaces import *

class TransactionBegin(object):
"""
This event denotes the beginning of an transaction.
Nested (sub-) transactions should not emit this signal.
"""
interface.implements(ITransactionEvent)


class TransactionCommit(object):
"""
This event is emitted when a transaction (toplevel) is successfully
commited.
"""
interface.implements(ITransactionEvent)

class TransactionRollback(object):
"""
If a set of operations fail (e.i. due to an exception) the transaction
should be marked for rollback. This event is emitted to tell the operation
has failed.
"""
interface.implements(ITransactionEvent)


# vim:sw=4:et:ai

23 changes: 23 additions & 0 deletions gaphor/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,27 @@ class IServiceEvent(interface.Interface):
service = interface.Attribute("The service that emits the event")


class ITransaction(interface.Interface):
"""
The methods each transaction should adhere.
"""

def commit(self):
"""
Commit the transaction.
"""

def rollback(self):
"""
Roll back the transaction.
"""


class ITransactionEvent(interface.Interface):
"""
Events related to transaction workflow (begin/commit/rollback) implements
this interface.
"""


# vim:sw=4:et

0 comments on commit 1bc568e

Please sign in to comment.