1 """
2 Manages adding, removing, resizing and drawing the canvas
3
4 The Canvas is the main area in Conduit, the area to which DataProviders are
5 dragged onto.
6
7 Copyright: John Stowers, 2006
8 Copyright: Thomas Van Machelen, 2007
9 License: GPLv2
10 """
11 import gobject
12 import gtk
13 import logging
14 log = logging.getLogger("hildonui.Canvas")
15
16 import conduit.gtkui.Canvas
17 import conduit.gtkui.Util as GtkUtil
18
19 LINE_WIDTH = 3.0
20
21 -class Canvas(conduit.gtkui.Canvas.Canvas, gobject.GObject):
22 """
23 This class manages many objects
24 """
25
26 __gsignals__ = {
27 "position-changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [])
28 }
29
30 - def __init__(self, parentWindow, typeConverter, syncManager):
31 """
32 Draws an empty canvas of the appropriate size
33 """
34
35 conduit.gtkui.Canvas.Canvas.__init__(self,
36 parentWindow,typeConverter,syncManager,
37 None,None,
38 None
39 )
40 self.position = -1
41
44
50
52 c_x,c_y,c_w,c_h = self.get_bounds()
53 self.welcome = goocanvas.Text(
54 x=c_w/2,
55 y=c_w/3,
56 width=3*c_w/5,
57 text=self.WELCOME_MESSAGE,
58 anchor=gtk.ANCHOR_CENTER,
59 alignment=pango.ALIGN_CENTER,
60 font="Sans 10",
61 fill_color="black",
62 )
63 self.root.add_child(self.welcome,-1)
64
66 log.debug("Clicked View: %s" % view.model)
67
68
69 if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
70 if not view.model.is_busy():
71 self.conduitMenu.popup(None, None,
72 None, event.button, event.time)
73
74
75 return True
76
96
98 """
99 Creates a ConduitCanvasItem for the new conduit
100 """
101 log.debug("Conduit added %s" % conduitAdded)
102 self.set_position(self.model.index(conduitAdded))
103
106
112
125
130
132 """
133 Moves the canvas to the next conduit
134 """
135 self.set_position(self.position + 1)
136
138 """
139 Moves the canvas to the previous conduit
140 """
141 self.set_position(self.position - 1)
142
144 """
145 Sets the Canvas position to the index provided
146 """
147 nr_of_conduits = self.model.num_conduits()
148
149 if index > nr_of_conduits:
150 return
151
152
153 if self.position == index:
154 return
155
156
157 self.position = index
158
159 log.debug("Current position %d, Lenght: %d" % (self.position, nr_of_conduits))
160
161
162 if self.position == nr_of_conduits:
163 self.position = 0
164 elif self.position < 0:
165 self.position = nr_of_conduits - 1
166
167 self._refresh_current_item()
168
169 self.emit("position-changed")
170
172 """
173 Gets the position
174 """
175 return self.position
176
178 """
179 Gets the position representation
180 """
181 return "%s/%s" % (self.position + 1, self.model.num_conduits())
182
194
196 """
197 Clears the current conduit from the Canvas
198 """
199 currentItem = self._get_child_conduit_canvas_item()
200
201 if not currentItem:
202 return
203
204
205 idx = self.root.find_child(currentItem)
206 if idx != -1:
207 self.root.remove_child(idx)
208 else:
209 log.warn("Error finding item")
210
211 self._remove_overlap()
212 self._show_welcome_message()
213
215 c_x,c_y,c_w,c_h = self.get_bounds()
216
217 bottom = self._get_bottom_of_conduits_coord()
218 conduitCanvasItem = ConduitCanvasItem(
219 parent=self.root,
220 model=conduit,
221 width=c_w)
222 conduitCanvasItem.translate(
223 LINE_WIDTH/2.0,
224 bottom+(LINE_WIDTH/2.0)
225 )
226
227
228 self.selectedConduitItem = conduitCanvasItem
229
230
231
232
233
234 conduitCanvasItem.connect('button-press-event', self.