~ubuntu-branches/ubuntu/oneiric/compizconfig-settings-manager/oneiric

« back to all changes in this revision

Viewing changes to ccm/Window.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2007-09-12 19:45:56 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20070912194556-ka6cvdxpqgj4b4ul
Tags: 0.5.2+git20070912-0ubuntu1
* new 0.6 snapshot
* fixes focus events and keyboard navigation
* debian/patches/02_rename_ccsm.patch:
  - set name to "Advanced Desktop Effects Settings"

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
_ = gettext.gettext
37
37
 
38
38
class MainWin(gtk.Window):
39
 
        def __init__(self, Context):
40
 
                gtk.Window.__init__(self)
41
 
                self.ShowingPlugin = None
42
 
                self.Context = Context
43
 
                self.connect("destroy", self.Quit)
44
 
                self.set_default_size(960, 580)
45
 
                self.set_title(_("CompizConfig Settings Manager"))
46
 
                try:
47
 
                        self.set_icon (gtk.gdk.pixbuf_new_from_file(IconDir+"/apps/ccsm.svg"))
48
 
                except:
49
 
                        pass
50
 
                
51
 
                self.Style = Style()
52
 
                
53
 
                # build the panes
54
 
                self.MainBox = gtk.HBox()
55
 
                self.add(self.MainBox)
56
 
                self.LeftPane = gtk.Alignment()
57
 
                self.LeftPane.set_size_request(230, 520)
58
 
                self.RightPane = gtk.Alignment()
59
 
                self.RightPane.set_border_width(5)
60
 
                self.RightPane.props.yscale = 1
61
 
                self.RightPane.props.xscale = 1
62
 
                self.RightPane.props.xalign = 0
63
 
                self.RightPane.props.yalign = 0
64
 
                self.LeftPane.props.yscale = 1
65
 
                self.LeftPane.props.xscale = 1
66
 
                self.LeftPane.props.xalign = 0
67
 
                self.LeftPane.props.yalign = 0
68
 
                self.MainBox.pack_start(self.LeftPane, False, False)
69
 
                self.MainBox.pack_start(self.RightPane, True, True)
70
 
                self.Categories = {}
71
 
                self.PluginImages = {}
72
 
                self.RightVadj = 0.0
73
 
                
74
 
                for pluginName, plugin in self.Context.Plugins.items():
75
 
                        self.PluginImages[pluginName] = Image(plugin.Name, ImagePlugin)
76
 
                
77
 
                for category in sorted(self.Context.Categories, self.CatSortCompare):
78
 
                        self.Categories[category] = []
79
 
                        for pluginName, plugin in self.Context.Plugins.items():
80
 
                                if plugin.Category == category:
81
 
                                        self.Categories[category].append(plugin)
82
 
                
83
 
                self.BlockEnablePlugin = 0
84
 
                self.ResetMainWidgets()
85
 
 
86
 
        def Quit(self, foo):
87
 
                gtk.main_quit()
88
 
 
89
 
        def ResetMainWidgets(self):
90
 
                pluginsVPort = gtk.Viewport()
91
 
                leftChild = gtk.VBox(False, 10)
92
 
                leftChild.set_border_width(15)
93
 
                
94
 
                # Filter
95
 
                filterLabel = Label()
96
 
                filterLabel.set_markup("<span color='%s' size='large' weight='800'>%s</span>" % (self.Style.BrightColor, _("Filter")))
97
 
                filterLabel.props.xalign = 0.1
98
 
                if has_sexy:
99
 
                        filterEntry = sexy.IconEntry()
100
 
                        filterEntry.add_clear_button()
101
 
                else:
102
 
                        filterEntry = gtk.Entry()
103
 
                Tooltips.set_tip(filterEntry, _("Filter your Plugin list"))
104
 
                filterEntry.connect("changed", self.FilterTable)
105
 
                leftChild.pack_start(filterLabel, False, False)
106
 
                leftChild.pack_start(filterEntry, False, False)
107
 
 
108
 
                # Screens
109
 
                if len(getScreens()) > 1:
110
 
                        screenBox = gtk.combo_box_new_text()
111
 
                        for screen in getScreens():
112
 
                                screenBox.append_text(_("Screen %i") % screen)
113
 
                        name = self.Context.CurrentBackend.Name
114
 
                        screenBox.set_active(CurrentScreenNum)
115
 
                        screenBox.connect("changed", self.ScreenChanged)
116
 
                        screenLabel = Label()
117
 
                        screenLabel.set_markup("<span color='%s' size='large' weight='800'>%s</span>" % (self.Style.BrightColor, _("Screen")))
118
 
                        leftChild.pack_start(screenLabel, False, False)
119
 
                        leftChild.pack_start(screenBox, False, False)
120
 
 
121
 
                # Categories
122
 
                categoryBox = gtk.VBox()
123
 
                categoryBox.set_border_width(10)
124
 
                for category in sorted(self.Categories, self.CatSortCompare):
125
 
                        name = category or _("Uncategorized")
126
 
                        categoryToggleLabel = Label(name)
127
 
                        categoryToggle = gtk.Button()
128
 
                        categoryToggle.set_relief(gtk.RELIEF_NONE)
129
 
                        categoryToggle.add(categoryToggleLabel)
130
 
                        categoryToggle.connect("clicked", self.ToggleCategory, category)
131
 
                        categoryBox.pack_start(categoryToggle, False, False)
132
 
                categoryLabel = Label()
