1
2 import gtk
3 import hildon
4 import os
5 import logging
6 log = logging.getLogger("hildonui.UI")
7
8 import conduit
9 from conduit.hildonui.List import DataProviderBox
10
11
12 from conduit.hildonui.Canvas import Canvas
13
14 from gettext import gettext as _
15
16 -class MainWindow(hildon.Program):
17 - def __init__(self, conduitApplication, moduleManager, typeConverter, syncManager):
18 hildon.Program.__init__(self)
19
20
21
22 icon_dirs = [
23 conduit.SHARED_DATA_DIR,
24 conduit.SHARED_MODULE_DIR,
25 os.path.join(conduit.SHARED_DATA_DIR,"icons"),
26 os.path.join(conduit.USER_DIR, "modules")
27 ]
28 for i in icon_dirs:
29 gtk.icon_theme_get_default().prepend_search_path(i)
30 log.debug("Adding %s to icon theme search path" % (i))
31
32 self.conduitApplication = conduitApplication
33 self.type_converter = typeConverter
34 self.sync_manager = syncManager
35 self.syncSet = None
36
37 self.mainWindow = hildon.Window()
38 self.mainWindow.set_icon_name("conduit")
39
40
41 self.mainWindow.connect("destroy", self.on_window_destroyed)
42 self.add_window(self.mainWindow)
43
44 self.provider_box = DataProviderBox ()
45 self.provider_box.combo.set_active (0)
46
47
48 self.canvas = Canvas(
49 parentWindow=self.mainWindow,
50 typeConverter=self.type_converter,
51 syncManager=self.sync_manager)
52
53 self.canvas.connect('drag-drop', self.drop_cb)
54 self.canvas.connect("drag-data-received", self.drag_data_received_data)
55
56 main_pane = gtk.HPaned ()
57 main_pane.add1(self.provider_box)
58 main_pane.add2(self.canvas)
59 self.mainWindow.add(main_pane)
60
61 - def set_model(self, syncSet):
62 self.syncSet = syncSet
63 self.toolbar = ConduitToolbar(self.syncSet, self.canvas)
64 self.canvas.set_sync_set(syncSet)
65
66 self.set_common_toolbar(self.toolbar)
67
69 """
70 Present the main window. Enjoy your window
71 """
72 self.mainWindow.show_all ()
73
75 """
76 Iconifies the main window
77 """
78 log.debug("Iconifying GUI")
79 self.mainWindow.hide()
80
81 - def is_visible(self):
82 """
83 Dummy for now
84 """
85 return True
86
87 - def drop_cb(self, wid, context, x, y, time):
88 """
89 drop cb
90 """
91 self.canvas.drag_get_data(context, context.targets[0], time)
92 return True
93
94 - def drag_data_received_data(self, treeview, context, x, y, selection, info, etime):
95 """
96 DND
97 """
98 dataproviderKey = selection.data
99
100
101 if dataproviderKey != "":
102
103 new = conduit.GLOBALS.moduleManager.get_module_wrapper_with_instance(dataproviderKey)
104 self.canvas.add_dataprovider_to_canvas(dataproviderKey, new, x, y)
105
106 context.finish(True, True, etime)
107 return
108
109 - def on_window_destroyed(self, widget, event=None):
110 """
111 Check if there are any synchronizations currently in progress and
112 ask the user if they wish to cancel them
113 """
114 busy = False
115 quit = False
116
117 if self.syncSet:
118 for c in self.syncSet.get_all_conduits():
119 if c.is_busy():
120 busy = True
121
122 if busy:
123 dialog = gtk.MessageDialog(
124 self.mainWindow,
125 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
126 gtk.MESSAGE_QUESTION,
127 gtk.BUTTONS_YES_NO,_("Synchronization in progress. Do you want to cancel it?")
128 )
129 response = dialog.run()
130 if response == gtk.RESPONSE_YES:
131 quit = True
132 else:
133
134 dialog.destroy()
135 return True
136 else:
137 quit = True
138
139
140
141
142 if quit:
143 log.debug("Quitting...")
144 self.conduitApplication.Quit()
145
146 - def save_settings(self, widget):
148