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
1=== modified file 'Makefile'
2--- Makefile 2009-03-15 20:06:25 +0000
3+++ Makefile 2012-03-22 06:31:18 +0000
4@@ -9,7 +9,7 @@
5 #
6
7 VERSION = `cat VERSION`
8-PREFIX = /usr
9+PREFIX = /usr/local
10 INSTALL_LOG = install.log
11
12 .PHONY : docs
13
14=== modified file 'potfiles.sh'
15--- potfiles.sh 2011-08-12 19:41:00 +0000
16+++ potfiles.sh 2012-03-22 06:31:18 +0000
17@@ -14,7 +14,7 @@
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 VERSION=$(cat VERSION)
21-
22+INDIV_ROOT=../indiv-screenlets/
23 function po()
24 {
25 tmpname="/tmp/$(uuidgen).pot"
26@@ -67,7 +67,23 @@
27 fi
28 }
29
30+function po_categories() {
31+ SAVEIFS=$IFS
32+ IFS=$(echo -en "\n\b")
33+ 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++)
34+printf "%s ",$i;print "" }'`
35+ echo -e "\n#Extracted categories from indiv-screenlets\n" >> $1/$1.pot
36+ for i in $CAT_LIST
37+ do
38+ i=`echo $i | sed 's/ *$//g'`
39+ l=`echo ${i:0:1} | tr "[:lower:]" "[:upper:]"`
40+ echo -e "msgid \"$l${i:1}\"\nmsgstr \"\"\n" >> $1/$1.pot
41+ done
42+ IFS=$SAVEIFS
43+}
44+
45 po "screenlets"
46 po "screenlets-manager"
47+po_categories "screenlets-manager"
48
49
50
51=== modified file 'src/lib/utils.py'
52--- src/lib/utils.py 2012-03-03 03:55:06 +0000
53+++ src/lib/utils.py 2012-03-22 06:31:18 +0000
54@@ -301,6 +301,16 @@
55 end = data.find(last, begin)
56 return data[begin:end]
57
58+def getCatBetween(data, first, last):
59+ x = len(first)
60+ f=data.find(first)
61+ if f==-1:
62+ return 'Miscellaneous'
63+ else:
64+ begin = f +x
65+ end = data.find(last, begin)
66+ return data[begin:end]
67+
68 def get_screenlet_metadata_by_path (path):
69 """Returns a dict with name, info, author and version of the given
70 screenlet. Use with care because it may import the screenlet
71@@ -325,14 +335,10 @@
72 author = getBetween(sldata,'__author__','\n')
73 author1 = getBetween(author ,"'","'")
74 if author1.find(' = ') != -1: author1 = getBetween(author ,chr(34),chr(34))
75- category = getBetween(sldata,'__category__','\n')
76- category1 = getBetween(category ,"'","'")
77- if category1.find(' = ') != -1: category1 = getBetween(category ,chr(34),chr(34))
78- try:
79- category1=int(category1)
80- except:
81- category1=10
82-
83+ category = getCatBetween(sldata,'__category__','\n')
84+ category1 = getCatBetween(category ,"'","'")
85+ if category1.find(' = ') != -1:
86+ category1 = getCatBetween(category ,chr(34),chr(34))
87 version = getBetween(sldata,'__version__','\n')
88 version1 = getBetween(version ,"'","'")
89 if version1.find(' = ') != -1: version1 = getBetween(version ,chr(34),chr(34))
90
91=== modified file 'src/share/screenlets-manager/screenlets-manager.py'
92--- src/share/screenlets-manager/screenlets-manager.py 2012-03-03 03:55:06 +0000
93+++ src/share/screenlets-manager/screenlets-manager.py 2012-03-22 06:31:18 +0000
94@@ -86,24 +86,21 @@
95
96 def __init__ (self):
97 #dict of categories that will be shown in combobox
98- self.available_categories = {
99- 0: _('All'),
100- 1: _('Alarms and alerts'),
101- 2: _('Date and time'),
102- 3: _('Fund and amusements'),
103- 4: _('Internet and email'),
104- 5: _('News'),
105- 6: _('System information'),
106- 7: _('Toolbars and launchers'),
107- 8: _('Weather'),
108- 9: _('Dictionaries and translations'),
109- 10: _('Miscellaneous')
110- }
111+ self.available_categories = [_('All categories')]
112
113 # create ui and populate it
114 self.create_ui()
115 # populate UI
116 self.load_screenlets()
117+
118+ tcats = sorted(self.tmp_cats.items(),key=lambda(k,v):(v,k))[::-1]
119+ i = 0
120+ while (i<min(10,len(tcats)-1)):
121+ self.available_categories.append(_(tcats[i][0]))
122+ i=i+1
123+ for cat in self.available_categories:
124+ self.combo1.append_text(cat)
125+ self.combo1.set_active(0)
126 # if we are running as root, show error
127 if USER == 0:
128 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."""),
129@@ -115,10 +112,6 @@
130 self.connect_daemon()
131
132 # screenlets stuff
133-
134-
135-
136-
137
138 def lookup_daemon (self):
139 """Find the screenlets-daemon or try to launch it. Initializes
140@@ -161,9 +154,9 @@
141 """Delete the selected screenlet from the user's screenlet dir."""
142 sel = self.view.get_selected_items()
143 if sel and len(sel) > 0 and len(sel[0]) > 0:
144- it = self.model.get_iter(sel[0][0])
145+ it = self.model_filter.get_iter(sel[0][0])
146 if it:
147- info = self.model.get_value(it, 2)
148+ info = self.model_filter.get_value(it, 2)
149 if info and not info.system:
150 # delete the file
151 if screenlets.show_question(None, _('Do you really want to permanently uninstall and delete the %sScreenlet from your system?') % info.name, _('Delete Screenlet')):
152@@ -178,8 +171,62 @@
153 screenlets.show_error(None, _('Can\'t delete system-wide screenlets.'))
154 return False
155
156+
157 def load_screenlets (self):
158 """Load all available screenlets, create ScreenletInfo-objects for
159+ them and add them into global dictionary used later for filtering."""
160+ # fallback icon
161+ self.noimg = gtk.gdk.pixbuf_new_from_file_at_size(\
162+ screenlets.INSTALL_PREFIX + '/share/screenlets-manager/noimage.svg',
163+ 56, 56)
164+ # get list of available/running screenlets
165+ self.loaded_screenlets = {}
166+ self.tmp_cats = {}
167+ lst_a = utils.list_available_screenlets()
168+ lst_a.sort()
169+ for s in lst_a:
170+ try:
171+ img = utils.get_screenlet_icon(s, 56, 56)
172+ except Exception, ex:
173+ #print "Exception while loading icon '%s': %s" % (path, ex)
174+ img = self.noimg
175+ # get metadata and create ScreenletInfo-object from it
176+ meta = utils.get_screenlet_metadata(s)
177+ if meta:
178+ # get meta values
179+ def setfield(name, default):
180+ if meta.has_key(name):
181+ if meta[name] != None:
182+ return meta[name]
183+ else:
184+ return default
185+ else:
186+ return default
187+ name = setfield('name', '')
188+ info = setfield('info', '')
189+ author = setfield('author', '')
190+ category= setfield('category', 'Miscellaneous')
191+ version = setfield('version', '')
192+ #Appends category into dict of categories that counts how much screenlets have defined that category.
193+ #It's used later to load top defined categories in category filter combobox
194+ if self.tmp_cats.has_key(category):
195+ self.tmp_cats[category] += 1
196+ else:
197+ self.tmp_cats[category] = 1
198+
199+
200+ # get info
201+ slinfo = utils.ScreenletInfo(s, name, info, author,category, version, img)
202+ else:
203+ print 'Error while loading screenlets metadata for "%s".' % s
204+ slinfo = utils.ScreenletInfo(s, '','', '','', '', img)
205+ #Append screenlet info into global dictionary used later to filter screenlets
206+ self.loaded_screenlets[slinfo.name] = slinfo
207+ self.model.append(['<span size="9000">%s</span>' % s, img, slinfo])
208+
209+
210+ def load_screenletss (self):
211+ """Load all available screenlets, create ScreenletInfo-objects for
212 them and add them to the iconview-model."""
213 # fallback icon
214 noimg = gtk.gdk.pixbuf_new_from_file_at_size(\
215@@ -224,7 +271,7 @@
216 name = setfield('name', '')
217 info = setfield('info', '')
218 author = setfield('author', '')
219- category= setfield('category', 10)
220+ category = setfield('category', 10)
221 version = setfield('version', '')
222 #If found defined category checks if its available, if not put in Miscellaneous
223 if category in self.available_categories.keys():
224@@ -248,7 +295,7 @@
225 # add to model
226
227 wshow = True
228- if self.available_categories.values()[combo_cat_sel]=='All':
229+ if self.available_categories.values()[combo_cat_sel]=='All categories':
230 wshow = True
231 elif self.available_categories.values()[combo_cat_sel]==slinfo.category:
232 wshow = True
233@@ -272,7 +319,7 @@
234
235 def get_Info_by_name (self, name):
236 """Returns a ScreenletInfo-object for the screenlet with given name."""
237- for row in self.model:
238+ for row in self.model_filter:
239 if row[2] and row[2].name == name:
240 return row[2]
241 return None
242@@ -282,17 +329,17 @@
243 int the IconView."""
244 sel = self.view.get_selected_items()
245 if sel and len(sel)>0 and len(sel[0])>0:
246- it = self.model.get_iter(sel[0][0])
247+ it = self.model_filter.get_iter(sel[0][0])
248 if it:
249- return self.model.get_value(it, 2)
250+ return self.model_filter.get_value(it, 2)
251 return None
252
253 def reset_selected_screenlet(self):
254 sel = self.view.get_selected_items()
255 if sel and len(sel) > 0 and len(sel[0]) > 0:
256- it = self.model.get_iter(sel[0][0])
257+ it = self.model_filter.get_iter(sel[0][0])
258 if it:
259- info = self.model.get_value(it, 2)
260+ info = self.model_filter.get_value(it, 2)
261 if screenlets.show_question(None, _('Do you really want to reset the %sScreenlet configuration?') % info.name, _('Reset Screenlet')):
262 # delete screenlet's config directory
263 os.system('rm -rf %s/%s' % (screenlets.DIR_CONFIG, info.name))
264@@ -306,7 +353,7 @@
265
266 def set_screenlet_active (self, name, active):
267 """Set the screenlet's active-state to active (True/False)."""
268- for row in self.model:
269+ for row in self.model_filter:
270 if row[2].name == name[:-9]:
271 row[2].active = active
272 # if selected, also toggle checkbox
273@@ -314,7 +361,67 @@
274 if sel and sel.name == name[:-9]:
275 self.recreate_infobox(sel)
276 break
277-
278+ def visible_cb(self, model, iter, data):
279+ slinfo = model.get_value(iter,2)
280+ if(slinfo != None):
281+ #Check if filter box value matches screenlet name
282+ if self.filter_input != '':
283+ filter_slname = str(slinfo.name).lower()
284+ filter_find = filter_slname.find(self.filter_input)
285+ if filter_find == -1:
286+ return False
287+
288+ wshow = True
289+ #Check if screenlet is currently running
290+ if self.combo_type_sel == 1:
291+ if self.loaded_screenlets[slinfo.name].active == False:
292+ return False
293+ elif self.combo_type_sel == 2:
294+ if slinfo.autostart != True:
295+ return False
296+ elif self.combo_type_sel == 3:
297+ if slinfo.system != True:
298+ return False
299+ elif self.combo_type_sel == 4:
300+ if slinfo.system != False:
301+ return False
302+ #Check if category selection matches screenlet category
303+ if self.available_categories[self.combo_cat_sel]=='All categories':
304+ wshow = True
305+ elif self.available_categories[self.combo_cat_sel]==slinfo.category:
306+ wshow = True
307+ elif (not(slinfo.category in self.available_categories)) and self.available_categories[self.combo_cat_sel]=='Miscellaneous':
308+ wshow = True
309+ else:
310+ wshow = False
311+ return wshow
312+
313+
314+
315+
316+ else:
317+ return False
318+
319+
320+
321+ def refilter_screenlets(self,widget,id):
322+ if id == 'search_clean':
323+ self.txtsearch.set_text('')
324+ self.filter_input = ''
325+ elif id == 'search_changed':
326+ self.filter_input = str(self.txtsearch.get_text()).lower()
327+ elif id == 'type_changed':
328+ self.combo_type_sel = self.combo.get_active()
329+ if(self.combo_type_sel == 1):
330+ lst_r = utils.list_running_screenlets()
331+ if lst_r != None:
332+ for item in lst_r:
333+ if item[:-9] in self.loaded_screenlets.keys():
334+ self.loaded_screenlets[item[:-9]].active=True
335+
336+ elif id == 'category_changed':
337+ self.combo_cat_sel = self.combo1.get_active()
338+ self.model_filter.refilter()
339 # ui creation
340
341 def create_ui (self):
342@@ -345,10 +452,11 @@
343 vbox.pack_start(hbox, True, True)
344 hbox.show()
345 # iconview
346- self.model= gtk.ListStore(object)
347 self.view = iv = gtk.IconView()
348 self.model = gtk.ListStore(str, gtk.gdk.Pixbuf, object)
349- iv.set_model(self.model)
350+ self.model_filter = self.model.filter_new()
351+ self.model_filter.set_visible_func(self.visible_cb, None)
352+ iv.set_model(self.model_filter)
353 iv.set_markup_column(0)
354 iv.set_pixbuf_column(1)
355 # disable UI for root user
356@@ -365,7 +473,7 @@
357 iv.connect("drag_data_received", self.drag_data_received)
358 # wrap iconview in scrollwin
359 sw = self.slwindow = gtk.ScrolledWindow()
360- sw.set_size_request(560, 350)
361+ sw.set_size_request(560, 380)
362 sw.set_shadow_type(gtk.SHADOW_IN)
363 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
364 sw.add(iv)
365@@ -457,33 +565,39 @@
366 self.label.set_width_chars(70)
367 self.label.set_alignment(0, 0)
368 self.label.set_size_request(-1, 65)
369+ self.filter_input=''
370 self.btnsearch = gtk.Button()
371+ self.filterbox = gtk.VBox()
372 self.searchbox = gtk.HBox()
373 self.txtsearch = gtk.Entry()
374 self.btnsearch.set_image(gtk.image_new_from_stock(gtk.STOCK_CLOSE,
375 gtk.ICON_SIZE_BUTTON))
376- self.btnsearch.connect("clicked",self.redraw_screenlets, 'clean')
377- self.txtsearch.connect("changed",self.redraw_screenlets, 'enter')
378- self.txtsearch.connect("backspace",self.redraw_screenlets, 'backspace')
379+ self.btnsearch.connect("clicked",self.refilter_screenlets, 'search_clean')
380+ self.txtsearch.connect("changed",self.refilter_screenlets, 'search_changed')
381+
382
383 self.searchbox.pack_start(self.txtsearch, 1)
384 self.searchbox.pack_start(self.btnsearch, False)
385- butbox.pack_start(self.searchbox, False,0,3)
386+ self.filterbox.pack_start(self.searchbox, False)
387+
388 self.combo = gtk.combo_box_new_text()
389 self.combo.append_text(_('All Screenlets'))
390 self.combo.append_text(_('Running Screenlets'))
391 self.combo.append_text(_('Autostart Screenlets'))
392 self.combo.append_text(_('Only native Screenlets'))
393 self.combo.append_text(_('Only third party'))
394+ self.combo_type_sel=0
395 self.combo.set_active(0)
396- self.combo.connect("changed",self.redraw_screenlets, 'enter')
397+ self.combo.connect("changed",self.refilter_screenlets, 'type_changed')
398 self.combo.show()
399 self.combo1 = gtk.combo_box_new_text()
400- for cat in self.available_categories.values():
401- self.combo1.append_text(_(cat))
402+ self.combo_cat_sel=0
403 self.combo1.set_active(0)
404- self.combo1.connect("changed",self.redraw_screenlets, 'enter')
405+ self.combo1.connect("changed",self.refilter_screenlets, 'category_changed')
406 self.combo1.show()
407+ self.filterbox.pack_start(self.combo1, False)
408+ self.filterbox.pack_start(self.combo, False)
409+ butbox.pack_start(self.filterbox, False,0,3)
410 butbox.pack_start(but1, False)
411 butbox.pack_start(but2, False)
412 butbox.pack_start(but3, False)
413@@ -495,8 +609,6 @@
414 #sep2 = gtk.HSeparator()
415 #butbox.pack_start(sep2, False,False,5)
416 butbox.pack_start(but8, False)
417- butbox.pack_start(self.combo, False)
418- butbox.pack_start(self.combo1, False)
419 #butbox.pack_start(self.label, False)
420 butbox.show_all()
421 hbox.pack_start(butbox, False, False, 10)
422@@ -616,10 +728,7 @@
423 self.bbox.pack_start(ibox, False,False)
424
425 def redraw_screenlets(self,widget,id):
426- if id == 'backspace':
427- if len(self.txtsearch.get_text()) == 1:
428- self.txtsearch.set_text('')
429- elif id == 'clean':
430+ if id == 'clean':
431 self.txtsearch.set_text('')
432 else:
433 self.model.clear()
434@@ -936,6 +1045,7 @@
435 os.system('sh '+ DIR_AUTOSTART + s + ' &')
436 elif id == 'closeall':
437 utils.quit_all_screenlets()
438+ self.refilter_screenlets(None,'type_changed')
439
440 elif id == 'download':
441 if screenlets.UBUNTU:
442@@ -1298,6 +1408,7 @@
443 widget.set_sensitive(False)
444 else:
445 utils.delete_autostarter(info.name)
446+ self.refilter_screenlets(None,'None')
447
448 def toggle_tray (self, widget):
449 """Callback for handling changes to the tray-CheckButton."""

Subscribers

People subscribed via source and target branches

to status/vote changes: