~conduit/conduit/trunk-debian

« back to all changes in this revision

Viewing changes to conduit/gtkui/Canvas.py

  • Committer: John Stowers
  • Date: 2008-07-29 22:52:24 UTC
  • Revision ID: john.stowers@gmail.com-20080729225224-j3igjlsqoe03z5t4
        * conduit/gtkui/Canvas.py: Expand the canvas when more conduits
        get added. Fixes #516646, #517877
        * conduit/gtkui/UI.py: Account for Canvas scrolled window on DND.

Show diffs side-by-side

added added

removed removed

Lines of Context:
105
105
        self.model = None
106
106
        
107
107
        log.info("Goocanvas version: %s" % str(goocanvas.pygoocanvas_version))
 
108
        
 
109
    def _setup_popup_menus(self, dataproviderPopupXML, conduitPopupXML):
 
110
        """
 
111
        Sets up the popup menus and their callbacks
 
112
 
 
113
        @param conduitPopupXML: The menu which is popped up when the user right
 
114
        clicks on a conduit
 
115
        @type conduitPopupXML: C{gtk.glade.XML}
 
116
        @param dataproviderPopupXML: The menu which is popped up when the user right
 
117
        clicks on a dataprovider
 
118
        @type dataproviderPopupXML: C{gtk.glade.XML}
 
119
        """
 
120
 
 
121
        self.dataproviderMenu = dataproviderPopupXML.get_widget("DataProviderMenu")
 
122
        self.configureMenuItem = dataproviderPopupXML.get_widget("configure")
 
123
 
 
124
        self.conduitMenu = conduitPopupXML.get_widget("ConduitMenu")
 
125
        self.twoWayMenuItem = conduitPopupXML.get_widget("two_way_sync")
 
126
        self.slowSyncMenuItem = conduitPopupXML.get_widget("slow_sync")
 
127
        self.autoSyncMenuItem = conduitPopupXML.get_widget("auto_sync")
 
128
 
 
129
        self.twoWayMenuItem.connect("toggled", self.on_two_way_sync_toggle)
 
130
        self.slowSyncMenuItem.connect("toggled", self.on_slow_sync_toggle)
 
131
        self.autoSyncMenuItem.connect("toggled", self.on_auto_sync_toggle)
 
132
 
 
133
        #connect the conflict popups
 
134
        self.policyWidgets = {}
 
135
        for policyName in Conduit.CONFLICT_POLICY_NAMES:
 
136
            for policyValue in Conduit.CONFLICT_POLICY_VALUES:
 
137
                widgetName = "%s_%s" % (policyName,policyValue)
 
138
                #store the widget and connect to toggled signal
 
139
                widget = conduitPopupXML.get_widget(widgetName)
 
140
                widget.connect("toggled", self.on_policy_toggle, policyName, policyValue)
 
141
                self.policyWidgets[widgetName] = widget
 
142
                
 
143
        #connect the menu callbacks
 
144
        conduitPopupXML.signal_autoconnect(self)
 
145
        dataproviderPopupXML.signal_autoconnect(self)
108
146
 
109
147
    def _show_welcome_message(self):
110
148
        """
153
191
        return items
154
192
 
155
193
    def _canvas_resized(self, widget, allocation):
156
 
        self.set_bounds(0,0,allocation.width,allocation.height)
 
194
        self.set_bounds(
 
195
                    0,0,
 
196
                    allocation.width,
 
197
                    self._get_minimum_canvas_size(allocation.height)
 
198
                    )
157
199
        for i in self._get_child_conduit_canvas_items():
158
200
            i.set_width(allocation.width)
159
201
 
160
 
 
161
202
    def _on_conduit_button_press(self, view, target, event):
162
203
        """
163
204
        Handle button clicks on conduits
235
276
        for i in self._get_child_conduit_canvas_items():
236
277
            y = y + i.get_height()
237
278
        return y
 
279
        
 
280
    def _get_minimum_canvas_size(self, allocH=None):
 
281
        if not allocH:
 
282
            allocH = self.get_allocation().height
 
283
    
 
284
        bottom = self._get_bottom_of_conduits_coord()
 
285
        return max(bottom + ConduitCanvasItem.WIDGET_HEIGHT + 20, allocH)
 
286
        
 
287
    def _remove_overlap(self):
 
288
        """
 
289
        Moves the ConduitCanvasItems to stop them overlapping visually
 
290
        """
 
291
        items = self._get_child_conduit_canvas_items()
 
292
        if len(items) > 0:
 
293
            #special case where the top one was deleted
 
294
            top = items[0].get_top()-(LINE_WIDTH/2)
 
295
            if top != 0.0:
 
296
                for item in items:
 
297
                    #translate all those below
 
298
                    item.translate(0,-top)
 
299
            else:
 
300
                for i in xrange(0, len(items)):
 
301
                    try:
 
302
                        overlap = items[i].get_bottom() - items[i+1].get_top()
 
303
                        if overlap != 0.0:
 
304
                            #translate all those below
 
