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