133
 
                categoryLabel.props.xalign = 0.1
134
 
                categoryLabel.set_markup("<span color='%s' size='large' weight='800'>%s</span>" % (self.Style.BrightColor, _("Category")))
135
 
                leftChild.pack_start(categoryLabel, False, False)
136
 
                leftChild.pack_start(categoryBox, False, False)
137
 
 
138
 
                # Exit Button
139
 
                exitButton = gtk.Button(gtk.STOCK_CLOSE)
140
 
                exitButton.set_use_stock(True)
141
 
                exitButton.connect('clicked', self.Quit)
142
 
                leftChild.pack_end(exitButton, False, False)
143
 
 
144
 
                # Advanced Search
145
 
                searchLabel = Label()
146
 
                searchLabel.set_markup("<span color='%s' size='large' weight='800'>%s</span>" % (self.Style.BrightColor, _("Advanced Search")))
147
 
                searchImage = gtk.Image()
148
 
                searchImage.set_from_stock(gtk.STOCK_GO_FORWARD, gtk.ICON_SIZE_BUTTON)
149
 
                searchButton = gtk.Button()
150
 
                searchButton.connect("clicked", self.ShowAdvancedFilter)
151
 
                searchButton.set_relief(gtk.RELIEF_NONE)
152
 
                searchFrame = gtk.HBox()
153
 
                searchFrame.pack_start(searchLabel, False, False)
154
 
                searchFrame.pack_end(searchImage, False, False)
155
 
                searchButton.add(searchFrame)
156
 
                leftChild.pack_end(searchButton, False, False)
157
 
 
158
 
                # Preferences
159
 
                prefLabel = Label()
160
 
                prefLabel.set_markup("<span color='%s' size='large' weight='800'>%s</span>" % (self.Style.BrightColor, _("Preferences")))
161
 
                prefImage = gtk.Image()
162
 
                prefImage.set_from_stock(gtk.STOCK_GO_FORWARD, gtk.ICON_SIZE_BUTTON)
163
 
                prefButton = gtk.Button()
164
 
                prefButton.connect("clicked", self.ShowPreferences)
165
 
                prefButton.set_relief(gtk.RELIEF_NONE)
166
 
                prefFrame = gtk.HBox()
167
 
                prefFrame.pack_start(prefLabel, False, False)
168
 
                prefFrame.pack_end(prefImage, False, False)
169
 
                prefButton.add(prefFrame)
170
 
                leftChild.pack_end(prefButton, False, False)
171
 
 
172
 
                pluginsVPort.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.Style.BackgroundColor))
173
 
                rightChild = gtk.ScrolledWindow()
174
 
                rightChild.props.hscrollbar_policy = gtk.POLICY_NEVER
175
 
                rightChild.props.vscrollbar_policy = gtk.POLICY_AUTOMATIC
176
 
                rightChild.set_size_request(280,-1)
177
 
                rightChild.add(pluginsVPort)
178
 
                self.BuildTable(pluginsVPort)
179
 
                rightChild.connect('size-allocate', self.RebuildTable)
180
 
                self.SetMainWidgets(leftChild, rightChild)
181
 
 
182
 
        def BuildTable(self, viewPort):
183
 
                pluginWindow = gtk.VBox()
184
 
                pluginWindow.set_border_width(10)
185
 
                viewPort.add(pluginWindow)
186
 
 
187
 
                self.TableCats = {}
188
 
                self.TableAttached = False
189
 
                self.LastCols = -1
190
 
                for category in sorted(self.Categories, self.CatSortCompare):
191
 
                        pluginList = sorted(self.Categories[category], PluginSortCompare)
192
 
                        categoryBox = gtk.VBox()
193
 
                        categoryHeader = gtk.HBox()
194
 
                        categoryHeader.set_spacing(10)
195
 
                        categoryLabel = Label('', -1)
196
 
                        pluginWindow.pack_start(categoryBox, False, False)
197
 
 
198
 
                        name = category or _("Uncategorized")
199
 
                        categoryLabel.set_markup("<span color='#aaa' size='x-large' weight='800'>%s</span>" % name)
200
 
                        categoryImg = Image(name.lower().replace(" ", "_"), ImageCategory)
201
 
                        if categoryImg:
202
 
                                categoryHeader.pack_start(categoryImg, False, False)
203
 
                        categoryHeader.pack_start(categoryLabel, False, False)
204
 
                        categoryBox.pack_start(categoryHeader, False, False)
205
 
                        
206
 
                        categoryTab = gtk.Table()
207
 
                        categoryTab.set_border_width(10)
208
 
                        self.TableCats[category] = (categoryTab, [], [])
209
 
                        categoryBox.pack_start(categoryTab, False, False)
210
 
                        
211
 
                        for plugin in pluginList:
212
 
                                pluginButton = gtk.Button()
213
 
                                pluginButton.connect('clicked', self.ShowPlugin, plugin)
214
 
                                pluginButton.set_size_request(200, -1)
215
 
                                pluginButton.set_relief(gtk.RELIEF_NONE)
216
 
                                pluginButtonBox = gtk.HBox(False, 10)
217
 
                                pluginButtonBox.set_border_width(10)
218
 
                                pluginImage = self.PluginImages[plugin.Name]
219
 
                                pluginLabel = Label(plugin.ShortDesc, 120)
220
 
                                pluginButtonBox.pack_start(pluginImage, False, False)
221
 
                                pluginButtonBox.pack_start(pluginLabel, True, True)
222
 
                                pluginButton.add(pluginButtonBox)
223
 
                                pluginBox = gtk.HBox()
224
 
 
225
 
                                if plugin.Name !=  'core':
226
 
                                        pluginEnable = gtk.CheckButton()
227
 
                                        Tooltips.set_tip(pluginEnable, _("Enable %s") % plugin.ShortDesc)
228
 
                                        pluginEnable.set_active(plugin.Enabled)
229
 
                                        pluginEnable.connect("toggled", self.EnablePlugin, plugin)
230
 
                                        pluginEnable.set_sensitive(self.Context.AutoSort)
231
 
                                        pluginBox.pack_start(pluginEnable, False, False)
232
 
 
233
 
                                Tooltips.set_tip(pluginButton, plugin.LongDesc)
234
 
                                pluginBox.pack_start(pluginButton, True, True)
235
 
                                pluginBox.set_size_request(220, -1)
236
 
                                self.TableCats[category][1].append(pluginBox)
237
 
                                self.TableCats[category][2].append(plugin)
238
 
 
239
 
        # targets:
240
 
        # 0 = plugin name and short description
241
 
        # 1 = plugin long description
242
 
        # 2 = category
243
 
        def FilterTable(self, widget, target=0):
244
 
                text = widget.get_text().lower()
245
 
                cols = self.LastCols
246
 
                foundPlugin = False
247
 
 
248
 
                if self.TableAttached:
249
 
                        for categoryName, categoryContainer in self.TableCats.items():
250
 
                                for pluginButton in categoryContainer[1]:
251
 
                                        if pluginButton.get_parent():
252
 
                                                categoryContainer[0].remove(pluginButton)
253
 
 
254
 
                for categoryName, categoryContainer in self.TableCats.items():
255
 
                        col = 0
256
 
                        row = 0
257
 
                        empty = True
258
 
                        for pluginButton in categoryContainer[1]:
259
 
                                index = categoryContainer[1].index(pluginButton)
260
 
                                shortDesc = categoryContainer[2][index].ShortDesc.lower()
261
 
                                longDesc = categoryContainer[2][index].LongDesc.lower()
262
 
                                name = categoryContainer[2][index].Name.lower()
263
 
                                category = categoryName.lower()
264
 
                                show = False
265
 
 
266
 
                                if target == 0:
267
 
                                        show = name.find(text) != -1 \
268
 
                                        or shortDesc.find(text) != -1
269
 
                                elif target == 1:
270
 
                                        show = name.find(text) != -1 \
271
 
                                        or shortDesc.find(text) != -1 \
272
 
                                        or longDesc.find(text) != -1
273
 
                                elif target == 2:
274
 
                                        show = category.find(text) != -1
275
 
 
276
 
                                if show:
277
 
                                        empty = False
278
 
                                        foundPlugin = True
279
 
                                        categoryContainer[0].attach(pluginButton, col, col+1, row, row+1, 0)
280
 
                                        col = col+1
281
 
                                        if col >=  cols:
282
 
                                                col = 0
283
 
                                                row = row+1
284
 
                        if empty:
285
 
                                categoryContainer[0].get_parent().set_no_show_all(True)
286
 
                                categoryContainer[0].get_parent().hide()
287
 
                        else:
288
 
                                categoryContainer[0].get_parent().set_no_show_all(False)
289
 
                                categoryContainer[0].attach(gtk.Label(), cols+5, cols+6, 0, 1, gtk.EXPAND)
290
 
        
291
 
                # Search in long description
292
 
                if not foundPlugin and target == 0:
293
 
                        self.FilterTable(widget, 1)
294
 
                # Search in category
295
 
                elif not foundPlugin and target == 1:
296
 
                        self.FilterTable(widget, 2)
297
 
                # Nothing found -- Ported from Gnome-Control-Center.
298
 
                elif not foundPlugin and target == 2:
299
 
 
300
 
                        # Already created only update message
301
 
                        if not self.TableAttached:
302
 
                                notFound = self.RightPane.get_child().get_child().get_child().get_children()[-1]
303
 
                                notFound.update(text)
304
 
                                return
305
 
                        
306
 
                        self.TableAttached = False
307
 
                        
308
 
                        box = self.RightPane.get_child().get_child().get_child()
309
 
                        notFound = NotFoundBox(text)
310
 
                        box.pack_start(notFound, True, False)
311
 
                        
312
 
                        self.show_all()
313
 
                # Something found, display it
314
 
                elif foundPlugin:
315
 
                        # Clean up not found Message
316
 
                        if not self.TableAttached:
317
 
                                self.RightPane.get_child().get_child().get_child().get_children()[-1].destroy()
318
 
                        
319
 
                        self.TableAttached = True
320
 
                        self.show_all()
321
 
 
322
 
        def RebuildTable(self, widget, request):
323
 
                cols = (request.width - 60) / 220
324
 
                if cols == self.LastCols:
325
 
                        return
326
 
                
327
 
                self.LastCols = cols
328
 
                if self.TableAttached:
329
 
                        for categoryName, categoryContainer in self.TableCats.items():
330
 
                                for pluginButton in categoryContainer[1]:
331
 
                                        categoryContainer[0].remove(pluginButton)
332
 
                
333
 
                for categoryName, categoryContainer in self.TableCats.items():
334
 
                        col = 0
335
 
                        row = 0
336
 
                        for pluginButton in categoryContainer[1]:
