home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.4)
-
- import os
- import os.path as os
- import gtk
- import gtk.gdk as gtk
- import gmenu
-
- def lookup_system_menu_file(menu_file):
- conf_dirs = None
- if os.environ.has_key('XDG_CONFIG_DIRS'):
- conf_dirs = os.environ['XDG_CONFIG_DIRS']
-
- if not conf_dirs:
- conf_dirs = '/etc/xdg'
-
- for conf_dir in conf_dirs.split(':'):
- menu_file_path = os.path.join(conf_dir, 'menus', menu_file)
- if os.path.isfile(menu_file_path):
- return menu_file_path
- continue
-
-
-
- def load_icon_from_path(icon_path):
- if os.path.isfile(icon_path):
-
- try:
- return gtk.gdk.pixbuf_new_from_file_at_size(icon_path, 24, 24)
-
-
-
-
- def load_icon_from_data_dirs(icon_value):
- data_dirs = None
- if os.environ.has_key('XDG_DATA_DIRS'):
- data_dirs = os.environ['XDG_DATA_DIRS']
-
- if not data_dirs:
- data_dirs = '/usr/local/share/:/usr/share/'
-
- for data_dir in data_dirs.split(':'):
- retval = load_icon_from_path(os.path.join(data_dir, 'pixmaps', icon_value))
- if retval:
- return retval
-
- retval = load_icon_from_path(os.path.join(data_dir, 'icons', icon_value))
- if retval:
- return retval
- continue
-
-
-
- def load_icon(icon_theme, icon_value):
- if not icon_value:
- return None
-
- if os.path.isabs(icon_value):
- icon = load_icon_from_path(icon_value)
- if icon:
- return icon
-
- icon_name = os.path.basename(icon_value)
- else:
- icon_name = icon_value
- if icon_name.endswith('.png'):
- icon_name = icon_name[:-len('.png')]
- elif icon_name.endswith('.xpm'):
- icon_name = icon_name[:-len('.xpm')]
- elif icon_name.endswith('.svg'):
- icon_name = icon_name[:-len('.svg')]
-
-
- try:
- return icon_theme.load_icon(icon_name, 24, 0)
- except:
- return load_icon_from_data_dirs(icon_value)
-
-
-
- class MenuTreeModel(gtk.TreeStore):
- (COLUMN_IS_ENTRY, COLUMN_ID, COLUMN_NAME, COLUMN_ICON, COLUMN_MENU_FILE, COLUMN_SYSTEM_VISIBLE, COLUMN_USER_VISIBLE) = range(7)
-
- def __init__(self, menu_files):
- gtk.TreeStore.__init__(self, bool, str, str, gtk.gdk.Pixbuf, str, bool, bool)
- self.entries_list_iter = None
- self.icon_theme = gtk.icon_theme_get_default()
- if len(menu_files) < 1:
- menu_files = [
- 'applications.menu',
- 'settings.menu']
-
- for menu_file in menu_files:
- tree = gmenu.lookup_tree(menu_file, gmenu.FLAGS_INCLUDE_EXCLUDED)
- self._MenuTreeModel__append_directory(tree.root, None, False, menu_file)
- system_file = lookup_system_menu_file(menu_file)
- if system_file:
- system_tree = gmenu.lookup_tree(system_file, gmenu.FLAGS_INCLUDE_EXCLUDED)
- self._MenuTreeModel__append_directory(system_tree.root, None, True, menu_file)
- continue
-
-
-
- def __append_directory(self, directory, parent_iter, system, menu_file):
- if not directory:
- return None
-
- iter = self.iter_children(parent_iter)
- while iter:
- if self[iter][self.COLUMN_ID] == directory.menu_id:
- break
-
- iter = self.iter_next(iter)
- if not iter:
- iter = self.append(parent_iter)
- self[iter][self.COLUMN_IS_ENTRY] = False
- self[iter][self.COLUMN_ID] = directory.menu_id
- self[iter][self.COLUMN_NAME] = directory.name
- self[iter][self.COLUMN_ICON] = load_icon(self.icon_theme, directory.icon)
- if menu_file is not None:
- self[iter][self.COLUMN_MENU_FILE] = menu_file
-
-
- if system:
- self[iter][self.COLUMN_SYSTEM_VISIBLE] = True
- else:
- self[iter][self.COLUMN_USER_VISIBLE] = True
- for child_item in directory.contents:
- if isinstance(child_item, gmenu.Directory):
- self._MenuTreeModel__append_directory(child_item, iter, system, None)
-
- if not isinstance(child_item, gmenu.Entry):
- continue
-
- child_iter = self.iter_children(iter)
- while child_iter:
- if child_item.type == gmenu.TYPE_ENTRY and self[child_iter][self.COLUMN_IS_ENTRY] and self[child_iter][self.COLUMN_ID] == child_item.desktop_file_id:
- break
-
- child_iter = self.iter_next(child_iter)
- if not child_iter:
- child_iter = self.append(iter)
- self[child_iter][self.COLUMN_IS_ENTRY] = True
- self[child_iter][self.COLUMN_ID] = child_item.desktop_file_id
- self[child_iter][self.COLUMN_NAME] = child_item.name
- self[child_iter][self.COLUMN_ICON] = load_icon(self.icon_theme, child_item.icon)
-
- if system:
- self[child_iter][self.COLUMN_SYSTEM_VISIBLE] = not (child_item.is_excluded)
- continue
- self[child_iter][self.COLUMN_USER_VISIBLE] = not (child_item.is_excluded)
-
-
-
-