|
1
by Oliver Grawert
initial code |
1 |
#!/usr/bin/python
|
2 |
# -*- encoding: utf-8 -*-
|
|
3 |
||
4 |
import gobject |
|
5 |
import gtk |
|
6 |
import xdg.Menu |
|
7 |
import xdg.Locale |
|
8 |
import xdg.IconTheme |
|
9 |
from xdg.DesktopEntry import * |
|
|
2
by Oliver Grawert
added doubleclick detection, adjusted for finger input atm |
10 |
import time |
|
1
by Oliver Grawert
initial code |
11 |
|
12 |
menufiles = ['applications.menu', 'settings.menu'] |
|
13 |
||
14 |
window=gtk.Window() |
|
15 |
window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP) |
|
16 |
rootwin = gtk.gdk.get_default_root_window() |
|
17 |
||
18 |
window.connect('destroy', gtk.main_quit) |
|
19 |
||
20 |
vbox=gtk.VBox(False,1) |
|
21 |
scrolled_win = gtk.ScrolledWindow() |
|
22 |
evbx = gtk.EventBox() |
|
23 |
||
|
2
by Oliver Grawert
added doubleclick detection, adjusted for finger input atm |
24 |
constant=0 |
25 |
stamp=time.time() |
|
26 |
oldx=0.0 |
|
27 |
oldy=0.0 |
|
28 |
click_tolerance=15.0 # radius a click can take (used for doubleclick detection) |
|
29 |
dblclick_delay=0.2 # how many seconds between two clicks are needed (takes float value) |
|
|
1
by Oliver Grawert
initial code |
30 |
|
31 |
def parse_menu (menu): |
|
32 |
for entry in menu.getEntries(hidden=False): |
|
33 |
if isinstance(entry, xdg.Menu.Menu): |
|
34 |
||
35 |
hbox=gtk.HBox() |
|
36 |
label = gtk.Label() |
|
37 |
image = gtk.Image() |
|
|
3
by Oliver Grawert
improve icon handling |
38 |
theme = gtk.icon_theme_get_default() |
|
1
by Oliver Grawert
initial code |
39 |
|
40 |
name = entry.getName().replace('&', '&') |
|
41 |
label.set_markup('<span font_desc="Sans Bold 14">'+name+'</span>') |
|
42 |
label.set_alignment(0.0, 0.5) |
|
43 |
||
|
3
by Oliver Grawert
improve icon handling |
44 |
pixbuf = theme.load_icon(entry.getIcon(), gtk.ICON_SIZE_DIALOG, gtk.ICON_LOOKUP_FORCE_SVG) |
|
1
by Oliver Grawert
initial code |
45 |
image.set_from_pixbuf(pixbuf) |
46 |
||
47 |
hbox.pack_start(image,False,False,5) |
|
48 |
hbox.pack_start(label,False,False,5) |
|
49 |
||
50 |
iconview = gtk.IconView() |
|
51 |
model = gtk.ListStore(str, gtk.gdk.Pixbuf, str) |
|
52 |
||
53 |
iconview.set_model(model) |
|
54 |
iconview.set_text_column(0) |
|
55 |
iconview.set_pixbuf_column(1) |
|
56 |
iconview.set_selection_mode(gtk.SELECTION_SINGLE) |
|
|
3
by Oliver Grawert
improve icon handling |
57 |
#iconview.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse('#6b6158'))
|
58 |
iconview.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse('#2e1b0c')) |
|
|
1
by Oliver Grawert
initial code |
59 |
iconview.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ffffff')) |
60 |
#iconview.connect('item-activated', on_select, model)
|
|
61 |
iconview.set_item_width(180) |
|
62 |
||
63 |
for item in entry.getEntries(): |
|
64 |
desktop = DesktopEntry(item.DesktopEntry.getFileName()) |
|
|
3
by Oliver Grawert
improve icon handling |
65 |
try: |
66 |
pixbuf = theme.load_icon(desktop.getIcon(), 64, gtk.ICON_LOOKUP_FORCE_SVG) |
|
67 |
except: |
|
68 |
iconpath = xdg.IconTheme.getIconPath(desktop.getIcon(), gtk.ICON_SIZE_BUTTON, 'Human', ["png", "xpm"]) |
|
69 |
if iconpath: |
|
70 |
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(iconpath, 64, 64) |
|
|
1
by Oliver Grawert
initial code |
71 |
appname = str(desktop) |
72 |
model.append([appname, pixbuf, item.DesktopEntry.getFileName()]) |
|
73 |
||
74 |
vbox.pack_start(hbox,False,False,5) |
|
75 |
vbox.pack_start(iconview,False,False,0) |
|
76 |
else: |
|
77 |
pass
|
|
78 |
||
79 |
for entry in menu.getEntries(): |
|
80 |
if isinstance(entry, xdg.Menu.Menu): |
|
81 |
parse_menu(entry) |
|
82 |
||
83 |
def scroll_func(widget, event): |
|
84 |
global constant |
|
85 |
||
86 |
adj = scrolled_win.get_vadjustment() |
|
87 |
old = adj.get_value() |
|
88 |
||
89 |
if event.y > constant+5 or event.y < constant-5: |
|
90 |
if event.y > constant: |
|
91 |
val = old-15.0 |
|
92 |
else: |
|
93 |
val = old+15.0 |
|
94 |
||
95 |
if val >= 3050: |
|
96 |
val = 3050 |
|
97 |
||
98 |
if val <= 10: |
|
99 |
val = 0 |
|
100 |
adj.set_value(val) |
|
101 |
||
102 |
while gtk.events_pending(): |
|
103 |
gtk.main_iteration(True) |
|
104 |
||
105 |
scrolled_win.set_vadjustment(adj) |
|
106 |
||
107 |
constant=event.y |
|
108 |
||
109 |
def pressure_cursor(widget, event): |
|
|
2
by Oliver Grawert
added doubleclick detection, adjusted for finger input atm |
110 |
global stamp |
111 |
global oldx |
|
112 |
global oldy |
|
|
1
by Oliver Grawert
initial code |
113 |
window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.DOT)) |
|
2
by Oliver Grawert
added doubleclick detection, adjusted for finger input atm |
114 |
current = time.time() |
115 |
diff = current-stamp |
|
116 |
diffx = oldx-event.x |
|
117 |
diffy = oldy-event.y |
|
118 |
if diff <= dblclick_delay: |
|
119 |
if (diffx < click_tolerance and diffx > -click_tolerance) and (diffy < click_tolerance and diffy > -click_tolerance): |
|
120 |
print "dblclick at: ",event.x,event.y |
|
121 |
oldx = event.x |
|
122 |
oldy = event.y |
|
123 |
stamp = time.time() |
|
|
1
by Oliver Grawert
initial code |
124 |
|
125 |
def release(widget, event): |
|
126 |
pixmap = gtk.gdk.Pixmap(None, 1, 1, 1) |
|
127 |
color = gtk.gdk.Color() |
|
128 |
cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 0, 0) |
|
129 |
window.window.set_cursor(cursor) |
|
130 |
||
131 |
for menufile in menufiles: |
|
132 |
mydir = os.path.join(xdg_config_home+'/menus/'+menufile) |
|
133 |
||
134 |
if not os.path.exists(mydir): |
|
135 |
mydir = os.path.join(xdg_config_dirs[1]+'/menus/'+menufile) |
|
136 |
||
137 |
parse_menu(xdg.Menu.parse(mydir)) |
|
138 |
||
139 |
scrolled_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER) |
|
140 |
scrolled_win.add_with_viewport(vbox) |
|
141 |
||
142 |
evbx.add(scrolled_win) |
|
143 |
evbx.set_above_child(True) |
|
144 |
evbx.connect('motion-notify-event', scroll_func) |
|
145 |
evbx.connect('button-release-event', release) |
|
146 |
evbx.connect('button-press-event', pressure_cursor) |
|
147 |
||
148 |
window.add(evbx) |
|
149 |
window.set_size_request(800, 430) |
|
150 |
window.move(0, 50) |
|
151 |
window.show_all() |
|
152 |
||
153 |
gtk.main() |