~ubuntu-branches/ubuntu/oneiric/gnome-menus/oneiric-201106291711

« back to all changes in this revision

Viewing changes to simple-editor/GMenuSimpleEditor/menutreemodel.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya, Josselin Mouette, Rodrigo Moya
  • Date: 2011-05-16 12:24:57 UTC
  • mfrom: (1.1.55 upstream) (2.1.14 experimental)
  • Revision ID: james.westby@ubuntu.com-20110516122457-xsdc47g3cj6d3cra
Tags: 3.0.0-0ubuntu1
[ Josselin Mouette ]
* Break alacarte < 0.13.2-2 (version without support for 
  settings.menu).

[ Rodrigo Moya ]
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Use Standards-Version: 3.8.4
  - Depends: python-xdg for update-gnome-menus-cache
  - Add python-gmenu-dbg package
* debian/gnome-menus.triggers:
  - Add gmenucache trigger
* debian/gnome-menus.postinst:
  - Disable blacklist to not break old applications
* debian/update-gnome-menus-cache:
  - Script to update the menu cache
* debian/python-gmenu.postinst:
  - Add code to generate the menu cache
* debian/patches/06_menus_rename.patch:
  - Rename applications.menu to gnome-applications.menu
* debian/patches/09_app_install_entry.patch:
  - Include Software Center in menus
* debian/patches/22_desktop-cache.patch:
  - Support a desktop.<localename>.cache file in e. g.
    /usr/share/applications/ to speed up menu loading. Those
    are generated with update-gnome-menus-cache <dir>.
* debian/patches/23_add_inherited_gnome_session.patch:
  - Add inherited GNOME session
* debian/patches/*:
  - Add missing descriptions to Ubuntu-specific patches
* debian/patches/series:
  - Disable 01_default_prefix.patch, which is Debian specific

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import os
20
20
import os.path
21
 
import gtk
22
 
import gtk.gdk
 
21
import gobject
 
22
from gi.repository import Gtk
 
23
from gi.repository import GdkPixbuf
23
24
import gmenu
24
25
 
25
26
def lookup_system_menu_file (menu_file):
39
40
def load_icon_from_path (icon_path):
40
41
    if os.path.isfile (icon_path):
41
42
        try:
42
 
            return gtk.gdk.pixbuf_new_from_file_at_size (icon_path, 24, 24)
 
43
            return GdkPixbuf.new_from_file_at_size (icon_path, 24, 24)
43
44
        except:
44
45
            pass
45
46
    return None
85
86
    except:
86
87
        return load_icon_from_data_dirs (icon_value)
87
88
 
88
 
class MenuTreeModel (gtk.TreeStore):
 
89
class MenuTreeModel (Gtk.TreeStore):
89
90
    (
90
91
        COLUMN_IS_ENTRY,
91
92
        COLUMN_ID,
97
98
    ) = range (7)
98
99
 
99
100
    def __init__ (self, menu_files):
100
 
        gtk.TreeStore.__init__ (self, bool, str, str, gtk.gdk.Pixbuf, str, bool, bool)
 
101
        Gtk.TreeStore.__init__ (self, bool, str, str, GdkPixbuf.Pixbuf, str, bool, bool)
101
102
 
102
103
        self.entries_list_iter = None
103
104
        
104
 
        self.icon_theme = gtk.icon_theme_get_default ()
 
105
        self.icon_theme = Gtk.IconTheme.get_default ()
105
106
 
106
107
        if (len (menu_files) < 1):
107
108
            menu_files = ["applications.menu", "settings.menu"]
125
126
            return
126
127
        
127
128
        iter = self.iter_children (parent_iter)
128
 
        while iter:
129
 
            if self[iter][self.COLUMN_ID] == directory.menu_id:
 
129
        while iter is not None:
 
130
            if self.get_value(iter, self.COLUMN_ID) == directory.menu_id:
130
131
                break
131
132
            iter = self.iter_next (iter)
132
133
 
133
 
        if not iter:
134
 
            iter = self.append (parent_iter)
135
 
 
136
 
            self[iter][self.COLUMN_IS_ENTRY] = False
137
 
            self[iter][self.COLUMN_ID]       = directory.menu_id
138
 
            self[iter][self.COLUMN_NAME]     = directory.name
139
 
            self[iter][self.COLUMN_ICON]     = load_icon (self.icon_theme, directory.icon)
140
 
 
141
 
            if not menu_file is None:
142
 
                self[iter][self.COLUMN_MENU_FILE] = menu_file
 
134
        if iter is None:
 
135
            row = (False, directory.menu_id, directory.name, load_icon (self.icon_theme, directory.icon), menu_file, False, False)
 
136
            iter = self.append (parent_iter, row)
143
137
 
144
138
        if system:
145
 
            self[iter][self.COLUMN_SYSTEM_VISIBLE] = True
 
139
            self.set_value (iter, self.COLUMN_SYSTEM_VISIBLE, True)
146
140
        else:
147
 
            self[iter][self.COLUMN_USER_VISIBLE]   = True
148
 
        
 
141
            self.set_value (iter, self.COLUMN_USER_VISIBLE, True)
 
142
 
149
143
        for child_item in directory.contents:
150
144
            if isinstance (child_item, gmenu.Directory):
151
145
                self.__append_directory (child_item, iter, system, None)
154
148
                continue
155
149
            
156
150
            child_iter = self.iter_children (iter)
157
 
            while child_iter:
 
151
            while child_iter is not None:
158
152
                if child_item.type == gmenu.TYPE_ENTRY and \
159
 
                   self[child_iter][self.COLUMN_IS_ENTRY] and \
160
 
                   self[child_iter][self.COLUMN_ID] == child_item.desktop_file_id:
 
153
                   self.get_value(child_iter, self.COLUMN_IS_ENTRY) and \
 
154
                   self.get_value(child_iter, self.COLUMN_ID) == child_item.desktop_file_id:
161
155
                        break
162
156
                child_iter = self.iter_next (child_iter)
163
157
 
164
 
            if not child_iter:
165
 
                child_iter = self.append (iter)
166
 
 
167
 
                self[child_iter][self.COLUMN_IS_ENTRY] = True
168
 
                self[child_iter][self.COLUMN_ID]       = child_item.desktop_file_id
169
 
                self[child_iter][self.COLUMN_NAME]     = child_item.display_name
170
 
                self[child_iter][self.COLUMN_ICON]     = load_icon (self.icon_theme,
171
 
                                                                    child_item.icon)
 
158
            if child_iter is None:
 
159
                row = (True, child_item.desktop_file_id, child_item.display_name, load_icon (self.icon_theme, child_item.icon), None, False, False)
 
160
                child_iter = self.append (iter, row)
172
161
 
173
162
            if system:
174
 
                self[child_iter][self.COLUMN_SYSTEM_VISIBLE] = not child_item.is_excluded
 
163
                self.set_value (child_iter, self.COLUMN_SYSTEM_VISIBLE, not child_item.is_excluded,)
175
164
            else:
176
 
                self[child_iter][self.COLUMN_USER_VISIBLE]   = not child_item.is_excluded
 
165
                self.set_value (child_iter, self.COLUMN_USER_VISIBLE, not child_item.is_excluded,)