1 | import gi |
---|
2 | gi.require_version('Gtk', '3.0') |
---|
3 | |
---|
4 | from gi.repository import Gtk,GdkPixbuf,Gdk |
---|
5 | |
---|
6 | import Core |
---|
7 | |
---|
8 | import gettext |
---|
9 | gettext.textdomain('lliurex-store') |
---|
10 | _ = gettext.gettext |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | class PopupMenu(Gtk.EventBox): |
---|
15 | |
---|
16 | def __init__(self): |
---|
17 | |
---|
18 | |
---|
19 | self.core=Core.Core.get_core() |
---|
20 | ui_path=self.core.ui_path |
---|
21 | |
---|
22 | popup_menu_x=400 |
---|
23 | popup_menu_y=765 |
---|
24 | percentage=0.8 |
---|
25 | shadow_size=50 |
---|
26 | |
---|
27 | Gtk.EventBox.__init__(self) |
---|
28 | self.set_valign(Gtk.Align.START) |
---|
29 | self.set_halign(Gtk.Align.START) |
---|
30 | |
---|
31 | builder=Gtk.Builder() |
---|
32 | builder.set_translation_domain('lliurex-store') |
---|
33 | builder.add_from_file(ui_path) |
---|
34 | |
---|
35 | |
---|
36 | self.revealer=Gtk.Revealer() |
---|
37 | self.revealer.set_transition_type(Gtk.RevealerTransitionType.SLIDE_LEFT) |
---|
38 | self.revealer.set_transition_duration(500) |
---|
39 | |
---|
40 | self.popup_image=builder.get_object("popup_image") |
---|
41 | self.popup_menu=builder.get_object("popup_box") |
---|
42 | self.popup_menu_left=builder.get_object("popup_box_left") |
---|
43 | self.popup_shadow=builder.get_object("popup_box_right") |
---|
44 | decorator_bar=builder.get_object("decoration_bar_box") |
---|
45 | |
---|
46 | eventbox=builder.get_object("eventbox1") |
---|
47 | eventbox.add_events(Gdk.EventMask.BUTTON_PRESS_MASK) |
---|
48 | eventbox.connect("button-press-event",self.hide_revealer) |
---|
49 | |
---|
50 | image=Gtk.Image.new_from_file(self.core.rsrc_dir+"lliurex-default-background.png") |
---|
51 | pixbuf=image.get_pixbuf() |
---|
52 | original_ratio=pixbuf.get_width(),pixbuf.get_height() |
---|
53 | pixbuf=pixbuf.scale_simple(400*percentage,225*percentage,GdkPixbuf.InterpType.BILINEAR) |
---|
54 | self.popup_image.set_from_pixbuf(pixbuf) |
---|
55 | |
---|
56 | self.revealer.add(self.popup_menu) |
---|
57 | self.add(self.revealer) |
---|
58 | |
---|
59 | |
---|
60 | self.popup_menu.set_name("TRANSPARENT") |
---|
61 | self.popup_shadow.set_name("POPUP_SHADOW_LEFTRIGHT") |
---|
62 | self.revealer.set_name("TRANSPARENT") |
---|
63 | self.popup_menu_left.set_name("DROPMENU") |
---|
64 | decorator_bar.set_name("DECORATOR_BAR") |
---|
65 | |
---|
66 | self.populate_menu() |
---|
67 | |
---|
68 | #def init |
---|
69 | |
---|
70 | def populate_menu(self): |
---|
71 | |
---|
72 | #for item in self.popup_menu_left.get_children(): |
---|
73 | # self.popup_menu_left.remove(item) |
---|
74 | |
---|
75 | |
---|
76 | b=Gtk.Button() |
---|
77 | hbox=Gtk.HBox() |
---|
78 | |
---|
79 | b.icon=self.core.rsrc_dir+"icons/small_icons/home.svg" |
---|
80 | b.icon_over=self.core.rsrc_dir+"icons/small_icons/home_white.svg" |
---|
81 | txt=_("Home") |
---|
82 | |
---|
83 | b.img=Gtk.Image.new_from_file(b.icon) |
---|
84 | b.img.set_margin_left(5) |
---|
85 | b.label=Gtk.Label(txt) |
---|
86 | b.label.set_halign(Gtk.Align.START) |
---|
87 | |
---|
88 | hbox.pack_start(b.img,False,False,0) |
---|
89 | hbox.pack_start(b.label,False,False,20) |
---|
90 | b.add(hbox) |
---|
91 | |
---|
92 | b.add_events( Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK ) |
---|
93 | b.connect("motion-notify-event",self.mouse_over) |
---|
94 | b.connect("leave_notify_event",self.mouse_left) |
---|
95 | b.connect("clicked",self.go_home) |
---|
96 | |
---|
97 | b.show_all() |
---|
98 | b.set_name("SECTION_BOX") |
---|
99 | self.popup_menu_left.pack_start(b,True,True,0) |
---|
100 | |
---|
101 | |
---|
102 | b=Gtk.Button() |
---|
103 | hbox=Gtk.HBox() |
---|
104 | |
---|
105 | b.icon=self.core.rsrc_dir+"icons/small_icons/favorite.svg" |
---|
106 | b.icon_over=self.core.rsrc_dir+"icons/small_icons/favorite_white.svg" |
---|
107 | txt=_("My applications") |
---|
108 | |
---|
109 | b.img=Gtk.Image.new_from_file(b.icon) |
---|
110 | b.img.set_margin_left(5) |
---|
111 | b.label=Gtk.Label(txt) |
---|
112 | b.label.set_halign(Gtk.Align.START) |
---|
113 | |
---|
114 | hbox.pack_start(b.img,False,False,0) |
---|
115 | hbox.pack_start(b.label,False,False,20) |
---|
116 | b.add(hbox) |
---|
117 | |
---|
118 | b.add_events( Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK ) |
---|
119 | b.connect("motion-notify-event",self.mouse_over) |
---|
120 | b.connect("leave_notify_event",self.mouse_left) |
---|
121 | b.connect("clicked",self.get_installed_list) |
---|
122 | |
---|
123 | b.show_all() |
---|
124 | b.set_name("SECTION_BOX") |
---|
125 | self.popup_menu_left.pack_start(b,False,False,0) |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | separator=Gtk.Separator() |
---|
131 | separator.set_name("SECTION_DIVIDER") |
---|
132 | self.popup_menu_left.pack_start(separator,False,False,0) |
---|
133 | |
---|
134 | |
---|
135 | for item in sorted(self.core.categories_manager.categories): |
---|
136 | |
---|
137 | #self.categories["audio"]["name"]="Audio" |
---|
138 | #self.categories["audio"]["icon"]="audio.svg" |
---|
139 | #self.categories["audio"]["icon_over"]="audio_white.svg" |
---|
140 | |
---|
141 | |
---|
142 | b=Gtk.Button() |
---|
143 | hbox=Gtk.HBox() |
---|
144 | |
---|
145 | b.icon=self.core.categories_manager.categories[item]["small_icon"] |
---|
146 | b.icon_over=self.core.categories_manager.categories[item]["small_icon_over"] |
---|
147 | txt=_(item) |
---|
148 | |
---|
149 | b.img=Gtk.Image.new_from_file(b.icon) |
---|
150 | b.img.set_margin_left(5) |
---|
151 | b.label=Gtk.Label(txt) |
---|
152 | b.label.set_halign(Gtk.Align.START) |
---|
153 | |
---|
154 | hbox.pack_start(b.img,False,False,0) |
---|
155 | hbox.pack_start(b.label,False,False,20) |
---|
156 | b.add(hbox) |
---|
157 | |
---|
158 | b.add_events( Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK ) |
---|
159 | b.connect("motion-notify-event",self.mouse_over) |
---|
160 | b.connect("leave_notify_event",self.mouse_left) |
---|
161 | |
---|
162 | b.show_all() |
---|
163 | b.set_name("SECTION_BOX") |
---|
164 | |
---|
165 | b.connect("clicked",self.category_clicked,item) |
---|
166 | |
---|
167 | self.popup_menu_left.pack_start(b,True,True,0) |
---|
168 | |
---|
169 | |
---|
170 | def mouse_over(self,widget,event): |
---|
171 | |
---|
172 | widget.img.set_from_file(widget.icon_over) |
---|
173 | |
---|
174 | #widget.get_children()[0].get_children()[0].set_from_file("favorite_white.svg") |
---|
175 | |
---|
176 | #def mouse_over |
---|
177 | |
---|
178 | def mouse_left(self,widget,event): |
---|
179 | |
---|
180 | widget.img.set_from_file(widget.icon) |
---|
181 | |
---|
182 | #widget.get_children()[0].get_children()[0].set_from_file("favorite.svg") |
---|
183 | |
---|
184 | #def mouse_left |
---|
185 | |
---|
186 | def hide_revealer(self,widget,event): |
---|
187 | |
---|
188 | self.core.main_window.main_eb_clicked(None,None) |
---|
189 | |
---|
190 | #def hide_revealer |
---|
191 | |
---|
192 | |
---|
193 | def category_clicked(self,widget,category): |
---|
194 | |
---|
195 | |
---|
196 | self.core.main_window.main_eb_clicked(None,None) |
---|
197 | self.core.main_menu.category_clicked(None,category) |
---|
198 | |
---|
199 | #def category_clicked |
---|
200 | |
---|
201 | def get_installed_list(self,widget): |
---|
202 | |
---|
203 | self.core.main_window.main_eb_clicked(None,None) |
---|
204 | self.core.main_window.get_installed_list() |
---|
205 | |
---|
206 | #def get_installed_list |
---|
207 | |
---|
208 | def go_home(self,widget): |
---|
209 | |
---|
210 | |
---|
211 | self.core.main_window.show_home() |
---|
212 | # Forcing main_eb_clicked call to hide both popup menu and fade_box |
---|
213 | self.core.main_window.main_eb_clicked(None,None) |
---|
214 | self.core.main_window.stack.set_transition_type(Gtk.RevealerTransitionType.CROSSFADE) |
---|
215 | |
---|
216 | #def go_home |
---|
217 | |
---|
218 | #class PopupMenu |
---|