Merge lp:~mmcg069/software-center/pathbar-atk into lp:software-center
- pathbar-atk
- Merge into trunk
Proposed by
Matthew McGowan
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~mmcg069/software-center/pathbar-atk |
Merge into: | lp:software-center |
Diff against target: |
4408 lines (+1961/-1978) 12 files modified
softwarecenter/app.py (+3/-2) softwarecenter/view/appview.py (+8/-3) softwarecenter/view/availablepane.py (+123/-78) softwarecenter/view/channelpane.py (+6/-1) softwarecenter/view/installedpane.py (+3/-1) softwarecenter/view/navhistory.py (+147/-88) softwarecenter/view/softwarepane.py (+1/-1) softwarecenter/view/widgets/backforward.py (+140/-132) softwarecenter/view/widgets/pathbar2.py (+0/-1605) softwarecenter/view/widgets/pathbar_common.py (+827/-0) softwarecenter/view/widgets/pathbar_gtk_atk.py (+703/-0) softwarecenter/view/widgets/rgb.py (+0/-67) |
To merge this branch: | bzr merge lp:~mmcg069/software-center/pathbar-atk |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
software-store-developers | Pending | ||
Review via email: mp+22778@code.launchpad.net |
Commit message
Description of the change
most notable:
* Modify PathBar to now use gtk.EventBox's for PathPart's
* Enable atk accessibility support
* Pathbar now provides for keyboard navigation, complete with focus box drawing
* Improve theme coverage
* All features of old PathBar retained in shift to new PathBar design
other:
* Tweak navhistory behaviour to better work with new Pathbar
* Other minor tweaks
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'softwarecenter/app.py' | |||
2 | --- softwarecenter/app.py 2010-04-01 19:48:40 +0000 | |||
3 | +++ softwarecenter/app.py 2010-04-04 06:00:32 +0000 | |||
4 | @@ -214,7 +214,8 @@ | |||
5 | 214 | 214 | ||
6 | 215 | # default focus | 215 | # default focus |
7 | 216 | self.available_pane.searchentry.grab_focus() | 216 | self.available_pane.searchentry.grab_focus() |
9 | 217 | 217 | self.window_main.set_size_request(600, 400) | |
10 | 218 | |||
11 | 218 | # restore state | 219 | # restore state |
12 | 219 | self.config = get_config() | 220 | self.config = get_config() |
13 | 220 | self.restore_state() | 221 | self.restore_state() |
14 | @@ -561,7 +562,7 @@ | |||
15 | 561 | def restore_state(self): | 562 | def restore_state(self): |
16 | 562 | if self.config.has_option("general", "size"): | 563 | if self.config.has_option("general", "size"): |
17 | 563 | (x, y) = self.config.get("general", "size").split(",") | 564 | (x, y) = self.config.get("general", "size").split(",") |
19 | 564 | self.window_main.resize(int(x), int(y)) | 565 | self.window_main.set_default_size(int(x), int(y)) |
20 | 565 | if (self.config.has_option("general", "maximized") and | 566 | if (self.config.has_option("general", "maximized") and |
21 | 566 | self.config.getboolean("general", "maximized")): | 567 | self.config.getboolean("general", "maximized")): |
22 | 567 | self.window_main.maximize() | 568 | self.window_main.maximize() |
23 | 568 | 569 | ||
24 | === modified file 'softwarecenter/view/appview.py' | |||
25 | --- softwarecenter/view/appview.py 2010-04-01 19:48:40 +0000 | |||
26 | +++ softwarecenter/view/appview.py 2010-04-04 06:00:32 +0000 | |||
27 | @@ -96,6 +96,7 @@ | |||
28 | 96 | data further. A python function that gets a pkgname | 96 | data further. A python function that gets a pkgname |
29 | 97 | """ | 97 | """ |
30 | 98 | gtk.GenericTreeModel.__init__(self) | 98 | gtk.GenericTreeModel.__init__(self) |
31 | 99 | self.search_query = search_query | ||
32 | 99 | self.cache = cache | 100 | self.cache = cache |
33 | 100 | self.db = db | 101 | self.db = db |
34 | 101 | self.icons = icons | 102 | self.icons = icons |
35 | @@ -258,7 +259,7 @@ | |||
36 | 258 | summary = app.pkgname | 259 | summary = app.pkgname |
37 | 259 | if self.db.is_appname_duplicated(appname): | 260 | if self.db.is_appname_duplicated(appname): |
38 | 260 | appname = "%s (%s)" % (appname, app.pkgname) | 261 | appname = "%s (%s)" % (appname, app.pkgname) |
40 | 261 | s = "%s\n<small>%s</small>" % ( | 262 | s = "<b>%s</b>\n<small>%s</small>" % ( |
41 | 262 | gobject.markup_escape_text(appname), | 263 | gobject.markup_escape_text(appname), |
42 | 263 | gobject.markup_escape_text(summary)) | 264 | gobject.markup_escape_text(summary)) |
43 | 264 | return s | 265 | return s |
44 | @@ -900,7 +901,9 @@ | |||
45 | 900 | """ | 901 | """ |
46 | 901 | (path, column) = self.get_cursor() | 902 | (path, column) = self.get_cursor() |
47 | 902 | model = self.get_model() | 903 | model = self.get_model() |
49 | 903 | action_in_progress = (model[path][AppStore.COL_ACTION_IN_PROGRESS] != -1) | 904 | action_in_progress = False |
50 | 905 | if path: | ||
51 | 906 | action_in_progress = (model[path][AppStore.COL_ACTION_IN_PROGRESS] != -1) | ||
52 | 904 | return action_in_progress | 907 | return action_in_progress |
53 | 905 | 908 | ||
54 | 906 | def _on_realize(self, widget, tr): | 909 | def _on_realize(self, widget, tr): |
55 | @@ -948,7 +951,9 @@ | |||
56 | 948 | def _on_cursor_changed(self, view): | 951 | def _on_cursor_changed(self, view): |
57 | 949 | # trigger callback, if we do it here get_selection() returns | 952 | # trigger callback, if we do it here get_selection() returns |
58 | 950 | # the previous selected row for some reason | 953 | # the previous selected row for some reason |
60 | 951 | gobject.timeout_add(10, self._app_selected_timeout_cb, view) | 954 | |
61 | 955 | # mvo: can we make this timeout 1? The AppView is much nicer this way... | ||
62 | 956 | gobject.timeout_add(1, self._app_selected_timeout_cb, view) | ||
63 | 952 | 957 | ||
64 | 953 | def _app_selected_timeout_cb(self, view): | 958 | def _app_selected_timeout_cb(self, view): |
65 | 954 | selection = view.get_selection() | 959 | selection = view.get_selection() |
66 | 955 | 960 | ||
67 | === modified file 'softwarecenter/view/availablepane.py' | |||
68 | --- softwarecenter/view/availablepane.py 2010-03-05 15:53:27 +0000 | |||
69 | +++ softwarecenter/view/availablepane.py 2010-04-04 06:00:32 +0000 | |||
70 | @@ -48,7 +48,7 @@ | |||
71 | 48 | (PAGE_CATEGORY, | 48 | (PAGE_CATEGORY, |
72 | 49 | PAGE_APPLIST, | 49 | PAGE_APPLIST, |
73 | 50 | PAGE_APP_DETAILS) = range(3) | 50 | PAGE_APP_DETAILS) = range(3) |
75 | 51 | 51 | ||
76 | 52 | # define ID values for the various buttons found in the navigation bar | 52 | # define ID values for the various buttons found in the navigation bar |
77 | 53 | NAV_BUTTON_ID_CATEGORY = "category" | 53 | NAV_BUTTON_ID_CATEGORY = "category" |
78 | 54 | NAV_BUTTON_ID_LIST = "list" | 54 | NAV_BUTTON_ID_LIST = "list" |
79 | @@ -73,14 +73,14 @@ | |||
80 | 73 | self.connect("app-list-changed", self._on_app_list_changed) | 73 | self.connect("app-list-changed", self._on_app_list_changed) |
81 | 74 | self.current_app_by_category = {} | 74 | self.current_app_by_category = {} |
82 | 75 | self.current_app_by_subcategory = {} | 75 | self.current_app_by_subcategory = {} |
83 | 76 | # track navigation history | ||
84 | 77 | self.nav_history = NavigationHistory(self) | ||
85 | 76 | # UI | 78 | # UI |
86 | 77 | self._build_ui() | 79 | self._build_ui() |
87 | 78 | # track navigation history | ||
88 | 79 | self.nav_history = NavigationHistory(self) | ||
89 | 80 | 80 | ||
90 | 81 | def _build_ui(self): | 81 | def _build_ui(self): |
91 | 82 | # categories, appview and details into the notebook in the bottom | 82 | # categories, appview and details into the notebook in the bottom |
93 | 83 | self.cat_view = CategoriesView(self.datadir, APP_INSTALL_PATH, | 83 | self.cat_view = CategoriesView(self.datadir, APP_INSTALL_PATH, |
94 | 84 | self.db, | 84 | self.db, |
95 | 85 | self.icons) | 85 | self.icons) |
96 | 86 | scroll_categories = gtk.ScrolledWindow() | 86 | scroll_categories = gtk.ScrolledWindow() |
97 | @@ -88,8 +88,8 @@ | |||
98 | 88 | scroll_categories.add(self.cat_view) | 88 | scroll_categories.add(self.cat_view) |
99 | 89 | self.notebook.append_page(scroll_categories, gtk.Label("categories")) | 89 | self.notebook.append_page(scroll_categories, gtk.Label("categories")) |
100 | 90 | # sub-categories view | 90 | # sub-categories view |
103 | 91 | self.subcategories_view = CategoriesView(self.datadir, | 91 | self.subcategories_view = CategoriesView(self.datadir, |
104 | 92 | APP_INSTALL_PATH, | 92 | APP_INSTALL_PATH, |
105 | 93 | self.db, | 93 | self.db, |
106 | 94 | self.icons, | 94 | self.icons, |
107 | 95 | self.cat_view.categories[0]) | 95 | self.cat_view.categories[0]) |
108 | @@ -108,7 +108,7 @@ | |||
109 | 108 | self.top_hbox.pack_start(self.back_forward, expand=False, padding=self.PADDING) | 108 | self.top_hbox.pack_start(self.back_forward, expand=False, padding=self.PADDING) |
110 | 109 | # nav buttons first in the panel | 109 | # nav buttons first in the panel |
111 | 110 | self.top_hbox.reorder_child(self.back_forward, 0) | 110 | self.top_hbox.reorder_child(self.back_forward, 0) |
113 | 111 | # now a vbox for subcategories and applist | 111 | # now a vbox for subcategories and applist |
114 | 112 | apps_vbox = gtk.VPaned() | 112 | apps_vbox = gtk.VPaned() |
115 | 113 | apps_vbox.pack1(self.scroll_subcategories, resize=True) | 113 | apps_vbox.pack1(self.scroll_subcategories, resize=True) |
116 | 114 | apps_vbox.pack2(self.scroll_app_list) | 114 | apps_vbox.pack2(self.scroll_app_list) |
117 | @@ -120,9 +120,10 @@ | |||
118 | 120 | # set status text | 120 | # set status text |
119 | 121 | self._update_status_text(len(self.db)) | 121 | self._update_status_text(len(self.db)) |
120 | 122 | # home button | 122 | # home button |
122 | 123 | self.navigation_bar.add_with_id(_("Get Software"), | 123 | self.navigation_bar.add_with_id(_("Get Software"), |
123 | 124 | self.on_navigation_category, | 124 | self.on_navigation_category, |
124 | 125 | self.NAV_BUTTON_ID_CATEGORY, | 125 | self.NAV_BUTTON_ID_CATEGORY, |
125 | 126 | do_callback=True, | ||
126 | 126 | animate=False) | 127 | animate=False) |
127 | 127 | 128 | ||
128 | 128 | def _get_query(self): | 129 | def _get_query(self): |
129 | @@ -137,7 +138,7 @@ | |||
130 | 137 | elif self.apps_category: | 138 | elif self.apps_category: |
131 | 138 | cat_query = self.apps_category.query | 139 | cat_query = self.apps_category.query |
132 | 139 | # mix category with the search terms and return query | 140 | # mix category with the search terms and return query |
134 | 140 | return self.db.get_query_list_from_search_entry(self.apps_search_term, | 141 | return self.db.get_query_list_from_search_entry(self.apps_search_term, |
135 | 141 | cat_query) | 142 | cat_query) |
136 | 142 | 143 | ||
137 | 143 | def _in_no_display_category(self): | 144 | def _in_no_display_category(self): |
138 | @@ -150,7 +151,7 @@ | |||
139 | 150 | def _show_hide_subcategories(self): | 151 | def _show_hide_subcategories(self): |
140 | 151 | # check if have subcategories and are not in a subcategory | 152 | # check if have subcategories and are not in a subcategory |
141 | 152 | # view - if so, show it | 153 | # view - if so, show it |
143 | 153 | if (self.apps_category and | 154 | if (self.apps_category and |
144 | 154 | self.apps_category.subcategories and | 155 | self.apps_category.subcategories and |
145 | 155 | not (self.apps_search_term or self.apps_subcategory)): | 156 | not (self.apps_search_term or self.apps_subcategory)): |
146 | 156 | self.scroll_subcategories.show() | 157 | self.scroll_subcategories.show() |
147 | @@ -163,16 +164,16 @@ | |||
148 | 163 | # not hide it | 164 | # not hide it |
149 | 164 | model = self.app_view.get_model() | 165 | model = self.app_view.get_model() |
150 | 165 | if (model and | 166 | if (model and |
152 | 166 | len(model) == 0 and | 167 | len(model) == 0 and |
153 | 167 | self.apps_category and | 168 | self.apps_category and |
155 | 168 | self.apps_category.subcategories and | 169 | self.apps_category.subcategories and |
156 | 169 | not self.apps_subcategory): | 170 | not self.apps_subcategory): |
157 | 170 | self.scroll_app_list.hide() | 171 | self.scroll_app_list.hide() |
158 | 171 | else: | 172 | else: |
159 | 172 | self.scroll_app_list.show() | 173 | self.scroll_app_list.show() |
160 | 173 | 174 | ||
161 | 174 | def refresh_apps(self): | 175 | def refresh_apps(self): |
163 | 175 | """refresh the applist after search changes and update the | 176 | """refresh the applist after search changes and update the |
164 | 176 | navigation bar | 177 | navigation bar |
165 | 177 | """ | 178 | """ |
166 | 178 | logging.debug("refresh_apps") | 179 | logging.debug("refresh_apps") |
167 | @@ -185,18 +186,28 @@ | |||
168 | 185 | def _refresh_apps_with_apt_cache(self): | 186 | def _refresh_apps_with_apt_cache(self): |
169 | 186 | # build query | 187 | # build query |
170 | 187 | query = self._get_query() | 188 | query = self._get_query() |
175 | 188 | logging.debug("availablepane query: %s" % query) | 189 | |
172 | 189 | # *ugh* deactivate the old model because otherwise it keeps | ||
173 | 190 | # getting progress_changed events and eats CPU time until its | ||
174 | 191 | # garbage collected | ||
176 | 192 | old_model = self.app_view.get_model() | 190 | old_model = self.app_view.get_model() |
177 | 193 | if old_model is not None: | 191 | if old_model is not None: |
179 | 194 | old_model.active = False | 192 | # check if new AppStore query == old query. if yes, do nothing |
180 | 193 | if isinstance(old_model, AppStore) and \ | ||
181 | 194 | str(old_model.search_query) == str(query): | ||
182 | 195 | # check if we show subcategoriy | ||
183 | 196 | self._show_hide_applist() | ||
184 | 197 | self.emit("app-list-changed", len(old_model)) | ||
185 | 198 | return | ||
186 | 199 | else: | ||
187 | 200 | # *ugh* deactivate the old model because otherwise it keeps | ||
188 | 201 | # getting progress_changed events and eats CPU time until its | ||
189 | 202 | # garbage collected | ||
190 | 203 | old_model.active = False | ||
191 | 204 | |||
192 | 205 | logging.debug("availablepane query: %s" % query) | ||
193 | 195 | # create new model and attach it | 206 | # create new model and attach it |
194 | 196 | new_model = AppStore(self.cache, | 207 | new_model = AppStore(self.cache, |
198 | 197 | self.db, | 208 | self.db, |
199 | 198 | self.icons, | 209 | self.icons, |
200 | 199 | query, | 210 | query, |
201 | 200 | limit=self.apps_limit, | 211 | limit=self.apps_limit, |
202 | 201 | sort=self.apps_sorted, | 212 | sort=self.apps_sorted, |
203 | 202 | filter=self.apps_filter) | 213 | filter=self.apps_filter) |
204 | @@ -210,15 +221,14 @@ | |||
205 | 210 | """Update the navigation button""" | 221 | """Update the navigation button""" |
206 | 211 | if self.apps_category and not self.apps_search_term: | 222 | if self.apps_category and not self.apps_search_term: |
207 | 212 | cat = self.apps_category.name | 223 | cat = self.apps_category.name |
209 | 213 | self.navigation_bar.add_with_id(cat, | 224 | self.navigation_bar.add_with_id(cat, |
210 | 214 | self.on_navigation_list, | 225 | self.on_navigation_list, |
213 | 215 | self.NAV_BUTTON_ID_LIST, | 226 | self.NAV_BUTTON_ID_LIST, True) |
214 | 216 | None) | 227 | |
215 | 217 | elif self.apps_search_term: | 228 | elif self.apps_search_term: |
216 | 218 | self.navigation_bar.add_with_id(_("Search Results"), | 229 | self.navigation_bar.add_with_id(_("Search Results"), |
220 | 219 | self.on_navigation_search, | 230 | self.on_navigation_search, |
221 | 220 | self.NAV_BUTTON_ID_SEARCH, | 231 | self.NAV_BUTTON_ID_SEARCH, True) |
219 | 221 | None) | ||
222 | 222 | 232 | ||
223 | 223 | # status text woo | 233 | # status text woo |
224 | 224 | def get_status_text(self): | 234 | def get_status_text(self): |
225 | @@ -228,7 +238,7 @@ | |||
226 | 228 | self._in_no_display_category()): | 238 | self._in_no_display_category()): |
227 | 229 | return "" | 239 | return "" |
228 | 230 | return self._status_text | 240 | return self._status_text |
230 | 231 | 241 | ||
231 | 232 | def get_current_app(self): | 242 | def get_current_app(self): |
232 | 233 | """return the current active application object""" | 243 | """return the current active application object""" |
233 | 234 | if self.is_category_view_showing(): | 244 | if self.is_category_view_showing(): |
234 | @@ -238,13 +248,13 @@ | |||
235 | 238 | return self.current_app_by_subcategory.get(self.apps_subcategory) | 248 | return self.current_app_by_subcategory.get(self.apps_subcategory) |
236 | 239 | else: | 249 | else: |
237 | 240 | return self.current_app_by_category.get(self.apps_category) | 250 | return self.current_app_by_category.get(self.apps_category) |
239 | 241 | 251 | ||
240 | 242 | def _on_app_list_changed(self, pane, length): | 252 | def _on_app_list_changed(self, pane, length): |
241 | 243 | """internal helper that keeps the status text up-to-date by | 253 | """internal helper that keeps the status text up-to-date by |
242 | 244 | keeping track of the app-list-changed signals | 254 | keeping track of the app-list-changed signals |
243 | 245 | """ | 255 | """ |
244 | 246 | self._update_status_text(length) | 256 | self._update_status_text(length) |
246 | 247 | 257 | ||
247 | 248 | def _update_status_text(self, length): | 258 | def _update_status_text(self, length): |
248 | 249 | """ | 259 | """ |
249 | 250 | update the text in the status bar | 260 | update the text in the status bar |
250 | @@ -280,11 +290,17 @@ | |||
251 | 280 | self.apps_search_term = "" | 290 | self.apps_search_term = "" |
252 | 281 | self.navigation_bar.remove_id(self.NAV_BUTTON_ID_SEARCH) | 291 | self.navigation_bar.remove_id(self.NAV_BUTTON_ID_SEARCH) |
253 | 282 | 292 | ||
254 | 293 | def _check_nav_history(self, display_cb): | ||
255 | 294 | if self.navigation_bar.get_last().label != self.nav_history.get_last_label(): | ||
256 | 295 | nav_item = NavigationItem(self, display_cb) | ||
257 | 296 | self.nav_history.navigate_no_cursor_step(nav_item) | ||
258 | 297 | return | ||
259 | 298 | |||
260 | 283 | # callbacks | 299 | # callbacks |
261 | 284 | def on_cache_ready(self, cache): | 300 | def on_cache_ready(self, cache): |
262 | 285 | """ refresh the application list when the cache is re-opened """ | 301 | """ refresh the application list when the cache is re-opened """ |
265 | 286 | # just re-draw in the available pane, nothing but the | 302 | # just re-draw in the available pane, nothing but the |
266 | 287 | # "is-installed" overlay icon will change when something | 303 | # "is-installed" overlay icon will change when something |
267 | 288 | # is installed or removed in the available pane | 304 | # is installed or removed in the available pane |
268 | 289 | self.app_view.queue_draw() | 305 | self.app_view.queue_draw() |
269 | 290 | 306 | ||
270 | @@ -322,67 +338,89 @@ | |||
271 | 322 | self.refresh_apps() | 338 | self.refresh_apps() |
272 | 323 | self._show_category_overview() | 339 | self._show_category_overview() |
273 | 324 | 340 | ||
274 | 341 | def display_category(self): | ||
275 | 342 | self._clear_search() | ||
276 | 343 | self._show_category_overview() | ||
277 | 344 | return | ||
278 | 345 | |||
279 | 346 | def display_search(self): | ||
280 | 347 | self.navigation_bar.remove_id(self.NAV_BUTTON_ID_DETAILS) | ||
281 | 348 | self.notebook.set_current_page(self.PAGE_APPLIST) | ||
282 | 349 | self.emit("app-list-changed", len(self.app_view.get_model())) | ||
283 | 350 | self.searchentry.show() | ||
284 | 351 | return | ||
285 | 352 | |||
286 | 353 | def display_list(self): | ||
287 | 354 | self.navigation_bar.remove_id(self.NAV_BUTTON_ID_SUBCAT) | ||
288 | 355 | self.navigation_bar.remove_id(self.NAV_BUTTON_ID_DETAILS) | ||
289 | 356 | |||
290 | 357 | if self.apps_subcategory: | ||
291 | 358 | self.apps_subcategory = None | ||
292 | 359 | self.set_category(self.apps_category) | ||
293 | 360 | if self.apps_search_term: | ||
294 | 361 | self._clear_search() | ||
295 | 362 | self.refresh_apps() | ||
296 | 363 | |||
297 | 364 | self.notebook.set_current_page(self.PAGE_APPLIST) | ||
298 | 365 | model = self.app_view.get_model() | ||
299 | 366 | self.emit("app-list-changed", len(model)) | ||
300 | 367 | self.searchentry.show() | ||
301 | 368 | return | ||
302 | 369 | |||
303 | 370 | def display_list_subcat(self): | ||
304 | 371 | if self.apps_search_term: | ||
305 | 372 | self._clear_search() | ||
306 | 373 | self.refresh_apps() | ||
307 | 374 | self.set_category(self.apps_subcategory) | ||
308 | 375 | self.navigation_bar.remove_id(self.NAV_BUTTON_ID_DETAILS) | ||
309 | 376 | self.notebook.set_current_page(self.PAGE_APPLIST) | ||
310 | 377 | self.emit("app-list-changed", len(self.app_view.get_model())) | ||
311 | 378 | self.searchentry.show() | ||
312 | 379 | return | ||
313 | 380 | |||
314 | 381 | def display_details(self): | ||
315 | 382 | self.notebook.set_current_page(self.PAGE_APP_DETAILS) | ||
316 | 383 | self.searchentry.hide() | ||
317 | 384 | return | ||
318 | 385 | |||
319 | 325 | def on_navigation_category(self, pathbar, part): | 386 | def on_navigation_category(self, pathbar, part): |
320 | 326 | """callback when the navigation button with id 'category' is clicked""" | 387 | """callback when the navigation button with id 'category' is clicked""" |
321 | 327 | if pathbar and not pathbar.get_active(): | ||
322 | 328 | return | ||
323 | 329 | # clear the search | 388 | # clear the search |
327 | 330 | self._clear_search() | 389 | self.display_category() |
328 | 331 | self._show_category_overview() | 390 | nav_item = NavigationItem(self, self.display_category) |
329 | 332 | self.nav_history.navigate(CategoryViewNavigationItem(self)) | 391 | self.nav_history.navigate(nav_item) |
330 | 333 | 392 | ||
331 | 334 | def on_navigation_search(self, pathbar, part): | 393 | def on_navigation_search(self, pathbar, part): |
332 | 335 | """ callback when the navigation button with id 'search' is clicked""" | 394 | """ callback when the navigation button with id 'search' is clicked""" |
338 | 336 | self.navigation_bar.remove_id(self.NAV_BUTTON_ID_DETAILS) | 395 | self.display_search() |
339 | 337 | self.notebook.set_current_page(self.PAGE_APPLIST) | 396 | nav_item = NavigationItem(self, self.display_search) |
340 | 338 | self.emit("app-list-changed", len(self.app_view.get_model())) | 397 | self.nav_history.navigate(nav_item) |
336 | 339 | self.nav_history.navigate(SearchNavigationItem(self)) | ||
337 | 340 | self.searchentry.show() | ||
341 | 341 | 398 | ||
342 | 342 | def on_navigation_list(self, pathbar, part): | 399 | def on_navigation_list(self, pathbar, part): |
343 | 343 | """callback when the navigation button with id 'list' is clicked""" | 400 | """callback when the navigation button with id 'list' is clicked""" |
359 | 344 | if pathbar and not pathbar.get_active(): | 401 | self.display_list() |
360 | 345 | return | 402 | nav_item = NavigationItem(self, self.display_list) |
361 | 346 | self.navigation_bar.remove_id(self.NAV_BUTTON_ID_SUBCAT) | 403 | self.nav_history.navigate(nav_item) |
347 | 347 | self.navigation_bar.remove_id(self.NAV_BUTTON_ID_DETAILS) | ||
348 | 348 | if self.apps_subcategory: | ||
349 | 349 | self.apps_subcategory = None | ||
350 | 350 | self.set_category(self.apps_category) | ||
351 | 351 | if self.apps_search_term: | ||
352 | 352 | self._clear_search() | ||
353 | 353 | self.refresh_apps() | ||
354 | 354 | self.notebook.set_current_page(self.PAGE_APPLIST) | ||
355 | 355 | model = self.app_view.get_model() | ||
356 | 356 | self.emit("app-list-changed", len(model)) | ||
357 | 357 | self.searchentry.show() | ||
358 | 358 | self.nav_history.navigate(AppListNavigationItem(self)) | ||
362 | 359 | 404 | ||
363 | 360 | def on_navigation_list_subcategory(self, pathbar, part): | 405 | def on_navigation_list_subcategory(self, pathbar, part): |
375 | 361 | if pathbar and not pathbar.get_active(): | 406 | self.display_list_subcat() |
376 | 362 | return | 407 | nav_item = NavigationItem(self, self.display_list_subcat) |
377 | 363 | if self.apps_search_term: | 408 | self.nav_history.navigate(nav_item) |
367 | 364 | self._clear_search() | ||
368 | 365 | self.refresh_apps() | ||
369 | 366 | self.set_category(self.apps_subcategory) | ||
370 | 367 | self.navigation_bar.remove_id(self.NAV_BUTTON_ID_DETAILS) | ||
371 | 368 | self.notebook.set_current_page(self.PAGE_APPLIST) | ||
372 | 369 | self.emit("app-list-changed", len(self.app_view.get_model())) | ||
373 | 370 | self.searchentry.show() | ||
374 | 371 | self.nav_history.navigate(AppListSubcategoryNavigationItem(self)) | ||
378 | 372 | 409 | ||
379 | 373 | def on_navigation_details(self, pathbar, part): | 410 | def on_navigation_details(self, pathbar, part): |
380 | 374 | """callback when the navigation button with id 'details' is clicked""" | 411 | """callback when the navigation button with id 'details' is clicked""" |
386 | 375 | if pathbar and not pathbar.get_active(): | 412 | self.display_details() |
387 | 376 | return | 413 | nav_item = NavigationItem(self, self.display_details) |
388 | 377 | self.notebook.set_current_page(self.PAGE_APP_DETAILS) | 414 | self.nav_history.navigate(nav_item) |
384 | 378 | self.searchentry.hide() | ||
385 | 379 | self.nav_history.navigate(AppDetailsNavigationItem(self)) | ||
389 | 380 | 415 | ||
390 | 381 | def on_subcategory_activated(self, cat_view, category): | 416 | def on_subcategory_activated(self, cat_view, category): |
391 | 382 | #print cat_view, name, query | 417 | #print cat_view, name, query |
392 | 383 | logging.debug("on_subcategory_activated: %s %s" % ( | 418 | logging.debug("on_subcategory_activated: %s %s" % ( |
393 | 384 | category.name, category)) | 419 | category.name, category)) |
394 | 385 | self.apps_subcategory = category | 420 | self.apps_subcategory = category |
395 | 421 | |||
396 | 422 | #self._check_nav_history(self.display_list) | ||
397 | 423 | |||
398 | 386 | self.navigation_bar.add_with_id( | 424 | self.navigation_bar.add_with_id( |
399 | 387 | category.name, self.on_navigation_list_subcategory, self.NAV_BUTTON_ID_SUBCAT) | 425 | category.name, self.on_navigation_list_subcategory, self.NAV_BUTTON_ID_SUBCAT) |
400 | 388 | 426 | ||
401 | @@ -392,21 +430,24 @@ | |||
402 | 392 | category.name, category)) | 430 | category.name, category)) |
403 | 393 | self.apps_category = category | 431 | self.apps_category = category |
404 | 394 | self.set_category(category) | 432 | self.set_category(category) |
406 | 395 | 433 | ||
407 | 396 | def on_application_selected(self, appview, app): | 434 | def on_application_selected(self, appview, app): |
408 | 397 | """callback when an app is selected""" | 435 | """callback when an app is selected""" |
409 | 398 | logging.debug("on_application_selected: '%s'" % app) | 436 | logging.debug("on_application_selected: '%s'" % app) |
410 | 437 | |||
411 | 399 | if self.apps_subcategory: | 438 | if self.apps_subcategory: |
412 | 439 | #self._check_nav_history(self.display_list_subcat) | ||
413 | 400 | self.current_app_by_subcategory[self.apps_subcategory] = app | 440 | self.current_app_by_subcategory[self.apps_subcategory] = app |
414 | 401 | else: | 441 | else: |
415 | 442 | #self._check_nav_history(self.display_list) | ||
416 | 402 | self.current_app_by_category[self.apps_category] = app | 443 | self.current_app_by_category[self.apps_category] = app |
418 | 403 | 444 | ||
419 | 404 | def on_nav_back_clicked(self, widget, event): | 445 | def on_nav_back_clicked(self, widget, event): |
420 | 405 | self.nav_history.nav_back() | 446 | self.nav_history.nav_back() |
421 | 406 | 447 | ||
422 | 407 | def on_nav_forward_clicked(self, widget, event): | 448 | def on_nav_forward_clicked(self, widget, event): |
423 | 408 | self.nav_history.nav_forward() | 449 | self.nav_history.nav_forward() |
425 | 409 | 450 | ||
426 | 410 | def is_category_view_showing(self): | 451 | def is_category_view_showing(self): |
427 | 411 | # check if we are in the category page or if we display a | 452 | # check if we are in the category page or if we display a |
428 | 412 | # sub-category page that has no visible applications | 453 | # sub-category page that has no visible applications |
429 | @@ -414,9 +455,13 @@ | |||
430 | 414 | not self.scroll_app_list.props.visible) | 455 | not self.scroll_app_list.props.visible) |
431 | 415 | 456 | ||
432 | 416 | def set_category(self, category): | 457 | def set_category(self, category): |
433 | 458 | def _cb(): | ||
434 | 459 | self.refresh_apps() | ||
435 | 460 | self.notebook.set_current_page(self.PAGE_APPLIST) | ||
436 | 461 | return False | ||
437 | 462 | |||
438 | 417 | self.update_navigation_button() | 463 | self.update_navigation_button() |
441 | 418 | self.refresh_apps() | 464 | gobject.idle_add(_cb) |
440 | 419 | self.notebook.set_current_page(self.PAGE_APPLIST) | ||
442 | 420 | 465 | ||
443 | 421 | if __name__ == "__main__": | 466 | if __name__ == "__main__": |
444 | 422 | #logging.basicConfig(level=logging.DEBUG) | 467 | #logging.basicConfig(level=logging.DEBUG) |
445 | 423 | 468 | ||
446 | === modified file 'softwarecenter/view/channelpane.py' | |||
447 | --- softwarecenter/view/channelpane.py 2010-03-23 16:50:23 +0000 | |||
448 | +++ softwarecenter/view/channelpane.py 2010-04-04 06:00:32 +0000 | |||
449 | @@ -23,6 +23,7 @@ | |||
450 | 23 | import os | 23 | import os |
451 | 24 | import sys | 24 | import sys |
452 | 25 | import xapian | 25 | import xapian |
453 | 26 | import gobject | ||
454 | 26 | 27 | ||
455 | 27 | from gettext import gettext as _ | 28 | from gettext import gettext as _ |
456 | 28 | 29 | ||
457 | @@ -99,6 +100,10 @@ | |||
458 | 99 | old_model = self.app_view.get_model() | 100 | old_model = self.app_view.get_model() |
459 | 100 | if old_model is not None: | 101 | if old_model is not None: |
460 | 101 | old_model.active = False | 102 | old_model.active = False |
461 | 103 | gobject.idle_add(self._make_new_model, query) | ||
462 | 104 | return False | ||
463 | 105 | |||
464 | 106 | def _make_new_model(self, query): | ||
465 | 102 | # get a new store and attach it to the view | 107 | # get a new store and attach it to the view |
466 | 103 | new_model = AppStore(self.cache, | 108 | new_model = AppStore(self.cache, |
467 | 104 | self.db, | 109 | self.db, |
468 | @@ -110,7 +115,7 @@ | |||
469 | 110 | self.app_view.set_model(new_model) | 115 | self.app_view.set_model(new_model) |
470 | 111 | self.emit("app-list-changed", len(new_model)) | 116 | self.emit("app-list-changed", len(new_model)) |
471 | 112 | return False | 117 | return False |
473 | 113 | 118 | ||
474 | 114 | def set_channel(self, channel): | 119 | def set_channel(self, channel): |
475 | 115 | """ | 120 | """ |
476 | 116 | set the current software channel object for display in the channel pane | 121 | set the current software channel object for display in the channel pane |
477 | 117 | 122 | ||
478 | === modified file 'softwarecenter/view/installedpane.py' | |||
479 | --- softwarecenter/view/installedpane.py 2010-03-03 15:39:40 +0000 | |||
480 | +++ softwarecenter/view/installedpane.py 2010-04-04 06:00:32 +0000 | |||
481 | @@ -50,6 +50,7 @@ | |||
482 | 50 | # UI | 50 | # UI |
483 | 51 | self._build_ui() | 51 | self._build_ui() |
484 | 52 | def _build_ui(self): | 52 | def _build_ui(self): |
485 | 53 | self.navigation_bar.set_size_request(26, -1) | ||
486 | 53 | self.notebook.append_page(self.scroll_app_list, gtk.Label("installed")) | 54 | self.notebook.append_page(self.scroll_app_list, gtk.Label("installed")) |
487 | 54 | # details | 55 | # details |
488 | 55 | self.notebook.append_page(self.scroll_details, gtk.Label("details")) | 56 | self.notebook.append_page(self.scroll_details, gtk.Label("details")) |
489 | @@ -82,7 +83,8 @@ | |||
490 | 82 | query = None | 83 | query = None |
491 | 83 | self.navigation_bar.add_with_id(_("Installed Software"), | 84 | self.navigation_bar.add_with_id(_("Installed Software"), |
492 | 84 | self.on_navigation_list, | 85 | self.on_navigation_list, |
494 | 85 | "list") | 86 | "list", |
495 | 87 | animate=False) | ||
496 | 86 | # *ugh* deactivate the old model because otherwise it keeps | 88 | # *ugh* deactivate the old model because otherwise it keeps |
497 | 87 | # getting progress_changed events and eats CPU time until it's | 89 | # getting progress_changed events and eats CPU time until it's |
498 | 88 | # garbage collected | 90 | # garbage collected |
499 | 89 | 91 | ||
500 | === modified file 'softwarecenter/view/navhistory.py' | |||
501 | --- softwarecenter/view/navhistory.py 2010-03-19 21:27:31 +0000 | |||
502 | +++ softwarecenter/view/navhistory.py 2010-04-04 06:00:32 +0000 | |||
503 | @@ -15,7 +15,8 @@ | |||
504 | 15 | # You should have received a copy of the GNU General Public License along with | 15 | # You should have received a copy of the GNU General Public License along with |
505 | 16 | # this program; if not, write to the Free Software Foundation, Inc., | 16 | # this program; if not, write to the Free Software Foundation, Inc., |
506 | 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
508 | 18 | import copy | 18 | |
509 | 19 | import gobject | ||
510 | 19 | import logging | 20 | import logging |
511 | 20 | 21 | ||
512 | 21 | from softwarecenter.utils import unescape | 22 | from softwarecenter.utils import unescape |
513 | @@ -28,94 +29,117 @@ | |||
514 | 28 | class to manage navigation history in the "Get Software" section (the | 29 | class to manage navigation history in the "Get Software" section (the |
515 | 29 | available pane). | 30 | available pane). |
516 | 30 | """ | 31 | """ |
518 | 31 | 32 | ||
519 | 33 | MAX_NAV_ITEMS = 10 # limit number of NavItems allowed in the NavStack | ||
520 | 34 | |||
521 | 35 | |||
522 | 32 | def __init__(self, available_pane): | 36 | def __init__(self, available_pane): |
523 | 33 | self.available_pane = available_pane | 37 | self.available_pane = available_pane |
524 | 34 | # always start at main category view | ||
525 | 35 | self._current_nav_item = CategoryViewNavigationItem(available_pane) | ||
526 | 36 | # use stacks to track navigation history | 38 | # use stacks to track navigation history |
531 | 37 | self._nav_back_stack = [] | 39 | self._nav_stack = NavigationStack(self.MAX_NAV_ITEMS) |
532 | 38 | self._nav_forward_stack = [] | 40 | |
533 | 39 | 41 | def navigate(self, nav_item): | |
530 | 40 | def navigate(self, dest_nav_item): | ||
534 | 41 | """ | 42 | """ |
535 | 42 | append a new NavigationItem to the history stack | 43 | append a new NavigationItem to the history stack |
536 | 43 | """ | 44 | """ |
537 | 44 | if in_replay_history_mode: | 45 | if in_replay_history_mode: |
538 | 45 | return | 46 | return |
549 | 46 | logging.debug("submit navitem for history: %s" % dest_nav_item) | 47 | |
550 | 47 | # TODO: Detect multiple clicks on the same nav button and filter | 48 | nav_item.parent = self |
551 | 48 | # them out - we don't want them in the history | 49 | self._nav_stack.append(nav_item) |
552 | 49 | dest_nav_item.parent = self | 50 | |
553 | 50 | self._nav_back_stack.append(self._current_nav_item) | 51 | if self._nav_stack.cursor > 0: |
554 | 51 | self._current_nav_item = dest_nav_item | 52 | self.available_pane.back_forward.left.set_sensitive(True) |
545 | 52 | # reset navigation forward stack on a direct navigation | ||
546 | 53 | self._nav_forward_stack = [] | ||
547 | 54 | # update buttons | ||
548 | 55 | self.available_pane.back_forward.left.set_sensitive(True) | ||
555 | 56 | self.available_pane.back_forward.right.set_sensitive(False) | 53 | self.available_pane.back_forward.right.set_sensitive(False) |
557 | 57 | 54 | ||
558 | 55 | def navigate_no_cursor_step(self, nav_item): | ||
559 | 56 | if in_replay_history_mode: | ||
560 | 57 | return | ||
561 | 58 | |||
562 | 59 | nav_item.parent = self | ||
563 | 60 | self._nav_stack.append_no_cursor_step(nav_item) | ||
564 | 61 | return | ||
565 | 62 | |||
566 | 58 | def nav_forward(self): | 63 | def nav_forward(self): |
567 | 59 | """ | 64 | """ |
568 | 60 | navigate forward one item in the history stack | 65 | navigate forward one item in the history stack |
569 | 61 | """ | 66 | """ |
570 | 67 | nav_item = self._nav_stack.step_forward() | ||
571 | 68 | nav_item.navigate_to() | ||
572 | 69 | |||
573 | 62 | self.available_pane.back_forward.left.set_sensitive(True) | 70 | self.available_pane.back_forward.left.set_sensitive(True) |
575 | 63 | if len(self._nav_forward_stack) <= 1: | 71 | if self._nav_stack.at_end(): |
576 | 72 | if self.available_pane.back_forward.right.has_focus(): | ||
577 | 73 | self.available_pane.back_forward.left.grab_focus() | ||
578 | 64 | self.available_pane.back_forward.right.set_sensitive(False) | 74 | self.available_pane.back_forward.right.set_sensitive(False) |
584 | 65 | nav_item = self._nav_forward_stack.pop() | 75 | |
580 | 66 | self._nav_back_stack.append(self._current_nav_item) | ||
581 | 67 | self._current_nav_item = nav_item | ||
582 | 68 | nav_item.navigate_to() | ||
583 | 69 | |||
585 | 70 | def nav_back(self): | 76 | def nav_back(self): |
586 | 71 | """ | 77 | """ |
587 | 72 | navigate back one item in the history stack | 78 | navigate back one item in the history stack |
588 | 73 | """ | 79 | """ |
589 | 80 | nav_item = self._nav_stack.step_back() | ||
590 | 81 | nav_item.navigate_to() | ||
591 | 82 | |||
592 | 74 | self.available_pane.back_forward.right.set_sensitive(True) | 83 | self.available_pane.back_forward.right.set_sensitive(True) |
594 | 75 | if len(self._nav_back_stack) <= 1: | 84 | if self._nav_stack.at_start(): |
595 | 85 | if self.available_pane.back_forward.left.has_focus(): | ||
596 | 86 | self.available_pane.back_forward.right.grab_focus() | ||
597 | 76 | self.available_pane.back_forward.left.set_sensitive(False) | 87 | self.available_pane.back_forward.left.set_sensitive(False) |
604 | 77 | nav_item = self._nav_back_stack.pop() | 88 | |
605 | 78 | logging.debug("nav_back: %s" % nav_item) | 89 | def get_last_label(self): |
606 | 79 | self._nav_forward_stack.append(self._current_nav_item) | 90 | if self._nav_stack.stack: |
607 | 80 | self._current_nav_item = nav_item | 91 | if self._nav_stack[-1].parts: |
608 | 81 | nav_item.navigate_to() | 92 | return self._nav_stack[-1].parts[-1].label |
609 | 82 | 93 | return None | |
610 | 94 | |||
611 | 95 | |||
612 | 83 | class NavigationItem(object): | 96 | class NavigationItem(object): |
613 | 84 | """ | 97 | """ |
614 | 85 | class to implement navigation points to be managed in the history queues | 98 | class to implement navigation points to be managed in the history queues |
615 | 86 | """ | 99 | """ |
616 | 87 | 100 | ||
618 | 88 | def __init__(self, available_pane): | 101 | def __init__(self, available_pane, update_available_pane_cb): |
619 | 89 | self.available_pane = available_pane | 102 | self.available_pane = available_pane |
620 | 103 | self.update_available_pane = update_available_pane_cb | ||
621 | 90 | self.apps_category = available_pane.apps_category | 104 | self.apps_category = available_pane.apps_category |
622 | 91 | self.apps_subcategory = available_pane.apps_subcategory | 105 | self.apps_subcategory = available_pane.apps_subcategory |
623 | 92 | self.apps_search_term = available_pane.apps_search_term | 106 | self.apps_search_term = available_pane.apps_search_term |
624 | 93 | self.current_app = available_pane.get_current_app() | 107 | self.current_app = available_pane.get_current_app() |
627 | 94 | self.parts = self.available_pane.navigation_bar.get_parts()[:] | 108 | self.parts = self.available_pane.navigation_bar.get_parts() |
628 | 95 | 109 | ||
629 | 96 | def navigate_to(self): | 110 | def navigate_to(self): |
630 | 97 | """ | 111 | """ |
631 | 98 | navigate to the view that corresponds to this NavigationItem | 112 | navigate to the view that corresponds to this NavigationItem |
632 | 99 | """ | 113 | """ |
633 | 100 | global in_replay_history_mode | 114 | global in_replay_history_mode |
634 | 101 | in_replay_history_mode = True | 115 | in_replay_history_mode = True |
643 | 102 | self.available_pane.apps_category = self.apps_category | 116 | available_pane = self.available_pane |
644 | 103 | self.available_pane.apps_subcategory = self.apps_subcategory | 117 | available_pane.apps_category = self.apps_category |
645 | 104 | self.available_pane.apps_search_term = self.apps_search_term | 118 | available_pane.apps_subcategory = self.apps_subcategory |
646 | 105 | self.available_pane.searchentry.set_text(self.apps_search_term) | 119 | available_pane.apps_search_term = self.apps_search_term |
647 | 106 | self.available_pane.searchentry.set_position(-1) | 120 | available_pane.searchentry.set_text(self.apps_search_term) |
648 | 107 | self.available_pane.app_details.show_app(self.current_app) | 121 | available_pane.searchentry.set_position(-1) |
649 | 108 | # first part is special and kept in remove_all | 122 | available_pane.app_details.show_app(self.current_app) |
650 | 109 | self.available_pane.navigation_bar.remove_all() | 123 | |
651 | 124 | nav_bar = self.available_pane.navigation_bar | ||
652 | 125 | nav_bar.remove_all(do_callback=False) | ||
653 | 126 | |||
654 | 110 | for part in self.parts[1:]: | 127 | for part in self.parts[1:]: |
661 | 111 | self.available_pane.navigation_bar.add_with_id(unescape(part.label), | 128 | nav_bar.add_with_id(unescape(part.label), |
662 | 112 | part.callback, | 129 | part.callback, |
663 | 113 | part.id, | 130 | part.get_name(), |
664 | 114 | do_callback=False, | 131 | do_callback=False, |
665 | 115 | animate=False) | 132 | animate=False) |
666 | 116 | self.parts[-1].activate() | 133 | |
667 | 134 | gobject.idle_add(self._update_available_pane_cb, nav_bar) | ||
668 | 117 | in_replay_history_mode = False | 135 | in_replay_history_mode = False |
670 | 118 | 136 | ||
671 | 137 | def _update_available_pane_cb(self, nav_bar): | ||
672 | 138 | last_part = nav_bar.get_parts()[-1] | ||
673 | 139 | nav_bar.set_active_no_callback(last_part) | ||
674 | 140 | self.update_available_pane() | ||
675 | 141 | return False | ||
676 | 142 | |||
677 | 119 | def __str__(self): | 143 | def __str__(self): |
678 | 120 | details = [] | 144 | details = [] |
679 | 121 | details.append("\n%s" % type(self)) | 145 | details.append("\n%s" % type(self)) |
680 | @@ -130,41 +154,76 @@ | |||
681 | 130 | details.append(" current_app: %s" % self.current_app) | 154 | details.append(" current_app: %s" % self.current_app) |
682 | 131 | details.append(" apps_search_term: %s" % self.apps_search_term) | 155 | details.append(" apps_search_term: %s" % self.apps_search_term) |
683 | 132 | return '\n'.join(details) | 156 | return '\n'.join(details) |
722 | 133 | 157 | ||
723 | 134 | class CategoryViewNavigationItem(NavigationItem): | 158 | |
724 | 135 | """ | 159 | class NavigationStack(object): |
725 | 136 | navigation item that corresponds to the main category view | 160 | |
726 | 137 | Note: all subclasses of NavigationItem are for debug use only and | 161 | def __init__(self, max_length): |
727 | 138 | can be collapsed to the NavigationItem class if desired | 162 | self.max_length = max_length |
728 | 139 | """ | 163 | self.stack = [] |
729 | 140 | 164 | self.cursor = 0 | |
730 | 141 | class AppListNavigationItem(NavigationItem): | 165 | return |
731 | 142 | """ | 166 | |
732 | 143 | navigation item that corresponds to the application list for the | 167 | def __len__(self): |
733 | 144 | specified category | 168 | return len(self.stack) |
734 | 145 | Note: all subclasses of NavigationItem are for debug use only and | 169 | |
735 | 146 | can be collapsed to the NavigationItem class if desired | 170 | def __repr__(self): |
736 | 147 | """ | 171 | BOLD = "\033[1m" |
737 | 148 | 172 | RESET = "\033[0;0m" | |
738 | 149 | class AppListSubcategoryNavigationItem(NavigationItem): | 173 | s = '[' |
739 | 150 | """ | 174 | for i, item in enumerate(self.stack): |
740 | 151 | navigation item that corresponds to the application list for the | 175 | if i != self.cursor: |
741 | 152 | specified category and subcategory | 176 | s += str(item.parts[-1].label) + ', ' |
742 | 153 | Note: all subclasses of NavigationItem are for debug use only and | 177 | else: |
743 | 154 | can be collapsed to the NavigationItem class if desired | 178 | s += BOLD + str(item.parts[-1].label) + RESET + ', ' |
744 | 155 | """ | 179 | return s + ']' |
745 | 156 | 180 | ||
746 | 157 | class AppDetailsNavigationItem(NavigationItem): | 181 | def __getitem__(self, item): |
747 | 158 | """ | 182 | return self.stack[item] |
748 | 159 | navigation item that corresponds to the details view for the | 183 | |
749 | 160 | specified application | 184 | def _isok(self, item): |
750 | 161 | Note: all subclasses of NavigationItem are for debug use only and | 185 | if len(self.stack) == 0: return True |
751 | 162 | can be collapsed to the NavigationItem class if desired | 186 | pre_item = self.stack[-1] |
752 | 163 | """ | 187 | if pre_item.parts[-1].label == item.parts[-1].label: |
753 | 164 | 188 | if pre_item.apps_search_term != item.apps_search_term: | |
754 | 165 | class SearchNavigationItem(NavigationItem): | 189 | return True |
755 | 166 | """ | 190 | return False |
756 | 167 | navigation item that corresponds to a search in progress | 191 | return True |
757 | 168 | Note: all subclasses of NavigationItem are for debug use only and | 192 | |
758 | 169 | can be collapsed to the NavigationItem class if desired | 193 | def append(self, item): |
759 | 170 | """ | 194 | if not self._isok(item): |
760 | 195 | self.cursor = len(self.stack)-1 | ||
761 | 196 | print 'A:', repr(self) | ||
762 | 197 | return | ||
763 | 198 | if len(self.stack) + 1 > self.max_length: | ||
764 | 199 | self.stack.pop(0) | ||
765 | 200 | self.stack.append(item) | ||
766 | 201 | self.cursor = len(self.stack)-1 | ||
767 | 202 | print 'A:', repr(self) | ||
768 | 203 | return | ||
769 | 204 | |||
770 | 205 | def append_no_cursor_step(self, item): | ||
771 | 206 | if not self._isok(item): | ||
772 | 207 | print 'a:', repr(self) | ||
773 | 208 | return | ||
774 | 209 | if len(self.stack) + 1 > self.max_length: | ||
775 | 210 | self.stack.pop(0) | ||
776 | 211 | self.stack.append(item) | ||
777 | 212 | print 'a:', repr(self) | ||
778 | 213 | return | ||
779 | 214 | |||
780 | 215 | def step_back(self): | ||
781 | 216 | self.cursor -= 1 | ||
782 | 217 | print 'B:', repr(self) | ||
783 | 218 | return self.stack[self.cursor] | ||
784 | 219 | |||
785 | 220 | def step_forward(self): | ||
786 | 221 | self.cursor += 1 | ||
787 | 222 | print 'B:', repr(self) | ||
788 | 223 | return self.stack[self.cursor] | ||
789 | 224 | |||
790 | 225 | def at_end(self): | ||
791 | 226 | return self.cursor == len(self.stack)-1 | ||
792 | 227 | |||
793 | 228 | def at_start(self): | ||
794 | 229 | return self.cursor == 0 | ||
795 | 171 | 230 | ||
796 | === modified file 'softwarecenter/view/softwarepane.py' | |||
797 | --- softwarecenter/view/softwarepane.py 2010-03-29 20:40:17 +0000 | |||
798 | +++ softwarecenter/view/softwarepane.py 2010-04-04 06:00:32 +0000 | |||
799 | @@ -29,7 +29,7 @@ | |||
800 | 29 | if "SOFTWARE_CENTER_OLD_PATHBAR" in os.environ: | 29 | if "SOFTWARE_CENTER_OLD_PATHBAR" in os.environ: |
801 | 30 | from widgets.navigationbar import NavigationBar | 30 | from widgets.navigationbar import NavigationBar |
802 | 31 | else: | 31 | else: |
804 | 32 | from widgets.pathbar2 import NavigationBar | 32 | from widgets.pathbar_gtk_atk import NavigationBar |
805 | 33 | 33 | ||
806 | 34 | from widgets.searchentry import SearchEntry | 34 | from widgets.searchentry import SearchEntry |
807 | 35 | 35 | ||
808 | 36 | 36 | ||
809 | === modified file 'softwarecenter/view/widgets/backforward.py' | |||
810 | --- softwarecenter/view/widgets/backforward.py 2010-02-15 02:53:26 +0000 | |||
811 | +++ softwarecenter/view/widgets/backforward.py 2010-04-04 06:00:32 +0000 | |||
812 | @@ -17,14 +17,14 @@ | |||
813 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
814 | 18 | 18 | ||
815 | 19 | 19 | ||
818 | 20 | 20 | import atk | |
817 | 21 | import rgb | ||
819 | 22 | import gtk | 21 | import gtk |
820 | 23 | import cairo | 22 | import cairo |
821 | 24 | import gobject | 23 | import gobject |
825 | 25 | import pathbar2 | 24 | import pathbar_common |
826 | 26 | 25 | ||
827 | 27 | from rgb import to_float as f | 26 | from gettext import gettext as _ |
828 | 27 | |||
829 | 28 | 28 | ||
830 | 29 | # pi constants | 29 | # pi constants |
831 | 30 | M_PI = 3.1415926535897931 | 30 | M_PI = 3.1415926535897931 |
832 | @@ -43,72 +43,132 @@ | |||
833 | 43 | 43 | ||
834 | 44 | def __init__(self): | 44 | def __init__(self): |
835 | 45 | gtk.HBox.__init__(self) | 45 | gtk.HBox.__init__(self) |
836 | 46 | self.theme = pathbar_common.PathBarStyle(self) | ||
837 | 46 | sep = SeparatorPart() | 47 | sep = SeparatorPart() |
838 | 47 | 48 | ||
839 | 48 | if self.get_direction() != gtk.TEXT_DIR_RTL: | 49 | if self.get_direction() != gtk.TEXT_DIR_RTL: |
840 | 50 | # ltr | ||
841 | 49 | self.left = ButtonPartLeft('left-clicked') | 51 | self.left = ButtonPartLeft('left-clicked') |
842 | 50 | self.right = ButtonPartRight('right-clicked') | 52 | self.right = ButtonPartRight('right-clicked') |
843 | 53 | self.set_button_atk_info_ltr() | ||
844 | 51 | else: | 54 | else: |
845 | 55 | # rtl | ||
846 | 52 | self.left = ButtonPartRight('left-clicked') | 56 | self.left = ButtonPartRight('left-clicked') |
847 | 53 | self.right = ButtonPartLeft('right-clicked') | 57 | self.right = ButtonPartLeft('right-clicked') |
848 | 58 | self.set_button_atk_info_rtl() | ||
849 | 59 | |||
850 | 60 | atk_obj = self.get_accessible() | ||
851 | 61 | atk_obj.set_name(_('History Navigation')) | ||
852 | 62 | atk_obj.set_description(_('Navigate forwards and backwards.')) | ||
853 | 63 | atk_obj.set_role(atk.ROLE_PANEL) | ||
854 | 54 | 64 | ||
855 | 55 | self.pack_start(self.left) | 65 | self.pack_start(self.left) |
856 | 56 | self.pack_start(sep, False) | 66 | self.pack_start(sep, False) |
857 | 57 | self.pack_end(self.right) | 67 | self.pack_end(self.right) |
858 | 58 | 68 | ||
875 | 59 | self.theme = self._pick_theme() | 69 | sep.connect_after("style-set", self._on_style_set) |
876 | 60 | self.connect("realize", self._on_realize) | 70 | return |
877 | 61 | return | 71 | |
878 | 62 | 72 | def set_button_atk_info_ltr(self): | |
879 | 63 | def _pick_theme(self, name=None): | 73 | # left button |
880 | 64 | name = name or gtk.settings_get_default().get_property("gtk-theme-name") | 74 | atk_obj = self.left.get_accessible() |
881 | 65 | themes = pathbar2.PathBarThemes.DICT | 75 | atk_obj.set_name(_('Back Button')) |
882 | 66 | if themes.has_key(name): | 76 | atk_obj.set_description(_('Navigates back.')) |
883 | 67 | return themes[name]() | 77 | atk_obj.set_role(atk.ROLE_PUSH_BUTTON) |
884 | 68 | print "No styling hints for %s are available" % name | 78 | |
885 | 69 | return pathbar2.PathBarThemeHuman() | 79 | # right button |
886 | 70 | 80 | atk_obj = self.right.get_accessible() | |
887 | 71 | def _on_realize(self, widget): | 81 | atk_obj.set_name(_('Forward Button')) |
888 | 72 | self.theme.load(self.style) | 82 | atk_obj.set_description(_('Navigates forward.')) |
889 | 73 | return | 83 | atk_obj.set_role(atk.ROLE_PUSH_BUTTON) |
890 | 74 | 84 | return | |
891 | 85 | |||
892 | 86 | def set_button_atk_info_rtl(self): | ||
893 | 87 | # right button | ||
894 | 88 | atk_obj = self.right.get_accessible() | ||
895 | 89 | atk_obj.set_name(_('Back Button')) | ||
896 | 90 | atk_obj.set_description(_('Navigates back.')) | ||
897 | 91 | atk_obj.set_role(atk.ROLE_PUSH_BUTTON) | ||
898 | 92 | |||
899 | 93 | # left button | ||
900 | 94 | atk_obj = self.left.get_accessible() | ||
901 | 95 | atk_obj.set_name(_('Forward Button')) | ||
902 | 96 | atk_obj.set_description(_('Navigates forward.')) | ||
903 | 97 | atk_obj.set_role(atk.ROLE_PUSH_BUTTON) | ||
904 | 98 | return | ||
905 | 99 | |||
906 | 100 | def _on_style_set(self, widget, oldstyle): | ||
907 | 101 | # when alloc.width == 1, this is typical of an unallocated widget, | ||
908 | 102 | # lets not break a sweat for nothing... | ||
909 | 103 | if self.allocation.width == 1: | ||
910 | 104 | return | ||
911 | 105 | |||
912 | 106 | old_xthickness = self.theme['xthickness'] | ||
913 | 107 | self.theme = pathbar_common.PathBarStyle(self) | ||
914 | 108 | if old_xthickness > self.theme['xthickness']: | ||
915 | 109 | a = self.allocation | ||
916 | 110 | self.queue_draw_area(a.x, a.y, | ||
917 | 111 | a.width+self.theme['xthickness'], a.height) | ||
918 | 112 | else: | ||
919 | 113 | self.queue_draw() | ||
920 | 114 | return | ||
921 | 75 | 115 | ||
922 | 76 | class SeparatorPart(gtk.DrawingArea): | 116 | class SeparatorPart(gtk.DrawingArea): |
923 | 77 | 117 | ||
924 | 78 | def __init__(self): | 118 | def __init__(self): |
925 | 79 | gtk.DrawingArea.__init__(self) | 119 | gtk.DrawingArea.__init__(self) |
927 | 80 | self.set_size_request(1, -1) | 120 | self.theme = pathbar_common.PathBarStyle(self) |
928 | 121 | self.set_size_request(self.theme['xthickness'], -1) | ||
929 | 122 | |||
930 | 123 | atk_obj = self.get_accessible() | ||
931 | 124 | atk_obj.set_role(atk.ROLE_SEPARATOR) | ||
932 | 125 | |||
933 | 81 | self.connect("expose-event", self._on_expose) | 126 | self.connect("expose-event", self._on_expose) |
934 | 127 | self.connect("style-set", self._on_style_set) | ||
935 | 82 | return | 128 | return |
936 | 83 | 129 | ||
937 | 84 | def _on_expose(self, widget, event): | 130 | def _on_expose(self, widget, event): |
938 | 131 | parent = self.get_parent() | ||
939 | 132 | if not parent: return | ||
940 | 85 | cr = widget.window.cairo_create() | 133 | cr = widget.window.cairo_create() |
944 | 86 | a = event.area | 134 | cr.rectangle(event.area) |
945 | 87 | cr.rectangle(a.x, a.y+1, a.width, a.height-2) | 135 | cr.set_source_rgb(*self.theme.dark_line[self.state].tofloats()) |
943 | 88 | cr.set_source_rgba(0, 0, 0, 0.45) | ||
946 | 89 | cr.fill() | 136 | cr.fill() |
947 | 90 | del cr | 137 | del cr |
948 | 91 | return | 138 | return |
949 | 92 | 139 | ||
950 | 140 | def _on_style_set(self, widget, old_style): | ||
951 | 141 | self.theme = pathbar_common.PathBarStyle(self) | ||
952 | 142 | self.set_size_request(self.theme['xthickness'], -1) | ||
953 | 143 | return | ||
954 | 144 | |||
955 | 93 | 145 | ||
956 | 94 | class ButtonPart(gtk.DrawingArea): | 146 | class ButtonPart(gtk.DrawingArea): |
957 | 95 | 147 | ||
958 | 96 | ARROW_SIZE = (12,12) | 148 | ARROW_SIZE = (12,12) |
960 | 97 | DEFAULT_SIZE = (30, 28) | 149 | DEFAULT_SIZE = (31, 27) |
961 | 98 | 150 | ||
962 | 99 | def __init__(self, arrow_type, signal_name): | 151 | def __init__(self, arrow_type, signal_name): |
963 | 100 | gtk.DrawingArea.__init__(self) | 152 | gtk.DrawingArea.__init__(self) |
964 | 101 | self.set_size_request(*self.DEFAULT_SIZE) | 153 | self.set_size_request(*self.DEFAULT_SIZE) |
965 | 154 | self.shape = pathbar_common.SHAPE_RECTANGLE | ||
966 | 102 | self.button_down = False | 155 | self.button_down = False |
967 | 103 | self.shadow_type = gtk.SHADOW_OUT | 156 | self.shadow_type = gtk.SHADOW_OUT |
968 | 104 | self.arrow_type = arrow_type | 157 | self.arrow_type = arrow_type |
969 | 158 | |||
970 | 159 | self.set_flags(gtk.CAN_FOCUS) | ||
971 | 105 | self.set_events(gtk.gdk.ENTER_NOTIFY_MASK| | 160 | self.set_events(gtk.gdk.ENTER_NOTIFY_MASK| |
972 | 106 | gtk.gdk.LEAVE_NOTIFY_MASK| | 161 | gtk.gdk.LEAVE_NOTIFY_MASK| |
973 | 107 | gtk.gdk.BUTTON_PRESS_MASK| | 162 | gtk.gdk.BUTTON_PRESS_MASK| |
974 | 108 | gtk.gdk.BUTTON_RELEASE_MASK) | 163 | gtk.gdk.BUTTON_RELEASE_MASK) |
975 | 164 | |||
976 | 109 | self.connect("enter-notify-event", self._on_enter) | 165 | self.connect("enter-notify-event", self._on_enter) |
977 | 110 | self.connect("leave-notify-event", self._on_leave) | 166 | self.connect("leave-notify-event", self._on_leave) |
978 | 111 | self.connect("button-press-event", self._on_press) | 167 | self.connect("button-press-event", self._on_press) |
979 | 168 | self.connect("key-press-event", self._on_key_press) | ||
980 | 169 | self.connect("key-release-event", self._on_key_release, signal_name) | ||
981 | 170 | self.connect('focus-in-event', self._on_focus_in) | ||
982 | 171 | self.connect('focus-out-event', self._on_focus_out) | ||
983 | 112 | self.connect("button-release-event", self._on_release, signal_name) | 172 | self.connect("button-release-event", self._on_release, signal_name) |
984 | 113 | return | 173 | return |
985 | 114 | 174 | ||
986 | @@ -135,11 +195,32 @@ | |||
987 | 135 | self.set_active(True) | 195 | self.set_active(True) |
988 | 136 | return | 196 | return |
989 | 137 | 197 | ||
990 | 198 | def _on_key_press(self, widget, event): | ||
991 | 199 | # react to spacebar, enter, numpad-enter | ||
992 | 200 | if event.keyval in (32, 65293, 65421): | ||
993 | 201 | self.set_state(gtk.STATE_ACTIVE) | ||
994 | 202 | return | ||
995 | 203 | |||
996 | 204 | def _on_key_release(self, widget, event, signal_name): | ||
997 | 205 | # react to spacebar, enter, numpad-enter | ||
998 | 206 | if event.keyval in (32, 65293, 65421): | ||
999 | 207 | self.set_state(gtk.STATE_SELECTED) | ||
1000 | 208 | self.get_parent().emit(signal_name, event) | ||
1001 | 209 | return | ||
1002 | 210 | |||
1003 | 138 | def _on_leave(self, widget, event): | 211 | def _on_leave(self, widget, event): |
1004 | 139 | if self.state == gtk.STATE_INSENSITIVE: return | 212 | if self.state == gtk.STATE_INSENSITIVE: return |
1005 | 140 | self.set_active(False) | 213 | self.set_active(False) |
1006 | 141 | return | 214 | return |
1007 | 142 | 215 | ||
1008 | 216 | def _on_focus_in(self, widget, event): | ||
1009 | 217 | self.queue_draw() | ||
1010 | 218 | return | ||
1011 | 219 | |||
1012 | 220 | def _on_focus_out(self, widget, event): | ||
1013 | 221 | self.queue_draw() | ||
1014 | 222 | return | ||
1015 | 223 | |||
1016 | 143 | def _on_press(self, widget, event): | 224 | def _on_press(self, widget, event): |
1017 | 144 | if self.state == gtk.STATE_INSENSITIVE: return | 225 | if self.state == gtk.STATE_INSENSITIVE: return |
1018 | 145 | self.button_down = True | 226 | self.button_down = True |
1019 | @@ -160,117 +241,41 @@ | |||
1020 | 160 | self.set_state(gtk.STATE_NORMAL) | 241 | self.set_state(gtk.STATE_NORMAL) |
1021 | 161 | return | 242 | return |
1022 | 162 | 243 | ||
1053 | 163 | # def expose_gtk(self, widget, area, x, y, width, height): | 244 | def expose_pathbar(self, widget, area, x, y, w, h, xo=0, wo=0): |
1054 | 164 | # # button background | 245 | if not self.parent: return |
1025 | 165 | # widget.style.paint_box(widget.window, | ||
1026 | 166 | # self.state, | ||
1027 | 167 | # self.shadow_type, | ||
1028 | 168 | # area, | ||
1029 | 169 | # widget, | ||
1030 | 170 | # "button", | ||
1031 | 171 | # x, | ||
1032 | 172 | # y, | ||
1033 | 173 | # width, | ||
1034 | 174 | # height) | ||
1035 | 175 | |||
1036 | 176 | # # arrow | ||
1037 | 177 | # aw, ah = self.ARROW_SIZE | ||
1038 | 178 | # widget.style.paint_arrow(widget.window, | ||
1039 | 179 | # self.state, | ||
1040 | 180 | # self.shadow_type, | ||
1041 | 181 | # area, | ||
1042 | 182 | # widget, | ||
1043 | 183 | # "button", | ||
1044 | 184 | # self.arrow_type, | ||
1045 | 185 | # True, | ||
1046 | 186 | # (area.width - aw)/2, | ||
1047 | 187 | # (area.height - ah)/2, | ||
1048 | 188 | # aw, | ||
1049 | 189 | # ah) | ||
1050 | 190 | # return | ||
1051 | 191 | |||
1052 | 192 | def expose_pathbar(self, widget, area, x, y, width, height): | ||
1055 | 193 | # background | 246 | # background |
1056 | 194 | cr = widget.window.cairo_create() | 247 | cr = widget.window.cairo_create() |
1057 | 195 | cr.rectangle(area) | 248 | cr.rectangle(area) |
1058 | 196 | cr.clip() | 249 | cr.clip() |
1059 | 197 | 250 | ||
1069 | 198 | cr.translate(x, y) | 251 | self.parent.theme.paint_bg(cr, |
1070 | 199 | 252 | self, | |
1071 | 200 | self._draw_bg(cr, | 253 | x, y, w, h) |
1063 | 201 | width, | ||
1064 | 202 | height, | ||
1065 | 203 | self.state, | ||
1066 | 204 | self.style, | ||
1067 | 205 | self.get_parent().theme, | ||
1068 | 206 | self.get_parent().theme.curvature) | ||
1072 | 207 | del cr | 254 | del cr |
1073 | 208 | 255 | ||
1074 | 209 | # arrow | 256 | # arrow |
1075 | 257 | if self.has_focus(): | ||
1076 | 258 | self.style.paint_focus(self.window, | ||
1077 | 259 | self.state, | ||
1078 | 260 | (x+4+xo, y+4, w-8+wo, h-8), | ||
1079 | 261 | self, | ||
1080 | 262 | 'button', | ||
1081 | 263 | x+4+xo, y+4, | ||
1082 | 264 | w-8+wo, h-8) | ||
1083 | 265 | |||
1084 | 210 | aw, ah = self.ARROW_SIZE | 266 | aw, ah = self.ARROW_SIZE |
1148 | 211 | widget.style.paint_arrow(widget.window, | 267 | ax, ay = (area.width - aw)/2, (area.height - ah)/2, |
1149 | 212 | self.state, | 268 | |
1150 | 213 | self.shadow_type, | 269 | self.style.paint_arrow(self.window, |
1151 | 214 | area, | 270 | self.state, |
1152 | 215 | widget, | 271 | self.shadow_type, |
1153 | 216 | "button", | 272 | (ax, ay, aw, ah), |
1154 | 217 | self.arrow_type, | 273 | self, |
1155 | 218 | True, | 274 | "button", |
1156 | 219 | (area.width - aw)/2, | 275 | self.arrow_type, |
1157 | 220 | (area.height - ah)/2, | 276 | True, |
1158 | 221 | aw, | 277 | ax, ay, |
1159 | 222 | ah) | 278 | aw, ah) |
1097 | 223 | return | ||
1098 | 224 | |||
1099 | 225 | def _draw_bg(self, cr, w, h, state, style, theme, r): | ||
1100 | 226 | # outer slight bevel or focal highlight | ||
1101 | 227 | self._draw_rect(cr, 0, 0, w, h, r) | ||
1102 | 228 | cr.set_source_rgba(0, 0, 0, 0.055) | ||
1103 | 229 | cr.fill() | ||
1104 | 230 | |||
1105 | 231 | # colour scheme dicts | ||
1106 | 232 | bg = theme.bg_colors | ||
1107 | 233 | outer = theme.dark_line_colors | ||
1108 | 234 | inner = theme.light_line_colors | ||
1109 | 235 | |||
1110 | 236 | # bg linear vertical gradient | ||
1111 | 237 | if state != gtk.STATE_PRELIGHT: | ||
1112 | 238 | color1, color2 = bg[state] | ||
1113 | 239 | else: | ||
1114 | 240 | if self.state == gtk.STATE_ACTIVE: | ||
1115 | 241 | color1, color2 = bg[theme.PRELIT_NORMAL] | ||
1116 | 242 | else: | ||
1117 | 243 | color1, color2 = bg[theme.PRELIT_ACTIVE] | ||
1118 | 244 | |||
1119 | 245 | self._draw_rect(cr, 1, 1, w-1, h-1, r) | ||
1120 | 246 | lin = cairo.LinearGradient(0, 0, 0, h-1) | ||
1121 | 247 | lin.add_color_stop_rgb(0.0, *color1) | ||
1122 | 248 | lin.add_color_stop_rgb(1.0, *color2) | ||
1123 | 249 | cr.set_source(lin) | ||
1124 | 250 | cr.fill() | ||
1125 | 251 | |||
1126 | 252 | cr.set_line_width(1.0) | ||
1127 | 253 | # strong outline | ||
1128 | 254 | self._draw_rect(cr, 1.5, 1.5, w-1.5, h-1.5, r) | ||
1129 | 255 | cr.set_source_rgb(*outer[state]) | ||
1130 | 256 | cr.stroke() | ||
1131 | 257 | |||
1132 | 258 | # inner bevel/highlight | ||
1133 | 259 | if theme.light_line_colors[state]: | ||
1134 | 260 | self._draw_rect(cr, 2.5, 2.5, w-2.5, h-2.5, r) | ||
1135 | 261 | r, g, b = inner[state] | ||
1136 | 262 | cr.set_source_rgba(r, g, b, 0.6) | ||
1137 | 263 | cr.stroke() | ||
1138 | 264 | return | ||
1139 | 265 | |||
1140 | 266 | def _draw_rect(self, cr, x, y, w, h, r): | ||
1141 | 267 | global M_PI, PI_OVER_180 | ||
1142 | 268 | cr.new_sub_path() | ||
1143 | 269 | cr.arc(r+x, r+y, r, M_PI, 270*PI_OVER_180) | ||
1144 | 270 | cr.arc(w-r, r+y, r, 270*PI_OVER_180, 0) | ||
1145 | 271 | cr.arc(w-r, h-r, r, 0, 90*PI_OVER_180) | ||
1146 | 272 | cr.arc(r+x, h-r, r, 90*PI_OVER_180, M_PI) | ||
1147 | 273 | cr.close_path() | ||
1160 | 274 | return | 279 | return |
1161 | 275 | 280 | ||
1162 | 276 | 281 | ||
1163 | @@ -288,7 +293,8 @@ | |||
1164 | 288 | area.x, | 293 | area.x, |
1165 | 289 | area.y, | 294 | area.y, |
1166 | 290 | area.width + 10, | 295 | area.width + 10, |
1168 | 291 | area.height) | 296 | area.height, |
1169 | 297 | wo=-10) | ||
1170 | 292 | return | 298 | return |
1171 | 293 | 299 | ||
1172 | 294 | 300 | ||
1173 | @@ -303,8 +309,10 @@ | |||
1174 | 303 | area = event.area | 309 | area = event.area |
1175 | 304 | expose_func(widget, | 310 | expose_func(widget, |
1176 | 305 | area, | 311 | area, |
1178 | 306 | area.x - 10, | 312 | area.x-10, |
1179 | 307 | area.y, | 313 | area.y, |
1182 | 308 | area.width + 10, | 314 | area.width+10, |
1183 | 309 | area.height) | 315 | area.height, |
1184 | 316 | xo=10, | ||
1185 | 317 | wo=-10) | ||
1186 | 310 | return | 318 | return |
1187 | 311 | 319 | ||
1188 | === removed file 'softwarecenter/view/widgets/pathbar2.py' | |||
1189 | --- softwarecenter/view/widgets/pathbar2.py 2010-03-03 09:18:00 +0000 | |||
1190 | +++ softwarecenter/view/widgets/pathbar2.py 1970-01-01 00:00:00 +0000 | |||
1191 | @@ -1,1605 +0,0 @@ | |||
1192 | 1 | # Copyright (C) 2009 Matthew McGowan | ||
1193 | 2 | # | ||
1194 | 3 | # Authors: | ||
1195 | 4 | # Matthew McGowan | ||
1196 | 5 | # | ||
1197 | 6 | # This program is free software: you can redistribute it and/or modify | ||
1198 | 7 | # it under the terms of the GNU General Public License as published by | ||
1199 | 8 | # the Free Software Foundation, either version 3 of the License, or | ||
1200 | 9 | # (at your option) any later version. | ||
1201 | 10 | # | ||
1202 | 11 | # This program is distributed in the hope that it will be useful, | ||
1203 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1204 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1205 | 14 | # GNU General Public License for more details. | ||
1206 | 15 | # | ||
1207 | 16 | # You should have received a copy of the GNU General Public License | ||
1208 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1209 | 18 | |||
1210 | 19 | import atk | ||
1211 | 20 | import cairo | ||
1212 | 21 | import gobject | ||
1213 | 22 | import gtk | ||
1214 | 23 | import pango | ||
1215 | 24 | import rgb | ||
1216 | 25 | |||
1217 | 26 | from rgb import to_float as f | ||
1218 | 27 | |||
1219 | 28 | # pi constants | ||
1220 | 29 | M_PI = 3.1415926535897931 | ||
1221 | 30 | PI_OVER_180 = 0.017453292519943295 | ||
1222 | 31 | |||
1223 | 32 | from gettext import gettext as _ | ||
1224 | 33 | |||
1225 | 34 | class PathBar(gtk.DrawingArea): | ||
1226 | 35 | |||
1227 | 36 | # shapes | ||
1228 | 37 | SHAPE_RECTANGLE = 0 | ||
1229 | 38 | SHAPE_START_ARROW = 1 | ||
1230 | 39 | SHAPE_MID_ARROW = 2 | ||
1231 | 40 | SHAPE_END_CAP = 3 | ||
1232 | 41 | |||
1233 | 42 | def __init__(self, group=None): | ||
1234 | 43 | gtk.DrawingArea.__init__(self) | ||
1235 | 44 | self.__init_drawing() | ||
1236 | 45 | self.set_redraw_on_allocate(False) | ||
1237 | 46 | |||
1238 | 47 | self.__parts = [] | ||
1239 | 48 | self.__active_part = None | ||
1240 | 49 | self.__focal_part = None | ||
1241 | 50 | self.__button_down = False, None | ||
1242 | 51 | |||
1243 | 52 | self.__scroller = None | ||
1244 | 53 | self.__scroll_xO = 0 | ||
1245 | 54 | |||
1246 | 55 | self.theme = self.__pick_theme() | ||
1247 | 56 | |||
1248 | 57 | atk_desc = self.get_accessible() | ||
1249 | 58 | # Accessibility name for the pathbar | ||
1250 | 59 | atk_desc.set_name(_("You are here:")) | ||
1251 | 60 | atk_desc.set_role(atk.ROLE_PANEL) | ||
1252 | 61 | |||
1253 | 62 | # setup event handling | ||
1254 | 63 | self.set_flags(gtk.CAN_FOCUS) | ||
1255 | 64 | self.set_events(gtk.gdk.POINTER_MOTION_MASK| | ||
1256 | 65 | gtk.gdk.BUTTON_PRESS_MASK| | ||
1257 | 66 | gtk.gdk.BUTTON_RELEASE_MASK| | ||
1258 | 67 | gtk.gdk.KEY_RELEASE_MASK| | ||
1259 | 68 | gtk.gdk.KEY_PRESS_MASK| | ||
1260 | 69 | gtk.gdk.ENTER_NOTIFY_MASK| | ||
1261 | 70 | gtk.gdk.LEAVE_NOTIFY_MASK) | ||
1262 | 71 | |||
1263 | 72 | self.connect("motion-notify-event", self.__motion_notify_cb) | ||
1264 | 73 | self.connect("enter-notify-event", self.__enter_notify_cb) | ||
1265 | 74 | self.connect("leave-notify-event", self.__leave_notify_cb) | ||
1266 | 75 | self.connect("button-press-event", self.__button_press_cb) | ||
1267 | 76 | self.connect("button-release-event", self.__button_release_cb) | ||
1268 | 77 | # self.connect("key-release-event", self.__key_release_cb) | ||
1269 | 78 | |||
1270 | 79 | self.connect("realize", self.__realize_cb) | ||
1271 | 80 | self.connect("expose-event", self.__expose_cb) | ||
1272 | 81 | self.connect("style-set", self.__style_change_cb) | ||
1273 | 82 | self.connect("size-allocate", self.__allocation_change_cb) | ||
1274 | 83 | return | ||
1275 | 84 | |||
1276 | 85 | def get_parts(self): | ||
1277 | 86 | return self.__parts | ||
1278 | 87 | |||
1279 | 88 | def set_active(self, part, do_callback=True): | ||
1280 | 89 | part.set_state(gtk.STATE_ACTIVE) | ||
1281 | 90 | prev, redraw = self.__set_active(part, do_callback) | ||
1282 | 91 | if redraw: | ||
1283 | 92 | self.queue_draw_area(*prev.get_allocation_tuple()) | ||
1284 | 93 | self.queue_draw_area(*part.get_allocation_tuple()) | ||
1285 | 94 | return | ||
1286 | 95 | |||
1287 | 96 | def get_active(self): | ||
1288 | 97 | return self.__active_part | ||
1289 | 98 | |||
1290 | 99 | # def get_left_part(self): | ||
1291 | 100 | # active = self.get_active() | ||
1292 | 101 | # if not active: | ||
1293 | 102 | # return self.__parts[0] | ||
1294 | 103 | |||
1295 | 104 | # i = self.__parts.index(active)+1 | ||
1296 | 105 | # if i > len(self.__parts)-1: | ||
1297 | 106 | # i = 0 | ||
1298 | 107 | # return self.__parts[i] | ||
1299 | 108 | |||
1300 | 109 | # def get_right_part(self): | ||
1301 | 110 | # active = self.get_active() | ||
1302 | 111 | # if not active: | ||
1303 | 112 | # return self.__parts[0] | ||
1304 | 113 | |||
1305 | 114 | # i = self.__parts.index(active)-1 | ||
1306 | 115 | # if i < 0: | ||
1307 | 116 | # i = len(self.__parts)-1 | ||
1308 | 117 | # return self.__parts[i] | ||
1309 | 118 | |||
1310 | 119 | def append(self, part, do_callback=True, animate=True): | ||
1311 | 120 | prev, did_shrink = self.__append(part, do_callback) | ||
1312 | 121 | if not self.get_property("visible"): | ||
1313 | 122 | return False | ||
1314 | 123 | |||
1315 | 124 | if animate and self.theme.animate and len(self.__parts) > 1: | ||
1316 | 125 | aw = self.theme.arrow_width | ||
1317 | 126 | |||
1318 | 127 | # calc draw_area | ||
1319 | 128 | x,y,w,h = part.get_allocation_tuple() | ||
1320 | 129 | w += aw | ||
1321 | 130 | |||
1322 | 131 | # begin scroll animation | ||
1323 | 132 | self.__hscroll_out_init( | ||
1324 | 133 | part.get_width(), | ||
1325 | 134 | gtk.gdk.Rectangle(x,y,w,h), | ||
1326 | 135 | self.theme.scroll_duration_ms, | ||
1327 | 136 | self.theme.scroll_fps | ||
1328 | 137 | ) | ||
1329 | 138 | else: | ||
1330 | 139 | self.queue_draw_area(*part.get_allocation_tuple()) | ||
1331 | 140 | return False | ||
1332 | 141 | |||
1333 | 142 | def append_no_callback(self, part): | ||
1334 | 143 | self.append(part, do_callback=False) | ||
1335 | 144 | |||
1336 | 145 | def remove(self, part): | ||
1337 | 146 | if len(self.__parts)-1 < 1: | ||
1338 | 147 | print 'The first part is sacred ;)' | ||
1339 | 148 | return | ||
1340 | 149 | |||
1341 | 150 | old_w = self.__draw_width() | ||
1342 | 151 | |||
1343 | 152 | # remove part from interal part list | ||
1344 | 153 | try: | ||
1345 | 154 | del self.__parts[self.__parts.index(part)] | ||
1346 | 155 | except: | ||
1347 | 156 | print 'part not in list!' | ||
1348 | 157 | return | ||
1349 | 158 | self.__compose_parts(self.__parts[-1], False) | ||
1350 | 159 | |||
1351 | 160 | if old_w >= self.allocation.width: | ||
1352 | 161 | self.__grow_check(old_w, self.allocation) | ||
1353 | 162 | self.queue_draw() | ||
1354 | 163 | |||
1355 | 164 | else: | ||
1356 | 165 | self.queue_draw_area(*part.get_allocation_tuple()) | ||
1357 | 166 | self.queue_draw_area(*self.__parts[-1].get_allocation_tuple()) | ||
1358 | 167 | return | ||
1359 | 168 | |||
1360 | 169 | def remove_all(self, keep_first_part=True): | ||
1361 | 170 | """remove all elements""" | ||
1362 | 171 | if keep_first_part: | ||
1363 | 172 | self.__parts = [self.__parts[0],] # keep first part though! | ||
1364 | 173 | self.__compose_parts(self.__parts[-1], False) | ||
1365 | 174 | else: | ||
1366 | 175 | self.__parts = [] | ||
1367 | 176 | self.id_to_part = {} | ||
1368 | 177 | self.queue_draw() | ||
1369 | 178 | return | ||
1370 | 179 | |||
1371 | 180 | def navigate_up(self): | ||
1372 | 181 | if len(self.__parts) > 1: | ||
1373 | 182 | nav_part = self.__parts[len(self.__parts) - 2] | ||
1374 | 183 | self.set_active(nav_part) | ||
1375 | 184 | return | ||
1376 | 185 | |||
1377 | 186 | # def navigate_up(self, remove_pathparts=False): | ||
1378 | 187 | # index = self.__parts.index(self.__active_part) | ||
1379 | 188 | # if index-1 == -1: return None, index-1, len(self.__parts) | ||
1380 | 189 | # self.set_active(self.__parts[index-1], remove_pathparts) | ||
1381 | 190 | # return self.__parts[index-1], index-1, len(self.__parts) | ||
1382 | 191 | |||
1383 | 192 | # def navigate_down(self): | ||
1384 | 193 | # index = self.__parts.index(self.__active_part) | ||
1385 | 194 | # if self.__parts[index] == self.__parts[-1]: return None, index+1, len(self.__parts) | ||
1386 | 195 | # self.set_active(self.__parts[index+1], False) | ||
1387 | 196 | # return self.__parts[index+1], index+1, len(self.__parts) | ||
1388 | 197 | |||
1389 | 198 | def __set_active(self, part, do_callback): | ||
1390 | 199 | prev_active = self.__active_part | ||
1391 | 200 | redraw = False | ||
1392 | 201 | if part.callback and do_callback: | ||
1393 | 202 | part.callback(self, part) | ||
1394 | 203 | if prev_active and prev_active != part: | ||
1395 | 204 | prev_active.set_state(gtk.STATE_NORMAL) | ||
1396 | 205 | redraw = True | ||
1397 | 206 | |||
1398 | 207 | self.__active_part = part | ||
1399 | 208 | return prev_active, redraw | ||
1400 | 209 | |||
1401 | 210 | def __append(self, part, do_callback=True): | ||
1402 | 211 | # clean up any exisitng scroll callbacks | ||
1403 | 212 | if self.__scroller: | ||
1404 | 213 | gobject.source_remove(self.__scroller) | ||
1405 | 214 | self.__scroll_xO = 0 | ||
1406 | 215 | |||
1407 | 216 | # the basics | ||
1408 | 217 | x = self.__draw_width() | ||
1409 | 218 | self.__parts.append(part) | ||
1410 | 219 | part.set_pathbar(self) | ||
1411 | 220 | |||
1412 | 221 | self.set_active(part, do_callback) | ||
1413 | 222 | |||
1414 | 223 | # determin part shapes, and calc modified parts widths | ||
1415 | 224 | prev = self.__compose_parts(part, True) | ||
1416 | 225 | # set the position of new part | ||
1417 | 226 | part.set_x(x) | ||
1418 | 227 | |||
1419 | 228 | # check parts fit to widgets allocated width | ||
1420 | 229 | if x + part.get_width() > self.allocation.width and \ | ||
1421 | 230 | self.allocation.width != 1: | ||
1422 | 231 | self.__shrink_check(self.allocation) | ||
1423 | 232 | return prev, True | ||
1424 | 233 | |||
1425 | 234 | return prev, False | ||
1426 | 235 | |||
1427 | 236 | # def __shorten(self, n): | ||
1428 | 237 | # n = int(n) | ||
1429 | 238 | # old_w = self.__draw_width() | ||
1430 | 239 | # end_active = self.get_active() == self.__parts[-1] | ||
1431 | 240 | |||
1432 | 241 | # if len(self.__parts)-n < 1: | ||
1433 | 242 | # print WARNING + 'The first part is sacred ;)' + ENDC | ||
1434 | 243 | # return old_w, False | ||
1435 | 244 | |||
1436 | 245 | # del self.__parts[-n:] | ||
1437 | 246 | # self.__compose_parts(self.__parts[-1], False) | ||
1438 | 247 | |||
1439 | 248 | # if end_active: | ||
1440 | 249 | # self.set_active(self.__parts[-1]) | ||
1441 | 250 | |||
1442 | 251 | # if old_w >= self.allocation.width: | ||
1443 | 252 | # self.__grow_check(old_w, self.allocation) | ||
1444 | 253 | # return old_w, True | ||
1445 | 254 | |||
1446 | 255 | # return old_w, False | ||
1447 | 256 | |||
1448 | 257 | def __shrink_check(self, allocation): | ||
1449 | 258 | path_w = self.__draw_width() | ||
1450 | 259 | shrinkage = path_w - allocation.width | ||
1451 | 260 | mpw = self.theme.min_part_width | ||
1452 | 261 | xO = 0 | ||
1453 | 262 | |||
1454 | 263 | for part in self.__parts[:-1]: | ||
1455 | 264 | w = part.get_width() | ||
1456 | 265 | dw = 0 | ||
1457 | 266 | |||
1458 | 267 | if w - shrinkage <= mpw: | ||
1459 | 268 | dw = w - mpw | ||
1460 | 269 | shrinkage -= dw | ||
1461 | 270 | part.set_size(mpw, -1) | ||
1462 | 271 | part.set_x(part.get_x() - xO) | ||
1463 | 272 | |||
1464 | 273 | else: | ||
1465 | 274 | part.set_size(w - shrinkage, -1) | ||
1466 | 275 | part.set_x(part.get_x() - xO) | ||
1467 | 276 | dw = shrinkage | ||
1468 | 277 | shrinkage = 0 | ||
1469 | 278 | |||
1470 | 279 | xO += dw | ||
1471 | 280 | |||
1472 | 281 | last = self.__parts[-1] | ||
1473 | 282 | last.set_x(last.get_x() - xO) | ||
1474 | 283 | return | ||
1475 | 284 | |||
1476 | 285 | def __grow_check(self, old_width, allocation): | ||
1477 | 286 | parts = self.__parts | ||
1478 | 287 | if len(parts) == 0: | ||
1479 | 288 | return | ||
1480 | 289 | |||
1481 | 290 | growth = old_width - self.__draw_width() | ||
1482 | 291 | parts.reverse() | ||
1483 | 292 | |||
1484 | 293 | for part in parts: | ||
1485 | 294 | bw = part.get_size_requisition()[0] | ||
1486 | 295 | w = part.get_width() | ||
1487 | 296 | |||
1488 | 297 | if w < bw: | ||
1489 | 298 | dw = bw - w | ||
1490 | 299 | |||
1491 | 300 | if dw <= growth: | ||
1492 | 301 | growth -= dw | ||
1493 | 302 | part.set_size(bw, -1) | ||
1494 | 303 | part.set_x(part.get_x() + growth) | ||
1495 | 304 | |||
1496 | 305 | else: | ||
1497 | 306 | part.set_size(w + growth, -1) | ||
1498 | 307 | growth = 0 | ||
1499 | 308 | |||
1500 | 309 | else: | ||
1501 | 310 | part.set_x(part.get_x() + growth) | ||
1502 | 311 | |||
1503 | 312 | parts.reverse() | ||
1504 | 313 | shift = parts[0].get_x() | ||
1505 | 314 | |||
1506 | 315 | # left align parts | ||
1507 | 316 | if shift > 0: | ||
1508 | 317 | for part in parts: part.set_x(part.get_x() - shift) | ||
1509 | 318 | return | ||
1510 | 319 | |||
1511 | 320 | def __compose_parts(self, last, prev_set_size): | ||
1512 | 321 | parts = self.__parts | ||
1513 | 322 | |||
1514 | 323 | if len(parts) == 1: | ||
1515 | 324 | last.set_shape(self.SHAPE_RECTANGLE) | ||
1516 | 325 | last.set_size(*last.calc_size_requisition()) | ||
1517 | 326 | prev = None | ||
1518 | 327 | |||
1519 | 328 | elif len(parts) == 2: | ||
1520 | 329 | prev = parts[0] | ||
1521 | 330 | prev.set_shape(self.SHAPE_START_ARROW) | ||
1522 | 331 | prev.calc_size_requisition() | ||
1523 | 332 | |||
1524 | 333 | last.set_shape(self.SHAPE_END_CAP) | ||
1525 | 334 | last.set_size(*last.calc_size_requisition()) | ||
1526 | 335 | |||
1527 | 336 | else: | ||
1528 | 337 | prev = parts[-2] | ||
1529 | 338 | prev.set_shape(self.SHAPE_MID_ARROW) | ||
1530 | 339 | prev.calc_size_requisition() | ||
1531 | 340 | |||
1532 | 341 | last.set_shape(self.SHAPE_END_CAP) | ||
1533 | 342 | last.set_size(*last.calc_size_requisition()) | ||
1534 | 343 | |||
1535 | 344 | if prev and prev_set_size: | ||
1536 | 345 | prev.set_size(*prev.get_size_requisition()) | ||
1537 | 346 | return prev | ||
1538 | 347 | |||
1539 | 348 | def __draw_width(self): | ||
1540 | 349 | l = len(self.__parts) | ||
1541 | 350 | if l == 0: | ||
1542 | 351 | return 0 | ||
1543 | 352 | a = self.__parts[-1].allocation | ||
1544 | 353 | return a[0] + a[2] | ||
1545 | 354 | |||
1546 | 355 | def __hscroll_out_init(self, distance, draw_area, duration, fps): | ||
1547 | 356 | self.__scroller = gobject.timeout_add( | ||
1548 | 357 | int(1000.0 / fps), # interval | ||
1549 | 358 | self.__hscroll_out_cb, | ||
1550 | 359 | distance, | ||
1551 | 360 | duration*0.001, # 1 over duration (converted to seconds) | ||
1552 | 361 | gobject.get_current_time(), | ||
1553 | 362 | draw_area.x, | ||
1554 | 363 | draw_area.y, | ||
1555 | 364 | draw_area.width, | ||
1556 | 365 | draw_area.height) | ||
1557 | 366 | return | ||
1558 | 367 | |||
1559 | 368 | def __hscroll_out_cb(self, distance, duration, start_t, x, y, w, h): | ||
1560 | 369 | cur_t = gobject.get_current_time() | ||
1561 | 370 | xO = distance - distance*((cur_t - start_t) / duration) | ||
1562 | 371 | |||
1563 | 372 | if xO > 0: | ||
1564 | 373 | self.__scroll_xO = xO | ||
1565 | 374 | self.queue_draw_area(x, y, w, h) | ||
1566 | 375 | else: # final frame | ||
1567 | 376 | self.__scroll_xO = 0 | ||
1568 | 377 | # redraw the entire widget | ||
1569 | 378 | # incase some timeouts are skipped due to high system load | ||
1570 | 379 | self.queue_draw() | ||
1571 | 380 | self.__scroller = None | ||
1572 | 381 | return False | ||
1573 | 382 | return True | ||
1574 | 383 | |||
1575 | 384 | def __part_at_xy(self, x, y): | ||
1576 | 385 | for part in self.__parts: | ||
1577 | 386 | a = part.get_allocation() | ||
1578 | 387 | region = gtk.gdk.region_rectangle(a) | ||
1579 | 388 | |||
1580 | 389 | if region.point_in(int(x), int(y)): | ||
1581 | 390 | return part | ||
1582 | 391 | return None | ||
1583 | 392 | |||
1584 | 393 | def __draw_hscroll(self, cr): | ||
1585 | 394 | if len(self.__parts) < 2: | ||
1586 | 395 | return | ||
1587 | 396 | |||
1588 | 397 | # draw the last two parts | ||
1589 | 398 | prev, last = self.__parts[-2:] | ||
1590 | 399 | |||
1591 | 400 | # style theme stuff | ||
1592 | 401 | style, r, aw, shapes = self.style, self.theme.curvature, \ | ||
1593 | 402 | self.theme.arrow_width, self.__shapes | ||
1594 | 403 | |||
1595 | 404 | # draw part that need scrolling | ||
1596 | 405 | self.__draw_part(cr, | ||
1597 | 406 | last, | ||
1598 | 407 | style, | ||
1599 | 408 | r, | ||
1600 | 409 | aw, | ||
1601 | 410 | shapes, | ||
1602 | 411 | self.__scroll_xO) | ||
1603 | 412 | |||
1604 | 413 | # draw the last part that does not scroll | ||
1605 | 414 | self.__draw_part(cr, | ||
1606 | 415 | prev, | ||
1607 | 416 | style, | ||
1608 | 417 | r, | ||
1609 | 418 | aw, | ||
1610 | 419 | shapes) | ||
1611 | 420 | return | ||
1612 | 421 | |||
1613 | 422 | def __draw_all(self, cr, event_area): | ||
1614 | 423 | style = self.style | ||
1615 | 424 | r = self.theme.curvature | ||
1616 | 425 | aw = self.theme.arrow_width | ||
1617 | 426 | shapes = self.__shapes | ||
1618 | 427 | region = gtk.gdk.region_rectangle(event_area) | ||
1619 | 428 | |||
1620 | 429 | # if a scroll is pending we want to not draw the final part, | ||
1621 | 430 | # as we don't want to prematurely reveal the part befor the | ||
1622 | 431 | # scroll animation has had a chance to start | ||
1623 | 432 | if self.__scroller: | ||
1624 | 433 | parts = self.__parts[:-1] | ||
1625 | 434 | else: | ||
1626 | 435 | parts = self.__parts | ||
1627 | 436 | |||
1628 | 437 | parts.reverse() | ||
1629 | 438 | for part in parts: | ||
1630 | 439 | if region.rect_in(part.get_allocation()) != gtk.gdk.OVERLAP_RECTANGLE_OUT: | ||
1631 | 440 | self.__draw_part(cr, part, style, r, aw, shapes) | ||
1632 | 441 | parts.reverse() | ||
1633 | 442 | return | ||
1634 | 443 | |||
1635 | 444 | def __draw_part_ltr(self, cr, part, style, r, aw, shapes, sxO=0): | ||
1636 | 445 | x, y, w, h = part.get_allocation() | ||
1637 | 446 | shape = part.shape | ||
1638 | 447 | state = part.state | ||
1639 | 448 | icon_pb = part.icon.pixbuf | ||
1640 | 449 | |||
1641 | 450 | cr.save() | ||
1642 | 451 | cr.translate(x-sxO, y) | ||
1643 | 452 | |||
1644 | 453 | # draw bg | ||
1645 | 454 | self.__draw_part_bg(cr, part, w, h, state, shape, style,r, aw, shapes) | ||
1646 | 455 | |||
1647 | 456 | # determine left margin. left margin depends on part shape | ||
1648 | 457 | # and whether there exists an icon or not | ||
1649 | 458 | if shape == self.SHAPE_MID_ARROW or shape == self.SHAPE_END_CAP: | ||
1650 | 459 | margin = int(0.75*self.theme.arrow_width + self.theme.xpadding) | ||
1651 | 460 | else: | ||
1652 | 461 | margin = self.theme.xpadding | ||
1653 | 462 | |||
1654 | 463 | # draw icon | ||
1655 | 464 | if icon_pb: | ||
1656 | 465 | cr.set_source_pixbuf( | ||
1657 | 466 | icon_pb, | ||
1658 | 467 | self.theme.xpadding-sxO, | ||
1659 | 468 | (alloc.height - icon_pb.get_height())/2) | ||
1660 | 469 | cr.paint() | ||
1661 | 470 | margin += icon_pb.get_width() + self.theme.spacing | ||
1662 | 471 | |||
1663 | 472 | # if space is limited and an icon is set, dont draw label | ||
1664 | 473 | # otherwise, draw label | ||
1665 | 474 | if w == self.theme.min_part_width and icon_pb: | ||
1666 | 475 | pass | ||
1667 | 476 | |||
1668 | 477 | else: | ||
1669 | 478 | layout = part.get_layout() | ||
1670 | 479 | lw, lh = layout.get_pixel_size() | ||
1671 | 480 | dst_x = x + margin - int(sxO) | ||
1672 | 481 | dst_y = (self.allocation.height - lh)/2+1 | ||
1673 | 482 | style.paint_layout( | ||
1674 | 483 | self.window, | ||
1675 | 484 | self.theme.text_state[state], | ||
1676 | 485 | False, | ||
1677 | 486 | (dst_x, dst_y, lw+4, lh), # clip area | ||
1678 | 487 | self, | ||
1679 | 488 | None, | ||
1680 | 489 | dst_x, | ||
1681 | 490 | dst_y, | ||
1682 | 491 | layout) | ||
1683 | 492 | |||
1684 | 493 | cr.restore() | ||
1685 | 494 | return | ||
1686 | 495 | |||
1687 | 496 | def __draw_part_rtl(self, cr, part, style, r, aw, shapes, sxO=0): | ||
1688 | 497 | x, y, w, h = part.get_allocation() | ||
1689 | 498 | shape = part.shape | ||
1690 | 499 | state = part.state | ||
1691 | 500 | icon_pb = part.icon.pixbuf | ||
1692 | 501 | |||
1693 | 502 | cr.save() | ||
1694 | 503 | cr.translate(x+sxO, y) | ||
1695 | 504 | |||
1696 | 505 | # draw bg | ||
1697 | 506 | self.__draw_part_bg(cr, part, w, h, state, shape, style,r, aw, shapes) | ||
1698 | 507 | |||
1699 | 508 | # determine left margin. left margin depends on part shape | ||
1700 | 509 | # and whether there exists an icon or not | ||
1701 | 510 | if shape == self.SHAPE_MID_ARROW or shape == self.SHAPE_END_CAP: | ||
1702 | 511 | margin = self.theme.arrow_width + self.theme.xpadding | ||
1703 | 512 | else: | ||
1704 | 513 | margin = self.theme.xpadding | ||
1705 | 514 | |||
1706 | 515 | # draw icon | ||
1707 | 516 | if icon_pb: | ||
1708 | 517 | margin += icon_pb.get_width() | ||
1709 | 518 | cr.set_source_pixbuf( | ||
1710 | 519 | icon_pb, | ||
1711 | 520 | w - margin + sxO, | ||
1712 | 521 | (h - icon_pb.get_height())/2) | ||
1713 | 522 | cr.paint() | ||
1714 | 523 | margin += self.spacing | ||
1715 | 524 | |||
1716 | 525 | # if space is limited and an icon is set, dont draw label | ||
1717 | 526 | # otherwise, draw label | ||
1718 | 527 | if w == self.theme.min_part_width and icon_pb: | ||
1719 | 528 | pass | ||
1720 | 529 | |||
1721 | 530 | else: | ||
1722 | 531 | layout = part.get_layout() | ||
1723 | 532 | lw, lh = layout.get_pixel_size() | ||
1724 | 533 | dst_x = x + part.get_width() - margin - lw + int(sxO) | ||
1725 | 534 | dst_y = (self.allocation.height - lh)/2+1 | ||
1726 | 535 | style.paint_layout( | ||
1727 | 536 | self.window, | ||
1728 | 537 | self.theme.text_state[state], | ||
1729 | 538 | False, | ||
1730 | 539 | None, | ||
1731 | 540 | self, | ||
1732 | 541 | None, | ||
1733 | 542 | dst_x, | ||
1734 | 543 | dst_y, | ||
1735 | 544 | layout) | ||
1736 | 545 | |||
1737 | 546 | cr.restore() | ||
1738 | 547 | return | ||
1739 | 548 | |||
1740 | 549 | def __draw_part_bg(self, cr, part, w, h, state, shape, style, r, aw, shapes): | ||
1741 | 550 | # outer slight bevel or focal highlight | ||
1742 | 551 | shapes[shape](cr, 0, 0, w, h, r, aw) | ||
1743 | 552 | cr.set_source_rgba(0, 0, 0, 0.055) | ||
1744 | 553 | cr.fill() | ||
1745 | 554 | |||
1746 | 555 | # colour scheme dicts | ||
1747 | 556 | bg = self.theme.bg_colors | ||
1748 | 557 | outer = self.theme.dark_line_colors | ||
1749 | 558 | inner = self.theme.light_line_colors | ||
1750 | 559 | |||
1751 | 560 | # bg linear vertical gradient | ||
1752 | 561 | if state != gtk.STATE_PRELIGHT: | ||
1753 | 562 | color1, color2 = bg[state] | ||
1754 | 563 | else: | ||
1755 | 564 | if part != self.get_active(): | ||
1756 | 565 | color1, color2 = bg[self.theme.PRELIT_NORMAL] | ||
1757 | 566 | else: | ||
1758 | 567 | color1, color2 = bg[self.theme.PRELIT_ACTIVE] | ||
1759 | 568 | |||
1760 | 569 | shapes[shape](cr, 1, 1, w-1, h-1, r, aw) | ||
1761 | 570 | lin = cairo.LinearGradient(0, 0, 0, h-1) | ||
1762 | 571 | lin.add_color_stop_rgb(0.0, *color1) | ||
1763 | 572 | lin.add_color_stop_rgb(1.0, *color2) | ||
1764 | 573 | cr.set_source(lin) | ||
1765 | 574 | cr.fill() | ||
1766 | 575 | |||
1767 | 576 | cr.set_line_width(1.0) | ||
1768 | 577 | # strong outline | ||
1769 | 578 | shapes[shape](cr, 1.5, 1.5, w-1.5, h-1.5, r, aw) | ||
1770 | 579 | cr.set_source_rgb(*outer[state]) | ||
1771 | 580 | cr.stroke() | ||
1772 | 581 | |||
1773 | 582 | # inner bevel/highlight | ||
1774 | 583 | if self.theme.light_line_colors[state]: | ||
1775 | 584 | shapes[shape](cr, 2.5, 2.5, w-2.5, h-2.5, r, aw) | ||
1776 | 585 | r, g, b = inner[state] | ||
1777 | 586 | cr.set_source_rgba(r, g, b, 0.6) | ||
1778 | 587 | cr.stroke() | ||
1779 | 588 | return | ||
1780 | 589 | |||
1781 | 590 | def __shape_rect(self, cr, x, y, w, h, r, aw): | ||
1782 | 591 | global M_PI, PI_OVER_180 | ||
1783 | 592 | cr.new_sub_path() | ||
1784 | 593 | cr.arc(r+x, r+y, r, M_PI, 270*PI_OVER_180) | ||
1785 | 594 | cr.arc(w-r, r+y, r, 270*PI_OVER_180, 0) | ||
1786 | 595 | cr.arc(w-r, h-r, r, 0, 90*PI_OVER_180) | ||
1787 | 596 | cr.arc(r+x, h-r, r, 90*PI_OVER_180, M_PI) | ||
1788 | 597 | cr.close_path() | ||
1789 | 598 | return | ||
1790 | 599 | |||
1791 | 600 | def __shape_start_arrow_ltr(self, cr, x, y, w, h, r, aw): | ||
1792 | 601 | global M_PI, PI_OVER_180 | ||
1793 | 602 | cr.new_sub_path() | ||
1794 | 603 | cr.arc(r+x, r+y, r, M_PI, 270*PI_OVER_180) | ||
1795 | 604 | # arrow head | ||
1796 | 605 | cr.line_to(w-aw+1, y) | ||
1797 | 606 | cr.line_to(w, (h+y)*0.5) | ||
1798 | 607 | cr.line_to(w-aw+1, h) | ||
1799 | 608 | cr.arc(r+x, h-r, r, 90*PI_OVER_180, M_PI) | ||
1800 | 609 | cr.close_path() | ||
1801 | 610 | return | ||
1802 | 611 | |||
1803 | 612 | def __shape_mid_arrow_ltr(self, cr, x, y, w, h, r, aw): | ||
1804 | 613 | cr.move_to(-1, y) | ||
1805 | 614 | # arrow head | ||
1806 | 615 | cr.line_to(w-aw+1, y) | ||
1807 | 616 | cr.line_to(w, (h+y)*0.5) | ||
1808 | 617 | cr.line_to(w-aw+1, h) | ||
1809 | 618 | cr.line_to(-1, h) | ||
1810 | 619 | cr.close_path() | ||
1811 | 620 | return | ||
1812 | 621 | |||
1813 | 622 | def __shape_end_cap_ltr(self, cr, x, y, w, h, r, aw): | ||
1814 | 623 | global M_PI, PI_OVER_180 | ||
1815 | 624 | cr.move_to(-1, y) | ||
1816 | 625 | cr.arc(w-r, r+y, r, 270*PI_OVER_180, 0) | ||
1817 | 626 | cr.arc(w-r, h-r, r, 0, 90*PI_OVER_180) | ||
1818 | 627 | cr.line_to(-1, h) | ||
1819 | 628 | cr.close_path() | ||
1820 | 629 | return | ||
1821 | 630 | |||
1822 | 631 | def __shape_start_arrow_rtl(self, cr, x, y, w, h, r, aw): | ||
1823 | 632 | global M_PI, PI_OVER_180 | ||
1824 | 633 | cr.new_sub_path() | ||
1825 | 634 | cr.move_to(x, (h+y)*0.5) | ||
1826 | 635 | cr.line_to(aw-1, y) | ||
1827 | 636 | cr.arc(w-r, r+y, r, 270*PI_OVER_180, 0) | ||
1828 | 637 | cr.arc(w-r, h-r, r, 0, 90*PI_OVER_180) | ||
1829 | 638 | cr.line_to(aw-1, h) | ||
1830 | 639 | cr.close_path() | ||
1831 | 640 | return | ||
1832 | 641 | |||
1833 | 642 | def __shape_mid_arrow_rtl(self, cr, x, y, w, h, r, aw): | ||
1834 | 643 | cr.move_to(x, (h+y)*0.5) | ||
1835 | 644 | cr.line_to(aw-1, y) | ||
1836 | 645 | cr.line_to(w+1, y) | ||
1837 | 646 | cr.line_to(w+1, h) | ||
1838 | 647 | cr.line_to(aw-1, h) | ||
1839 | 648 | cr.close_path() | ||
1840 | 649 | return | ||
1841 | 650 | |||
1842 | 651 | def __shape_end_cap_rtl(self, cr, x, y, w, h, r, aw): | ||
1843 | 652 | global M_PI, PI_OVER_180 | ||
1844 | 653 | cr.arc(r+x, r+y, r, M_PI, 270*PI_OVER_180) | ||
1845 | 654 | cr.line_to(w+1, y) | ||
1846 | 655 | cr.line_to(w+1, h) | ||
1847 | 656 | cr.arc(r+x, h-r, r, 90*PI_OVER_180, M_PI) | ||
1848 | 657 | cr.close_path() | ||
1849 | 658 | return | ||
1850 | 659 | |||
1851 | 660 | def __state(self, part): | ||
1852 | 661 | # returns the idle state of the part depending on | ||
1853 | 662 | # whether part is active or not. | ||
1854 | 663 | if part == self.__active_part: | ||
1855 | 664 | return gtk.STATE_ACTIVE | ||
1856 | 665 | return gtk.STATE_NORMAL | ||
1857 | 666 | |||
1858 | 667 | def __tooltip_check(self, part): | ||
1859 | 668 | # only show a tooltip if part is truncated, i.e. not all label text is | ||
1860 | 669 | # visible. | ||
1861 | 670 | if part.is_truncated(): | ||
1862 | 671 | self.set_has_tooltip(False) | ||
1863 | 672 | gobject.timeout_add(50, self.__set_tooltip_cb, part.label) | ||
1864 | 673 | else: | ||
1865 | 674 | self.set_has_tooltip(False) | ||
1866 | 675 | return | ||
1867 | 676 | |||
1868 | 677 | def __set_tooltip_cb(self, text): | ||
1869 | 678 | # callback allows the tooltip position to be updated as pointer moves | ||
1870 | 679 | # accross different parts | ||
1871 | 680 | self.set_has_tooltip(True) | ||
1872 | 681 | self.set_tooltip_markup(text) | ||
1873 | 682 | return False | ||
1874 | 683 | |||
1875 | 684 | def __pick_theme(self, name=None): | ||
1876 | 685 | name = name or gtk.settings_get_default().get_property("gtk-theme-name") | ||
1877 | 686 | themes = PathBarThemes.DICT | ||
1878 | 687 | if themes.has_key(name): | ||
1879 | 688 | return themes[name]() | ||
1880 | 689 | print "No styling hints for %s are available" % name | ||
1881 | 690 | return PathBarThemeHuman() | ||
1882 | 691 | |||
1883 | 692 | def __init_drawing(self): | ||
1884 | 693 | if self.get_direction() != gtk.TEXT_DIR_RTL: | ||
1885 | 694 | self.__draw_part = self.__draw_part_ltr | ||
1886 | 695 | self.__shapes = { | ||
1887 | 696 | self.SHAPE_RECTANGLE : self.__shape_rect, | ||
1888 | 697 | self.SHAPE_START_ARROW : self.__shape_start_arrow_ltr, | ||
1889 | 698 | self.SHAPE_MID_ARROW : self.__shape_mid_arrow_ltr, | ||
1890 | 699 | self.SHAPE_END_CAP : self.__shape_end_cap_ltr} | ||
1891 | 700 | else: | ||
1892 | 701 | self.__draw_part = self.__draw_part_rtl | ||
1893 | 702 | self.__shapes = { | ||
1894 | 703 | self.SHAPE_RECTANGLE : self.__shape_rect, | ||
1895 | 704 | self.SHAPE_START_ARROW : self.__shape_start_arrow_rtl, | ||
1896 | 705 | self.SHAPE_MID_ARROW : self.__shape_mid_arrow_rtl, | ||
1897 | 706 | self.SHAPE_END_CAP : self.__shape_end_cap_rtl} | ||
1898 | 707 | return | ||
1899 | 708 | |||
1900 | 709 | def __motion_notify_cb(self, widget, event): | ||
1901 | 710 | if self.__scroll_xO > 0: | ||
1902 | 711 | return | ||
1903 | 712 | |||
1904 | 713 | part = self.__part_at_xy(event.x, event.y) | ||
1905 | 714 | prev_focal = self.__focal_part | ||
1906 | 715 | |||
1907 | 716 | if self.__button_down[0]: | ||
1908 | 717 | if part and prev_focal and part != prev_focal: | ||
1909 | 718 | if self.__button_down[1] == part: | ||
1910 | 719 | part.set_state(gtk.STATE_SELECTED) | ||
1911 | 720 | else: | ||
1912 | 721 | part.set_state(gtk.STATE_PRELIGHT) | ||
1913 | 722 | |||
1914 | 723 | prev_focal.set_state(self.__state(prev_focal)) | ||
1915 | 724 | self.queue_draw_area(*prev_focal.get_allocation_tuple()) | ||
1916 | 725 | self.queue_draw_area(*part.get_allocation_tuple()) | ||
1917 | 726 | self.__focal_part = part | ||
1918 | 727 | return | ||
1919 | 728 | |||
1920 | 729 | if part and part.state != gtk.STATE_PRELIGHT: | ||
1921 | 730 | self.__tooltip_check(part) | ||
1922 | 731 | part.set_state(gtk.STATE_PRELIGHT) | ||
1923 | 732 | |||
1924 | 733 | if prev_focal: | ||
1925 | 734 | prev_focal.set_state(self.__state(prev_focal)) | ||
1926 | 735 | self.queue_draw_area(*prev_focal.get_allocation_tuple()) | ||
1927 | 736 | |||
1928 | 737 | self.__focal_part = part | ||
1929 | 738 | self.queue_draw_area(*part.get_allocation_tuple()) | ||
1930 | 739 | |||
1931 | 740 | elif not part and prev_focal != None and \ | ||
1932 | 741 | not widget.window.get_pointer()[2] & gtk.gdk.BUTTON1_MASK: | ||
1933 | 742 | prev_focal.set_state(self.__state(prev_focal)) | ||
1934 | 743 | self.queue_draw_area(*prev_focal.get_allocation_tuple()) | ||
1935 | 744 | self.__focal_part = None | ||
1936 | 745 | return | ||
1937 | 746 | |||
1938 | 747 | def __enter_notify_cb(self, widget, event): | ||
1939 | 748 | if not self.__button_down[0] and not widget.window.get_pointer()[2] & gtk.gdk.BUTTON1_MASK: | ||
1940 | 749 | return | ||
1941 | 750 | |||
1942 | 751 | part = self.__part_at_xy(event.x, event.y) | ||
1943 | 752 | prev_focal = self.__focal_part | ||
1944 | 753 | |||
1945 | 754 | if part and prev_focal == part: | ||
1946 | 755 | part.set_state(gtk.STATE_SELECTED) | ||
1947 | 756 | self.queue_draw_area(*part.get_allocation_tuple()) | ||
1948 | 757 | return | ||
1949 | 758 | |||
1950 | 759 | def __leave_notify_cb(self, widget, event): | ||
1951 | 760 | prev_focal = self.__focal_part | ||
1952 | 761 | if prev_focal: | ||
1953 | 762 | prev_focal.set_state(self.__state(prev_focal)) | ||
1954 | 763 | self.queue_draw_area(*prev_focal.get_allocation_tuple()) | ||
1955 | 764 | |||
1956 | 765 | if not widget.window.get_pointer()[2] & gtk.gdk.BUTTON1_MASK: | ||
1957 | 766 | self.__focal_part = None | ||
1958 | 767 | return | ||
1959 | 768 | |||
1960 | 769 | def __button_press_cb(self, widget, event): | ||
1961 | 770 | part = self.__part_at_xy(event.x, event.y) | ||
1962 | 771 | self.__button_down = True, part | ||
1963 | 772 | if part: | ||
1964 | 773 | part.set_state(gtk.STATE_SELECTED) | ||
1965 | 774 | self.queue_draw_area(*part.get_allocation_tuple()) | ||
1966 | 775 | self.__focal_part = part | ||
1967 | 776 | return | ||
1968 | 777 | |||
1969 | 778 | def __button_release_cb(self, widget, event): | ||
1970 | 779 | part = self.__part_at_xy(event.x, event.y) | ||
1971 | 780 | if self.__focal_part and self.__focal_part != part: | ||
1972 | 781 | pass | ||
1973 | 782 | elif part and self.__button_down[0]: | ||
1974 | 783 | prev_active, redraw = self.__set_active(part, True) | ||
1975 | 784 | part.set_state(gtk.STATE_PRELIGHT) | ||
1976 | 785 | self.queue_draw_area(*part.get_allocation_tuple()) | ||
1977 | 786 | |||
1978 | 787 | if redraw: | ||
1979 | 788 | self.queue_draw_area(*prev_active.get_allocation_tuple()) | ||
1980 | 789 | self.__button_down = False, None | ||
1981 | 790 | return | ||
1982 | 791 | |||
1983 | 792 | # def __key_release_cb(self, widget, event): | ||
1984 | 793 | # part = None | ||
1985 | 794 | |||
1986 | 795 | # # left key pressed | ||
1987 | 796 | # if event.keyval == 65363: | ||
1988 | 797 | # part = self.get_left_part() | ||
1989 | 798 | |||
1990 | 799 | # # right key pressed | ||
1991 | 800 | # elif event.keyval == 65361: | ||
1992 | 801 | # part = self.get_right_part() | ||
1993 | 802 | |||
1994 | 803 | # if not part: return | ||
1995 | 804 | |||
1996 | 805 | # prev_active = self.set_active(part) | ||
1997 | 806 | # self.queue_draw_area(*part.allocation) | ||
1998 | 807 | # if prev_active: | ||
1999 | 808 | # self.queue_draw_area(*prev_active.allocation) | ||
2000 | 809 | |||
2001 | 810 | # part.emit("clicked", event.copy()) | ||
2002 | 811 | # return | ||
2003 | 812 | |||
2004 | 813 | def __realize_cb(self, widget): | ||
2005 | 814 | self.theme.load(widget.style) | ||
2006 | 815 | return | ||
2007 | 816 | |||
2008 | 817 | def __expose_cb(self, widget, event): | ||
2009 | 818 | cr = widget.window.cairo_create() | ||
2010 | 819 | |||
2011 | 820 | if self.theme.base_hack: | ||
2012 | 821 | cr.set_source_rgb(*self.theme.base_hack) | ||
2013 | 822 | cr.paint() | ||
2014 | 823 | |||
2015 | 824 | if self.__scroll_xO: | ||
2016 | 825 | self.__draw_hscroll(cr) | ||
2017 | 826 | else: | ||
2018 | 827 | self.__draw_all(cr, event.area) | ||
2019 | 828 | |||
2020 | 829 | del cr | ||
2021 | 830 | return | ||
2022 | 831 | |||
2023 | 832 | def __style_change_cb(self, widget, old_style): | ||
2024 | 833 | # when alloc.width == 1, this is typical of an unallocated widget, | ||
2025 | 834 | # lets not break a sweat for nothing... | ||
2026 | 835 | if self.allocation.width == 1: | ||
2027 | 836 | return | ||
2028 | 837 | |||
2029 | 838 | self.theme = self.__pick_theme() | ||
2030 | 839 | self.theme.load(widget.style) | ||
2031 | 840 | # set height to 0 so that if part height has been reduced the widget will | ||
2032 | 841 | # shrink to an appropriate new height based on new font size | ||
2033 | 842 | self.set_size_request(-1, 28) | ||
2034 | 843 | |||
2035 | 844 | parts = self.__parts | ||
2036 | 845 | self.__parts = [] | ||
2037 | 846 | |||
2038 | 847 | # recalc best fits, re-append then draw all | ||
2039 | 848 | for part in parts: | ||
2040 | 849 | |||
2041 | 850 | if part.icon.pixbuf: | ||
2042 | 851 | part.icon.load_pixbuf() | ||
2043 | 852 | |||
2044 | 853 | part.calc_size_requisition() | ||
2045 | 854 | self.__append(part) | ||
2046 | 855 | |||
2047 | 856 | self.queue_draw() | ||
2048 | 857 | return | ||
2049 | 858 | |||
2050 | 859 | def __allocation_change_cb(self, widget, allocation): | ||
2051 | 860 | if allocation.width == 1: | ||
2052 | 861 | return | ||
2053 | 862 | |||
2054 | 863 | path_w = self.__draw_width() | ||
2055 | 864 | if path_w == allocation.width: | ||
2056 | 865 | return | ||
2057 | 866 | elif path_w > allocation.width: | ||
2058 | 867 | self.__shrink_check(allocation) | ||
2059 | 868 | else: | ||
2060 | 869 | self.__grow_check(allocation.width, allocation) | ||
2061 | 870 | |||
2062 | 871 | self.queue_draw() | ||
2063 | 872 | return | ||
2064 | 873 | |||
2065 | 874 | # FIXME: stubs currently and not working | ||
2066 | 875 | class IAtkComponent(atk.Component): | ||
2067 | 876 | # atk -------------------------------------------------------- | ||
2068 | 877 | def contains(x, y, coord_type): | ||
2069 | 878 | # atk stub | ||
2070 | 879 | return False | ||
2071 | 880 | def ref_accessible_at_point(x, y, coord_type): | ||
2072 | 881 | # atk stub | ||
2073 | 882 | pass | ||
2074 | 883 | def get_extents(coord_type): | ||
2075 | 884 | # atk stub | ||
2076 | 885 | (0, 0, 0, 0) | ||
2077 | 886 | def get_position(coord_type): | ||
2078 | 887 | # atk stub | ||
2079 | 888 | (0, 0) | ||
2080 | 889 | def get_size(self): | ||
2081 | 890 | # atk stub | ||
2082 | 891 | (0, 0) | ||
2083 | 892 | def grab_focus(self): | ||
2084 | 893 | # atk stub | ||
2085 | 894 | return False | ||
2086 | 895 | def remove_focus_handler(self, handler_id): | ||
2087 | 896 | # atk stub | ||
2088 | 897 | pass | ||
2089 | 898 | def set_extents(self, x, y, width, height, coord_type): | ||
2090 | 899 | # atk stub | ||
2091 | 900 | return False | ||
2092 | 901 | def set_position(self, x, y, coord_type): | ||
2093 | 902 | # atk stub | ||
2094 | 903 | return False | ||
2095 | 904 | def set_size(self, width, height): | ||
2096 | 905 | # atk stub | ||
2097 | 906 | return False | ||
2098 | 907 | def get_layer(self): | ||
2099 | 908 | # atk stub | ||
2100 | 909 | return atk.LAYER_WIDGET | ||
2101 | 910 | def get_mdi_zorder(self): | ||
2102 | 911 | # atk stub | ||
2103 | 912 | return 1 | ||
2104 | 913 | #-------------------------------- | ||
2105 | 914 | |||
2106 | 915 | |||
2107 | 916 | class PathPart(atk.Object, IAtkComponent): | ||
2108 | 917 | |||
2109 | 918 | def __init__(self, parent, label=None, callback=None): | ||
2110 | 919 | atk.Object.__init__(self) | ||
2111 | 920 | self.__requisition = (0,0) | ||
2112 | 921 | self.__layout = None | ||
2113 | 922 | self.__pbar = None | ||
2114 | 923 | |||
2115 | 924 | # self.set_name() would work as well, *but* we have that | ||
2116 | 925 | # function already for a different purpose, so we need to | ||
2117 | 926 | # explicitely call | ||
2118 | 927 | parent_atk = parent.get_accessible() | ||
2119 | 928 | atk.Object.set_name(self, label) | ||
2120 | 929 | atk.Object.set_role(self, atk.ROLE_PUSH_BUTTON) | ||
2121 | 930 | atk.Object.add_relationship(self, atk.RELATION_MEMBER_OF, parent_atk) | ||
2122 | 931 | atk.Object.set_parent(self, parent_atk) | ||
2123 | 932 | #print parent_atk | ||
2124 | 933 | #print parent_atk.get_n_accessible_children() | ||
2125 | 934 | |||
2126 | 935 | self.allocation = [0, 0, 0, 0] | ||
2127 | 936 | self.state = gtk.STATE_NORMAL | ||
2128 | 937 | self.shape = PathBar.SHAPE_RECTANGLE | ||
2129 | 938 | |||
2130 | 939 | self.name = None | ||
2131 | 940 | self.callback = callback | ||
2132 | 941 | self.set_label(label or "") | ||
2133 | 942 | self.icon = PathBarIcon() | ||
2134 | 943 | return | ||
2135 | 944 | |||
2136 | 945 | def set_callback(self, cb): | ||
2137 | 946 | self.callback = cb | ||
2138 | 947 | return | ||
2139 | 948 | |||
2140 | 949 | def set_name(self, name): | ||
2141 | 950 | self.name = name | ||
2142 | 951 | return | ||
2143 | 952 | |||
2144 | 953 | def set_label(self, label): | ||
2145 | 954 | # escape special characters | ||
2146 | 955 | label = gobject.markup_escape_text(label.strip()) | ||
2147 | 956 | # some hackery to preserve italics markup | ||
2148 | 957 | label = label.replace('<i>', '<i>').replace('</i>', '</i>') | ||
2149 | 958 | self.label = label | ||
2150 | 959 | atk.Object.set_name(self, label) | ||
2151 | 960 | return | ||
2152 | 961 | |||
2153 | 962 | def set_icon(self, stock_icon, size=gtk.ICON_SIZE_BUTTON): | ||
2154 | 963 | self.icon.specify(stock_icon, size) | ||
2155 | 964 | self.icon.load_pixbuf() | ||
2156 | 965 | return | ||
2157 | 966 | |||
2158 | 967 | def set_state(self, gtk_state): | ||
2159 | 968 | self.state = gtk_state | ||
2160 | 969 | return | ||
2161 | 970 | |||
2162 | 971 | def set_shape(self, shape): | ||
2163 | 972 | self.shape = shape | ||
2164 | 973 | return | ||
2165 | 974 | |||
2166 | 975 | def set_x(self, x): | ||
2167 | 976 | self.allocation[0] = int(x) | ||
2168 | 977 | return | ||
2169 | 978 | |||
2170 | 979 | def set_size(self, w, h): | ||
2171 | 980 | if w != -1: self.allocation[2] = int(w) | ||
2172 | 981 | if h != -1: self.allocation[3] = int(h) | ||
2173 | 982 | self.__calc_layout_width(self.__layout, self.shape, self.__pbar) | ||
2174 | 983 | return | ||
2175 | 984 | |||
2176 | 985 | def set_pathbar(self, path_bar): | ||
2177 | 986 | self.__pbar = path_bar | ||
2178 | 987 | return | ||
2179 | 988 | |||
2180 | 989 | def get_x(self): | ||
2181 | 990 | return self.allocation[0] | ||
2182 | 991 | |||
2183 | 992 | def get_width(self): | ||
2184 | 993 | return self.allocation[2] | ||
2185 | 994 | |||
2186 | 995 | def get_height(self): | ||
2187 | 996 | return self.allocation[3] | ||
2188 | 997 | |||
2189 | 998 | def get_label(self): | ||
2190 | 999 | return self.label | ||
2191 | 1000 | |||
2192 | 1001 | def get_allocation(self): | ||
2193 | 1002 | return gtk.gdk.Rectangle(*self.get_allocation_tuple()) | ||
2194 | 1003 | |||
2195 | 1004 | def get_allocation_tuple(self): | ||
2196 | 1005 | if self.__pbar.get_direction() != gtk.TEXT_DIR_RTL: | ||
2197 | 1006 | return self.allocation | ||
2198 | 1007 | x, y, w, h = self.allocation | ||
2199 | 1008 | x = self.__pbar.allocation[2]-x-w | ||
2200 | 1009 | return x, y, w, h | ||
2201 | 1010 | |||
2202 | 1011 | def get_size_requisition(self): | ||
2203 | 1012 | return self.__requisition | ||
2204 | 1013 | |||
2205 | 1014 | def get_layout(self): | ||
2206 | 1015 | return self.__layout | ||
2207 | 1016 | |||
2208 | 1017 | def activate(self, do_callback=True): | ||
2209 | 1018 | self.__pbar.set_active(self, do_callback) | ||
2210 | 1019 | return | ||
2211 | 1020 | |||
2212 | 1021 | def calc_size_requisition(self): | ||
2213 | 1022 | pbar = self.__pbar | ||
2214 | 1023 | |||
2215 | 1024 | # determine widget size base on label width | ||
2216 | 1025 | self.__layout = self.__layout_text(self.label, pbar.get_pango_context()) | ||
2217 | 1026 | extents = self.__layout.get_pixel_extents() | ||
2218 | 1027 | |||
2219 | 1028 | # calc text width + 2 * padding, text height + 2 * ypadding | ||
2220 | 1029 | w = extents[1][2] + 2*pbar.theme.xpadding | ||
2221 | 1030 | h = max(extents[1][3] + 2*pbar.theme.ypadding, pbar.get_size_request()[1]) | ||
2222 | 1031 | |||
2223 | 1032 | # if has icon add some more pixels on | ||
2224 | 1033 | if self.icon.pixbuf: | ||
2225 | 1034 | w += self.icon.pixbuf.get_width() + pbar.theme.spacing | ||
2226 | 1035 | h = max(self.icon.pixbuf.get_height() + 2*pbar.theme.ypadding, h) | ||
2227 | 1036 | |||
2228 | 1037 | # extend width depending on part shape ... | ||
2229 | 1038 | if self.shape == PathBar.SHAPE_START_ARROW or \ | ||
2230 | 1039 | self.shape == PathBar.SHAPE_END_CAP: | ||
2231 | 1040 | w += pbar.theme.arrow_width | ||
2232 | 1041 | |||
2233 | 1042 | elif self.shape == PathBar.SHAPE_MID_ARROW: | ||
2234 | 1043 | w += 2*pbar.theme.arrow_width | ||
2235 | 1044 | |||
2236 | 1045 | # if height greater than current height request, | ||
2237 | 1046 | # reset height request to higher value | ||
2238 | 1047 | # i get the feeling this should be in set_size_request(), but meh | ||
2239 | 1048 | if h > pbar.get_size_request()[1]: | ||
2240 | 1049 | pbar.set_size_request(-1, h) | ||
2241 | 1050 | |||
2242 | 1051 | self.__requisition = (w,h) | ||
2243 | 1052 | return w, h | ||
2244 | 1053 | |||
2245 | 1054 | def is_truncated(self): | ||
2246 | 1055 | return self.__requisition[0] != self.allocation[2] | ||
2247 | 1056 | |||
2248 | 1057 | def __layout_text(self, text, pango_context): | ||
2249 | 1058 | layout = pango.Layout(pango_context) | ||
2250 | 1059 | layout.set_markup('%s' % text) | ||
2251 | 1060 | layout.set_ellipsize(pango.ELLIPSIZE_END) | ||
2252 | 1061 | return layout | ||
2253 | 1062 | |||
2254 | 1063 | def __calc_layout_width(self, layout, shape, pbar): | ||
2255 | 1064 | # set layout width | ||
2256 | 1065 | if self.icon.pixbuf: | ||
2257 | 1066 | icon_w = self.icon.pixbuf.get_width() + pbar.theme.spacing | ||
2258 | 1067 | else: | ||
2259 | 1068 | icon_w = 0 | ||
2260 | 1069 | |||
2261 | 1070 | w = self.allocation[2] | ||
2262 | 1071 | if shape == PathBar.SHAPE_MID_ARROW: | ||
2263 | 1072 | layout.set_width((w - 2*pbar.theme.arrow_width - | ||
2264 | 1073 | 2*pbar.theme.xpadding - icon_w)*pango.SCALE) | ||
2265 | 1074 | |||
2266 | 1075 | elif shape == PathBar.SHAPE_START_ARROW or \ | ||
2267 | 1076 | shape == PathBar.SHAPE_END_CAP: | ||
2268 | 1077 | layout.set_width((w - pbar.theme.arrow_width - 2*pbar.theme.xpadding - | ||
2269 | 1078 | icon_w)*pango.SCALE) | ||
2270 | 1079 | else: | ||
2271 | 1080 | layout.set_width((w - 2*pbar.theme.xpadding - icon_w)*pango.SCALE) | ||
2272 | 1081 | return | ||
2273 | 1082 | |||
2274 | 1083 | |||
2275 | 1084 | class PathBarIcon: | ||
2276 | 1085 | |||
2277 | 1086 | def __init__(self, name=None, size=None): | ||
2278 | 1087 | self.name = name | ||
2279 | 1088 | self.size = size | ||
2280 | 1089 | self.pixbuf = None | ||
2281 | 1090 | return | ||
2282 | 1091 | |||
2283 | 1092 | def specify(self, name, size): | ||
2284 | 1093 | self.name = name | ||
2285 | 1094 | self.size = size | ||
2286 | 1095 | return | ||
2287 | 1096 | |||
2288 | 1097 | def load_pixbuf(self): | ||
2289 | 1098 | if not self.name: | ||
2290 | 1099 | print 'Error: No icon specified.' | ||
2291 | 1100 | return | ||
2292 | 1101 | if not self.size: | ||
2293 | 1102 | print 'Note: No icon size specified.' | ||
2294 | 1103 | |||
2295 | 1104 | def render_icon(icon_set, name, size): | ||
2296 | 1105 | self.pixbuf = icon_set.render_icon( | ||
2297 | 1106 | style, | ||
2298 | 1107 | gtk.TEXT_DIR_NONE, | ||
2299 | 1108 | gtk.STATE_NORMAL, | ||
2300 | 1109 | self.size or gtk.ICON_SIZE_BUTTON, | ||
2301 | 1110 | gtk.Image(), | ||
2302 | 1111 | None) | ||
2303 | 1112 | return | ||
2304 | 1113 | |||
2305 | 1114 | style = gtk.Style() | ||
2306 | 1115 | icon_set = style.lookup_icon_set(self.name) | ||
2307 | 1116 | |||
2308 | 1117 | if not icon_set: | ||
2309 | 1118 | t = gtk.icon_theme_get_default() | ||
2310 | 1119 | self.pixbuf = t.lookup_icon(self.name, self.size, 0).load_icon() | ||
2311 | 1120 | else: | ||
2312 | 1121 | icon_set = style.lookup_icon_set(self.name) | ||
2313 | 1122 | render_icon(icon_set, self.name, self.size) | ||
2314 | 1123 | |||
2315 | 1124 | if not self.pixbuf: | ||
2316 | 1125 | print 'Error: No name failed to match any installed icon set.' | ||
2317 | 1126 | self.name = gtk.STOCK_MISSING_IMAGE | ||
2318 | 1127 | icon_set = style.lookup_icon_set(self.name) | ||
2319 | 1128 | render_icon(icon_set, self.name, self.size) | ||
2320 | 1129 | return | ||
2321 | 1130 | |||
2322 | 1131 | |||
2323 | 1132 | class PathBarThemeHuman: | ||
2324 | 1133 | |||
2325 | 1134 | PRELIT_NORMAL = 10 | ||
2326 | 1135 | PRELIT_ACTIVE = 11 | ||
2327 | 1136 | |||
2328 | 1137 | curvature = 2.5 | ||
2329 | 1138 | min_part_width = 56 | ||
2330 | 1139 | xpadding = 8 | ||
2331 | 1140 | ypadding = 2 | ||
2332 | 1141 | spacing = 4 | ||
2333 | 1142 | arrow_width = 13 | ||
2334 | 1143 | scroll_duration_ms = 150 | ||
2335 | 1144 | scroll_fps = 50 | ||
2336 | 1145 | animate = gtk.settings_get_default().get_property("gtk-enable-animations") | ||
2337 | 1146 | |||
2338 | 1147 | def __init__(self): | ||
2339 | 1148 | return | ||
2340 | 1149 | |||
2341 | 1150 | def load(self, style): | ||
2342 | 1151 | mid = style.mid | ||
2343 | 1152 | dark = style.dark | ||
2344 | 1153 | light = style.light | ||
2345 | 1154 | text = style.text | ||
2346 | 1155 | active = rgb.mix_color(mid[gtk.STATE_NORMAL], | ||
2347 | 1156 | mid[gtk.STATE_SELECTED], 0.25) | ||
2348 | 1157 | |||
2349 | 1158 | self.bg_colors = { | ||
2350 | 1159 | gtk.STATE_NORMAL: (f(rgb.shade(mid[gtk.STATE_NORMAL], 1.2)), | ||
2351 | 1160 | f(mid[gtk.STATE_NORMAL])), | ||
2352 | 1161 | |||
2353 | 1162 | gtk.STATE_ACTIVE: (f(rgb.shade(active, 1.2)), | ||
2354 | 1163 | f(active)), | ||
2355 | 1164 | |||
2356 | 1165 | gtk.STATE_SELECTED: (f(mid[gtk.STATE_ACTIVE]), | ||
2357 | 1166 | f(mid[gtk.STATE_ACTIVE])), | ||
2358 | 1167 | |||
2359 | 1168 | gtk.STATE_INSENSITIVE: (f(mid[gtk.STATE_INSENSITIVE]), | ||
2360 | 1169 | f(mid[gtk.STATE_INSENSITIVE])), | ||
2361 | 1170 | |||
2362 | 1171 | self.PRELIT_NORMAL: (f(rgb.shade(mid[gtk.STATE_NORMAL], 1.25)), | ||
2363 | 1172 | f(rgb.shade(mid[gtk.STATE_NORMAL], 1.05))), | ||
2364 | 1173 | |||
2365 | 1174 | self.PRELIT_ACTIVE: (f(rgb.shade(active, 1.25)), | ||
2366 | 1175 | f(rgb.shade(active, 1.05))) | ||
2367 | 1176 | } | ||
2368 | 1177 | |||
2369 | 1178 | self.dark_line_colors = { | ||
2370 | 1179 | gtk.STATE_NORMAL: f(dark[gtk.STATE_NORMAL]), | ||
2371 | 1180 | gtk.STATE_ACTIVE: f(dark[gtk.STATE_ACTIVE]), | ||
2372 | 1181 | gtk.STATE_SELECTED: f(rgb.shade(dark[gtk.STATE_ACTIVE], 0.9)), | ||
2373 | 1182 | gtk.STATE_PRELIGHT: f(dark[gtk.STATE_PRELIGHT]), | ||
2374 | 1183 | gtk.STATE_INSENSITIVE: f(dark[gtk.STATE_PRELIGHT]) | ||
2375 | 1184 | } | ||
2376 | 1185 | |||
2377 | 1186 | self.light_line_colors = { | ||
2378 | 1187 | gtk.STATE_NORMAL: f(light[gtk.STATE_NORMAL]), | ||
2379 | 1188 | gtk.STATE_ACTIVE: f(light[gtk.STATE_ACTIVE]), | ||
2380 | 1189 | gtk.STATE_SELECTED: None, | ||
2381 | 1190 | gtk.STATE_PRELIGHT: f(light[gtk.STATE_PRELIGHT]), | ||
2382 | 1191 | gtk.STATE_INSENSITIVE: f(mid[gtk.STATE_PRELIGHT]) | ||
2383 | 1192 | } | ||
2384 | 1193 | |||
2385 | 1194 | self.text_state = { | ||
2386 | 1195 | gtk.STATE_NORMAL: gtk.STATE_NORMAL, | ||
2387 | 1196 | gtk.STATE_ACTIVE: gtk.STATE_ACTIVE, | ||
2388 | 1197 | gtk.STATE_SELECTED: gtk.STATE_ACTIVE, | ||
2389 | 1198 | gtk.STATE_PRELIGHT: gtk.STATE_PRELIGHT, | ||
2390 | 1199 | gtk.STATE_INSENSITIVE: gtk.STATE_INSENSITIVE | ||
2391 | 1200 | } | ||
2392 | 1201 | |||
2393 | 1202 | self.base_hack = None | ||
2394 | 1203 | return | ||
2395 | 1204 | |||
2396 | 1205 | |||
2397 | 1206 | class PathBarThemeInHuman(PathBarThemeHuman): | ||
2398 | 1207 | |||
2399 | 1208 | def __init__(self): | ||
2400 | 1209 | PathBarThemeHuman.__init__(self) | ||
2401 | 1210 | return | ||
2402 | 1211 | |||
2403 | 1212 | def load(self, style): | ||
2404 | 1213 | mid = style.mid | ||
2405 | 1214 | dark = style.dark | ||
2406 | 1215 | light = style.light | ||
2407 | 1216 | text = style.text | ||
2408 | 1217 | active = rgb.mix_color(mid[gtk.STATE_NORMAL], | ||
2409 | 1218 | mid[gtk.STATE_SELECTED], 0.25) | ||
2410 | 1219 | |||
2411 | 1220 | self.bg_colors = { | ||
2412 | 1221 | gtk.STATE_NORMAL: (f(rgb.shade(mid[gtk.STATE_NORMAL], 1.175)), | ||
2413 | 1222 | f(mid[gtk.STATE_NORMAL])), | ||
2414 | 1223 | |||
2415 | 1224 | gtk.STATE_ACTIVE: (f(rgb.shade(active, 1.2)), | ||
2416 | 1225 | f(active)), | ||
2417 | 1226 | |||
2418 | 1227 | gtk.STATE_SELECTED: (f(mid[gtk.STATE_ACTIVE]), | ||
2419 | 1228 | f(mid[gtk.STATE_ACTIVE])), | ||
2420 | 1229 | |||
2421 | 1230 | gtk.STATE_INSENSITIVE: (f(rgb.shade(mid[gtk.STATE_INSENSITIVE], 1.15)), | ||
2422 | 1231 | f(rgb.shade(mid[gtk.STATE_INSENSITIVE], 1.1))), | ||
2423 | 1232 | |||
2424 | 1233 | self.PRELIT_NORMAL: (f(rgb.shade(mid[gtk.STATE_NORMAL], 1.25)), | ||
2425 | 1234 | f(rgb.shade(mid[gtk.STATE_NORMAL], 1.05))), | ||
2426 | 1235 | |||
2427 | 1236 | self.PRELIT_ACTIVE: (f(rgb.shade(active, 1.25)), | ||
2428 | 1237 | f(rgb.shade(active, 1.05))) | ||
2429 | 1238 | } | ||
2430 | 1239 | |||
2431 | 1240 | self.dark_line_colors = { | ||
2432 | 1241 | gtk.STATE_NORMAL: f(dark[gtk.STATE_NORMAL]), | ||
2433 | 1242 | gtk.STATE_ACTIVE: f(dark[gtk.STATE_ACTIVE]), | ||
2434 | 1243 | gtk.STATE_SELECTED: f(rgb.shade(dark[gtk.STATE_ACTIVE], 0.9)), | ||
2435 | 1244 | gtk.STATE_PRELIGHT: f(dark[gtk.STATE_PRELIGHT]), | ||
2436 | 1245 | gtk.STATE_INSENSITIVE: f(dark[gtk.STATE_PRELIGHT]) | ||
2437 | 1246 | } | ||
2438 | 1247 | |||
2439 | 1248 | self.light_line_colors = { | ||
2440 | 1249 | gtk.STATE_NORMAL: f(light[gtk.STATE_NORMAL]), | ||
2441 | 1250 | gtk.STATE_ACTIVE: f(light[gtk.STATE_ACTIVE]), | ||
2442 | 1251 | gtk.STATE_SELECTED: None, | ||
2443 | 1252 | gtk.STATE_PRELIGHT: f(light[gtk.STATE_PRELIGHT]), | ||
2444 | 1253 | gtk.STATE_INSENSITIVE: f(light[gtk.STATE_PRELIGHT]) | ||
2445 | 1254 | } | ||
2446 | 1255 | |||
2447 | 1256 | self.text_state = { | ||
2448 | 1257 | gtk.STATE_NORMAL: gtk.STATE_NORMAL, | ||
2449 | 1258 | gtk.STATE_ACTIVE: gtk.STATE_ACTIVE, | ||
2450 | 1259 | gtk.STATE_SELECTED: gtk.STATE_ACTIVE, | ||
2451 | 1260 | gtk.STATE_PRELIGHT: gtk.STATE_PRELIGHT, | ||
2452 | 1261 | gtk.STATE_INSENSITIVE: gtk.STATE_INSENSITIVE | ||
2453 | 1262 | } | ||
2454 | 1263 | |||
2455 | 1264 | self.base_hack = None | ||
2456 | 1265 | return | ||
2457 | 1266 | |||
2458 | 1267 | |||
2459 | 1268 | class PathBarThemeHumanClearlooks(PathBarThemeHuman): | ||
2460 | 1269 | |||
2461 | 1270 | def __init__(self): | ||
2462 | 1271 | PathBarThemeHuman.__init__(self) | ||
2463 | 1272 | return | ||
2464 | 1273 | |||
2465 | 1274 | def load(self, style): | ||
2466 | 1275 | mid = style.mid | ||
2467 | 1276 | dark = style.dark | ||
2468 | 1277 | light = style.light | ||
2469 | 1278 | text = style.text | ||
2470 | 1279 | active = rgb.mix_color(mid[gtk.STATE_NORMAL], | ||
2471 | 1280 | mid[gtk.STATE_SELECTED], 0.25) | ||
2472 | 1281 | |||
2473 | 1282 | self.bg_colors = { | ||
2474 | 1283 | gtk.STATE_NORMAL: (f(rgb.shade(mid[gtk.STATE_NORMAL], 1.20)), | ||
2475 | 1284 | f(rgb.shade(mid[gtk.STATE_NORMAL], 1.05))), | ||
2476 | 1285 | |||
2477 | 1286 | gtk.STATE_ACTIVE: (f(rgb.shade(active, 1.20)), | ||
2478 | 1287 | f(rgb.shade(active, 1.05))), | ||
2479 | 1288 | |||
2480 | 1289 | gtk.STATE_SELECTED: (f(rgb.shade(mid[gtk.STATE_ACTIVE], 1.15)), | ||
2481 | 1290 | f(mid[gtk.STATE_ACTIVE])), | ||
2482 | 1291 | |||
2483 | 1292 | gtk.STATE_INSENSITIVE: (f(mid[gtk.STATE_INSENSITIVE]), | ||
2484 | 1293 | f(mid[gtk.STATE_INSENSITIVE])), | ||
2485 | 1294 | |||
2486 | 1295 | self.PRELIT_NORMAL: (f(rgb.shade(mid[gtk.STATE_NORMAL], 1.35)), | ||
2487 | 1296 | f(rgb.shade(mid[gtk.STATE_NORMAL], 1.15))), | ||
2488 | 1297 | |||
2489 | 1298 | self.PRELIT_ACTIVE: (f(rgb.shade(active, 1.35)), | ||
2490 | 1299 | f(rgb.shade(active, 1.15))) | ||
2491 | 1300 | } | ||
2492 | 1301 | |||
2493 | 1302 | self.dark_line_colors = { | ||
2494 | 1303 | gtk.STATE_NORMAL: f(rgb.shade(dark[gtk.STATE_ACTIVE], 0.975)), | ||
2495 | 1304 | gtk.STATE_ACTIVE: f(rgb.shade(dark[gtk.STATE_ACTIVE], 0.975)), | ||
2496 | 1305 | gtk.STATE_SELECTED: f(rgb.shade(dark[gtk.STATE_ACTIVE], 0.95)), | ||
2497 | 1306 | gtk.STATE_PRELIGHT: f(dark[gtk.STATE_PRELIGHT]), | ||
2498 | 1307 | gtk.STATE_INSENSITIVE: f(dark[gtk.STATE_INSENSITIVE]) | ||
2499 | 1308 | } | ||
2500 | 1309 | |||
2501 | 1310 | self.light_line_colors = { | ||
2502 | 1311 | gtk.STATE_NORMAL: None, | ||
2503 | 1312 | gtk.STATE_ACTIVE: None, | ||
2504 | 1313 | gtk.STATE_SELECTED: f(mid[gtk.STATE_ACTIVE]), | ||
2505 | 1314 | gtk.STATE_PRELIGHT: f(light[gtk.STATE_PRELIGHT]), | ||
2506 | 1315 | gtk.STATE_INSENSITIVE: f(light[gtk.STATE_INSENSITIVE]) | ||
2507 | 1316 | } | ||
2508 | 1317 | |||
2509 | 1318 | self.text_state = { | ||
2510 | 1319 | gtk.STATE_NORMAL: gtk.STATE_NORMAL, | ||
2511 | 1320 | gtk.STATE_ACTIVE: gtk.STATE_ACTIVE, | ||
2512 | 1321 | gtk.STATE_SELECTED: gtk.STATE_NORMAL, | ||
2513 | 1322 | gtk.STATE_PRELIGHT: gtk.STATE_PRELIGHT, | ||
2514 | 1323 | gtk.STATE_INSENSITIVE: gtk.STATE_INSENSITIVE | ||
2515 | 1324 | } | ||
2516 | 1325 | |||
2517 | 1326 | self.base_hack = None | ||
2518 | 1327 | return | ||
2519 | 1328 | |||
2520 | 1329 | |||
2521 | 1330 | class PathBarThemeDust(PathBarThemeHuman): | ||
2522 | 1331 | |||
2523 | 1332 | def __init__(self): | ||
2524 | 1333 | PathBarThemeHuman.__init__(self) | ||
2525 | 1334 | return | ||
2526 | 1335 | |||
2527 | 1336 | def load(self, style): | ||
2528 | 1337 | mid = style.mid | ||
2529 | 1338 | dark = style.dark | ||
2530 | 1339 | light = style.light | ||
2531 | 1340 | text = style.text | ||
2532 | 1341 | active = rgb.mix_color(mid[gtk.STATE_NORMAL], | ||
2533 | 1342 | light[gtk.STATE_SELECTED], 0.3) | ||
2534 | 1343 | |||
2535 | 1344 | self.bg_colors = { | ||
2536 | 1345 | gtk.STATE_NORMAL: (f(rgb.shade(mid[gtk.STATE_NORMAL], 1.3)), | ||
2537 | 1346 | f(mid[gtk.STATE_NORMAL])), | ||
2538 | 1347 | |||
2539 | 1348 | gtk.STATE_ACTIVE: (f(rgb.shade(active, 1.3)), | ||
2540 | 1349 | f(active)), | ||
2541 | 1350 | |||
2542 | 1351 | gtk.STATE_SELECTED: (f(rgb.shade(mid[gtk.STATE_NORMAL], 0.95)), | ||
2543 | 1352 | f(rgb.shade(mid[gtk.STATE_NORMAL], 0.95))), | ||
2544 | 1353 | |||
2545 | 1354 | self.PRELIT_NORMAL: (f(rgb.shade(mid[gtk.STATE_NORMAL], 1.35)), | ||
2546 | 1355 | f(rgb.shade(mid[gtk.STATE_NORMAL], 1.15))), | ||
2547 | 1356 | |||
2548 | 1357 | gtk.STATE_INSENSITIVE: (f(rgb.shade(mid[gtk.STATE_INSENSITIVE], 1.09)), | ||
2549 | 1358 | f(rgb.shade(mid[gtk.STATE_INSENSITIVE], 1.08))), | ||
2550 | 1359 | |||
2551 | 1360 | self.PRELIT_ACTIVE: (f(rgb.shade(active, 1.35)), | ||
2552 | 1361 | f(rgb.shade(active, 1.15))) | ||
2553 | 1362 | } | ||
2554 | 1363 | |||
2555 | 1364 | self.dark_line_colors = { | ||
2556 | 1365 | gtk.STATE_NORMAL: f(dark[gtk.STATE_ACTIVE]), | ||
2557 | 1366 | gtk.STATE_ACTIVE: f(dark[gtk.STATE_ACTIVE]), | ||
2558 | 1367 | gtk.STATE_SELECTED: f(rgb.shade(dark[gtk.STATE_ACTIVE], 0.95)), | ||
2559 | 1368 | gtk.STATE_PRELIGHT: f(dark[gtk.STATE_PRELIGHT]), | ||
2560 | 1369 | gtk.STATE_INSENSITIVE: f(dark[gtk.STATE_INSENSITIVE]) | ||
2561 | 1370 | } | ||
2562 | 1371 | |||
2563 | 1372 | self.light_line_colors = { | ||
2564 | 1373 | gtk.STATE_NORMAL: f(light[gtk.STATE_NORMAL]), | ||
2565 | 1374 | gtk.STATE_ACTIVE: f(light[gtk.STATE_NORMAL]), | ||
2566 | 1375 | gtk.STATE_SELECTED: None, | ||
2567 | 1376 | gtk.STATE_PRELIGHT: f(light[gtk.STATE_PRELIGHT]), | ||
2568 | 1377 | gtk.STATE_INSENSITIVE: f(rgb.shade(light[gtk.STATE_INSENSITIVE], 0.96)) | ||
2569 | 1378 | } | ||
2570 | 1379 | |||
2571 | 1380 | self.text_state = { | ||
2572 | 1381 | gtk.STATE_NORMAL: gtk.STATE_NORMAL, | ||
2573 | 1382 | gtk.STATE_ACTIVE: gtk.STATE_ACTIVE, | ||
2574 | 1383 | gtk.STATE_SELECTED: gtk.STATE_NORMAL, | ||
2575 | 1384 | gtk.STATE_PRELIGHT: gtk.STATE_PRELIGHT, | ||
2576 | 1385 | gtk.STATE_INSENSITIVE: gtk.STATE_INSENSITIVE | ||
2577 | 1386 | } | ||
2578 | 1387 | |||
2579 | 1388 | self.base_hack = None | ||
2580 | 1389 | return | ||
2581 | 1390 | |||
2582 | 1391 | |||
2583 | 1392 | class PathBarThemeNewWave(PathBarThemeHuman): | ||
2584 | 1393 | |||
2585 | 1394 | curvature = 1.5 | ||
2586 | 1395 | |||
2587 | 1396 | def __init__(self): | ||
2588 | 1397 | PathBarThemeHuman.__init__(self) | ||
2589 | 1398 | return | ||
2590 | 1399 | |||
2591 | 1400 | def load(self, style): | ||
2592 | 1401 | mid = style.mid | ||
2593 | 1402 | dark = style.dark | ||
2594 | 1403 | light = style.light | ||
2595 | 1404 | text = style.text | ||
2596 | 1405 | active = rgb.mix_color(mid[gtk.STATE_NORMAL], | ||
2597 | 1406 | light[gtk.STATE_SELECTED], 0.5) | ||
2598 | 1407 | top_step = gtk.gdk.color_parse('#FDCF9D') | ||
2599 | 1408 | btm_step = gtk.gdk.color_parse('#FCAE87') | ||
2600 | 1409 | |||
2601 | 1410 | self.bg_colors = { | ||
2602 | 1411 | gtk.STATE_NORMAL: (f(rgb.shade(mid[gtk.STATE_NORMAL], 1.01)), | ||
2603 | 1412 | f(mid[gtk.STATE_NORMAL])), | ||
2604 | 1413 | |||
2605 | 1414 | gtk.STATE_ACTIVE: (f(top_step), | ||
2606 | 1415 | f(btm_step)), | ||
2607 | 1416 | |||
2608 | 1417 | gtk.STATE_SELECTED: (f(top_step), | ||
2609 | 1418 | f(btm_step)), | ||
2610 | 1419 | |||
2611 | 1420 | gtk.STATE_INSENSITIVE: (f(rgb.shade(mid[gtk.STATE_INSENSITIVE], 1.075)), | ||
2612 | 1421 | f(rgb.shade(mid[gtk.STATE_INSENSITIVE], 1.075))), | ||
2613 | 1422 | |||
2614 | 1423 | self.PRELIT_NORMAL: (f(rgb.shade(mid[gtk.STATE_NORMAL], 1.2)), | ||
2615 | 1424 | f(rgb.shade(mid[gtk.STATE_NORMAL], 1.15))), | ||
2616 | 1425 | |||
2617 | 1426 | self.PRELIT_ACTIVE: (f(rgb.shade(top_step, 1.11)), | ||
2618 | 1427 | f(rgb.shade(btm_step, 1.06))), | ||
2619 | 1428 | } | ||
2620 | 1429 | |||
2621 | 1430 | self.dark_line_colors = { | ||
2622 | 1431 | gtk.STATE_NORMAL: f(rgb.shade(dark[gtk.STATE_ACTIVE], 0.95)), | ||
2623 | 1432 | gtk.STATE_ACTIVE: f(rgb.shade(dark[gtk.STATE_ACTIVE], 0.95)), | ||
2624 | 1433 | gtk.STATE_SELECTED: f(rgb.shade(dark[gtk.STATE_ACTIVE], 0.95)), | ||
2625 | 1434 | gtk.STATE_PRELIGHT: f(dark[gtk.STATE_PRELIGHT]), | ||
2626 | 1435 | gtk.STATE_INSENSITIVE: f(dark[gtk.STATE_INSENSITIVE]) | ||
2627 | 1436 | } | ||
2628 | 1437 | |||
2629 | 1438 | self.light_line_colors = { | ||
2630 | 1439 | gtk.STATE_NORMAL: f(rgb.shade(light[gtk.STATE_NORMAL], 1.2)), | ||
2631 | 1440 | gtk.STATE_ACTIVE: f(rgb.shade(light[gtk.STATE_NORMAL], 1.2)), | ||
2632 | 1441 | gtk.STATE_SELECTED: None, | ||
2633 | 1442 | gtk.STATE_PRELIGHT: f(rgb.shade(light[gtk.STATE_PRELIGHT], 1.2)), | ||
2634 | 1443 | gtk.STATE_INSENSITIVE: f(light[gtk.STATE_INSENSITIVE]) | ||
2635 | 1444 | } | ||
2636 | 1445 | |||
2637 | 1446 | self.text_state = { | ||
2638 | 1447 | gtk.STATE_NORMAL: gtk.STATE_NORMAL, | ||
2639 | 1448 | gtk.STATE_ACTIVE: gtk.STATE_ACTIVE, | ||
2640 | 1449 | gtk.STATE_SELECTED: gtk.STATE_NORMAL, | ||
2641 | 1450 | gtk.STATE_PRELIGHT: gtk.STATE_PRELIGHT, | ||
2642 | 1451 | gtk.STATE_INSENSITIVE: gtk.STATE_INSENSITIVE | ||
2643 | 1452 | } | ||
2644 | 1453 | |||
2645 | 1454 | self.base_hack = f(gtk.gdk.color_parse("#F2F2F2")) | ||
2646 | 1455 | return | ||
2647 | 1456 | |||
2648 | 1457 | |||
2649 | 1458 | class PathBarThemeHicolor: | ||
2650 | 1459 | |||
2651 | 1460 | PRELIT_NORMAL = 10 | ||
2652 | 1461 | PRELIT_ACTIVE = 11 | ||
2653 | 1462 | |||
2654 | 1463 | curvature = 0.5 | ||
2655 | 1464 | min_part_width = 56 | ||
2656 | 1465 | xpadding = 15 | ||
2657 | 1466 | ypadding = 10 | ||
2658 | 1467 | spacing = 10 | ||
2659 | 1468 | arrow_width = 15 | ||
2660 | 1469 | scroll_duration_ms = 150 | ||
2661 | 1470 | scroll_fps = 50 | ||
2662 | 1471 | animate = gtk.settings_get_default().get_property("gtk-enable-animations") | ||
2663 | 1472 | |||
2664 | 1473 | def __init__(self): | ||
2665 | 1474 | return | ||
2666 | 1475 | |||
2667 | 1476 | def load(self, style): | ||
2668 | 1477 | mid = style.mid | ||
2669 | 1478 | dark = style.dark | ||
2670 | 1479 | light = style.light | ||
2671 | 1480 | text = style.text | ||
2672 | 1481 | |||
2673 | 1482 | self.bg_colors = { | ||
2674 | 1483 | gtk.STATE_NORMAL: (f(mid[gtk.STATE_NORMAL]), | ||
2675 | 1484 | f(mid[gtk.STATE_NORMAL])), | ||
2676 | 1485 | |||
2677 | 1486 | gtk.STATE_ACTIVE: (f(mid[gtk.STATE_ACTIVE]), | ||
2678 | 1487 | f(mid[gtk.STATE_ACTIVE])), | ||
2679 | 1488 | |||
2680 | 1489 | gtk.STATE_SELECTED: (f(mid[gtk.STATE_SELECTED]), | ||
2681 | 1490 | f(mid[gtk.STATE_SELECTED])), | ||
2682 | 1491 | |||
2683 | 1492 | gtk.STATE_INSENSITIVE: (f(mid[gtk.STATE_INSENSITIVE]), | ||
2684 | 1493 | f(mid[gtk.STATE_INSENSITIVE])), | ||
2685 | 1494 | |||
2686 | 1495 | self.PRELIT_NORMAL: (f(mid[gtk.STATE_PRELIGHT]), | ||
2687 | 1496 | f(mid[gtk.STATE_PRELIGHT])), | ||
2688 | 1497 | |||
2689 | 1498 | self.PRELIT_ACTIVE: (f(mid[gtk.STATE_PRELIGHT]), | ||
2690 | 1499 | f(mid[gtk.STATE_PRELIGHT])) | ||
2691 | 1500 | } | ||
2692 | 1501 | |||
2693 | 1502 | self.dark_line_colors = { | ||
2694 | 1503 | gtk.STATE_NORMAL: f(dark[gtk.STATE_NORMAL]), | ||
2695 | 1504 | gtk.STATE_ACTIVE: f(dark[gtk.STATE_ACTIVE]), | ||
2696 | 1505 | gtk.STATE_SELECTED: f(dark[gtk.STATE_SELECTED]), | ||
2697 | 1506 | gtk.STATE_PRELIGHT: f(dark[gtk.STATE_PRELIGHT]), | ||
2698 | 1507 | gtk.STATE_INSENSITIVE: f(dark[gtk.STATE_INSENSITIVE]) | ||
2699 | 1508 | } | ||
2700 | 1509 | |||
2701 | 1510 | self.light_line_colors = { | ||
2702 | 1511 | gtk.STATE_NORMAL: f(light[gtk.STATE_NORMAL]), | ||
2703 | 1512 | gtk.STATE_ACTIVE: f(light[gtk.STATE_ACTIVE]), | ||
2704 | 1513 | gtk.STATE_SELECTED: None, | ||
2705 | 1514 | gtk.STATE_PRELIGHT: f(light[gtk.STATE_PRELIGHT]), | ||
2706 | 1515 | gtk.STATE_INSENSITIVE: f(light[gtk.STATE_INSENSITIVE]) | ||
2707 | 1516 | } | ||
2708 | 1517 | |||
2709 | 1518 | self.text_state = { | ||
2710 | 1519 | gtk.STATE_NORMAL: gtk.STATE_NORMAL, | ||
2711 | 1520 | gtk.STATE_ACTIVE: gtk.STATE_ACTIVE, | ||
2712 | 1521 | gtk.STATE_SELECTED: gtk.STATE_SELECTED, | ||
2713 | 1522 | gtk.STATE_PRELIGHT: gtk.STATE_PRELIGHT, | ||
2714 | 1523 | gtk.STATE_INSENSITIVE: gtk.STATE_INSENSITIVE | ||
2715 | 1524 | } | ||
2716 | 1525 | |||
2717 | 1526 | self.base_hack = None | ||
2718 | 1527 | return | ||
2719 | 1528 | |||
2720 | 1529 | |||
2721 | 1530 | class PathBarThemes: | ||
2722 | 1531 | |||
2723 | 1532 | DICT = { | ||
2724 | 1533 | "Human": PathBarThemeHuman, | ||
2725 | 1534 | "Human-Clearlooks": PathBarThemeHumanClearlooks, | ||
2726 | 1535 | "InHuman": PathBarThemeInHuman, | ||
2727 | 1536 | "HighContrastInverse": PathBarThemeHicolor, | ||
2728 | 1537 | "HighContrastLargePrintInverse": PathBarThemeHicolor, | ||
2729 | 1538 | "Dust": PathBarThemeDust, | ||
2730 | 1539 | "Dust Sand": PathBarThemeDust, | ||
2731 | 1540 | "New Wave": PathBarThemeNewWave | ||
2732 | 1541 | } | ||
2733 | 1542 | |||
2734 | 1543 | |||
2735 | 1544 | class NavigationBar(PathBar): | ||
2736 | 1545 | def __init__(self, group=None): | ||
2737 | 1546 | PathBar.__init__(self) | ||
2738 | 1547 | self.set_size_request(-1, 28) | ||
2739 | 1548 | self.id_to_part = {} | ||
2740 | 1549 | return | ||
2741 | 1550 | |||
2742 | 1551 | def add_with_id(self, label, callback, id, icon=None, do_callback=True, animate=True): | ||
2743 | 1552 | """ | ||
2744 | 1553 | Add a new button with the given label/callback | ||
2745 | 1554 | |||
2746 | 1555 | If there is the same id already, replace the existing one | ||
2747 | 1556 | with the new one | ||
2748 | 1557 | """ | ||
2749 | 1558 | |||
2750 | 1559 | # check if we have the button of that id or need a new one | ||
2751 | 1560 | if id in self.id_to_part: | ||
2752 | 1561 | part = self.id_to_part[id] | ||
2753 | 1562 | part.set_label(label) | ||
2754 | 1563 | else: | ||
2755 | 1564 | part = PathPart(parent=self, label=label, callback=callback) | ||
2756 | 1565 | part.set_name(id) | ||
2757 | 1566 | part.set_pathbar(self) | ||
2758 | 1567 | part.id = id | ||
2759 | 1568 | self.id_to_part[id] = part | ||
2760 | 1569 | # check if animation should be used | ||
2761 | 1570 | if animate: | ||
2762 | 1571 | if do_callback: | ||
2763 | 1572 | gobject.timeout_add(150, self.append, part) | ||
2764 | 1573 | else: | ||
2765 | 1574 | gobject.timeout_add(150, self.append_no_callback, part) | ||
2766 | 1575 | else: | ||
2767 | 1576 | self.append(part, do_callback, animate=False) | ||
2768 | 1577 | |||
2769 | 1578 | if icon: | ||
2770 | 1579 | part.set_icon(icon) | ||
2771 | 1580 | return | ||
2772 | 1581 | |||
2773 | 1582 | def remove_id(self, id): | ||
2774 | 1583 | if not id in self.id_to_part: | ||
2775 | 1584 | return | ||
2776 | 1585 | |||
2777 | 1586 | part = self.id_to_part[id] | ||
2778 | 1587 | del self.id_to_part[id] | ||
2779 | 1588 | self.remove(part) | ||
2780 | 1589 | return | ||
2781 | 1590 | |||
2782 | 1591 | def get_button_from_id(self, id): | ||
2783 | 1592 | """ | ||
2784 | 1593 | return the button for the given id (or None) | ||
2785 | 1594 | """ | ||
2786 | 1595 | if not id in self.id_to_part: | ||
2787 | 1596 | return None | ||
2788 | 1597 | return self.id_to_part[id] | ||
2789 | 1598 | |||
2790 | 1599 | def get_label(self, id): | ||
2791 | 1600 | """ | ||
2792 | 1601 | Return the label of the navigation button with the given id | ||
2793 | 1602 | """ | ||
2794 | 1603 | if not id in self.id_to_part: | ||
2795 | 1604 | return | ||
2796 | 1605 | |||
2797 | 1606 | 0 | ||
2798 | === added file 'softwarecenter/view/widgets/pathbar_common.py' | |||
2799 | --- softwarecenter/view/widgets/pathbar_common.py 1970-01-01 00:00:00 +0000 | |||
2800 | +++ softwarecenter/view/widgets/pathbar_common.py 2010-04-04 06:00:32 +0000 | |||
2801 | @@ -0,0 +1,827 @@ | |||
2802 | 1 | # Copyright (C) 2010 Matthew McGowan | ||
2803 | 2 | # | ||
2804 | 3 | # Authors: | ||
2805 | 4 | # Matthew McGowan | ||
2806 | 5 | # | ||
2807 | 6 | # This program is free software: you can redistribute it and/or modify | ||
2808 | 7 | # it under the terms of the GNU General Public License as published by | ||
2809 | 8 | # the Free Software Foundation, either version 3 of the License, or | ||
2810 | 9 | # (at your option) any later version. | ||
2811 | 10 | # | ||
2812 | 11 | # This program is distributed in the hope that it will be useful, | ||
2813 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2814 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2815 | 14 | # GNU General Public License for more details. | ||
2816 | 15 | # | ||
2817 | 16 | # You should have received a copy of the GNU General Public License | ||
2818 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2819 | 18 | |||
2820 | 19 | |||
2821 | 20 | import gtk | ||
2822 | 21 | import cairo | ||
2823 | 22 | import colorsys | ||
2824 | 23 | |||
2825 | 24 | |||
2826 | 25 | # pi constants | ||
2827 | 26 | M_PI = 3.1415926535897931 | ||
2828 | 27 | PI_OVER_180 = 0.017453292519943295 | ||
2829 | 28 | |||
2830 | 29 | SHAPE_RECTANGLE = 0 | ||
2831 | 30 | SHAPE_START_ARROW = 1 | ||
2832 | 31 | SHAPE_MID_ARROW = 2 | ||
2833 | 32 | SHAPE_END_CAP = 3 | ||
2834 | 33 | |||
2835 | 34 | |||
2836 | 35 | class PathBarStyle: | ||
2837 | 36 | |||
2838 | 37 | def __init__(self, pathbar): | ||
2839 | 38 | self.shape_map = self._load_shape_map(pathbar) | ||
2840 | 39 | |||
2841 | 40 | gtk_settings = gtk.settings_get_default() | ||
2842 | 41 | self.theme = self._load_theme(gtk_settings) | ||
2843 | 42 | self.theme.build_palette(gtk_settings) | ||
2844 | 43 | self.properties = self.theme.get_properties(gtk_settings) | ||
2845 | 44 | self.gradients = self.theme.get_grad_palette() | ||
2846 | 45 | self.dark_line = self.theme.get_dark_line_palette() | ||
2847 | 46 | self.light_line = self.theme.get_light_line_palette() | ||
2848 | 47 | self.text = self.theme.get_text_palette() | ||
2849 | 48 | self.text_states = self.theme.get_text_states() | ||
2850 | 49 | self.base_color = None | ||
2851 | 50 | return | ||
2852 | 51 | |||
2853 | 52 | def __getitem__(self, item): | ||
2854 | 53 | if self.properties.has_key(item): | ||
2855 | 54 | return self.properties[item] | ||
2856 | 55 | print 'Key does not exist in the style profile:', item | ||
2857 | 56 | return None | ||
2858 | 57 | |||
2859 | 58 | def _load_shape_map(self, pathbar): | ||
2860 | 59 | if pathbar.get_direction() != gtk.TEXT_DIR_RTL: | ||
2861 | 60 | shmap = {SHAPE_RECTANGLE: self._shape_rectangle, | ||
2862 | 61 | SHAPE_START_ARROW: self._shape_start_arrow_ltr, | ||
2863 | 62 | SHAPE_MID_ARROW: self._shape_mid_arrow_ltr, | ||
2864 | 63 | SHAPE_END_CAP: self._shape_end_cap_ltr} | ||
2865 | 64 | else: | ||
2866 | 65 | shmap = {SHAPE_RECTANGLE: self._shape_rectangle, | ||
2867 | 66 | SHAPE_START_ARROW: self._shape_start_arrow_rtl, | ||
2868 | 67 | SHAPE_MID_ARROW: self._shape_mid_arrow_rtl, | ||
2869 | 68 | SHAPE_END_CAP: self._shape_end_cap_rtl} | ||
2870 | 69 | return shmap | ||
2871 | 70 | |||
2872 | 71 | def _load_theme(self, gtksettings): | ||
2873 | 72 | name = gtksettings.get_property("gtk-theme-name") | ||
2874 | 73 | r = ThemeRegistry() | ||
2875 | 74 | return r.retrieve(name) | ||
2876 | 75 | |||
2877 | 76 | def _shape_rectangle(self, cr, x, y, w, h, r, aw): | ||
2878 | 77 | global M_PI, PI_OVER_180 | ||
2879 | 78 | cr.new_sub_path() | ||
2880 | 79 | cr.arc(r+x, r+y, r, M_PI, 270*PI_OVER_180) | ||
2881 | 80 | cr.arc(w-r, r+y, r, 270*PI_OVER_180, 0) | ||
2882 | 81 | cr.arc(w-r, h-r, r, 0, 90*PI_OVER_180) | ||
2883 | 82 | cr.arc(r+x, h-r, r, 90*PI_OVER_180, M_PI) | ||
2884 | 83 | cr.close_path() | ||
2885 | 84 | return | ||
2886 | 85 | |||
2887 | 86 | def _shape_start_arrow_ltr(self, cr, x, y, w, h, r, aw): | ||
2888 | 87 | global M_PI, PI_OVER_180 | ||
2889 | 88 | cr.new_sub_path() | ||
2890 | 89 | cr.arc(r+x, r+y, r, M_PI, 270*PI_OVER_180) | ||
2891 | 90 | # arrow head | ||
2892 | 91 | cr.line_to(w-aw, y) | ||
2893 | 92 | cr.line_to(w-x+1, (h+y)/2) | ||
2894 | 93 | cr.line_to(w-aw, h) | ||
2895 | 94 | cr.arc(r+x, h-r, r, 90*PI_OVER_180, M_PI) | ||
2896 | 95 | cr.close_path() | ||
2897 | 96 | return | ||
2898 | 97 | |||
2899 | 98 | def _shape_mid_arrow_ltr(self, cr, x, y, w, h, r, aw): | ||
2900 | 99 | cr.move_to(0, y) | ||
2901 | 100 | # arrow head | ||
2902 | 101 | cr.line_to(w-aw, y) | ||
2903 | 102 | cr.line_to(w-x+1, (h+y)/2) | ||
2904 | 103 | cr.line_to(w-aw, h) | ||
2905 | 104 | cr.line_to(0, h) | ||
2906 | 105 | cr.close_path() | ||
2907 | 106 | return | ||
2908 | 107 | |||
2909 | 108 | def _shape_end_cap_ltr(self, cr, x, y, w, h, r, aw): | ||
2910 | 109 | global M_PI, PI_OVER_180 | ||
2911 | 110 | cr.move_to(0, y) | ||
2912 | 111 | cr.arc(w-r, r+y, r, 270*PI_OVER_180, 0) | ||
2913 | 112 | cr.arc(w-r, h-r, r, 0, 90*PI_OVER_180) | ||
2914 | 113 | cr.line_to(0, h) | ||
2915 | 114 | cr.close_path() | ||
2916 | 115 | return | ||
2917 | 116 | |||
2918 | 117 | def _shape_start_arrow_rtl(self, cr, x, y, w, h, r, aw): | ||
2919 | 118 | global M_PI, PI_OVER_180 | ||
2920 | 119 | cr.new_sub_path() | ||
2921 | 120 | cr.move_to(x, (h+y)/2) | ||
2922 | 121 | cr.line_to(aw, y) | ||
2923 | 122 | cr.arc(w-r, r+y, r, 270*PI_OVER_180, 0) | ||
2924 | 123 | cr.arc(w-r, h-r, r, 0, 90*PI_OVER_180) | ||
2925 | 124 | cr.line_to(aw, h) | ||
2926 | 125 | cr.close_path() | ||
2927 | 126 | return | ||
2928 | 127 | |||
2929 | 128 | def _shape_mid_arrow_rtl(self, cr, x, y, w, h, r, aw): | ||
2930 | 129 | cr.move_to(x, (h+y)/2) | ||
2931 | 130 | cr.line_to(aw, y) | ||
2932 | 131 | cr.line_to(w, y) | ||
2933 | 132 | cr.line_to(w, h) | ||
2934 | 133 | cr.line_to(aw, h) | ||
2935 | 134 | cr.close_path() | ||
2936 | 135 | return | ||
2937 | 136 | |||
2938 | 137 | def _shape_end_cap_rtl(self, cr, x, y, w, h, r, aw): | ||
2939 | 138 | global M_PI, PI_OVER_180 | ||
2940 | 139 | cr.arc(r+x, r+y, r, M_PI, 270*PI_OVER_180) | ||
2941 | 140 | cr.line_to(w, y) | ||
2942 | 141 | cr.line_to(w, h) | ||
2943 | 142 | cr.arc(r+x, h-r, r, 90*PI_OVER_180, M_PI) | ||
2944 | 143 | cr.close_path() | ||
2945 | 144 | return | ||
2946 | 145 | |||
2947 | 146 | def set_direction(self, direction): | ||
2948 | 147 | if direction != gtk.TEXT_DIR_RTL: | ||
2949 | 148 | self.shape_map = {SHAPE_RECTANGLE: self._shape_rectangle, | ||
2950 | 149 | SHAPE_START_ARROW: self._shape_start_arrow_ltr, | ||
2951 | 150 | SHAPE_MID_ARROW: self._shape_mid_arrow_ltr, | ||
2952 | 151 | SHAPE_END_CAP: self._shape_end_cap_ltr} | ||
2953 | 152 | else: | ||
2954 | 153 | self.shape_map = {SHAPE_RECTANGLE: self._shape_rectangle, | ||
2955 | 154 | SHAPE_START_ARROW: self._shape_start_arrow_rtl, | ||
2956 | 155 | SHAPE_MID_ARROW: self._shape_mid_arrow_rtl, | ||
2957 | 156 | SHAPE_END_CAP: self._shape_end_cap_rtl} | ||
2958 | 157 | return | ||
2959 | 158 | |||
2960 | 159 | def paint_bg(self, cr, part, x, y, w, h, sxO=0): | ||
2961 | 160 | shape = self.shape_map[part.shape] | ||
2962 | 161 | state = part.state | ||
2963 | 162 | r = self["curvature"] | ||
2964 | 163 | aw = self["arrow_width"] | ||
2965 | 164 | |||
2966 | 165 | cr.save() | ||
2967 | 166 | cr.rectangle(x, y, w+1, h) | ||
2968 | 167 | cr.clip() | ||
2969 | 168 | cr.translate(x+0.5-sxO, y+0.5) | ||
2970 | 169 | |||
2971 | 170 | w -= 1 | ||
2972 | 171 | h -= 1 | ||
2973 | 172 | |||
2974 | 173 | # bg linear vertical gradient | ||
2975 | 174 | color1, color2 = self.gradients[state] | ||
2976 | 175 | |||
2977 | 176 | shape(cr, 0, 0, w, h, r, aw) | ||
2978 | 177 | lin = cairo.LinearGradient(0, 0, 0, h) | ||
2979 | 178 | lin.add_color_stop_rgb(0.0, *color1.tofloats()) | ||
2980 | 179 | lin.add_color_stop_rgb(1.0, *color2.tofloats()) | ||
2981 | 180 | cr.set_source(lin) | ||
2982 | 181 | cr.fill() | ||
2983 | 182 | |||
2984 | 183 | cr.set_line_width(1.0) | ||
2985 | 184 | # strong outline | ||
2986 | 185 | shape(cr, 0, 0, w, h, r, aw) | ||
2987 | 186 | cr.set_source_rgb(*self.dark_line[state].tofloats()) | ||
2988 | 187 | cr.stroke() | ||
2989 | 188 | |||
2990 | 189 | # inner bevel/highlight | ||
2991 | 190 | if r == 0: w += 1 | ||
2992 | 191 | shape(cr, 1, 1, w-1, h-1, r, aw) | ||
2993 | 192 | cr.set_source_rgb(*self.light_line[state].tofloats()) | ||
2994 | 193 | cr.stroke() | ||
2995 | 194 | cr.restore() | ||
2996 | 195 | return | ||
2997 | 196 | |||
2998 | 197 | def paint_layout(self, widget, part, x, y, sxO=0): | ||
2999 | 198 | # draw layout | ||
3000 | 199 | layout = part.get_layout() | ||
3001 | 200 | widget.style.paint_layout(widget.window, | ||
3002 | 201 | self.text_states[part.state], | ||
3003 | 202 | False, | ||
3004 | 203 | None, # clip area | ||
3005 | 204 | widget, | ||
3006 | 205 | None, | ||
3007 | 206 | x, y, | ||
3008 | 207 | layout) | ||
3009 | 208 | return | ||
3010 | 209 | |||
3011 | 210 | def paint_focus(self, cr, x, y, w, h): | ||
3012 | 211 | self._shape_rectangle(cr, 4, 4, w-4, h-4, self["curvature"], 0) | ||
3013 | 212 | cr.set_source_rgb(*self.theme.bg[gtk.STATE_SELECTED].tofloats()) | ||
3014 | 213 | cr.stroke() | ||
3015 | 214 | return | ||
3016 | 215 | |||
3017 | 216 | |||
3018 | 217 | class PathBarColorArray: | ||
3019 | 218 | |||
3020 | 219 | def __init__(self, color_array): | ||
3021 | 220 | self.color_array = {} | ||
3022 | 221 | for state in (gtk.STATE_NORMAL, gtk.STATE_ACTIVE, gtk.STATE_SELECTED, \ | ||
3023 | 222 | gtk.STATE_PRELIGHT, gtk.STATE_INSENSITIVE): | ||
3024 | 223 | self.color_array[state] = color_from_gdkcolor(color_array[state]) | ||
3025 | 224 | return | ||
3026 | 225 | |||
3027 | 226 | def __getitem__(self, state): | ||
3028 | 227 | return self.color_array[state] | ||
3029 | 228 | |||
3030 | 229 | |||
3031 | 230 | class PathBarColor: | ||
3032 | 231 | |||
3033 | 232 | def __init__(self, red, green, blue): | ||
3034 | 233 | self.red = red | ||
3035 | 234 | self.green = green | ||
3036 | 235 | self.blue = blue | ||
3037 | 236 | return | ||
3038 | 237 | |||
3039 | 238 | def set_alpha(self, value): | ||
3040 | 239 | self.alpha = value | ||
3041 | 240 | return | ||
3042 | 241 | |||
3043 | 242 | def tofloats(self): | ||
3044 | 243 | return self.red, self.green, self.blue | ||
3045 | 244 | |||
3046 | 245 | def toclutter(self): | ||
3047 | 246 | try: | ||
3048 | 247 | from clutter import Color | ||
3049 | 248 | except Exception, e: | ||
3050 | 249 | print 'Error parsing color:', e | ||
3051 | 250 | raise SystemExit | ||
3052 | 251 | r,g,b = self.tofloats() | ||
3053 | 252 | return Color(int(r*255), int(g*255), int(b*255)) | ||
3054 | 253 | |||
3055 | 254 | def togtkgdk(self): | ||
3056 | 255 | r,g,b = self.tofloats() | ||
3057 | 256 | return gtk.gdk.Color(int(r*65535), int(g*65535), int(b*65535)) | ||
3058 | 257 | |||
3059 | 258 | def lighten(self): | ||
3060 | 259 | return self.shade(1.3) | ||
3061 | 260 | |||
3062 | 261 | def darken(self): | ||
3063 | 262 | return self.shade(0.7) | ||
3064 | 263 | |||
3065 | 264 | def shade(self, factor): | ||
3066 | 265 | # as seen in clutter-color.c | ||
3067 | 266 | h,l,s = colorsys.rgb_to_hls(*self.tofloats()) | ||
3068 | 267 | |||
3069 | 268 | l *= factor | ||
3070 | 269 | if l > 1.0: | ||
3071 | 270 | l = 1.0 | ||
3072 | 271 | elif l < 0: | ||
3073 | 272 | l = 0 | ||
3074 | 273 | |||
3075 | 274 | s *= factor | ||
3076 | 275 | if s > 1.0: | ||
3077 | 276 | s = 1.0 | ||
3078 | 277 | elif s < 0: | ||
3079 | 278 | s = 0 | ||
3080 | 279 | |||
3081 | 280 | r,g,b = colorsys.hls_to_rgb(h,l,s) | ||
3082 | 281 | return PathBarColor(r,g,b) | ||
3083 | 282 | |||
3084 | 283 | def mix(self, color2, mix_factor): | ||
3085 | 284 | # as seen in Murrine's cairo-support.c | ||
3086 | 285 | r1, g1, b1 = self.tofloats() | ||
3087 | 286 | r2, g2, b2 = color2.tofloats() | ||
3088 | 287 | r = r1*(1-mix_factor)+r2*mix_factor | ||
3089 | 288 | g = g1*(1-mix_factor)+g2*mix_factor | ||
3090 | 289 | b = b1*(1-mix_factor)+b2*mix_factor | ||
3091 | 290 | return PathBarColor(r,g,b) | ||
3092 | 291 | |||
3093 | 292 | |||
3094 | 293 | class Theme: | ||
3095 | 294 | |||
3096 | 295 | def build_palette(self, gtksettings): | ||
3097 | 296 | style = gtk.rc_get_style_by_paths(gtksettings, | ||
3098 | 297 | 'GtkWindow', | ||
3099 | 298 | 'GtkWindow', | ||
3100 | 299 | gtk.Window) | ||
3101 | 300 | |||
3102 | 301 | style = style or gtk.widget_get_default_style() | ||
3103 | 302 | |||
3104 | 303 | # build pathbar color palette | ||
3105 | 304 | self.fg = PathBarColorArray(style.fg) | ||
3106 | 305 | self.bg = PathBarColorArray(style.bg) | ||
3107 | 306 | self.text = PathBarColorArray(style.text) | ||
3108 | 307 | self.base = PathBarColorArray(style.base) | ||
3109 | 308 | self.light = PathBarColorArray(style.base) | ||
3110 | 309 | self.mid = PathBarColorArray(style.base) | ||
3111 | 310 | self.dark = PathBarColorArray(style.base) | ||
3112 | 311 | return | ||
3113 | 312 | |||
3114 | 313 | |||
3115 | 314 | class Human(Theme): | ||
3116 | 315 | |||
3117 | 316 | def get_properties(self, gtksettings): | ||
3118 | 317 | props = { | ||
3119 | 318 | 'curvature': 2.5, | ||
3120 | 319 | 'min_part_width': 48, | ||
3121 | 320 | 'xpad': 8, | ||
3122 | 321 | 'ypad': 4, | ||
3123 | 322 | 'xthickness': 1, | ||
3124 | 323 | 'ythickness': 1, | ||
3125 | 324 | 'spacing': 5, | ||
3126 | 325 | 'arrow_width': 13, | ||
3127 | 326 | 'scroll_duration': 150, | ||
3128 | 327 | 'enable-animations': gtksettings.get_property("gtk-enable-animations"), | ||
3129 | 328 | 'override_base': False | ||
3130 | 329 | } | ||
3131 | 330 | return props | ||
3132 | 331 | |||
3133 | 332 | def get_grad_palette(self): | ||
3134 | 333 | # provide two colours per state for background vertical linear gradients | ||
3135 | 334 | palette = {gtk.STATE_NORMAL: (self.bg[gtk.STATE_NORMAL].shade(1.1), | ||
3136 | 335 | self.bg[gtk.STATE_NORMAL].shade(0.95)), | ||
3137 | 336 | |||
3138 | 337 | gtk.STATE_ACTIVE: (self.bg[gtk.STATE_NORMAL].shade(1.00), | ||
3139 | 338 | self.bg[gtk.STATE_NORMAL].shade(0.75)), | ||
3140 | 339 | |||
3141 | 340 | gtk.STATE_SELECTED: (self.bg[gtk.STATE_NORMAL].shade(1.11), | ||
3142 | 341 | self.bg[gtk.STATE_NORMAL]), | ||
3143 | 342 | |||
3144 | 343 | gtk.STATE_PRELIGHT: (self.bg[gtk.STATE_NORMAL].shade(0.96), | ||
3145 | 344 | self.bg[gtk.STATE_NORMAL].shade(0.91)), | ||
3146 | 345 | |||
3147 | 346 | gtk.STATE_INSENSITIVE: (self.bg[gtk.STATE_INSENSITIVE], | ||
3148 | 347 | self.bg[gtk.STATE_INSENSITIVE]) | ||
3149 | 348 | } | ||
3150 | 349 | return palette | ||
3151 | 350 | |||
3152 | 351 | def get_text_palette(self): | ||
3153 | 352 | palette = {gtk.STATE_NORMAL: self.fg[gtk.STATE_NORMAL], | ||
3154 | 353 | gtk.STATE_ACTIVE: self.fg[gtk.STATE_NORMAL], | ||
3155 | 354 | gtk.STATE_SELECTED: self.fg[gtk.STATE_NORMAL], | ||
3156 | 355 | gtk.STATE_PRELIGHT: self.fg[gtk.STATE_NORMAL], | ||
3157 | 356 | gtk.STATE_INSENSITIVE: self.text[gtk.STATE_INSENSITIVE]} | ||
3158 | 357 | return palette | ||
3159 | 358 | |||
3160 | 359 | def get_dark_line_palette(self): | ||
3161 | 360 | palette = {gtk.STATE_NORMAL: self.bg[gtk.STATE_NORMAL].darken(), | ||
3162 | 361 | gtk.STATE_ACTIVE: self.bg[gtk.STATE_NORMAL].darken(), | ||
3163 | 362 | gtk.STATE_PRELIGHT: self.bg[gtk.STATE_NORMAL].darken(), | ||
3164 | 363 | gtk.STATE_SELECTED: self.bg[gtk.STATE_NORMAL].darken(), | ||
3165 | 364 | gtk.STATE_INSENSITIVE: self.bg[gtk.STATE_INSENSITIVE].darken()} | ||
3166 | 365 | return palette | ||
3167 | 366 | |||
3168 | 367 | def get_light_line_palette(self): | ||
3169 | 368 | palette = {gtk.STATE_NORMAL: self.bg[gtk.STATE_NORMAL].lighten(), | ||
3170 | 369 | gtk.STATE_ACTIVE: self.fg[gtk.STATE_NORMAL], | ||
3171 | 370 | gtk.STATE_PRELIGHT: self.bg[gtk.STATE_NORMAL].lighten(), | ||
3172 | 371 | gtk.STATE_SELECTED: self.bg[gtk.STATE_NORMAL].lighten(), | ||
3173 | 372 | gtk.STATE_INSENSITIVE: self.light[gtk.STATE_INSENSITIVE]} | ||
3174 | 373 | return palette | ||
3175 | 374 | |||
3176 | 375 | def get_text_states(self): | ||
3177 | 376 | states = {gtk.STATE_NORMAL: gtk.STATE_NORMAL, | ||
3178 | 377 | gtk.STATE_ACTIVE: gtk.STATE_NORMAL, | ||
3179 | 378 | gtk.STATE_PRELIGHT: gtk.STATE_NORMAL, | ||
3180 | 379 | gtk.STATE_SELECTED: gtk.STATE_NORMAL, | ||
3181 | 380 | gtk.STATE_INSENSITIVE: gtk.STATE_INSENSITIVE} | ||
3182 | 381 | return states | ||
3183 | 382 | |||
3184 | 383 | |||
3185 | 384 | class Clearlooks(Human): | ||
3186 | 385 | |||
3187 | 386 | def get_properties(self, gtksettings): | ||
3188 | 387 | props = Human.get_properties(self, gtksettings) | ||
3189 | 388 | props['curvature'] = 3.5 | ||
3190 | 389 | return props | ||
3191 | 390 | |||
3192 | 391 | def get_grad_palette(self): | ||
3193 | 392 | # provide two colours per state for background vertical linear gradients | ||
3194 | 393 | |||
3195 | 394 | selected_color = self.bg[gtk.STATE_NORMAL].mix(self.bg[gtk.STATE_SELECTED], | ||
3196 | 395 | 0.2) | ||
3197 | 396 | |||
3198 | 397 | palette = {gtk.STATE_NORMAL: (self.bg[gtk.STATE_NORMAL].shade(1.15), | ||
3199 | 398 | self.bg[gtk.STATE_NORMAL].shade(0.95)), | ||
3200 | 399 | |||
3201 | 400 | gtk.STATE_ACTIVE: (self.bg[gtk.STATE_ACTIVE], | ||
3202 | 401 | self.bg[gtk.STATE_ACTIVE]), | ||
3203 | 402 | |||
3204 | 403 | gtk.STATE_SELECTED: (selected_color.shade(1.175), | ||
3205 | 404 | selected_color), | ||
3206 | 405 | |||
3207 | 406 | gtk.STATE_PRELIGHT: (self.bg[gtk.STATE_NORMAL].shade(1.3), | ||
3208 | 407 | selected_color.shade(1.1)), | ||
3209 | 408 | |||
3210 | 409 | gtk.STATE_INSENSITIVE: (self.bg[gtk.STATE_INSENSITIVE], | ||
3211 | 410 | self.bg[gtk.STATE_INSENSITIVE]) | ||
3212 | 411 | } | ||
3213 | 412 | return palette | ||
3214 | 413 | |||
3215 | 414 | def get_light_line_palette(self): | ||
3216 | 415 | palette = Human.get_light_line_palette(self) | ||
3217 | 416 | palette[gtk.STATE_ACTIVE] = self.bg[gtk.STATE_ACTIVE] | ||
3218 | 417 | return palette | ||
3219 | 418 | |||
3220 | 419 | |||
3221 | 420 | class InHuman(Theme): | ||
3222 | 421 | |||
3223 | 422 | def get_properties(self, gtksettings): | ||
3224 | 423 | props = { | ||
3225 | 424 | 'curvature': 2.5, | ||
3226 | 425 | 'min_part_width': 48, | ||
3227 | 426 | 'xpad': 8, | ||
3228 | 427 | 'ypad': 4, | ||
3229 | 428 | 'xthickness': 1, | ||
3230 | 429 | 'ythickness': 1, | ||
3231 | 430 | 'spacing': 5, | ||
3232 | 431 | 'arrow_width': 13, | ||
3233 | 432 | 'scroll_duration': 150, | ||
3234 | 433 | 'enable-animations': gtksettings.get_property("gtk-enable-animations"), | ||
3235 | 434 | 'override_base': False | ||
3236 | 435 | } | ||
3237 | 436 | return props | ||
3238 | 437 | |||
3239 | 438 | def get_grad_palette(self): | ||
3240 | 439 | # provide two colours per state for background vertical linear gradients | ||
3241 | 440 | palette = {gtk.STATE_NORMAL: (self.bg[gtk.STATE_NORMAL].shade(1.1), | ||
3242 | 441 | self.bg[gtk.STATE_NORMAL].shade(0.95)), | ||
3243 | 442 | |||
3244 | 443 | gtk.STATE_ACTIVE: (self.bg[gtk.STATE_NORMAL].shade(1.00), | ||
3245 | 444 | self.bg[gtk.STATE_NORMAL].shade(0.75)), | ||
3246 | 445 | |||
3247 | 446 | gtk.STATE_SELECTED: (self.bg[gtk.STATE_NORMAL].shade(1.09), | ||
3248 | 447 | self.bg), | ||
3249 | 448 | |||
3250 | 449 | gtk.STATE_PRELIGHT: (self.bg[gtk.STATE_SELECTED].shade(1.35), | ||
3251 | 450 | self.bg[gtk.STATE_SELECTED].shade(1.1)), | ||
3252 | 451 | |||
3253 | 452 | gtk.STATE_INSENSITIVE: (self.bg[gtk.STATE_INSENSITIVE], | ||
3254 | 453 | self.bg[gtk.STATE_INSENSITIVE]) | ||
3255 | 454 | } | ||
3256 | 455 | return palette | ||
3257 | 456 | |||
3258 | 457 | def get_text_palette(self): | ||
3259 | 458 | palette = {gtk.STATE_NORMAL: self.text[gtk.STATE_NORMAL], | ||
3260 | 459 | gtk.STATE_ACTIVE: self.text[gtk.STATE_NORMAL], | ||
3261 | 460 | gtk.STATE_SELECTED: self.text[gtk.STATE_NORMAL], | ||
3262 | 461 | gtk.STATE_PRELIGHT: self.text[gtk.STATE_PRELIGHT], | ||
3263 | 462 | gtk.STATE_INSENSITIVE: self.text[gtk.STATE_INSENSITIVE]} | ||
3264 | 463 | return palette | ||
3265 | 464 | |||
3266 | 465 | def get_dark_line_palette(self): | ||
3267 | 466 | palette = {gtk.STATE_NORMAL: self.bg[gtk.STATE_NORMAL].darken(), | ||
3268 | 467 | gtk.STATE_ACTIVE: self.bg[gtk.STATE_NORMAL].darken(), | ||
3269 | 468 | gtk.STATE_PRELIGHT: self.bg[gtk.STATE_NORMAL].darken(), | ||
3270 | 469 | gtk.STATE_SELECTED: self.bg[gtk.STATE_NORMAL].darken(), | ||
3271 | 470 | gtk.STATE_INSENSITIVE: self.bg[gtk.STATE_INSENSITIVE].darken()} | ||
3272 | 471 | return palette | ||
3273 | 472 | |||
3274 | 473 | def get_light_line_palette(self): | ||
3275 | 474 | palette = {gtk.STATE_NORMAL: self.bg[gtk.STATE_NORMAL].lighten(), | ||
3276 | 475 | gtk.STATE_ACTIVE: self.bg[gtk.STATE_ACTIVE].lighten(), | ||
3277 | 476 | gtk.STATE_PRELIGHT: self.bg[gtk.STATE_NORMAL].lighten(), | ||
3278 | 477 | gtk.STATE_SELECTED: self.bg[gtk.STATE_NORMAL].lighten(), | ||
3279 | 478 | gtk.STATE_INSENSITIVE: self.bg[gtk.STATE_INSENSITIVE]} | ||
3280 | 479 | return palette | ||
3281 | 480 | |||
3282 | 481 | def get_text_states(self): | ||
3283 | 482 | states = {gtk.STATE_NORMAL: gtk.STATE_NORMAL, | ||
3284 | 483 | gtk.STATE_ACTIVE: gtk.STATE_NORMAL, | ||
3285 | 484 | gtk.STATE_PRELIGHT: gtk.STATE_NORMAL, | ||
3286 | 485 | gtk.STATE_SELECTED: gtk.STATE_NORMAL, | ||
3287 | 486 | gtk.STATE_INSENSITIVE: gtk.STATE_INSENSITIVE} | ||
3288 | 487 | return states | ||
3289 | 488 | |||
3290 | 489 | |||
3291 | 490 | class DustSand(Theme): | ||
3292 | 491 | |||
3293 | 492 | def get_properties(self, gtksettings): | ||
3294 | 493 | props = { | ||
3295 | 494 | 'curvature': 2.5, | ||
3296 | 495 | 'min_part_width': 48, | ||
3297 | 496 | 'xpad': 8, | ||
3298 | 497 | 'ypad': 4, | ||
3299 | 498 | 'xthickness': 1, | ||
3300 | 499 | 'ythickness': 1, | ||
3301 | 500 | 'spacing': 5, | ||
3302 | 501 | 'arrow_width': 13, | ||
3303 | 502 | 'scroll_duration': 150, | ||
3304 | 503 | 'enable-animations': gtksettings.get_property("gtk-enable-animations"), | ||
3305 | 504 | 'override_base': False | ||
3306 | 505 | } | ||
3307 | 506 | return props | ||
3308 | 507 | |||
3309 | 508 | def get_grad_palette(self): | ||
3310 | 509 | |||
3311 | 510 | selected_color = self.bg[gtk.STATE_NORMAL].mix(self.bg[gtk.STATE_SELECTED], | ||
3312 | 511 | 0.4) | ||
3313 | 512 | |||
3314 | 513 | prelight_color = self.bg[gtk.STATE_NORMAL].mix(self.bg[gtk.STATE_SELECTED], | ||
3315 | 514 | 0.175) | ||
3316 | 515 | |||
3317 | 516 | # provide two colours per state for background vertical linear gradients | ||
3318 | 517 | palette = {gtk.STATE_NORMAL: (self.bg[gtk.STATE_NORMAL].shade(1.42), | ||
3319 | 518 | self.bg[gtk.STATE_NORMAL].shade(1.1)), | ||
3320 | 519 | |||
3321 | 520 | gtk.STATE_ACTIVE: (prelight_color, | ||
3322 | 521 | prelight_color.shade(1.07)), | ||
3323 | 522 | |||
3324 | 523 | gtk.STATE_SELECTED: (selected_color.shade(1.35), | ||
3325 | 524 | selected_color.shade(1.1)), | ||
3326 | 525 | |||
3327 | 526 | gtk.STATE_PRELIGHT: (prelight_color.shade(1.74), | ||
3328 | 527 | prelight_color.shade(1.42)), | ||
3329 | 528 | |||
3330 | 529 | gtk.STATE_INSENSITIVE: (self.bg[gtk.STATE_INSENSITIVE], | ||
3331 | 530 | self.bg[gtk.STATE_INSENSITIVE]) | ||
3332 | 531 | } | ||
3333 | 532 | return palette | ||
3334 | 533 | |||
3335 | 534 | def get_text_palette(self): | ||
3336 | 535 | palette = {gtk.STATE_NORMAL: self.text[gtk.STATE_NORMAL], | ||
3337 | 536 | gtk.STATE_ACTIVE: self.text[gtk.STATE_ACTIVE], | ||
3338 | 537 | gtk.STATE_SELECTED: self.text[gtk.STATE_SELECTED], | ||
3339 | 538 | gtk.STATE_PRELIGHT: self.text[gtk.STATE_PRELIGHT], | ||
3340 | 539 | gtk.STATE_INSENSITIVE: self.text[gtk.STATE_INSENSITIVE]} | ||
3341 | 540 | return palette | ||
3342 | 541 | |||
3343 | 542 | def get_dark_line_palette(self): | ||
3344 | 543 | palette = {gtk.STATE_NORMAL: self.bg[gtk.STATE_NORMAL].shade(0.575), | ||
3345 | 544 | gtk.STATE_ACTIVE: self.bg[gtk.STATE_ACTIVE].shade(0.5), | ||
3346 | 545 | gtk.STATE_PRELIGHT: self.bg[gtk.STATE_PRELIGHT].shade(0.575), | ||
3347 | 546 | gtk.STATE_SELECTED: self.bg[gtk.STATE_SELECTED].shade(0.575), | ||
3348 | 547 | gtk.STATE_INSENSITIVE: self.bg[gtk.STATE_NORMAL].darken()} | ||
3349 | 548 | return palette | ||
3350 | 549 | |||
3351 | 550 | def get_light_line_palette(self): | ||
3352 | 551 | palette = {gtk.STATE_NORMAL: self.bg[gtk.STATE_NORMAL].lighten(), | ||
3353 | 552 | gtk.STATE_ACTIVE: self.bg[gtk.STATE_ACTIVE].shade(0.95), | ||
3354 | 553 | gtk.STATE_PRELIGHT: self.bg[gtk.STATE_PRELIGHT].lighten(), | ||
3355 | 554 | gtk.STATE_SELECTED: self.bg[gtk.STATE_NORMAL].lighten(), | ||
3356 | 555 | gtk.STATE_INSENSITIVE: self.bg[gtk.STATE_INSENSITIVE]} | ||
3357 | 556 | return palette | ||
3358 | 557 | |||
3359 | 558 | def get_text_states(self): | ||
3360 | 559 | states = {gtk.STATE_NORMAL: gtk.STATE_NORMAL, | ||
3361 | 560 | gtk.STATE_ACTIVE: gtk.STATE_NORMAL, | ||
3362 | 561 | gtk.STATE_PRELIGHT: gtk.STATE_NORMAL, | ||
3363 | 562 | gtk.STATE_SELECTED: gtk.STATE_NORMAL, | ||
3364 | 563 | gtk.STATE_INSENSITIVE: gtk.STATE_INSENSITIVE} | ||
3365 | 564 | return states | ||
3366 | 565 | |||
3367 | 566 | |||
3368 | 567 | class Dust(DustSand): | ||
3369 | 568 | |||
3370 | 569 | def get_grad_palette(self): | ||
3371 | 570 | |||
3372 | 571 | selected_color = self.bg[gtk.STATE_NORMAL].mix(self.bg[gtk.STATE_SELECTED], | ||
3373 | 572 | 0.5) | ||
3374 | 573 | |||
3375 | 574 | prelight_color = self.bg[gtk.STATE_NORMAL].mix(self.bg[gtk.STATE_SELECTED], | ||
3376 | 575 | 0.175) | ||
3377 | 576 | |||
3378 | 577 | # provide two colours per state for background vertical linear gradients | ||
3379 | 578 | palette = {gtk.STATE_NORMAL: (self.bg[gtk.STATE_NORMAL].shade(1.4), | ||
3380 | 579 | self.bg[gtk.STATE_NORMAL].shade(1.1)), | ||
3381 | 580 | |||
3382 | 581 | gtk.STATE_ACTIVE: (self.bg[gtk.STATE_ACTIVE].shade(1.2), | ||
3383 | 582 | self.bg[gtk.STATE_ACTIVE]), | ||
3384 | 583 | |||
3385 | 584 | gtk.STATE_SELECTED: (selected_color.shade(1.5), | ||
3386 | 585 | selected_color.shade(1.2)), | ||
3387 | 586 | |||
3388 | 587 | gtk.STATE_PRELIGHT: (prelight_color.shade(1.74), | ||
3389 | 588 | prelight_color.shade(1.42)), | ||
3390 | 589 | |||
3391 | 590 | gtk.STATE_INSENSITIVE: (self.bg[gtk.STATE_INSENSITIVE], | ||
3392 | 591 | self.bg[gtk.STATE_INSENSITIVE]) | ||
3393 | 592 | } | ||
3394 | 593 | return palette | ||
3395 | 594 | |||
3396 | 595 | def get_dark_line_palette(self): | ||
3397 | 596 | palette = DustSand.get_dark_line_palette(self) | ||
3398 | 597 | palette[gtk.STATE_SELECTED] = self.bg[gtk.STATE_NORMAL].shade(0.575) | ||
3399 | 598 | return palette | ||
3400 | 599 | |||
3401 | 600 | def get_light_line_palette(self): | ||
3402 | 601 | palette = DustSand.get_light_line_palette(self) | ||
3403 | 602 | palette[gtk.STATE_SELECTED] = self.bg[gtk.STATE_NORMAL].shade(1.15) | ||
3404 | 603 | return palette | ||
3405 | 604 | |||
3406 | 605 | |||
3407 | 606 | class Ambiance(DustSand): | ||
3408 | 607 | |||
3409 | 608 | def get_properties(self, gtksettings): | ||
3410 | 609 | props = DustSand.get_properties(self, gtksettings) | ||
3411 | 610 | props['curvature'] = 4.5 | ||
3412 | 611 | return props | ||
3413 | 612 | |||
3414 | 613 | def get_grad_palette(self): | ||
3415 | 614 | focus_color = color_from_string('#FE765E') | ||
3416 | 615 | selected_color = self.bg[gtk.STATE_NORMAL].mix(focus_color, | ||
3417 | 616 | 0.07) | ||
3418 | 617 | prelight_color = self.bg[gtk.STATE_NORMAL].mix(focus_color, | ||
3419 | 618 | 0.33) | ||
3420 | 619 | |||
3421 | 620 | # provide two colours per state for background vertical linear gradients | ||
3422 | 621 | palette = {gtk.STATE_NORMAL: (self.bg[gtk.STATE_NORMAL].shade(1.2), | ||
3423 | 622 | self.bg[gtk.STATE_NORMAL].shade(0.85)), | ||
3424 | 623 | |||
3425 | 624 | gtk.STATE_ACTIVE: (self.bg[gtk.STATE_NORMAL].shade(0.96), | ||
3426 | 625 | self.bg[gtk.STATE_NORMAL].shade(0.65)), | ||
3427 | 626 | |||
3428 | 627 | gtk.STATE_SELECTED: (selected_color.shade(1.075), | ||
3429 | 628 | selected_color.shade(0.875)), | ||
3430 | 629 | |||
3431 | 630 | gtk.STATE_PRELIGHT: (prelight_color.shade(1.35), | ||
3432 | 631 | prelight_color.shade(1.1)), | ||
3433 | 632 | |||
3434 | 633 | gtk.STATE_INSENSITIVE: (self.bg[gtk.STATE_INSENSITIVE], | ||
3435 | 634 | self.bg[gtk.STATE_INSENSITIVE]) | ||
3436 | 635 | } | ||
3437 | 636 | return palette | ||
3438 | 637 | |||
3439 | 638 | |||
3440 | 639 | class Radiance(Ambiance): | ||
3441 | 640 | |||
3442 | 641 | def get_grad_palette(self): | ||
3443 | 642 | palette = Ambiance.get_grad_palette(self) | ||
3444 | 643 | palette[gtk.STATE_NORMAL] = (self.mid[gtk.STATE_NORMAL].shade(1.25), | ||
3445 | 644 | self.bg[gtk.STATE_NORMAL].shade(0.9)) | ||
3446 | 645 | return palette | ||
3447 | 646 | |||
3448 | 647 | |||
3449 | 648 | class NewWave(Theme): | ||
3450 | 649 | |||
3451 | 650 | def get_properties(self, gtksettings): | ||
3452 | 651 | props = { | ||
3453 | 652 | 'curvature': 2, | ||
3454 | 653 | 'min_part_width': 48, | ||
3455 | 654 | 'xpad': 8, | ||
3456 | 655 | 'ypad': 4, | ||
3457 | 656 | 'xthickness': 1, | ||
3458 | 657 | 'ythickness': 1, | ||
3459 | 658 | 'spacing': 4, | ||
3460 | 659 | 'arrow_width': 13, | ||
3461 | 660 | 'scroll_duration': 150, | ||
3462 | 661 | 'enable-animations': gtksettings.get_property("gtk-enable-animations"), | ||
3463 | 662 | 'override_base': True | ||
3464 | 663 | } | ||
3465 | 664 | return props | ||
3466 | 665 | |||
3467 | 666 | def get_grad_palette(self): | ||
3468 | 667 | # provide two colours per state for background vertical linear gradients | ||
3469 | 668 | |||
3470 | 669 | active_color = self.bg[gtk.STATE_ACTIVE].mix(color_from_string('#FDCF9D'), | ||
3471 | 670 | 0.45) | ||
3472 | 671 | |||
3473 | 672 | selected_color = self.bg[gtk.STATE_NORMAL].mix(color_from_string('#FDCF9D'), | ||
3474 | 673 | 0.2) | ||
3475 | 674 | |||
3476 | 675 | palette = {gtk.STATE_NORMAL: (self.bg[gtk.STATE_NORMAL].shade(1.1), | ||
3477 | 676 | self.bg[gtk.STATE_NORMAL].shade(0.95)), | ||
3478 | 677 | |||
3479 | 678 | gtk.STATE_ACTIVE: (active_color.shade(1.1), | ||
3480 | 679 | self.bg[gtk.STATE_ACTIVE].shade(0.95)), | ||
3481 | 680 | |||
3482 | 681 | gtk.STATE_PRELIGHT: (color_from_string('#FDCF9D'), | ||
3483 | 682 | color_from_string('#FCAE87')), | ||
3484 | 683 | |||
3485 | 684 | gtk.STATE_SELECTED: (selected_color.shade(1.2), | ||
3486 | 685 | selected_color), | ||
3487 | 686 | |||
3488 | 687 | gtk.STATE_INSENSITIVE: (self.bg[gtk.STATE_INSENSITIVE], | ||
3489 | 688 | self.bg[gtk.STATE_INSENSITIVE]) | ||
3490 | 689 | } | ||
3491 | 690 | return palette | ||
3492 | 691 | |||
3493 | 692 | def get_text_palette(self): | ||
3494 | 693 | palette = {gtk.STATE_NORMAL: self.text[gtk.STATE_NORMAL], | ||
3495 | 694 | gtk.STATE_ACTIVE: self.text[gtk.STATE_NORMAL], | ||
3496 | 695 | gtk.STATE_PRELIGHT: self.text[gtk.STATE_NORMAL], | ||
3497 | 696 | gtk.STATE_SELECTED: self.text[gtk.STATE_SELECTED], | ||
3498 | 697 | gtk.STATE_INSENSITIVE: self.text[gtk.STATE_INSENSITIVE]} | ||
3499 | 698 | return palette | ||
3500 | 699 | |||
3501 | 700 | def get_dark_line_palette(self): | ||
3502 | 701 | palette = {gtk.STATE_NORMAL: self.bg[gtk.STATE_NORMAL].darken(), | ||
3503 | 702 | gtk.STATE_ACTIVE: self.bg[gtk.STATE_NORMAL].darken(), | ||
3504 | 703 | gtk.STATE_PRELIGHT: self.bg[gtk.STATE_NORMAL].darken(), | ||
3505 | 704 | gtk.STATE_SELECTED: self.bg[gtk.STATE_NORMAL].darken(), | ||
3506 | 705 | gtk.STATE_INSENSITIVE: self.bg[gtk.STATE_INSENSITIVE].darken()} | ||
3507 | 706 | return palette | ||
3508 | 707 | |||
3509 | 708 | def get_light_line_palette(self): | ||
3510 | 709 | palette = {gtk.STATE_NORMAL: self.bg[gtk.STATE_NORMAL].lighten(), | ||
3511 | 710 | gtk.STATE_ACTIVE: self.bg[gtk.STATE_ACTIVE].shade(0.97), | ||
3512 | 711 | gtk.STATE_PRELIGHT: color_from_string('#FDCF9D'), | ||
3513 | 712 | gtk.STATE_SELECTED: self.bg[gtk.STATE_SELECTED].lighten(), | ||
3514 | 713 | gtk.STATE_INSENSITIVE: self.bg[gtk.STATE_INSENSITIVE]} | ||
3515 | 714 | return palette | ||
3516 | 715 | |||
3517 | 716 | def get_text_states(self): | ||
3518 | 717 | states = {gtk.STATE_NORMAL: gtk.STATE_NORMAL, | ||
3519 | 718 | gtk.STATE_ACTIVE: gtk.STATE_NORMAL, | ||
3520 | 719 | gtk.STATE_PRELIGHT: gtk.STATE_NORMAL, | ||
3521 | 720 | gtk.STATE_SELECTED: gtk.STATE_NORMAL, | ||
3522 | 721 | gtk.STATE_INSENSITIVE: gtk.STATE_INSENSITIVE} | ||
3523 | 722 | return states | ||
3524 | 723 | |||
3525 | 724 | |||
3526 | 725 | class Hicolor(Theme): | ||
3527 | 726 | |||
3528 | 727 | def get_properties(self, gtksettings): | ||
3529 | 728 | props = { | ||
3530 | 729 | 'curvature': 0, | ||
3531 | 730 | 'min_part_width': 48, | ||
3532 | 731 | 'xpad': 15, | ||
3533 | 732 | 'ypad': 10, | ||
3534 | 733 | 'xthickness': 2, | ||
3535 | 734 | 'ythickness': 2, | ||
3536 | 735 | 'spacing': 10, | ||
3537 | 736 | 'arrow_width': 15, | ||
3538 | 737 | 'scroll_duration': 150, | ||
3539 | 738 | 'enable-animations': gtksettings.get_property("gtk-enable-animations"), | ||
3540 | 739 | 'override_base': False | ||
3541 | 740 | } | ||
3542 | 741 | return props | ||
3543 | 742 | |||
3544 | 743 | def get_grad_palette(self): | ||
3545 | 744 | # provide two colours per state for background vertical linear gradients | ||
3546 | 745 | palette = {gtk.STATE_NORMAL: (self.mid[gtk.STATE_NORMAL], | ||
3547 | 746 | self.mid[gtk.STATE_NORMAL]), | ||
3548 | 747 | |||
3549 | 748 | gtk.STATE_ACTIVE: (self.mid[gtk.STATE_ACTIVE], | ||
3550 | 749 | self.mid[gtk.STATE_ACTIVE]), | ||
3551 | 750 | |||
3552 | 751 | gtk.STATE_SELECTED: (self.mid[gtk.STATE_SELECTED], | ||
3553 | 752 | self.mid[gtk.STATE_SELECTED]), | ||
3554 | 753 | |||
3555 | 754 | gtk.STATE_PRELIGHT: (self.mid[gtk.STATE_PRELIGHT], | ||
3556 | 755 | self.mid[gtk.STATE_PRELIGHT]), | ||
3557 | 756 | |||
3558 | 757 | gtk.STATE_INSENSITIVE: (self.bg[gtk.STATE_INSENSITIVE], | ||
3559 | 758 | self.bg[gtk.STATE_INSENSITIVE]) | ||
3560 | 759 | } | ||
3561 | 760 | return palette | ||
3562 | 761 | |||
3563 | 762 | def get_text_palette(self): | ||
3564 | 763 | palette = {gtk.STATE_NORMAL: self.text[gtk.STATE_NORMAL], | ||
3565 | 764 | gtk.STATE_ACTIVE: self.text[gtk.STATE_ACTIVE], | ||
3566 | 765 | gtk.STATE_SELECTED: self.text[gtk.STATE_SELECTED], | ||
3567 | 766 | gtk.STATE_PRELIGHT: self.text[gtk.STATE_PRELIGHT], | ||
3568 | 767 | gtk.STATE_INSENSITIVE: self.text[gtk.STATE_INSENSITIVE]} | ||
3569 | 768 | return palette | ||
3570 | 769 | |||
3571 | 770 | def get_dark_line_palette(self): | ||
3572 | 771 | palette = {gtk.STATE_NORMAL: self.bg[gtk.STATE_SELECTED], | ||
3573 | 772 | gtk.STATE_ACTIVE: self.dark[gtk.STATE_ACTIVE], | ||
3574 | 773 | gtk.STATE_PRELIGHT: self.dark[gtk.STATE_PRELIGHT], | ||
3575 | 774 | gtk.STATE_SELECTED: self.dark[gtk.STATE_SELECTED], | ||
3576 | 775 | gtk.STATE_INSENSITIVE: self.dark[gtk.STATE_INSENSITIVE]} | ||
3577 | 776 | return palette | ||
3578 | 777 | |||
3579 | 778 | def get_light_line_palette(self): | ||
3580 | 779 | palette = {gtk.STATE_NORMAL: self.bg[gtk.STATE_SELECTED], | ||
3581 | 780 | gtk.STATE_ACTIVE: self.light[gtk.STATE_ACTIVE], | ||
3582 | 781 | gtk.STATE_PRELIGHT: self.light[gtk.STATE_PRELIGHT], | ||
3583 | 782 | gtk.STATE_SELECTED: self.light[gtk.STATE_SELECTED], | ||
3584 | 783 | gtk.STATE_INSENSITIVE: self.light[gtk.STATE_INSENSITIVE]} | ||
3585 | 784 | return palette | ||
3586 | 785 | |||
3587 | 786 | def get_text_states(self): | ||
3588 | 787 | states = {gtk.STATE_NORMAL: gtk.STATE_NORMAL, | ||
3589 | 788 | gtk.STATE_ACTIVE: gtk.STATE_ACTIVE, | ||
3590 | 789 | gtk.STATE_PRELIGHT: gtk.STATE_PRELIGHT, | ||
3591 | 790 | gtk.STATE_SELECTED: gtk.STATE_SELECTED, | ||
3592 | 791 | gtk.STATE_INSENSITIVE: gtk.STATE_INSENSITIVE} | ||
3593 | 792 | return states | ||
3594 | 793 | |||
3595 | 794 | |||
3596 | 795 | class ThemeRegistry: | ||
3597 | 796 | |||
3598 | 797 | REGISTRY = {"Human": Human, | ||
3599 | 798 | "Human-Clearlooks": Clearlooks, | ||
3600 | 799 | "Clearlooks": Clearlooks, | ||
3601 | 800 | "InHuman": InHuman, | ||
3602 | 801 | "HighContrastInverse": Hicolor, | ||
3603 | 802 | "HighContrastLargePrintInverse": Hicolor, | ||
3604 | 803 | "Dust": Dust, | ||
3605 | 804 | "Dust Sand": DustSand, | ||
3606 | 805 | "New Wave": NewWave, | ||
3607 | 806 | "Ambiance": Ambiance, | ||
3608 | 807 | "Radiance": Radiance} | ||
3609 | 808 | |||
3610 | 809 | def retrieve(self, theme_name): | ||
3611 | 810 | if self.REGISTRY.has_key(theme_name): | ||
3612 | 811 | print 'Styling hints found for %s...' % theme_name | ||
3613 | 812 | return self.REGISTRY[theme_name]() | ||
3614 | 813 | print "No styling hints for %s were found... using Human hints." % theme_name | ||
3615 | 814 | return Clearlooks() | ||
3616 | 815 | |||
3617 | 816 | |||
3618 | 817 | def color_from_gdkcolor(gdkcolor): | ||
3619 | 818 | return PathBarColor(gdkcolor.red_float, gdkcolor.green_float, gdkcolor.blue_float) | ||
3620 | 819 | |||
3621 | 820 | |||
3622 | 821 | def color_from_string(spec): | ||
3623 | 822 | color = gtk.gdk.color_parse(spec) | ||
3624 | 823 | return PathBarColor(color.red_float, color.green_float, color.blue_float) | ||
3625 | 824 | |||
3626 | 825 | |||
3627 | 826 | |||
3628 | 827 | |||
3629 | 0 | 828 | ||
3630 | === added file 'softwarecenter/view/widgets/pathbar_gtk_atk.py' | |||
3631 | --- softwarecenter/view/widgets/pathbar_gtk_atk.py 1970-01-01 00:00:00 +0000 | |||
3632 | +++ softwarecenter/view/widgets/pathbar_gtk_atk.py 2010-04-04 06:00:32 +0000 | |||
3633 | @@ -0,0 +1,703 @@ | |||
3634 | 1 | # Copyright (C) 2010 Matthew McGowan | ||
3635 | 2 | # | ||
3636 | 3 | # Authors: | ||
3637 | 4 | # Matthew McGowan | ||
3638 | 5 | # | ||
3639 | 6 | # This program is free software: you can redistribute it and/or modify | ||
3640 | 7 | # it under the terms of the GNU General Public License as published by | ||
3641 | 8 | # the Free Software Foundation, either version 3 of the License, or | ||
3642 | 9 | # (at your option) any later version. | ||
3643 | 10 | # | ||
3644 | 11 | # This program is distributed in the hope that it will be useful, | ||
3645 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3646 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3647 | 14 | # GNU General Public License for more details. | ||
3648 | 15 | # | ||
3649 | 16 | # You should have received a copy of the GNU General Public License | ||
3650 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3651 | 18 | |||
3652 | 19 | import atk | ||
3653 | 20 | import cairo | ||
3654 | 21 | import gobject | ||
3655 | 22 | import gtk | ||
3656 | 23 | import pango | ||
3657 | 24 | import pathbar_common | ||
3658 | 25 | |||
3659 | 26 | from gettext import gettext as _ | ||
3660 | 27 | |||
3661 | 28 | |||
3662 | 29 | class PathBar(gtk.HBox): | ||
3663 | 30 | |||
3664 | 31 | ANIMATE_FPS = 50 | ||
3665 | 32 | ANIMATE_DELAY = 150 | ||
3666 | 33 | ANIMATE_DURATION = 150 | ||
3667 | 34 | |||
3668 | 35 | def __init__(self, group=None): | ||
3669 | 36 | gtk.HBox.__init__(self) | ||
3670 | 37 | self.set_redraw_on_allocate(False) | ||
3671 | 38 | |||
3672 | 39 | self._width = 0 | ||
3673 | 40 | self._queue = [] | ||
3674 | 41 | self._active_part = None | ||
3675 | 42 | self._out_of_width = False | ||
3676 | 43 | self._button_press_origin = None | ||
3677 | 44 | |||
3678 | 45 | self._animate = False, None | ||
3679 | 46 | self._scroll_xO = 0 | ||
3680 | 47 | self._no_draw = False | ||
3681 | 48 | self._scroller = None | ||
3682 | 49 | |||
3683 | 50 | self.theme = pathbar_common.PathBarStyle(self) | ||
3684 | 51 | |||
3685 | 52 | # Accessibility info | ||
3686 | 53 | atk_desc = self.get_accessible() | ||
3687 | 54 | atk_desc.set_name(_("You are here:")) | ||
3688 | 55 | atk_desc.set_role(atk.ROLE_PANEL) | ||
3689 | 56 | |||
3690 | 57 | self.set_events(gtk.gdk.EXPOSURE_MASK) | ||
3691 | 58 | self.connect('expose-event', self._on_expose_event) | ||
3692 | 59 | self.connect('size-allocate', self._on_size_allocate) | ||
3693 | 60 | self.connect('style-set', self._on_style_set) | ||
3694 | 61 | self.connect('realize', self._append_on_realize) | ||
3695 | 62 | return | ||
3696 | 63 | |||
3697 | 64 | def _shrink_check(self, allocation): | ||
3698 | 65 | path_w = self._width | ||
3699 | 66 | overhang = path_w - allocation.width | ||
3700 | 67 | self._width -= overhang | ||
3701 | 68 | mpw = self.theme['min_part_width'] | ||
3702 | 69 | for part in self.get_children(): | ||
3703 | 70 | w = part.get_size_request()[0] | ||
3704 | 71 | dw = 0 | ||
3705 | 72 | if w - overhang <= mpw: | ||
3706 | 73 | overhang -= w-mpw | ||
3707 | 74 | part.set_width(mpw) | ||
3708 | 75 | else: | ||
3709 | 76 | part.set_width(w-overhang) | ||
3710 | 77 | break | ||
3711 | 78 | self._out_of_width = True | ||
3712 | 79 | self.queue_draw() | ||
3713 | 80 | return | ||
3714 | 81 | |||
3715 | 82 | def _grow_check(self, allocation): | ||
3716 | 83 | w_freed = allocation.width - self._width | ||
3717 | 84 | parts = self.get_children() | ||
3718 | 85 | parts.reverse() | ||
3719 | 86 | for part in parts: | ||
3720 | 87 | bw = part.get_best_width() | ||
3721 | 88 | w = part.get_size_request()[0] | ||
3722 | 89 | if w < bw: | ||
3723 | 90 | dw = bw - w | ||
3724 | 91 | if dw <= w_freed: | ||
3725 | 92 | w_freed -= dw | ||
3726 | 93 | part.restore_best_width() | ||
3727 | 94 | else: | ||
3728 | 95 | part.set_width(w + w_freed) | ||
3729 | 96 | w_freed = 0 | ||
3730 | 97 | break | ||
3731 | 98 | |||
3732 | 99 | self._width = allocation.width - w_freed | ||
3733 | 100 | if self._width < allocation.width: | ||
3734 | 101 | self._out_of_width = False | ||
3735 | 102 | self.queue_draw() | ||
3736 | 103 | return | ||
3737 | 104 | |||
3738 | 105 | def _compose_on_append(self, last_part): | ||
3739 | 106 | parts = self.get_children() | ||
3740 | 107 | if len(parts) == 0: | ||
3741 | 108 | last_part.set_shape(pathbar_common.SHAPE_RECTANGLE) | ||
3742 | 109 | elif len(parts) == 1: | ||
3743 | 110 | root_part = parts[0] | ||
3744 | 111 | root_part.set_shape(pathbar_common.SHAPE_START_ARROW) | ||
3745 | 112 | last_part.set_shape(pathbar_common.SHAPE_END_CAP) | ||
3746 | 113 | else: | ||
3747 | 114 | tail_part = parts[-1] | ||
3748 | 115 | tail_part.set_shape(pathbar_common.SHAPE_MID_ARROW) | ||
3749 | 116 | last_part.set_shape(pathbar_common.SHAPE_END_CAP) | ||
3750 | 117 | return | ||
3751 | 118 | |||
3752 | 119 | def _compose_on_remove(self, last_part): | ||
3753 | 120 | parts = self.get_children() | ||
3754 | 121 | if len(parts) == 1: | ||
3755 | 122 | last_part.set_shape(pathbar_common.SHAPE_RECTANGLE) | ||
3756 | 123 | elif len(parts) == 2: | ||
3757 | 124 | root_part = parts[0] | ||
3758 | 125 | root_part.set_shape(pathbar_common.SHAPE_START_ARROW) | ||
3759 | 126 | last_part.set_shape(pathbar_common.SHAPE_END_CAP) | ||
3760 | 127 | else: | ||
3761 | 128 | tail_part = parts[-1] | ||
3762 | 129 | tail_part.set_shape(pathbar_common.SHAPE_MID_ARROW) | ||
3763 | 130 | last_part.set_shape(pathbar_common.SHAPE_END_CAP) | ||
3764 | 131 | return | ||
3765 | 132 | |||
3766 | 133 | def _part_enter_notify(self, part, event): | ||
3767 | 134 | if part == self._button_press_origin: | ||
3768 | 135 | part.set_state(gtk.STATE_ACTIVE) | ||
3769 | 136 | else: | ||
3770 | 137 | part.set_state(gtk.STATE_PRELIGHT) | ||
3771 | 138 | self._part_queue_draw(part) | ||
3772 | 139 | return | ||
3773 | 140 | |||
3774 | 141 | def _part_leave_notify(self, part, event): | ||
3775 | 142 | if part == self._active_part: | ||
3776 | 143 | part.set_state(gtk.STATE_SELECTED) | ||
3777 | 144 | else: | ||
3778 | 145 | part.set_state(gtk.STATE_NORMAL) | ||
3779 | 146 | self._part_queue_draw(part) | ||
3780 | 147 | return | ||
3781 | 148 | |||
3782 | 149 | def _part_button_press(self, part, event): | ||
3783 | 150 | if event.button != 1: return | ||
3784 | 151 | self._button_press_origin = part | ||
3785 | 152 | part.set_state(gtk.STATE_ACTIVE) | ||
3786 | 153 | self._part_queue_draw(part) | ||
3787 | 154 | return | ||
3788 | 155 | |||
3789 | 156 | def _part_button_release(self, part, event): | ||
3790 | 157 | if event.button != 1: return | ||
3791 | 158 | |||
3792 | 159 | part_region = gtk.gdk.region_rectangle(part.allocation) | ||
3793 | 160 | if not part_region.point_in(*self.window.get_pointer()[:2]): | ||
3794 | 161 | self._button_press_origin = None | ||
3795 | 162 | return | ||
3796 | 163 | if part != self._button_press_origin: return | ||
3797 | 164 | if self._active_part: | ||
3798 | 165 | self._active_part.set_state(gtk.STATE_NORMAL) | ||
3799 | 166 | self._part_queue_draw(self._active_part) | ||
3800 | 167 | |||
3801 | 168 | self.set_active(part) | ||
3802 | 169 | part.set_state(gtk.STATE_PRELIGHT) | ||
3803 | 170 | self._button_press_origin = None | ||
3804 | 171 | self._part_queue_draw(part) | ||
3805 | 172 | return | ||
3806 | 173 | |||
3807 | 174 | def _part_key_press(self, part, event): | ||
3808 | 175 | # react to spacebar, enter, numpad-enter | ||
3809 | 176 | if event.keyval in (32, 65293, 65421): | ||
3810 | 177 | part.set_state(gtk.STATE_ACTIVE) | ||
3811 | 178 | self._part_queue_draw(part) | ||
3812 | 179 | return | ||
3813 | 180 | |||
3814 | 181 | def _part_key_release(self, part, event): | ||
3815 | 182 | # react to spacebar, enter, numpad-enter | ||
3816 | 183 | if event.keyval in (32, 65293, 65421): | ||
3817 | 184 | self.set_active(part) | ||
3818 | 185 | part.set_state(gtk.STATE_SELECTED) | ||
3819 | 186 | self._part_queue_draw(part) | ||
3820 | 187 | return | ||
3821 | 188 | |||
3822 | 189 | def _part_focus_in(self, part, event): | ||
3823 | 190 | self._part_queue_draw(part) | ||
3824 | 191 | return | ||
3825 | 192 | |||
3826 | 193 | def _part_focus_out(self, part, event): | ||
3827 | 194 | self._part_queue_draw(part) | ||
3828 | 195 | return | ||
3829 | 196 | |||
3830 | 197 | def _part_connect_signals(self, part): | ||
3831 | 198 | part.connect('enter-notify-event', self._part_enter_notify) | ||
3832 | 199 | part.connect('leave-notify-event', self._part_leave_notify) | ||
3833 | 200 | part.connect("button-press-event", self._part_button_press) | ||
3834 | 201 | part.connect("button-release-event", self._part_button_release) | ||
3835 | 202 | part.connect("key-press-event", self._part_key_press) | ||
3836 | 203 | part.connect("key-release-event", self._part_key_release) | ||
3837 | 204 | part.connect('focus-in-event', self._part_focus_in) | ||
3838 | 205 | part.connect('focus-out-event', self._part_focus_out) | ||
3839 | 206 | return | ||
3840 | 207 | |||
3841 | 208 | def _part_queue_draw(self, part): | ||
3842 | 209 | a = part.get_allocation() | ||
3843 | 210 | x, y, h = a.x, a.y, a.height | ||
3844 | 211 | w = part.get_draw_width() | ||
3845 | 212 | xo = part.get_draw_xoffset() | ||
3846 | 213 | self.queue_draw_area(x+xo, y, w, h) | ||
3847 | 214 | return | ||
3848 | 215 | |||
3849 | 216 | def _on_expose_event(self, widget, event): | ||
3850 | 217 | if self._scroll_xO: | ||
3851 | 218 | self._expose_scroll(widget, event) | ||
3852 | 219 | else: | ||
3853 | 220 | self._expose_normal(widget, event) | ||
3854 | 221 | return | ||
3855 | 222 | |||
3856 | 223 | def _expose_normal(self, widget, event): | ||
3857 | 224 | theme = self.theme | ||
3858 | 225 | parts = self.get_children() | ||
3859 | 226 | parts.reverse() | ||
3860 | 227 | region = gtk.gdk.region_rectangle(event.area) | ||
3861 | 228 | |||
3862 | 229 | cr = widget.window.cairo_create() | ||
3863 | 230 | cr.rectangle(event.area) | ||
3864 | 231 | cr.clip() | ||
3865 | 232 | |||
3866 | 233 | for part in parts: | ||
3867 | 234 | if not part.invisible: | ||
3868 | 235 | a = part.get_allocation() | ||
3869 | 236 | xo = part.get_draw_xoffset() | ||
3870 | 237 | x, y, w, h = a.x, a.y, a.width, a.height | ||
3871 | 238 | w = part.get_draw_width() | ||
3872 | 239 | theme.paint_bg(cr, part, x+xo, y, w, h) | ||
3873 | 240 | |||
3874 | 241 | x, y, w, h = part.get_layout_points() | ||
3875 | 242 | |||
3876 | 243 | if part.has_focus(): | ||
3877 | 244 | self.style.paint_focus(self.window, | ||
3878 | 245 | part.state, | ||
3879 | 246 | (a.x+x-4, a.y+y-2, w+8, h+4), | ||
3880 | 247 | self, | ||
3881 | 248 | 'button', | ||
3882 | 249 | a.x+x-4, a.y+y-2, w+8, h+4) | ||
3883 | 250 | |||
3884 | 251 | theme.paint_layout(widget, part, a.x+x, a.y+y) | ||
3885 | 252 | else: | ||
3886 | 253 | part.invisible = False | ||
3887 | 254 | del cr | ||
3888 | 255 | return | ||
3889 | 256 | |||
3890 | 257 | def _expose_scroll(self, widget, event): | ||
3891 | 258 | parts = self.get_children() | ||
3892 | 259 | if len(parts) < 2: return | ||
3893 | 260 | static_tail, scroller = parts[-2:] | ||
3894 | 261 | |||
3895 | 262 | if self.get_direction() != gtk.TEXT_DIR_RTL: | ||
3896 | 263 | sxO = self._scroll_xO | ||
3897 | 264 | else: | ||
3898 | 265 | sxO = -self._scroll_xO | ||
3899 | 266 | |||
3900 | 267 | theme = self.theme | ||
3901 | 268 | |||
3902 | 269 | cr = widget.window.cairo_create() | ||
3903 | 270 | cr.rectangle(event.area) | ||
3904 | 271 | cr.clip() | ||
3905 | 272 | |||
3906 | 273 | a = scroller.get_allocation() | ||
3907 | 274 | x, y, w, h = a.x, a.y, a.width, a.height | ||
3908 | 275 | w = scroller.get_draw_width() | ||
3909 | 276 | xo = scroller.get_draw_xoffset() | ||
3910 | 277 | theme.paint_bg(cr, scroller, x+xo-sxO, y, w, h) | ||
3911 | 278 | x, y, w, h = scroller.get_layout_points() | ||
3912 | 279 | theme.paint_layout(widget, scroller, a.x+x-int(sxO), a.y+y) | ||
3913 | 280 | |||
3914 | 281 | a = static_tail.get_allocation() | ||
3915 | 282 | x, y, w, h = a.x, a.y, a.width, a.height | ||
3916 | 283 | w = static_tail.get_draw_width() | ||
3917 | 284 | xo = static_tail.get_draw_xoffset() | ||
3918 | 285 | theme.paint_bg(cr, static_tail, x+xo, y, w, h) | ||
3919 | 286 | del cr | ||
3920 | 287 | return | ||
3921 | 288 | |||
3922 | 289 | def _on_size_allocate(self, widget, allocation): | ||
3923 | 290 | if self._width < allocation.width and self._out_of_width: | ||
3924 | 291 | self._grow_check(allocation) | ||
3925 | 292 | elif self._width >= allocation.width: | ||
3926 | 293 | self._shrink_check(allocation) | ||
3927 | 294 | |||
3928 | 295 | if self._animate[0] and self.theme['enable-animations']: | ||
3929 | 296 | part = self._animate[1] | ||
3930 | 297 | part.invisible = True | ||
3931 | 298 | self._animate = False, None | ||
3932 | 299 | gobject.timeout_add(self.ANIMATE_DELAY, self._scroll_out_init, part) | ||
3933 | 300 | else: | ||
3934 | 301 | self.queue_draw() | ||
3935 | 302 | return | ||
3936 | 303 | |||
3937 | 304 | def _on_style_set(self, widget, old_style): | ||
3938 | 305 | self.theme = pathbar_common.PathBarStyle(self) | ||
3939 | 306 | for part in self.get_children(): | ||
3940 | 307 | part.recalc_dimensions() | ||
3941 | 308 | self.queue_draw() | ||
3942 | 309 | return | ||
3943 | 310 | |||
3944 | 311 | def _append_on_realize(self, widget): | ||
3945 | 312 | for part, do_callback, animate in self._queue: | ||
3946 | 313 | self.append(part, do_callback, animate) | ||
3947 | 314 | return | ||
3948 | 315 | |||
3949 | 316 | def _scroll_out_init(self, part): | ||
3950 | 317 | draw_area = part.get_allocation() | ||
3951 | 318 | self._scroller = gobject.timeout_add( | ||
3952 | 319 | max(int(1000.0 / self.ANIMATE_FPS), 10), # interval | ||
3953 | 320 | self._scroll_out_cb, | ||
3954 | 321 | part.get_size_request()[0], | ||
3955 | 322 | self.ANIMATE_DURATION*0.001, # 1 over duration (converted to seconds) | ||
3956 | 323 | gobject.get_current_time(), | ||
3957 | 324 | (draw_area.x, draw_area.y, | ||
3958 | 325 | draw_area.width, draw_area.height)) | ||
3959 | 326 | return False | ||
3960 | 327 | |||
3961 | 328 | def _scroll_out_cb(self, distance, duration, start_t, draw_area): | ||
3962 | 329 | cur_t = gobject.get_current_time() | ||
3963 | 330 | xO = distance - distance*((cur_t - start_t) / duration) | ||
3964 | 331 | |||
3965 | 332 | if xO > 0: | ||
3966 | 333 | self._scroll_xO = xO | ||
3967 | 334 | self.queue_draw_area(*draw_area) | ||
3968 | 335 | |||
3969 | 336 | else: # final frame | ||
3970 | 337 | self._scroll_xO = 0 | ||
3971 | 338 | # redraw the entire widget | ||
3972 | 339 | # incase some timeouts are skipped due to high system load | ||
3973 | 340 | self.queue_draw_area(*draw_area) | ||
3974 | 341 | self._scroller = None | ||
3975 | 342 | return False | ||
3976 | 343 | return True | ||
3977 | 344 | |||
3978 | 345 | def has_parts(self): | ||
3979 | 346 | return self.get_children() == True | ||
3980 | 347 | |||
3981 | 348 | def get_parts(self): | ||
3982 | 349 | return self.get_children() | ||
3983 | 350 | |||
3984 | 351 | def get_last(self): | ||
3985 | 352 | if self.get_children(): | ||
3986 | 353 | return self.get_children()[-1] | ||
3987 | 354 | return None | ||
3988 | 355 | |||
3989 | 356 | def set_active(self, part, do_callback=True): | ||
3990 | 357 | if part == self._active_part: return | ||
3991 | 358 | if self._active_part: | ||
3992 | 359 | self._active_part.set_state(gtk.STATE_NORMAL) | ||
3993 | 360 | self._part_queue_draw(self._active_part) | ||
3994 | 361 | |||
3995 | 362 | part.set_state(gtk.STATE_SELECTED) | ||
3996 | 363 | self._part_queue_draw(part) | ||
3997 | 364 | self._active_part = part | ||
3998 | 365 | if do_callback and part.callback: | ||
3999 | 366 | part.callback(self, part) | ||
4000 | 367 | return | ||
4001 | 368 | |||
4002 | 369 | def get_active(self): | ||
4003 | 370 | return self._active_part | ||
4004 | 371 | |||
4005 | 372 | def set_active_no_callback(self, part): | ||
4006 | 373 | self.set_active(part, False) | ||
4007 | 374 | return | ||
4008 | 375 | |||
4009 | 376 | def append(self, part, do_callback=True, animate=True): | ||
4010 | 377 | if not self.get_property('visible'): | ||
4011 | 378 | self._queue.append([part, do_callback, animate]) | ||
4012 | 379 | return | ||
4013 | 380 | |||
4014 | 381 | if self._scroller: | ||
4015 | 382 | gobject.source_remove(self._scroller) | ||
4016 | 383 | self._scroll_xO = 0 | ||
4017 | 384 | |||
4018 | 385 | self._compose_on_append(part) | ||
4019 | 386 | self._width += part.get_size_request()[0] | ||
4020 | 387 | |||
4021 | 388 | self.pack_start(part, False) | ||
4022 | 389 | self._part_connect_signals(part) | ||
4023 | 390 | self._animate = animate, part | ||
4024 | 391 | part.show() | ||
4025 | 392 | |||
4026 | 393 | if do_callback: | ||
4027 | 394 | self.set_active(part) | ||
4028 | 395 | else: | ||
4029 | 396 | self.set_active_no_callback(part) | ||
4030 | 397 | return | ||
4031 | 398 | |||
4032 | 399 | def append_no_callback(self, part): | ||
4033 | 400 | self.append(part, do_callback=False) | ||
4034 | 401 | |||
4035 | 402 | def remove(self, part): | ||
4036 | 403 | parts = self.get_children() | ||
4037 | 404 | if len(parts) <= 1: return # protect last part | ||
4038 | 405 | self._width -= part.get_size_request()[0] | ||
4039 | 406 | part.destroy() | ||
4040 | 407 | self._compose_on_remove(parts[-2]) | ||
4041 | 408 | return | ||
4042 | 409 | |||
4043 | 410 | def remove_all(self, keep_first_part=True, do_callback=True): | ||
4044 | 411 | parts = self.get_children() | ||
4045 | 412 | if len(parts) < 1: return | ||
4046 | 413 | if keep_first_part: | ||
4047 | 414 | if len(parts) <= 1: return | ||
4048 | 415 | parts = parts[1:] | ||
4049 | 416 | for part in parts: | ||
4050 | 417 | part.destroy() | ||
4051 | 418 | |||
4052 | 419 | self._width = 0 | ||
4053 | 420 | if keep_first_part: | ||
4054 | 421 | root = self.get_parts()[0] | ||
4055 | 422 | root.set_shape(pathbar_common.SHAPE_RECTANGLE) | ||
4056 | 423 | self._width = root.get_size_request()[0] | ||
4057 | 424 | if do_callback: root.callback(self, root) | ||
4058 | 425 | return | ||
4059 | 426 | |||
4060 | 427 | def navigate_up(self): | ||
4061 | 428 | parts = self.get_children() | ||
4062 | 429 | if len(parts) > 1: | ||
4063 | 430 | nav_part = parts[len(parts) - 2] | ||
4064 | 431 | self.set_active(nav_part) | ||
4065 | 432 | return | ||
4066 | 433 | |||
4067 | 434 | |||
4068 | 435 | class PathPart(gtk.EventBox): | ||
4069 | 436 | |||
4070 | 437 | def __init__(self, parent, label, callback=None): | ||
4071 | 438 | gtk.EventBox.__init__(self) | ||
4072 | 439 | self.set_redraw_on_allocate(False) | ||
4073 | 440 | self.set_visible_window(False) | ||
4074 | 441 | |||
4075 | 442 | part_atk = self.get_accessible() | ||
4076 | 443 | part_atk.set_name(label) | ||
4077 | 444 | part_atk.set_description(_('Navigates to the %s page.' % label)) | ||
4078 | 445 | part_atk.set_role(atk.ROLE_PUSH_BUTTON) | ||
4079 | 446 | |||
4080 | 447 | self.invisible = False | ||
4081 | 448 | self._parent = parent | ||
4082 | 449 | self._draw_shift = 0 | ||
4083 | 450 | self._draw_width = 0 | ||
4084 | 451 | self._best_width = 0 | ||
4085 | 452 | self._layout_points = 0,0,0,0 | ||
4086 | 453 | self._size_requisition = 0,0 | ||
4087 | 454 | |||
4088 | 455 | self.label = None | ||
4089 | 456 | self.shape = pathbar_common.SHAPE_RECTANGLE | ||
4090 | 457 | self.layout = None | ||
4091 | 458 | self.callback = callback | ||
4092 | 459 | self.set_label(label) | ||
4093 | 460 | |||
4094 | 461 | self.set_flags(gtk.CAN_FOCUS) | ||
4095 | 462 | self.set_events(gtk.gdk.BUTTON_PRESS_MASK| | ||
4096 | 463 | gtk.gdk.BUTTON_RELEASE_MASK| | ||
4097 | 464 | gtk.gdk.KEY_RELEASE_MASK| | ||
4098 | 465 | gtk.gdk.KEY_PRESS_MASK| | ||
4099 | 466 | gtk.gdk.ENTER_NOTIFY_MASK| | ||
4100 | 467 | gtk.gdk.LEAVE_NOTIFY_MASK) | ||
4101 | 468 | return | ||
4102 | 469 | |||
4103 | 470 | def __repr__(self): | ||
4104 | 471 | return self.label | ||
4105 | 472 | |||
4106 | 473 | def _make_layout(self): | ||
4107 | 474 | pc = self._parent.get_pango_context() | ||
4108 | 475 | layout = pango.Layout(pc) | ||
4109 | 476 | layout.set_markup(self.label) | ||
4110 | 477 | layout.set_ellipsize(pango.ELLIPSIZE_END) | ||
4111 | 478 | self.layout = layout | ||
4112 | 479 | return | ||
4113 | 480 | |||
4114 | 481 | def _set_best_width(self, best_width): | ||
4115 | 482 | self._best_width = best_width | ||
4116 | 483 | return | ||
4117 | 484 | |||
4118 | 485 | def _calc_layout_points(self): | ||
4119 | 486 | if not self.layout: self._make_layout() | ||
4120 | 487 | x = self._parent.theme['xpad'] | ||
4121 | 488 | y = self._parent.theme['ypad'] | ||
4122 | 489 | w, h = self.layout.get_pixel_extents()[1][2:] | ||
4123 | 490 | self._layout_points = [x, y, w, h] | ||
4124 | 491 | return | ||
4125 | 492 | |||
4126 | 493 | def _adjust_width(self, shape, w): | ||
4127 | 494 | self._draw_xoffset = 0 | ||
4128 | 495 | self._draw_width = w | ||
4129 | 496 | |||
4130 | 497 | arrow_width = self._parent.theme['arrow_width'] | ||
4131 | 498 | if shape == pathbar_common.SHAPE_RECTANGLE: | ||
4132 | 499 | return w | ||
4133 | 500 | |||
4134 | 501 | elif shape == pathbar_common.SHAPE_START_ARROW: | ||
4135 | 502 | self._draw_width += arrow_width | ||
4136 | 503 | if self.get_direction() == gtk.TEXT_DIR_RTL: | ||
4137 | 504 | self._draw_xoffset -= arrow_width | ||
4138 | 505 | |||
4139 | 506 | elif shape == pathbar_common.SHAPE_END_CAP: | ||
4140 | 507 | w += arrow_width | ||
4141 | 508 | self._draw_width += arrow_width | ||
4142 | 509 | if self.get_direction() != gtk.TEXT_DIR_RTL: | ||
4143 | 510 | self._layout_points[0] += arrow_width | ||
4144 | 511 | |||
4145 | 512 | elif shape == pathbar_common.SHAPE_MID_ARROW: | ||
4146 | 513 | w += arrow_width | ||
4147 | 514 | self._draw_width += 2*arrow_width | ||
4148 | 515 | if self.get_direction() == gtk.TEXT_DIR_RTL: | ||
4149 | 516 | self._draw_xoffset -= arrow_width | ||
4150 | 517 | else: | ||
4151 | 518 | self._layout_points[0] += arrow_width | ||
4152 | 519 | return w | ||
4153 | 520 | |||
4154 | 521 | def _calc_size(self, shape): | ||
4155 | 522 | lx, ly, w, h = self.layout.get_pixel_extents()[1] | ||
4156 | 523 | w += 2*self._parent.theme['xpad'] | ||
4157 | 524 | h += 2*self._parent.theme['ypad'] | ||
4158 | 525 | |||
4159 | 526 | w = self._adjust_width(shape, w) | ||
4160 | 527 | if not self.get_best_width(): | ||
4161 | 528 | self._set_best_width(w) | ||
4162 | 529 | self.set_size_request(w, h) | ||
4163 | 530 | return | ||
4164 | 531 | |||
4165 | 532 | def do_callback(self): | ||
4166 | 533 | self.callback(self._parent, self) | ||
4167 | 534 | return | ||
4168 | 535 | |||
4169 | 536 | def set_label(self, label): | ||
4170 | 537 | if label == self.label: return | ||
4171 | 538 | self.label = gobject.markup_escape_text(label.strip()) | ||
4172 | 539 | if not self.layout: | ||
4173 | 540 | self._make_layout() | ||
4174 | 541 | else: | ||
4175 | 542 | self.layout.set_markup(self.label) | ||
4176 | 543 | |||
4177 | 544 | self._calc_layout_points() | ||
4178 | 545 | self._calc_size(self.shape) | ||
4179 | 546 | return | ||
4180 | 547 | |||
4181 | 548 | def set_shape(self, shape): | ||
4182 | 549 | self.shape = shape | ||
4183 | 550 | self._calc_layout_points() | ||
4184 | 551 | self._calc_size(shape) | ||
4185 | 552 | return | ||
4186 | 553 | |||
4187 | 554 | def set_width(self, w): | ||
4188 | 555 | theme = self._parent.theme | ||
4189 | 556 | lw = w-theme['arrow_width'] | ||
4190 | 557 | if self.shape != pathbar_common.SHAPE_START_ARROW: | ||
4191 | 558 | lw -= theme['xpad'] | ||
4192 | 559 | if self.shape == pathbar_common.SHAPE_MID_ARROW: | ||
4193 | 560 | lw -= theme['arrow_width'] | ||
4194 | 561 | self.layout.set_width(lw*pango.SCALE) | ||
4195 | 562 | |||
4196 | 563 | self._draw_width = w+theme['arrow_width'] | ||
4197 | 564 | self.set_size_request(w, -1) | ||
4198 | 565 | return | ||
4199 | 566 | |||
4200 | 567 | def restore_best_width(self): | ||
4201 | 568 | w = self.get_best_width() | ||
4202 | 569 | arrow_width = self._parent.theme['arrow_width'] | ||
4203 | 570 | |||
4204 | 571 | if self.shape == pathbar_common.SHAPE_MID_ARROW: | ||
4205 | 572 | w += arrow_width | ||
4206 | 573 | if self.shape == pathbar_common.SHAPE_END_CAP and \ | ||
4207 | 574 | self.get_direction() == gtk.TEXT_DIR_RTL: | ||
4208 | 575 | self._draw_xoffset -= arrow_width | ||
4209 | 576 | self._layout_points[0] -= arrow_width | ||
4210 | 577 | |||
4211 | 578 | self.layout.set_width(-1) | ||
4212 | 579 | self._draw_width = w+arrow_width | ||
4213 | 580 | self.set_size_request(w, -1) | ||
4214 | 581 | return | ||
4215 | 582 | |||
4216 | 583 | def get_draw_width(self): | ||
4217 | 584 | return self._draw_width | ||
4218 | 585 | |||
4219 | 586 | def get_draw_xoffset(self): | ||
4220 | 587 | return self._draw_xoffset | ||
4221 | 588 | |||
4222 | 589 | def get_best_width(self): | ||
4223 | 590 | return self._best_width | ||
4224 | 591 | |||
4225 | 592 | def get_layout_points(self): | ||
4226 | 593 | x, y, w, h = self._layout_points | ||
4227 | 594 | y = int(max((self.allocation.height-h)*0.5+0.5, y)) | ||
4228 | 595 | return x, y, w, h | ||
4229 | 596 | |||
4230 | 597 | def get_layout(self): | ||
4231 | 598 | return self.layout | ||
4232 | 599 | |||
4233 | 600 | def recalc_dimensions(self): | ||
4234 | 601 | self.layout = None | ||
4235 | 602 | self._calc_layout_points() | ||
4236 | 603 | self._calc_size(self.shape) | ||
4237 | 604 | return | ||
4238 | 605 | |||
4239 | 606 | class NavigationBar(PathBar): | ||
4240 | 607 | |||
4241 | 608 | APPEND_DELAY = 150 | ||
4242 | 609 | |||
4243 | 610 | def __init__(self, group=None): | ||
4244 | 611 | PathBar.__init__(self) | ||
4245 | 612 | self.id_to_part = {} | ||
4246 | 613 | return | ||
4247 | 614 | |||
4248 | 615 | def add_with_id(self, label, callback, id, do_callback=True, animate=True): | ||
4249 | 616 | """ | ||
4250 | 617 | Add a new button with the given label/callback | ||
4251 | 618 | |||
4252 | 619 | If there is the same id already, replace the existing one | ||
4253 | 620 | with the new one | ||
4254 | 621 | """ | ||
4255 | 622 | |||
4256 | 623 | # check if we have the button of that id or need a new one | ||
4257 | 624 | if id in self.id_to_part: | ||
4258 | 625 | part = self.id_to_part[id] | ||
4259 | 626 | part.set_label(label) | ||
4260 | 627 | else: | ||
4261 | 628 | part = PathPart(parent=self, label=label, callback=callback) | ||
4262 | 629 | part.set_name(id) | ||
4263 | 630 | self.id_to_part[id] = part | ||
4264 | 631 | self.append(part, do_callback, animate) | ||
4265 | 632 | return | ||
4266 | 633 | |||
4267 | 634 | def remove_id(self, id): | ||
4268 | 635 | if not id in self.id_to_part: | ||
4269 | 636 | return | ||
4270 | 637 | part = self.id_to_part[id] | ||
4271 | 638 | del self.id_to_part[id] | ||
4272 | 639 | self.remove(part) | ||
4273 | 640 | return | ||
4274 | 641 | |||
4275 | 642 | def remove_all(self, keep_first_part=True, do_callback=True): | ||
4276 | 643 | if len(self.get_parts()) <= 1: return | ||
4277 | 644 | root = self.get_children()[0] | ||
4278 | 645 | self.id_to_part = {root.get_name(): root} | ||
4279 | 646 | PathBar.remove_all(self, do_callback=do_callback) | ||
4280 | 647 | return | ||
4281 | 648 | |||
4282 | 649 | def get_button_from_id(self, id): | ||
4283 | 650 | """ | ||
4284 | 651 | return the button for the given id (or None) | ||
4285 | 652 | """ | ||
4286 | 653 | if not id in self.id_to_part: | ||
4287 | 654 | return None | ||
4288 | 655 | return self.id_to_part[id] | ||
4289 | 656 | |||
4290 | 657 | |||
4291 | 658 | class Test: | ||
4292 | 659 | |||
4293 | 660 | def __init__(self): | ||
4294 | 661 | self.counter = 0 | ||
4295 | 662 | w = gtk.Window() | ||
4296 | 663 | w.connect("destroy", gtk.main_quit) | ||
4297 | 664 | w.set_size_request(384, -1) | ||
4298 | 665 | w.set_default_size(512, -1) | ||
4299 | 666 | w.set_border_width(3) | ||
4300 | 667 | |||
4301 | 668 | vb = gtk.VBox() | ||
4302 | 669 | w.add(vb) | ||
4303 | 670 | |||
4304 | 671 | pb = PathBar() | ||
4305 | 672 | vb.pack_start(pb, False) | ||
4306 | 673 | part = PathPart(pb, 'Get Free Software?') | ||
4307 | 674 | pb.append(part) | ||
4308 | 675 | |||
4309 | 676 | add = gtk.Button(stock=gtk.STOCK_ADD) | ||
4310 | 677 | rem = gtk.Button(stock=gtk.STOCK_REMOVE) | ||
4311 | 678 | self.entry = gtk.Entry() | ||
4312 | 679 | |||
4313 | 680 | vb.pack_start(add, False) | ||
4314 | 681 | vb.pack_start(self.entry, False) | ||
4315 | 682 | vb.pack_start(rem, False) | ||
4316 | 683 | add.connect('clicked', self.add_cb, pb) | ||
4317 | 684 | rem.connect('clicked', self.rem_cb, pb) | ||
4318 | 685 | |||
4319 | 686 | w.show_all() | ||
4320 | 687 | gtk.main() | ||
4321 | 688 | return | ||
4322 | 689 | |||
4323 | 690 | def add_cb(self, widget, pb): | ||
4324 | 691 | text = self.entry.get_text() or ('unnammed%s' % self.counter) | ||
4325 | 692 | part = PathPart(pb, text) | ||
4326 | 693 | pb.append(part) | ||
4327 | 694 | self.counter += 1 | ||
4328 | 695 | return | ||
4329 | 696 | |||
4330 | 697 | def rem_cb(self, widget, pb): | ||
4331 | 698 | last = pb.get_children()[-1] | ||
4332 | 699 | pb.remove(last) | ||
4333 | 700 | return | ||
4334 | 701 | |||
4335 | 702 | if __name__ == '__main__': | ||
4336 | 703 | Test() | ||
4337 | 0 | 704 | ||
4338 | === removed file 'softwarecenter/view/widgets/rgb.py' | |||
4339 | --- softwarecenter/view/widgets/rgb.py 2009-10-09 13:44:41 +0000 | |||
4340 | +++ softwarecenter/view/widgets/rgb.py 1970-01-01 00:00:00 +0000 | |||
4341 | @@ -1,67 +0,0 @@ | |||
4342 | 1 | # Copyright (C) 2009 Matthew McGowan | ||
4343 | 2 | # | ||
4344 | 3 | # Authors: | ||
4345 | 4 | # Matthew McGowan | ||
4346 | 5 | # | ||
4347 | 6 | # This program is free software: you can redistribute it and/or modify | ||
4348 | 7 | # it under the terms of the GNU General Public License as published by | ||
4349 | 8 | # the Free Software Foundation, either version 3 of the License, or | ||
4350 | 9 | # (at your option) any later version. | ||
4351 | 10 | # | ||
4352 | 11 | # This program is distributed in the hope that it will be useful, | ||
4353 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4354 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4355 | 14 | # GNU General Public License for more details. | ||
4356 | 15 | # | ||
4357 | 16 | # You should have received a copy of the GNU General Public License | ||
4358 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4359 | 18 | |||
4360 | 19 | |||
4361 | 20 | import colorsys | ||
4362 | 21 | from gtk.gdk import Color | ||
4363 | 22 | |||
4364 | 23 | |||
4365 | 24 | def parse_colour_scheme(colour_scheme_str): | ||
4366 | 25 | scheme_dict = {} | ||
4367 | 26 | for ln in colour_scheme_str.splitlines(): | ||
4368 | 27 | k, v = ln.split(':') | ||
4369 | 28 | scheme_dict[k.strip()] = gtk.gdk.color_parse(v.strip()) | ||
4370 | 29 | return scheme_dict | ||
4371 | 30 | |||
4372 | 31 | |||
4373 | 32 | def shade(color, k): | ||
4374 | 33 | # as seen in Murrine's cairo-support.c | ||
4375 | 34 | r = color.red_float | ||
4376 | 35 | g = color.green_float | ||
4377 | 36 | b = color.blue_float | ||
4378 | 37 | |||
4379 | 38 | if (k == 1.0): | ||
4380 | 39 | return color | ||
4381 | 40 | |||
4382 | 41 | h,l,s = colorsys.rgb_to_hls(r,g,b) | ||
4383 | 42 | |||
4384 | 43 | l *= k | ||
4385 | 44 | if (l > 1.0): | ||
4386 | 45 | l = 1.0 | ||
4387 | 46 | elif (l < 0.0): | ||
4388 | 47 | l = 0.0 | ||
4389 | 48 | |||
4390 | 49 | s *= k | ||
4391 | 50 | if (s > 1.0): | ||
4392 | 51 | s = 1.0 | ||
4393 | 52 | elif (s < 0.0): | ||
4394 | 53 | s = 0.0 | ||
4395 | 54 | |||
4396 | 55 | r, g, b = colorsys.hls_to_rgb(h,l,s) | ||
4397 | 56 | |||
4398 | 57 | return Color(int(r*65535), int(g*65535), int(b*65535)) | ||
4399 | 58 | |||
4400 | 59 | def mix_color(color1, color2, mix_factor): | ||
4401 | 60 | # as seen in Murrine's cairo-support.c | ||
4402 | 61 | r = color1.red_float*(1-mix_factor)+color2.red_float*mix_factor | ||
4403 | 62 | g = color1.green_float*(1-mix_factor)+color2.green_float*mix_factor | ||
4404 | 63 | b = color1.blue_float*(1-mix_factor)+color2.blue_float*mix_factor | ||
4405 | 64 | return Color(int(r*65535), int(g*65535), int(b*65535)) | ||
4406 | 65 | |||
4407 | 66 | def to_float(color): | ||
4408 | 67 | return color.red_float, color.green_float, color.blue_float |