337
 
                                categoryContainer[0].attach(pluginButton, col, col+1, row, row+1, 0)
338
 
                                col = col+1
339
 
                                if col >= cols:
340
 
                                        col = 0
341
 
                                        row = row+1
342
 
                        categoryContainer[0].attach(gtk.Label(), cols+5, cols+6, 0, 1, gtk.EXPAND)
343
 
                self.TableAttached = True
344
 
                self.show_all()
345
 
                self.RightPane.get_child().props.vadjustment.value = self.RightVadj
346
 
 
347
 
        def SetMainWidgets(self, leftWidget, rightWidget):
348
 
                pane = self.LeftPane.get_child()
349
 
                if pane:
350
 
                        pane.destroy()
351
 
                pane = self.RightPane.get_child()
352
 
                if (pane):
353
 
                        pane.destroy()
354
 
                self.LeftPane.add(leftWidget)
355
 
                self.RightPane.add(rightWidget)
356
 
                self.show_all()
357
 
 
358
 
        def CatSortCompare(self, v1, v2):
359
 
                if v1 == v2:
360
 
                        return cmp(v1, v2)
361
 
                if self.Context.Plugins['core'].Category == v1:
362
 
                        return cmp('', v2 or 'zzzzzzzz')
363
 
                if self.Context.Plugins['core'].Category == v2:
364
 
                        return cmp(v1 or 'zzzzzzz', '')
365
 
                return cmp(v1 or 'zzzzzzzz', v2 or 'zzzzzzzz')
366
 
 
367
 
        def ShowPlugin(self, obj, select):
368
 
                self.RightVadj = self.RightPane.get_child().get_vadjustment().get_value()
369
 
                for name, value in self.PluginImages.items():
370
 
                        widget = value.get_parent()
371
 
                        if widget:
372
 
                                widget.remove(value)
373
 
                pluginPage = PluginPage(select, self)
374
 
                self.ShowingPlugin = pluginPage
375
 
                self.SetMainWidgets(pluginPage.LeftWidget, pluginPage.RightWidget)
376
 
        
377
 
        def ShowAdvancedFilter(self, widget, run=0):
378
 
                if run == 0: # Well thats rather a hack but it works...
379
 
                        self.TitleBuffer = self.get_title()
380
 
                        self.set_title(self.TitleBuffer + " - Loading...")
381
 
                        gobject.timeout_add(100, self.ShowAdvancedFilter, widget, 1)
382
 
                        return
383
 
 
384
 
                self.RightVadj = self.RightPane.get_child().get_vadjustment().get_value()
385
 
                for name, value in self.PluginImages.items():
386
 
                        widget = value.get_parent()
387
 
                        if widget:
388
 
                                widget.remove(value)
389
 
                filterPage = FilterPage(self, self.Context)
390
 
                self.SetMainWidgets(filterPage.LeftWidget, filterPage.RightWidget)
391
 
        
392
 
                self.set_title(self.TitleBuffer)
393
 
                self.TitleBuffer = False
394
 
 
395
 
                return False
396
 
        
397
 
        def ShowPreferences(self, widget):
398
 
                self.RightVadj = self.RightPane.get_child().get_vadjustment().get_value()
399
 
                for name, value in self.PluginImages.items():
400
 
                        widget = value.get_parent()
401
 
                        if widget:
402
 
                                widget.remove(value)
403
 
                preferencesPage = PreferencesPage(self, self.Context)
404
 
                self.SetMainWidgets(preferencesPage.LeftWidget, preferencesPage.RightWidget)
405
 
 
406
 
        def UpdatePlugins(self):
407
 
                for category, container, plugins in self.TableCats.values():
408
 
                                for i in range(len(plugins)):
409
 
                                        if plugins[i].Name != 'core':
410
 
                                                check = container[i].get_children()[0]
411
 
                                                self.BlockEnablePlugin += 1
412
 
                                                check.set_active(plugins[i].Enabled)
413
 
                                                self.BlockEnablePlugin -= 1
414
 
        
415
 
        def EnablePlugin(self, widget, plugin):
416
 
                if self.BlockEnablePlugin > 0:
417
 
                        return 
418
 
 
419
 
                # attempt to resolve conflicts...
420
 
                conflicts = plugin.Enabled and plugin.DisableConflicts or plugin.EnableConflicts
421
 
                conflict = PluginConflict(plugin, conflicts)
422
 
                if conflict.Resolve():
423
 
                        plugin.Enabled = widget.get_active()
424
 
                        self.UpdatePlugins()
425
 
                else:
426
 
                        widget.set_active(plugin.Enabled)
427
 
                plugin.Context.Write()
428
 
 
429
 
        def ToggleCategory(self, widget, category):
430
 
                categoryContainer = self.TableCats[category]
431
 
                categoryY = categoryContainer[0].get_parent().get_allocation().y
432
 
                parentY = self.RightPane.get_child().get_allocation().y
433
 
                parentHeight = self.RightPane.get_child().get_allocation().height
434
 
                categoryBox = self.RightPane.get_child().get_child().get_child()
435
 
                boxHeight = categoryBox.get_allocation().height
436
 
                posY = categoryY - parentY
437
 
                neededHeight = posY + parentHeight
438
 
                if neededHeight > boxHeight:
439
 
                        posY =  boxHeight - parentHeight
440
 
                self.RightPane.get_child().props.vadjustment.value = posY
441
 
        
442
 
        def ScreenChanged(self, widget):
