| 1 |
''' |
|---|
| 2 |
PackageItem diagram item |
|---|
| 3 |
''' |
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
from __future__ import generators |
|---|
| 7 |
|
|---|
| 8 |
import gobject |
|---|
| 9 |
import pango |
|---|
| 10 |
import diacanvas |
|---|
| 11 |
import gaphor.UML as UML |
|---|
| 12 |
from gaphor.diagram import initialize_item |
|---|
| 13 |
from classifier import ClassifierItem |
|---|
| 14 |
|
|---|
| 15 |
class PackageItem(ClassifierItem): |
|---|
| 16 |
TAB_X=50 |
|---|
| 17 |
TAB_Y=20 |
|---|
| 18 |
MARGIN_X=60 |
|---|
| 19 |
MARGIN_Y=30 |
|---|
| 20 |
|
|---|
| 21 |
def __init__(self, id=None): |
|---|
| 22 |
ClassifierItem.__init__(self, id) |
|---|
| 23 |
self.set(height=50, width=100) |
|---|
| 24 |
self._border = diacanvas.shape.Path() |
|---|
| 25 |
self._border.set_line_width(2.0) |
|---|
| 26 |
|
|---|
| 27 |
def on_update(self, affine): |
|---|
| 28 |
|
|---|
| 29 |
w, h = self.get_name_size() |
|---|
| 30 |
self.set(min_width=w + PackageItem.MARGIN_X, |
|---|
| 31 |
min_height=h + PackageItem.MARGIN_Y) |
|---|
| 32 |
self.update_name(x=0, y=(self.height - h + PackageItem.TAB_Y) / 2, |
|---|
| 33 |
width=self.width, height=h) |
|---|
| 34 |
|
|---|
| 35 |
ClassifierItem.on_update(self, affine) |
|---|
| 36 |
|
|---|
| 37 |
o = 0.0 |
|---|
| 38 |
h = self.height |
|---|
| 39 |
w = self.width |
|---|
| 40 |
x = PackageItem.TAB_X |
|---|
| 41 |
y = PackageItem.TAB_Y |
|---|
| 42 |
line = ((x, y), (x, o), (o, o), (o, h), (w, h), (w, y), (o, y)) |
|---|
| 43 |
self._border.line(line) |
|---|
| 44 |
self.expand_bounds(1.0) |
|---|
| 45 |
|
|---|
| 46 |
def on_shape_iter(self): |
|---|
| 47 |
yield self._border |
|---|
| 48 |
for s in ClassifierItem.on_shape_iter(self): |
|---|
| 49 |
yield s |
|---|
| 50 |
|
|---|
| 51 |
initialize_item(PackageItem, UML.Package) |
|---|