305
                            for item in items[i+1:]:
 
306
                                item.translate(0,overlap)
 
307
                    except IndexError: 
 
308
                        break
238
309
 
239
310
    def on_conduit_removed(self, sender, conduitRemoved):
240
311
        for item in self._get_child_conduit_canvas_items():
248
319
        self._remove_overlap()
249
320
        self._show_welcome_message()
250
321
 
 
322
        c_x,c_y,c_w,c_h = self.get_bounds()
 
323
        self.set_bounds(
 
324
                    0,
 
325
                    0,
 
326
                    c_w,
 
327
                    self._get_minimum_canvas_size()
 
328
                    )
 
329
 
251
330
    def on_conduit_added(self, sender, conduitAdded):
252
331
        """
253
332
        Creates a ConduitCanvasItem for the new conduit
277
356
        conduitAdded.connect("dataprovider-removed", self.on_dataprovider_removed, conduitCanvasItem)
278
357
 
279
358
        self._show_welcome_message()
 
359
        self.set_bounds(
 
360
                    0,
 
361
                    0,
 
362
                    c_w,
 
363
                    self._get_minimum_canvas_size()
 
364
                    )
280
365
 
281
366
    def on_dataprovider_removed(self, sender, dataproviderRemoved, conduitCanvasItem):
282
367
        for item in self._get_child_dataprovider_canvas_items():
304
389
        self._remove_overlap()
305
390
        self._show_welcome_message()
306
391
 
307
 
    def _remove_overlap(self):
308
 
        """
309
 
        Moves the ConduitCanvasItems to stop them overlapping visually
310
 
        """
311
 
        items = self._get_child_conduit_canvas_items()
312
 
        if len(items) > 0:
313
 
            #special case where the top one was deleted
314
 
            top = items[0].get_top()-(LINE_WIDTH/2)
315
 
            if top != 0.0:
316
 
                for item in items:
317
 
                    #translate all those below
318
 
                    item.translate(0,-top)
319
 
            else:
320
 
                for i in xrange(0, len(items)):
321
 
                    try:
322
 
                        overlap = items[i].get_bottom() - items[i+1].get_top()
323
 
                        if overlap != 0.0:
324
 
                            #translate all those below
325
 
                            for item in items[i+1:]:
326
 
                                item.translate(0,overlap)
327
 
                    except IndexError: 
328
 
                        break
329
 
 
330
 
 
331
392
    def get_sync_set(self):
332
393
        return self.model
333
394
 
345
406
        context.drag_status(gtk.gdk.ACTION_COPY, time)
346
407
        return True
347
408
 
348
 
    def _setup_popup_menus(self, dataproviderPopupXML, conduitPopupXML):
349
 
        """
350
 
        Sets up the popup menus and their callbacks
351
 
 
352
 
        @param conduitPopupXML: The menu which is popped up when the user right
353
 
        clicks on a conduit
354
 
        @type conduitPopupXML: C{gtk.glade.XML}
355
 
        @param dataproviderPopupXML: The menu which is popped up when the user right
356
 
        clicks on a dataprovider
357
 
        @type dataproviderPopupXML: C{gtk.glade.XML}
358
 
        """
359
 
 
360
 
        self.dataproviderMenu = dataproviderPopupXML.get_widget("DataProviderMenu")
361
 
        self.configureMenuItem = dataproviderPopupXML.get_widget("configure")
362
 
 
363
 
        self.conduitMenu = conduitPopupXML.get_widget("ConduitMenu")
364
 
        self.twoWayMenuItem = conduitPopupXML.get_widget("two_way_sync")
365
 
        self.slowSyncMenuItem = conduitPopupXML.get_widget("slow_sync")
366
 
        self.autoSyncMenuItem = conduitPopupXML.get_widget("auto_sync")
367
 
 
368
 
        self.twoWayMenuItem.connect("toggled", self.on_two_way_sync_toggle)
369
 
        self.slowSyncMenuItem.connect("toggled", self.on_slow_sync_toggle)
370
 
        self.autoSyncMenuItem.connect("toggled", self.on_auto_sync_toggle)
371
 
 
372
 
        #connect the conflict popups
373
 
        self.policyWidgets = {}
374
 
        for policyName in Conduit.CONFLICT_POLICY_NAMES:
375
 
            for policyValue in Conduit.CONFLICT_POLICY_VALUES:
376
 
                widgetName = "%s_%s" % (policyName,policyValue)
377
 
                #store the widget and connect to toggled signal
378
 
                widget = conduitPopupXML.get_widget(widgetName)
379
 
                widget.connect("toggled", self.on_policy_toggle, policyName, policyValue)
380
 
                self.policyWidgets[widgetName] = widget
381
 
                
382
 
        #connect the menu callbacks
383
 
        conduitPopupXML.signal_autoconnect(self)
384
 
        dataproviderPopupXML.signal_autoconnect(self)        
385
 
 
386
409
    def on_delete_conduit_clicked(self, widget):
387
410
        """
388
411
        Delete a conduit and all its associated dataproviders