443
 
                self.Context.Write()
444
 
                self.CurrentScreenNum = widget.get_active()
445
 
                self.Context.Read()
446
 
 
447
 
        def BackToMain(self, obj):
448
 
                self.VisibleSettings = []
449
 
                self.ResetMainWidgets()
450
 
                del self.ShowingPlugin
451
 
                # make sure its cleaned up here, since this is a nice safe place to do so
452
 
                self.ShowingPlugin = None
 
39
    def __init__(self, Context):
 
40
        gtk.Window.__init__(self)
 
41
        self.ShowingPlugin = None
 
42
        self.Context = Context
 
43
        self.connect("destroy", self.Quit)
 
44
        self.set_default_size(960, 580)
 
45
        self.set_title(_("CompizConfig Settings Manager"))
 
46
        try:
 
47
            self.set_icon (gtk.gdk.pixbuf_new_from_file(IconDir+"/apps/ccsm.svg"))
 
48
        except:
 
49
            pass
 
50
        
 
51
        self.Style = Style()
 
52
        
 
53
        # build the panes
 
54
        self.MainBox = gtk.HBox()
 
55
        self.add(self.MainBox)
 
56
        self.LeftPane = gtk.Alignment()
 
57
        self.LeftPane.set_size_request(230, 520)
 
58
        self.RightPane = gtk.Alignment()
 
59
        self.RightPane.set_border_width(5)
 
60
        self.RightPane.props.yscale = 1
 
61
        self.RightPane.props.xscale = 1
 
62
        self.RightPane.props.xalign = 0
 
63
        self.RightPane.props.yalign = 0
 
64
        self.LeftPane.props.yscale = 1
 
65
        self.LeftPane.props.xscale = 1
 
66
        self.LeftPane.props.xalign = 0
 
67
        self.LeftPane.props.yalign = 0
 
68
        self.MainBox.pack_start(self.LeftPane, False, False)
 
69
        self.MainBox.pack_start(self.RightPane, True, True)
 
70
        self.Categories = {}
 
71
        self.PluginImages = {}
 
72
        self.RightVadj = 0.0
 
73
        
 
74
        for pluginName, plugin in self.Context.Plugins.items():
 
75
            self.PluginImages[pluginName] = Image(plugin.Name, ImagePlugin)
 
76
        
 
77
        for category in sorted(self.Context.Categories, self.CatSortCompare):
 
78
            self.Categories[category] = []
 
79
            for pluginName, plugin in self.Context.Plugins.items():
 
80
                if plugin.Category == category:
 
81
                    self.Categories[category].append(plugin)
 
82
        
 
83
        self.BlockEnablePlugin = 0
 
84
        self.ResetMainWidgets()
 
85
 
 
86
    def Quit(self, *args):
 
87
        gtk.main_quit()
 
88
 
 
89
    def ResetMainWidgets(self):
 
90
        pluginsVPort = gtk.Viewport()
 
91
        leftChild = gtk.VBox(False, 10)
 
92
        leftChild.set_border_width(15)
 
93
        
 
94
        # Filter
 
95
        filterLabel = Label()
 
96
        filterLabel.set_markup("<span color='%s' size='large' weight='800'>%s</span>" % (self.Style.BrightColor, _("Filter")))
 
97
        filterLabel.props.xalign = 0.1
 
98
        if has_sexy:
 
99
            filterEntry = sexy.IconEntry()
 
100
            filterEntry.add_clear_button()
 
101
        else:
 
102
            filterEntry = gtk.Entry()
 
103
        Tooltips.set_tip(filterEntry, _("Filter your Plugin list"))
 
104
        filterEntry.connect("changed", self.FilterTable)
 
105
        leftChild.pack_start(filterLabel, False, False)
 
106
        leftChild.pack_start(filterEntry, False, False)
 
107
 
 
108
        # Screens
 
109
        if len(getScreens()) > 1:
 
110
            screenBox = gtk.combo_box_new_text()
 
111
            for screen in getScreens():
 
112
                screenBox.append_text(_("Screen %i") % screen)
 
113
            name = self.Context.CurrentBackend.Name
 
114
            screenBox.set_active(CurrentScreenNum)
 
115
            screenBox.connect("changed", self.ScreenChanged)
 
116
            screenLabel = Label()
 
117
            screenLabel.set_markup("<span color='%s' size='large' weight='800'>%s</span>" % (self.Style.BrightColor, _("Screen")))
 
118
            leftChild.pack_start(screenLabel, False, False)
 
119
            leftChild.pack_start(screenBox, False, False)
 
120
 
 
121
        # Categories
 
122
        categoryBox = gtk.VBox()
 
123
        categoryBox.set_border_width(10)
 
124
        for category in sorted(self.Categories, self.CatSortCompare):
 
125
            name = category or _("Uncategorized")
 
126
            categoryToggleLabel = Label(name)
 
127
            categoryToggle = PrettyButton()
 
128
            categoryToggle.set_relief(gtk.RELIEF_NONE)
 
129
            categoryToggle.add(categoryToggleLabel)
 
130
            categoryToggle.connect("clicked", self.ToggleCategory, category)
 
131
            categoryBox.pack_start(categoryToggle, False, False)
 
132
        categoryLabel = Label()
 
133
        categoryLabel.props.xalign = 0.1
 
134
        categoryLabel.set_markup("<span color='%s' size='large' weight='800'>%s</span>" % (self.Style.BrightColor, _("Category")))
 
