Merge lp:~rastkokaradzic/screenlets/testing into lp:screenlets

Proposed by Märt Põder
Status: Merged
Merged at revision: 785
Proposed branch: lp:~rastkokaradzic/screenlets/testing
Merge into: lp:screenlets
Diff against target: 449 lines (+188/-55)
4 files modified
Makefile (+1/-1)
potfiles.sh (+17/-1)
src/lib/utils.py (+14/-8)
src/share/screenlets-manager/screenlets-manager.py (+156/-45)
To merge this branch: bzr merge lp:~rastkokaradzic/screenlets/testing
Reviewer Review Type Date Requested Status
Märt Põder Approve
Review via email: mp+98786@code.launchpad.net

Description of the change

Add screenlet categories to Screenlets Manager

To post a comment you must log in.
Revision history for this message
Märt Põder (boamaod) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile'
--- Makefile 2009-03-15 20:06:25 +0000
+++ Makefile 2012-03-22 06:31:18 +0000
@@ -9,7 +9,7 @@
9#9#
1010
11VERSION = `cat VERSION`11VERSION = `cat VERSION`
12PREFIX = /usr12PREFIX = /usr/local
13INSTALL_LOG = install.log13INSTALL_LOG = install.log
1414
15.PHONY : docs15.PHONY : docs
1616
=== modified file 'potfiles.sh'
--- potfiles.sh 2011-08-12 19:41:00 +0000
+++ potfiles.sh 2012-03-22 06:31:18 +0000
@@ -14,7 +14,7 @@
14# along with this program. If not, see <http://www.gnu.org/licenses/>.14# along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
16VERSION=$(cat VERSION)16VERSION=$(cat VERSION)
1717INDIV_ROOT=../indiv-screenlets/
18function po()18function po()
19{19{
20 tmpname="/tmp/$(uuidgen).pot"20 tmpname="/tmp/$(uuidgen).pot"
@@ -67,7 +67,23 @@
67 fi67 fi
68}68}
6969
70function po_categories() {
71 SAVEIFS=$IFS
72 IFS=$(echo -en "\n\b")
73 CAT_LIST=`cat $INDIV_ROOT/src/*/*.py | grep __category__ | awk -F\' '{print tolower($(NF-1))}' | sort -r |uniq -c| awk '{for(i=2;i<=NF;i++)
74printf "%s ",$i;print "" }'`
75 echo -e "\n#Extracted categories from indiv-screenlets\n" >> $1/$1.pot
76 for i in $CAT_LIST
77 do
78 i=`echo $i | sed 's/ *$//g'`
79 l=`echo ${i:0:1} | tr "[:lower:]" "[:upper:]"`
80 echo -e "msgid \"$l${i:1}\"\nmsgstr \"\"\n" >> $1/$1.pot
81 done
82 IFS=$SAVEIFS
83}
84
70po "screenlets"85po "screenlets"
71po "screenlets-manager"86po "screenlets-manager"
87po_categories "screenlets-manager"
7288
7389
7490
=== modified file 'src/lib/utils.py'
--- src/lib/utils.py 2012-03-03 03:55:06 +0000
+++ src/lib/utils.py 2012-03-22 06:31:18 +0000
@@ -301,6 +301,16 @@
301 end = data.find(last, begin)301 end = data.find(last, begin)
302 return data[begin:end]302 return data[begin:end]
303303
304def getCatBetween(data, first, last):
305 x = len(first)
306 f=data.find(first)
307 if f==-1:
308 return 'Miscellaneous'
309 else:
310 begin = f +x
311 end = data.find(last, begin)
312 return data[begin:end]
313
304def get_screenlet_metadata_by_path (path):314def get_screenlet_metadata_by_path (path):
305 """Returns a dict with name, info, author and version of the given315 """Returns a dict with name, info, author and version of the given
306 screenlet. Use with care because it may import the screenlet 316 screenlet. Use with care because it may import the screenlet
@@ -325,14 +335,10 @@
325 author = getBetween(sldata,'__author__','\n')335 author = getBetween(sldata,'__author__','\n')
326 author1 = getBetween(author ,"'","'")336 author1 = getBetween(author ,"'","'")
327 if author1.find(' = ') != -1: author1 = getBetween(author ,chr(34),chr(34))337 if author1.find(' = ') != -1: author1 = getBetween(author ,chr(34),chr(34))
328 category = getBetween(sldata,'__category__','\n')338 category = getCatBetween(sldata,'__category__','\n')
329 category1 = getBetween(category ,"'","'")339 category1 = getCatBetween(category ,"'","'")
330 if category1.find(' = ') != -1: category1 = getBetween(category ,chr(34),chr(34))340 if category1.find(' = ') != -1:
331 try: 341 category1 = getCatBetween(category ,chr(34),chr(34))
332 category1=int(category1)
333 except:
334 category1=10
335
336 version = getBetween(sldata,'__version__','\n')342 version = getBetween(sldata,'__version__','\n')
337 version1 = getBetween(version ,"'","'")343 version1 = getBetween(version ,"'","'")
338 if version1.find(' = ') != -1: version1 = getBetween(version ,chr(34),chr(34))344 if version1.find(' = ') != -1: version1 = getBetween(version ,chr(34),chr(34))
339345
=== modified file 'src/share/screenlets-manager/screenlets-manager.py'
--- src/share/screenlets-manager/screenlets-manager.py 2012-03-03 03:55:06 +0000
+++ src/share/screenlets-manager/screenlets-manager.py 2012-03-22 06:31:18 +0000
@@ -86,24 +86,21 @@
86 86
87 def __init__ (self):87 def __init__ (self):
88 #dict of categories that will be shown in combobox88 #dict of categories that will be shown in combobox
89 self.available_categories = {89 self.available_categories = [_('All categories')]
90 0: _('All'),
91 1: _('Alarms and alerts'),
92 2: _('Date and time'),
93 3: _('Fund and amusements'),
94 4: _('Internet and email'),
95 5: _('News'),
96 6: _('System information'),
97 7: _('Toolbars and launchers'),
98 8: _('Weather'),
99 9: _('Dictionaries and translations'),
100 10: _('Miscellaneous')
101 }
102 90
103 # create ui and populate it91 # create ui and populate it
104 self.create_ui()92 self.create_ui()
105 # populate UI93 # populate UI
106 self.load_screenlets()94 self.load_screenlets()
95
96 tcats = sorted(self.tmp_cats.items(),key=lambda(k,v):(v,k))[::-1]
97 i = 0
98 while (i<min(10,len(tcats)-1)):
99 self.available_categories.append(_(tcats[i][0]))
100 i=i+1
101 for cat in self.available_categories:
102 self.combo1.append_text(cat)
103 self.combo1.set_active(0)
107 # if we are running as root, show error104 # if we are running as root, show error
108 if USER == 0:105 if USER == 0:
109 screenlets.show_error(None, _("""Important! You are running this application as root user, almost all functionality is disabled. You can use this to install screenlets into the system-wide path."""), 106 screenlets.show_error(None, _("""Important! You are running this application as root user, almost all functionality is disabled. You can use this to install screenlets into the system-wide path."""),
@@ -115,10 +112,6 @@
115 self.connect_daemon() 112 self.connect_daemon()
116 113
117 # screenlets stuff114 # screenlets stuff
118
119
120
121
122 115
123 def lookup_daemon (self):116 def lookup_daemon (self):
124 """Find the screenlets-daemon or try to launch it. Initializes 117 """Find the screenlets-daemon or try to launch it. Initializes
@@ -161,9 +154,9 @@
161 """Delete the selected screenlet from the user's screenlet dir."""154 """Delete the selected screenlet from the user's screenlet dir."""
162 sel = self.view.get_selected_items()155 sel = self.view.get_selected_items()
163 if sel and len(sel) > 0 and len(sel[0]) > 0:156 if sel and len(sel) > 0 and len(sel[0]) > 0:
164 it = self.model.get_iter(sel[0][0])157 it = self.model_filter.get_iter(sel[0][0])
165 if it:158 if it:
166 info = self.model.get_value(it, 2)159 info = self.model_filter.get_value(it, 2)
167 if info and not info.system:160 if info and not info.system:
168 # delete the file161 # delete the file
169 if screenlets.show_question(None, _('Do you really want to permanently uninstall and delete the %sScreenlet from your system?') % info.name, _('Delete Screenlet')):162 if screenlets.show_question(None, _('Do you really want to permanently uninstall and delete the %sScreenlet from your system?') % info.name, _('Delete Screenlet')):
@@ -178,8 +171,62 @@
178 screenlets.show_error(None, _('Can\'t delete system-wide screenlets.'))171 screenlets.show_error(None, _('Can\'t delete system-wide screenlets.'))
179 return False172 return False
180 173
174
181 def load_screenlets (self):175 def load_screenlets (self):
182 """Load all available screenlets, create ScreenletInfo-objects for176 """Load all available screenlets, create ScreenletInfo-objects for
177 them and add them into global dictionary used later for filtering."""
178 # fallback icon
179 self.noimg = gtk.gdk.pixbuf_new_from_file_at_size(\
180 screenlets.INSTALL_PREFIX + '/share/screenlets-manager/noimage.svg',
181 56, 56)
182 # get list of available/running screenlets
183 self.loaded_screenlets = {}
184 self.tmp_cats = {}
185 lst_a = utils.list_available_screenlets()
186 lst_a.sort()
187 for s in lst_a:
188 try:
189 img = utils.get_screenlet_icon(s, 56, 56)
190 except Exception, ex:
191 #print "Exception while loading icon '%s': %s" % (path, ex)
192 img = self.noimg
193 # get metadata and create ScreenletInfo-object from it
194 meta = utils.get_screenlet_metadata(s)
195 if meta:
196 # get meta values
197 def setfield(name, default):
198 if meta.has_key(name):
199 if meta[name] != None:
200 return meta[name]
201 else:
202 return default
203 else:
204 return default
205 name = setfield('name', '')
206 info = setfield('info', '')
207 author = setfield('author', '')
208 category= setfield('category', 'Miscellaneous')
209 version = setfield('version', '')
210 #Appends category into dict of categories that counts how much screenlets have defined that category.
211 #It's used later to load top defined categories in category filter combobox
212 if self.tmp_cats.has_key(category):
213 self.tmp_cats[category] += 1
214 else:
215 self.tmp_cats[category] = 1
216
217
218 # get info
219 slinfo = utils.ScreenletInfo(s, name, info, author,category, version, img)
220 else:
221 print 'Error while loading screenlets metadata for "%s".' % s
222 slinfo = utils.ScreenletInfo(s, '','', '','', '', img)
223 #Append screenlet info into global dictionary used later to filter screenlets
224 self.loaded_screenlets[slinfo.name] = slinfo
225 self.model.append(['<span size="9000">%s</span>' % s, img, slinfo])
226
227
228 def load_screenletss (self):
229 """Load all available screenlets, create ScreenletInfo-objects for
183 them and add them to the iconview-model."""230 them and add them to the iconview-model."""
184 # fallback icon231 # fallback icon
185 noimg = gtk.gdk.pixbuf_new_from_file_at_size(\232 noimg = gtk.gdk.pixbuf_new_from_file_at_size(\
@@ -224,7 +271,7 @@
224 name = setfield('name', '')271 name = setfield('name', '')
225 info = setfield('info', '')272 info = setfield('info', '')
226 author = setfield('author', '')273 author = setfield('author', '')
227 category= setfield('category', 10)274 category = setfield('category', 10)
228 version = setfield('version', '')275 version = setfield('version', '')
229 #If found defined category checks if its available, if not put in Miscellaneous276 #If found defined category checks if its available, if not put in Miscellaneous
230 if category in self.available_categories.keys():277 if category in self.available_categories.keys():
@@ -248,7 +295,7 @@
248 # add to model295 # add to model
249 296
250 wshow = True297 wshow = True
251 if self.available_categories.values()[combo_cat_sel]=='All':298 if self.available_categories.values()[combo_cat_sel]=='All categories':
252 wshow = True299 wshow = True
253 elif self.available_categories.values()[combo_cat_sel]==slinfo.category:300 elif self.available_categories.values()[combo_cat_sel]==slinfo.category:
254 wshow = True301 wshow = True
@@ -272,7 +319,7 @@
272 319
273 def get_Info_by_name (self, name):320 def get_Info_by_name (self, name):
274 """Returns a ScreenletInfo-object for the screenlet with given name."""321 """Returns a ScreenletInfo-object for the screenlet with given name."""
275 for row in self.model:322 for row in self.model_filter:
276 if row[2] and row[2].name == name:323 if row[2] and row[2].name == name:
277 return row[2]324 return row[2]
278 return None325 return None
@@ -282,17 +329,17 @@
282 int the IconView."""329 int the IconView."""
283 sel = self.view.get_selected_items()330 sel = self.view.get_selected_items()
284 if sel and len(sel)>0 and len(sel[0])>0:331 if sel and len(sel)>0 and len(sel[0])>0:
285 it = self.model.get_iter(sel[0][0])332 it = self.model_filter.get_iter(sel[0][0])
286 if it:333 if it:
287 return self.model.get_value(it, 2)334 return self.model_filter.get_value(it, 2)
288 return None335 return None
289 336
290 def reset_selected_screenlet(self):337 def reset_selected_screenlet(self):
291 sel = self.view.get_selected_items()338 sel = self.view.get_selected_items()
292 if sel and len(sel) > 0 and len(sel[0]) > 0:339 if sel and len(sel) > 0 and len(sel[0]) > 0:
293 it = self.model.get_iter(sel[0][0])340 it = self.model_filter.get_iter(sel[0][0])
294 if it:341 if it:
295 info = self.model.get_value(it, 2)342 info = self.model_filter.get_value(it, 2)
296 if screenlets.show_question(None, _('Do you really want to reset the %sScreenlet configuration?') % info.name, _('Reset Screenlet')):343 if screenlets.show_question(None, _('Do you really want to reset the %sScreenlet configuration?') % info.name, _('Reset Screenlet')):
297 # delete screenlet's config directory 344 # delete screenlet's config directory
298 os.system('rm -rf %s/%s' % (screenlets.DIR_CONFIG, info.name))345 os.system('rm -rf %s/%s' % (screenlets.DIR_CONFIG, info.name))
@@ -306,7 +353,7 @@
306 353
307 def set_screenlet_active (self, name, active):354 def set_screenlet_active (self, name, active):
308 """Set the screenlet's active-state to active (True/False)."""355 """Set the screenlet's active-state to active (True/False)."""
309 for row in self.model:356 for row in self.model_filter:
310 if row[2].name == name[:-9]:357 if row[2].name == name[:-9]:
311 row[2].active = active358 row[2].active = active
312 # if selected, also toggle checkbox359 # if selected, also toggle checkbox
@@ -314,7 +361,67 @@
314 if sel and sel.name == name[:-9]:361 if sel and sel.name == name[:-9]:
315 self.recreate_infobox(sel)362 self.recreate_infobox(sel)
316 break363 break
317 364 def visible_cb(self, model, iter, data):
365 slinfo = model.get_value(iter,2)
366 if(slinfo != None):
367 #Check if filter box value matches screenlet name
368 if self.filter_input != '':
369 filter_slname = str(slinfo.name).lower()
370 filter_find = filter_slname.find(self.filter_input)
371 if filter_find == -1:
372 return False
373
374 wshow = True
375 #Check if screenlet is currently running
376 if self.combo_type_sel == 1:
377 if self.loaded_screenlets[slinfo.name].active == False:
378 return False
379 elif self.combo_type_sel == 2:
380 if slinfo.autostart != True:
381 return False
382 elif self.combo_type_sel == 3:
383 if slinfo.system != True:
384 return False
385 elif self.combo_type_sel == 4:
386 if slinfo.system != False:
387 return False
388 #Check if category selection matches screenlet category
389 if self.available_categories[self.combo_cat_sel]=='All categories':
390 wshow = True
391 elif self.available_categories[self.combo_cat_sel]==slinfo.category:
392 wshow = True
393 elif (not(slinfo.category in self.available_categories)) and self.available_categories[self.combo_cat_sel]=='Miscellaneous':
394 wshow = True
395 else:
396 wshow = False
397 return wshow
398
399
400
401
402 else:
403 return False
404
405
406
407 def refilter_screenlets(self,widget,id):
408 if id == 'search_clean':
409 self.txtsearch.set_text('')
410 self.filter_input = ''
411 elif id == 'search_changed':
412 self.filter_input = str(self.txtsearch.get_text()).lower()
413 elif id == 'type_changed':
414 self.combo_type_sel = self.combo.get_active()
415 if(self.combo_type_sel == 1):
416 lst_r = utils.list_running_screenlets()
417 if lst_r != None:
418 for item in lst_r:
419 if item[:-9] in self.loaded_screenlets.keys():
420 self.loaded_screenlets[item[:-9]].active=True
421
422 elif id == 'category_changed':
423 self.combo_cat_sel = self.combo1.get_active()
424 self.model_filter.refilter()
318 # ui creation425 # ui creation
319 426
320 def create_ui (self):427 def create_ui (self):
@@ -345,10 +452,11 @@
345 vbox.pack_start(hbox, True, True)452 vbox.pack_start(hbox, True, True)
346 hbox.show()453 hbox.show()
347 # iconview454 # iconview
348 self.model= gtk.ListStore(object)
349 self.view = iv = gtk.IconView()455 self.view = iv = gtk.IconView()
350 self.model = gtk.ListStore(str, gtk.gdk.Pixbuf, object)456 self.model = gtk.ListStore(str, gtk.gdk.Pixbuf, object)
351 iv.set_model(self.model)457 self.model_filter = self.model.filter_new()
458 self.model_filter.set_visible_func(self.visible_cb, None)
459 iv.set_model(self.model_filter)
352 iv.set_markup_column(0)460 iv.set_markup_column(0)
353 iv.set_pixbuf_column(1)461 iv.set_pixbuf_column(1)
354 # disable UI for root user462 # disable UI for root user
@@ -365,7 +473,7 @@
365 iv.connect("drag_data_received", self.drag_data_received)473 iv.connect("drag_data_received", self.drag_data_received)
366 # wrap iconview in scrollwin474 # wrap iconview in scrollwin
367 sw = self.slwindow = gtk.ScrolledWindow()475 sw = self.slwindow = gtk.ScrolledWindow()
368 sw.set_size_request(560, 350)476 sw.set_size_request(560, 380)
369 sw.set_shadow_type(gtk.SHADOW_IN)477 sw.set_shadow_type(gtk.SHADOW_IN)
370 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)478 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
371 sw.add(iv)479 sw.add(iv)
@@ -457,33 +565,39 @@
457 self.label.set_width_chars(70)565 self.label.set_width_chars(70)
458 self.label.set_alignment(0, 0)566 self.label.set_alignment(0, 0)
459 self.label.set_size_request(-1, 65)567 self.label.set_size_request(-1, 65)
568 self.filter_input=''
460 self.btnsearch = gtk.Button()569 self.btnsearch = gtk.Button()
570 self.filterbox = gtk.VBox()
461 self.searchbox = gtk.HBox()571 self.searchbox = gtk.HBox()
462 self.txtsearch = gtk.Entry()572 self.txtsearch = gtk.Entry()
463 self.btnsearch.set_image(gtk.image_new_from_stock(gtk.STOCK_CLOSE, 573 self.btnsearch.set_image(gtk.image_new_from_stock(gtk.STOCK_CLOSE,
464 gtk.ICON_SIZE_BUTTON))574 gtk.ICON_SIZE_BUTTON))
465 self.btnsearch.connect("clicked",self.redraw_screenlets, 'clean')575 self.btnsearch.connect("clicked",self.refilter_screenlets, 'search_clean')
466 self.txtsearch.connect("changed",self.redraw_screenlets, 'enter')576 self.txtsearch.connect("changed",self.refilter_screenlets, 'search_changed')
467 self.txtsearch.connect("backspace",self.redraw_screenlets, 'backspace')577
468578
469 self.searchbox.pack_start(self.txtsearch, 1)579 self.searchbox.pack_start(self.txtsearch, 1)
470 self.searchbox.pack_start(self.btnsearch, False)580 self.searchbox.pack_start(self.btnsearch, False)
471 butbox.pack_start(self.searchbox, False,0,3)581 self.filterbox.pack_start(self.searchbox, False)
582
472 self.combo = gtk.combo_box_new_text()583 self.combo = gtk.combo_box_new_text()
473 self.combo.append_text(_('All Screenlets'))584 self.combo.append_text(_('All Screenlets'))
474 self.combo.append_text(_('Running Screenlets'))585 self.combo.append_text(_('Running Screenlets'))
475 self.combo.append_text(_('Autostart Screenlets'))586 self.combo.append_text(_('Autostart Screenlets'))
476 self.combo.append_text(_('Only native Screenlets'))587 self.combo.append_text(_('Only native Screenlets'))
477 self.combo.append_text(_('Only third party'))588 self.combo.append_text(_('Only third party'))
589 self.combo_type_sel=0
478 self.combo.set_active(0)590 self.combo.set_active(0)
479 self.combo.connect("changed",self.redraw_screenlets, 'enter')591 self.combo.connect("changed",self.refilter_screenlets, 'type_changed')
480 self.combo.show()592 self.combo.show()
481 self.combo1 = gtk.combo_box_new_text()593 self.combo1 = gtk.combo_box_new_text()
482 for cat in self.available_categories.values():594 self.combo_cat_sel=0
483 self.combo1.append_text(_(cat))
484 self.combo1.set_active(0)595 self.combo1.set_active(0)
485 self.combo1.connect("changed",self.redraw_screenlets, 'enter')596 self.combo1.connect("changed",self.refilter_screenlets, 'category_changed')
486 self.combo1.show()597 self.combo1.show()
598 self.filterbox.pack_start(self.combo1, False)
599 self.filterbox.pack_start(self.combo, False)
600 butbox.pack_start(self.filterbox, False,0,3)
487 butbox.pack_start(but1, False)601 butbox.pack_start(but1, False)
488 butbox.pack_start(but2, False)602 butbox.pack_start(but2, False)
489 butbox.pack_start(but3, False)603 butbox.pack_start(but3, False)
@@ -495,8 +609,6 @@
495 #sep2 = gtk.HSeparator()609 #sep2 = gtk.HSeparator()
496 #butbox.pack_start(sep2, False,False,5)610 #butbox.pack_start(sep2, False,False,5)
497 butbox.pack_start(but8, False)611 butbox.pack_start(but8, False)
498 butbox.pack_start(self.combo, False)
499 butbox.pack_start(self.combo1, False)
500 #butbox.pack_start(self.label, False)612 #butbox.pack_start(self.label, False)
501 butbox.show_all()613 butbox.show_all()
502 hbox.pack_start(butbox, False, False, 10)614 hbox.pack_start(butbox, False, False, 10)
@@ -616,10 +728,7 @@
616 self.bbox.pack_start(ibox, False,False)728 self.bbox.pack_start(ibox, False,False)
617729
618 def redraw_screenlets(self,widget,id):730 def redraw_screenlets(self,widget,id):
619 if id == 'backspace':731 if id == 'clean':
620 if len(self.txtsearch.get_text()) == 1:
621 self.txtsearch.set_text('')
622 elif id == 'clean':
623 self.txtsearch.set_text('')732 self.txtsearch.set_text('')
624 else:733 else:
625 self.model.clear()734 self.model.clear()
@@ -936,6 +1045,7 @@
936 os.system('sh '+ DIR_AUTOSTART + s + ' &') 1045 os.system('sh '+ DIR_AUTOSTART + s + ' &')
937 elif id == 'closeall':1046 elif id == 'closeall':
938 utils.quit_all_screenlets()1047 utils.quit_all_screenlets()
1048 self.refilter_screenlets(None,'type_changed')
9391049
940 elif id == 'download':1050 elif id == 'download':
941 if screenlets.UBUNTU:1051 if screenlets.UBUNTU:
@@ -1298,6 +1408,7 @@
1298 widget.set_sensitive(False)1408 widget.set_sensitive(False)
1299 else:1409 else:
1300 utils.delete_autostarter(info.name)1410 utils.delete_autostarter(info.name)
1411 self.refilter_screenlets(None,'None')
13011412
1302 def toggle_tray (self, widget):1413 def toggle_tray (self, widget):
1303 """Callback for handling changes to the tray-CheckButton."""1414 """Callback for handling changes to the tray-CheckButton."""

Subscribers

People subscribed via source and target branches

to status/vote changes: