#! @PYTHON@ @PYOPTIONS@ # -*- python -*- # -*- coding: utf-8 -*- # Desktop Effects Settings - Configure desktop effects # Copyright (c) 2007 Travis Watkins # Based on libslab, Copyright (c) 2006 Novell, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import gtk from desktopeffects import backend, tile, plugintile, section, shellwindow, appresizer import sys class Category(object): category = '' group_launcher = None section = None launcher_list = None filtered_launcher_list = [] class AppShell(gtk.Window): category_list = [] selected_group = None category_sort = { 'Desktop': ('core', 'clone', 'cube', 'plane', 'rotate', 'showdesktop'), 'Development': ('crashhandler', 'inotify'), 'Extras': ( 'annotate', 'benchmark', 'dbus', 'screenshot', 'snow', 'splash', 'water' ), 'Image Format': ('png', 'svg', 'jpg'), 'Visual Effects': ( '3d', 'animation', 'blur', 'blurfx', 'fade', 'trailfocus', 'decoration', 'wobbly', 'inputzoom', 'zoom', 'neg', 'opacify' ), 'Window Management': ( 'switcher', 'move', 'place', 'put', 'resize', 'scale', 'state', 'minimize' ) } advanced_plugins = ('clone', 'crashhandler', 'inotify', 'benchmark', 'dbus', 'png', 'svg', 'jpg', 'put', 'place', 'state', 'gconf', 'keybinding', 'gconf-dump') show_advanced = False def __init__(self): super(AppShell, self).__init__() self.set_title('Desktop Effects Settings') self.connect('delete-event', self.on_delete_event) self.set_position(gtk.WIN_POS_CENTER) self.context = backend.Context() self.generateCategories() self.layoutShell() self.show_all() gtk.main() def on_delete_event(self, widget, event): gtk.main_quit() def layoutShell(self): self.shell = shellwindow.ShellWindow(self) right_vbox = gtk.VBox() self.num_cols = 3 if gtk.gdk.screen_width() <= 1024: if gtk.gdk.screen_width() <= 800: self.num_cols = 1 else: self.num_cols = 2 self.category_layout = appresizer.AppResizer(right_vbox, self.num_cols, self) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.set_shadow_type(gtk.SHADOW_IN) sw.add(self.category_layout) adjustment = sw.get_vadjustment() adjustment.set_property('step-increment', 20) self.populateApplicationCategorySections(right_vbox) self.category_layout.setTableCache(self.cached_tables_list) right_vbox.set_focus_vadjustment(sw.get_vadjustment()) left_vbox = gtk.VBox(False, 15) self.filter_section = self.createFilterSection() left_vbox.pack_start(self.filter_section, False, False) self.groups_section = self.createGroupsSection() self.populateGroupsSection() left_vbox.pack_start(self.groups_section, False, False) self.advanced_section = self.createAdvancedSection() left_vbox.pack_start(self.advanced_section, False, False) self.shell.setContents(left_vbox, sw) self.add(self.shell) def generateCategories(self): for category in self.category_list: category.destroy() categories = self.category_sort.keys() categories.sort() plugins = self.context.getPlugins() plugins.sort(self.pluginCmp) for name in categories: category = Category() category.category = name category.group_launcher = tile.Tile(header=name) category.section = section.Section(name, 2) category.launcher_list = self.generateLauncherList(name, plugins) category.filtered_launcher_list = list(category.launcher_list) hbox = gtk.HBox() table = gtk.Table(1, 1, True) table.set_col_spacings(5) table.set_row_spacings(5) hbox.pack_start(table, False, False, 15) category.section.setContents(hbox) self.category_list.append(category) #unsorted plugins go into 'Other' category = Category() category.category = 'Other' category.group_launcher = tile.Tile(header='Other') category.section = section.Section('Other', 2) plugin_launchers = [] keys = self.category_sort.keys() plugin_list = [] for key in keys: plugin_list += self.category_sort[key] for plugin in plugins: if plugin.getName() not in plugin_list: if not self.show_advanced and plugin.getName() in self.advanced_plugins: continue plugin_launchers.append(plugintile.PluginTile(plugin)) plugin_launchers[-1].set_size_request(230, -1) category.launcher_list = plugin_launchers category.filtered_launcher_list = list(category.launcher_list) hbox = gtk.HBox() table = gtk.Table(1, 1, True) table.set_col_spacings(5) table.set_row_spacings(5) hbox.pack_start(table, False, False, 15) category.section.setContents(hbox) self.category_list.append(category) def pluginCmp(self, a, b): return cmp(a.getMetadata()['short_desc'].lower(), b.getMetadata()['short_desc'].lower()) def generateLauncherList(self, category_name, plugins): plugin_launchers = [] for plugin in plugins: if plugin.getName() in self.category_sort[category_name]: if not self.show_advanced and plugin.getName() in self.advanced_plugins: continue plugin_launchers.append(plugintile.PluginTile(plugin)) plugin_launchers[-1].set_size_request(230, -1) return plugin_launchers def populateApplicationCategorySections(self, container): filtered_out_everything = True self.cached_tables_list = [] for child in container.get_children(): container.remove(child) for category in self.category_list: if len(category.filtered_launcher_list): self.populateApplicationCategorySection(category.section, category.filtered_launcher_list) container.pack_start(category.section) filtered_out_everything = False def populateApplicationCategorySection(self, section, launcher_list): table = section.contents.get_children()[0] self.cached_tables_list.append(table) self.category_layout.layoutTableDefault(table, launcher_list) def createFilterSection(self): filter_section = section.Section('Filter', 1) hbox = gtk.HBox(False, 3) alignment = gtk.Alignment(0, 0.5, 1, 0) hbox.pack_start(alignment) entry = gtk.Entry() alignment.add(entry) filter_section.setContents(hbox) return filter_section def createGroupsSection(self): groups_section = section.Section('Groups', 1) vbox = gtk.VBox() groups_section.setContents(vbox) return groups_section def populateGroupsSection(self): for category in self.category_list: if len(category.filtered_launcher_list): category.group_launcher.set_state(gtk.STATE_NORMAL) self.groups_section.contents.pack_start( category.group_launcher, False, False) def createAdvancedSection(self): advanced_section = section.Section('', 1) vbox = gtk.VBox() advanced_section.setContents(vbox) advanced_tile = tile.Tile(header='Show/Hide Advanced Options', ellipsize=False) vbox.pack_start(advanced_tile, False, False) return advanced_section foo = AppShell()