135
        leftChild.pack_start(categoryLabel, False, False)
 
136
        leftChild.pack_start(categoryBox, False, False)
 
137
 
 
138
        # Exit Button
 
139
        exitButton = gtk.Button(gtk.STOCK_CLOSE)
 
140
        exitButton.set_use_stock(True)
 
141
        exitButton.connect('clicked', self.Quit)
 
142
        leftChild.pack_end(exitButton, False, False)
 
143
 
 
144
        # Advanced Search
 
145
        searchLabel = Label()
 
146
        searchLabel.set_markup("<span color='%s' size='large' weight='800'>%s</span>" % (self.Style.BrightColor, _("Advanced Search")))
 
147
        searchImage = gtk.Image()
 
148
        searchImage.set_from_stock(gtk.STOCK_GO_FORWARD, gtk.ICON_SIZE_BUTTON)
 
149
        searchButton = gtk.Button()
 
150
        searchButton.connect("clicked", self.ShowAdvancedFilter)
 
151
        searchButton.set_relief(gtk.RELIEF_NONE)
 
152
        searchFrame = gtk.HBox()
 
153
        searchFrame.pack_start(searchLabel, False, False)
 
154
        searchFrame.pack_end(searchImage, False, False)
 
155
        searchButton.add(searchFrame)
 
156
        leftChild.pack_end(searchButton, False, False)
 
157
 
 
158
        # Preferences
 
159
        prefLabel = Label()
 
160
        prefLabel.set_markup("<span color='%s' size='large' weight='800'>%s</span>" % (self.Style.BrightColor, _("Preferences")))
 
161
        prefImage = gtk.Image()
 
162
        prefImage.set_from_stock(gtk.STOCK_GO_FORWARD, gtk.ICON_SIZE_BUTTON)
 
163
        prefButton = gtk.Button()
 
164
        prefButton.connect("clicked", self.ShowPreferences)
 
165
        prefButton.set_relief(gtk.RELIEF_NONE)
 
166
        prefFrame = gtk.HBox()
 
167
        prefFrame.pack_start(prefLabel, False, False)
 
168
        prefFrame.pack_end(prefImage, False, False)
 
169
        prefButton.add(prefFrame)
 
170
        leftChild.pack_end(prefButton, False, False)
 
171
 
 
172
        pluginsVPort.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.Style.BackgroundColor))
 
173
        rightChild = gtk.ScrolledWindow()
 
174
        rightChild.props.hscrollbar_policy = gtk.POLICY_NEVER
 
175
        rightChild.props.vscrollbar_policy = gtk.POLICY_AUTOMATIC
 
176
        rightChild.set_size_request(280,-1)
 
177
        pluginsVPort.set_focus_vadjustment (rightChild.get_vadjustment ())
 
178
        rightChild.add(pluginsVPort)
 
179
        self.BuildTable(pluginsVPort)
 
180
        rightChild.connect('size-allocate', self.RebuildTable)
 
181
        self.SetMainWidgets(leftChild, rightChild)
 
182
 
 
183
    def BuildTable(self, viewPort):
 
184
        pluginWindow = gtk.VBox()
 
185
        pluginWindow.set_border_width(10)
 
186
        viewPort.add(pluginWindow)
 
187
 
 
188
        self.TableCats = {}
 
189
        self.TableAttached = False
 
190
        self.LastCols = -1
 
191
        for category in sorted(self.Categories, self.CatSortCompare):
 
192
            pluginList = sorted(self.Categories[category], PluginSortCompare)
 
193
            categoryBox = gtk.VBox()
 
194
            categoryHeader = gtk.HBox()
 
195
            categoryHeader.set_spacing(10)
 
196
            categoryLabel = Label('', -1)
 
197
            pluginWindow.pack_start(categoryBox, False, False)
 
198
 
 
199
            name = category or _("Uncategorized")
 
200
            categoryLabel.set_markup("<span color='#aaa' size='x-large' weight='800'>%s</span>" % name)
 
201
            categoryImg = Image(name.lower().replace(" ", "_"), ImageCategory)
 
202
            if categoryImg:
 
203
                categoryHeader.pack_start(categoryImg, False, False)
 
204
            categoryHeader.pack_start(categoryLabel, False, False)
 
205
            categoryBox.pack_start(categoryHeader, False, False)
 
206
            
 
207
            categoryTab = gtk.Table()
 
208
            categoryTab.set_border_width(10)
 
209
            self.TableCats[category] = (categoryTab, [], [])
 
210
            categoryBox.pack_start(categoryTab, False, False)
 
211
            
 
212
            for plugin in pluginList:
 
213
                pluginButton = PrettyButton ()
 
214
                pluginButton.connect('clicked', self.ShowPlugin, plugin)
 
215
                pluginButton.set_size_request(200, -1)
 
216
                pluginButtonBox = gtk.HBox(False, 10)
 
217
                pluginButtonBox.set_border_width(10)
 
218
                pluginImage = self.PluginImages[plugin.Name]
 
219
                pluginLabel = Label(plugin.ShortDesc, 120)
 
220
                pluginButtonBox.pack_start(pluginImage, False, False)
 
221
                pluginButtonBox.pack_start(pluginLabel, True, True)
 
222
                pluginButton.add(pluginButtonBox)
 
223
                pluginBox = gtk.HBox()
 
224
 
 
225
                if plugin.Name !=  'core':
 
226
                    pluginEnable = gtk.CheckButton()
 
227
                    Tooltips.set_tip(pluginEnable, _("Enable %s") % plugin.ShortDesc)
 
228
                    pluginEnable.set_active(plugin.Enabled)
 
229
                    pluginEnable.connect("toggled", self.EnablePlugin, plugin)
 
230
                    pluginEnable.set_sensitive(self.Context.AutoSort)
 
231
                    pluginBox.pack_start(pluginEnable, False, False)
 
232
 
 
233
                Tooltips.set_tip(pluginButton, plugin.LongDesc)
 
234
                pluginBox.pack_start(pluginButton, True, True)
 
235
                pluginBox.set_size_request(220, -1)
 
236
                self.TableCats[category][1].append(pluginBox)
 
237
                self.TableCats[category][2].append(plugin)
 
238
 
 
239
    # targets:
 
240
    # 0 = plugin name and short description
 
241
    # 1 = plugin long description
 
242
    # 2 = category
 
243
    def FilterTable(self, widget, target=0):
 
244
        text = widget.get_text().lower()
 
245
        cols = self.LastCols
 
246
        foundPlugin = False
 
247
 
 
248
        if self.TableAttached:
 
249
            for categoryName, categoryContainer in self.TableCats.items():
 
250
                for pluginButton in categoryContainer[1]:
 
251
                    if pluginButton.get_parent():
 
252
                        categoryContainer[0].remove(pluginButton)
 
253
 
 
254
        for categoryName, categoryContainer in self.TableCats.items():
 
255
            col = 0
 
256
            row = 0
 
257
            empty = True
 
258
            for pluginButton in categoryContainer[1]:
 
259
                index = categoryContainer[1].index(pluginButton)
 
260
                shortDesc = categoryContainer[2][index].ShortDesc.lower()
 
261
                longDesc = categoryContainer[2][index].LongDesc.lower()
 
262
                name = categoryContainer[2][index].Name.lower()
 
263
                category = categoryName.lower()
 
264
                show = False
 
265
 
 
266
                if target == 0:
 
267
                    show = name.find(text) != -1 \
 
268
                    or shortDesc.find(text) != -1
 
269
                elif target == 1:
 
270
                    show = name.find(text) != -1 \
 
271
                    or shortDesc.find(text) != -1 \
 
272
                    or longDesc.find(text) != -1
 
273
                elif target == 2:
 
274
                    show = category.find(text) != -1
 
275
 
 
276
                if show:
 
277
                    empty = False
 
278
                    foundPlugin = True
 
279
                    categoryContainer[0].attach(pluginButton, col, col+1, row, row+1, 0)
 
280
                    col = col+1
 
281
                    if col >=  cols:
 
282
                        col = 0
 
283
                        row = row+1
 
284
            if empty:
 
285
                categoryContainer[0].get_parent().set_no_show_all(True)
 
286
                categoryContainer[0].get_parent().hide()
 
287
            else:
 
288
                categoryContainer[0].get_parent().set_no_show_all(False)
 
289
                categoryContainer[0].attach(gtk.Label(), cols+5, cols+6, 0, 1, gtk.EXPAND)
 
290
    
 
291
        # Search in long description
 
292
        if not foundPlugin and target == 0:
 
293
            self.FilterTable(widget, 1)
 
294
        # Search in category
 
295
        elif not foundPlugin and target == 1:
 
296
            self.FilterTable(widget, 2)
 
297
        # Nothing found -- Ported from Gnome-Control-Center.
 
298
        elif not foundPlugin and target == 2:
 
299
 
 
300
            # Already created only update message
 
301
            if not self.TableAttached:
 
302
                notFound = self.RightPane.get_child().get_child().get_child().get_children()[-1]
 
303
                notFound.update(text)
 
304
                return
 
305
            
 
306
            self.TableAttached = False
 
307
            
 
308
            box = self.RightPane.get_child().get_child().get_child()
 
309
            notFound = NotFoundBox(text)
 
310
            box.pack_start(notFound, True, False)
 
311
            
 
312
            self.show_all()
 
313
        # Something found, display it
 
314
        elif foundPlugin:
 
315
            # Clean up not found Message
 
316
            if not self.TableAttached:
 
317
                self.RightPane.get_child().get_child().get_child().get_children()[-1].destroy()
 
318
            
 
319
            self.TableAttached = True
 
320
            self.show_all()
 
321
 
 
322
    def RebuildTable(self, widget, request):
 
323
        cols = (request.width - 60) / 220
 
324
        if cols == self.LastCols:
 
325
            return
 
326
        
 
327
        self.LastCols = cols
 
328
        if self.TableAttached:
 
329
            for categoryName, categoryContainer in self.TableCats.items():
 
330
                for pluginButton in categoryContainer[1]:
 
331
                    categoryContainer[0].remove(pluginButton)
 
332
        
 
333
        for categoryName, categoryContainer in self.TableCats.items():
 
334
            col = 0
 
335
            row = 0
 
336
            for pluginButton in categoryContainer[1]:
 
337
                categoryContainer[0].attach(pluginButton, col, col+1, row, row+1, 0)
 
338
                col = col+1
 
339
                if col >= cols:
 
340
                    col = 0
 
341
                    row = row+1
 
342
            categoryContainer[0].attach(gtk.Label(), cols+5, cols+6, 0, 1, gtk.EXPAND)
 
343
        self.TableAttached = True
 
344
        self.show_all()
 
345
        self.RightPane.get_child().props.vadjustment.value = self.RightVadj
 
346
 
 
347
    def SetMainWidgets(self, leftWidget, rightWidget):
 
348
        pane = self.LeftPane.get_child()
 
349
        if pane:
 
350
            pane.destroy()
 
351
        pane = self.RightPane.get_child()
 
352
        if (pane):
 
353
            pane.destroy()
 
354
        self.LeftPane.add(leftWidget)
 
355
        self.RightPane.add(rightWidget)
 
356
        self.show_all()
 
357
 
 
358
    def CatSortCompare(self, v1, v2):
 
359
        if v1 == v2:
 
360
            return cmp(v1, v2)
 
361
        if self.Context.Plugins['core'].Category == v1:
 
362
            return cmp('', v2 or 'zzzzzzzz')
 
363
        if self.Context.Plugins['core'].Category == v2:
 
364
            return cmp(v1 or 'zzzzzzz', '')
 
365
        return cmp(v1 or 'zzzzzzzz', v2 or 'zzzzzzzz')
 
366
 
 
367
    def ShowPlugin(self, obj, select):
 
368
        self.RightVadj = self.RightPane.get_child().get_vadjustment().get_value()
 
369
        for name, value in self.PluginImages.items():
 
370
            widget = value.get_parent()
 
371
            if widget:
 
372
                widget.remove(value)
 
373
        pluginPage = PluginPage(select, self)
 
374
        self.ShowingPlugin = pluginPage
 
375
        self.SetMainWidgets(pluginPage.LeftWidget, pluginPage.RightWidget)
 
376
    
 
377
    def ShowAdvancedFilter(self, widget, run=0):
 
378
        if run == 0: # Well thats rather a hack but it works...
 
379
            self.TitleBuffer = self.get_title()
 
380
            self.set_title(self.TitleBuffer + " - Loading...")
 
381
            gobject.timeout_add(100, self.ShowAdvancedFilter, widget, 1)
 
382
            return
 
383
 
 
384
        self.RightVadj = self.RightPane.get_child().get_vadjustment().get_value()
 
385
        for name, value in self.PluginImages.items():
 
386
            widget = value.get_parent()
 
387
            if widget:
 
388
                widget.remove(value)
 
389
        filterPage = FilterPage(self, self.Context)
 
390
        self.SetMainWidgets(filterPage.LeftWidget, filterPage.RightWidget)
 
391
    
 
392
        self.set_title(self.TitleBuffer)
 
393
        self.TitleBuffer = False
 
394
 
 
395
        return False
 
396
    
 
397
    def ShowPreferences(self, widget):
 
398
        self.RightVadj = self.RightPane.get_child().get_vadjustment().get_value()
 
399
        for name, value in self.PluginImages.items():
 
400
            widget = value.get_parent()
 
401
            if widget:
 
402
                widget.remove(value)
 
403
        preferencesPage = PreferencesPage(self, self.Context)
 
404
        self.SetMainWidgets(preferencesPage.LeftWidget, preferencesPage.RightWidget)
 
405
 
 
406
    def UpdatePlugins(self):
 
407
        for category, container, plugins in self.TableCats.values():
 
408
                for i in range(len(plugins)):
 
409
                    if plugins[i].Name != 'core':
 
410
                        check = container[i].get_children()[0]
 
411
                        self.BlockEnablePlugin += 1
 
412
                        check.set_active(plugins[i].Enabled)
 
413
                        self.BlockEnablePlugin -= 1
 
414
    
 
415
    def EnablePlugin(self, widget, plugin):
 
416
        if self.BlockEnablePlugin > 0:
 
417
            return 
 
418
 
 
419
        # attempt to resolve conflicts...
 
420
        conflicts = plugin.Enabled and plugin.DisableConflicts or plugin.EnableConflicts
 
421
        conflict = PluginConflict(plugin, conflicts)
 
422
        if conflict.Resolve():
 
423
            plugin.Enabled = widget.get_active()
 
424
            self.UpdatePlugins()
 
425
        else:
 
426
            self.BlockEnablePlugin += 1
 
427
            widget.set_active(plugin.Enabled)
 
428
            self.BlockEnablePlugin -= 1
 
429
        plugin.Context.Write()
 
430
 
 
431
    def ToggleCategory(self, widget, category):
 
432
        categoryContainer = self.TableCats[category]
 
433
        categoryY = categoryContainer[0].get_parent().get_allocation().y
 
434
        parentY = self.RightPane.get_child().get_allocation().y
 
435
        parentHeight = self.RightPane.get_child().get_allocation().height
 
436
        categoryBox = self.RightPane.get_child().get_child().get_child()
 
437
        boxHeight = categoryBox.get_allocation().height
 
438
        posY = categoryY - parentY
 
439
        neededHeight = posY + parentHeight
 
440
        if neededHeight > boxHeight:
 
441
            posY =  boxHeight - parentHeight
 
442
        self.RightPane.get_child().props.vadjustment.value = posY
 
443
    
 
444
    def ScreenChanged(self, widget):
 
445
        self.Context.Write()
 
446
        self.CurrentScreenNum = widget.get_active()
 
447
        self.Context.Read()
 
448
 
 
449
    def BackToMain(self, obj):
 
450
        self.VisibleSettings = []
 
451
        self.ResetMainWidgets()
 
452
        del self.ShowingPlugin
 
453
        # make sure its cleaned up here, since this is a nice safe place to do so
 
454
        self.ShowingPlugin = None