1 | import gi |
---|
2 | gi.require_version('Gtk', '3.0') |
---|
3 | |
---|
4 | from gi.repository import Gtk, Pango, GdkPixbuf, Gdk, Gio, GObject,GLib |
---|
5 | |
---|
6 | import signal |
---|
7 | signal.signal(signal.SIGINT, signal.SIG_DFL) |
---|
8 | |
---|
9 | import gettext |
---|
10 | import urllib.request as urllib2 |
---|
11 | import shutil |
---|
12 | import json |
---|
13 | import random |
---|
14 | |
---|
15 | import Core |
---|
16 | import Screenshot |
---|
17 | import ImageManager |
---|
18 | import Package |
---|
19 | |
---|
20 | _=gettext.gettext |
---|
21 | |
---|
22 | RSRC_DIR="./" |
---|
23 | |
---|
24 | HOME_CONTENT_URL="http://svn.lliurex.net/xenial/lliurex-store/trunk/fuentes/lliurex-store-gui/home_content.json" |
---|
25 | HOME_CONTENT_URL="file:///srv/svn/xenial/lliurex-store/trunk/fuentes/lliurex-store-gui/home_content.json" |
---|
26 | TMP_STORE_DIR="/tmp/.lliurex-store/" |
---|
27 | |
---|
28 | class MainMenu(Gtk.VBox): |
---|
29 | |
---|
30 | def __init__(self): |
---|
31 | |
---|
32 | Gtk.VBox.__init__(self) |
---|
33 | |
---|
34 | self.paused=False |
---|
35 | self.max_image_id=5 |
---|
36 | |
---|
37 | self.banner_large_x=735 |
---|
38 | self.banner_large_y=180 |
---|
39 | self.banner_small=134 |
---|
40 | |
---|
41 | self.core=Core.Core.get_core() |
---|
42 | |
---|
43 | ui_path=self.core.ui_path |
---|
44 | |
---|
45 | builder=Gtk.Builder() |
---|
46 | builder.add_from_file(ui_path) |
---|
47 | |
---|
48 | |
---|
49 | self.main_view_box=builder.get_object("main_view_box") |
---|
50 | self.divider1=builder.get_object("mv_divider1") |
---|
51 | self.divider2=builder.get_object("mv_divider2") |
---|
52 | self.divider3=builder.get_object("mv_divider3") |
---|
53 | self.featured_label=builder.get_object("featured_label") |
---|
54 | self.categories_label=builder.get_object("categories_label") |
---|
55 | self.featured_extra_box=builder.get_object("featured_extra_box") |
---|
56 | self.rewind_button=builder.get_object("media_rewind_button") |
---|
57 | self.play_button=builder.get_object("media_play_button") |
---|
58 | self.forward_button=builder.get_object("media_forward_button") |
---|
59 | self.media_play_image=builder.get_object("media_play_image") |
---|
60 | self.categories_grid=builder.get_object("categories_grid") |
---|
61 | |
---|
62 | self.image_stack=Gtk.Stack() |
---|
63 | self.image_stack.set_transition_duration(800) |
---|
64 | self.image_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT) |
---|
65 | self.image_stack.set_margin_right(10) |
---|
66 | self.image_stack.set_margin_left(10) |
---|
67 | self.image_stack.set_size_request(self.banner_large_x,self.banner_large_y) |
---|
68 | self.image_stack.set_halign(Gtk.Align.CENTER) |
---|
69 | |
---|
70 | self.main_view_box.pack_start(self.image_stack,False,False,10) |
---|
71 | self.main_view_box.reorder_child(self.image_stack,2) |
---|
72 | |
---|
73 | ''' |
---|
74 | self.categories_flowbox = Gtk.FlowBox() |
---|
75 | self.categories_flowbox.set_max_children_per_line(30) |
---|
76 | self.categories_flowbox.set_column_spacing(0) |
---|
77 | self.categories_flowbox.set_row_spacing(0) |
---|
78 | self.categories_flowbox.set_margin_left(10) |
---|
79 | self.categories_flowbox.set_margin_right(10) |
---|
80 | self.categories_flowbox.set_halign(Gtk.Align.FILL) |
---|
81 | |
---|
82 | self.main_view_box.pack_start(self.categories_flowbox,False,False,10) |
---|
83 | ''' |
---|
84 | |
---|
85 | self.pack_start(self.main_view_box,True,True,0) |
---|
86 | |
---|
87 | self.rewind_button.connect("clicked",self.rewind_clicked) |
---|
88 | self.play_button.connect("clicked",self.play_clicked) |
---|
89 | self.forward_button.connect("clicked",self.forward_clicked) |
---|
90 | |
---|
91 | self.build_categories() |
---|
92 | self.set_css_names() |
---|
93 | |
---|
94 | GLib.timeout_add(3000,self.next_image) |
---|
95 | |
---|
96 | #def __init__ |
---|
97 | |
---|
98 | def download_home_info(self): |
---|
99 | |
---|
100 | #HOME_CONTENT_URL |
---|
101 | |
---|
102 | header = { |
---|
103 | 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11' |
---|
104 | } |
---|
105 | |
---|
106 | try: |
---|
107 | |
---|
108 | self.core.dprint("Downloading home_content.json...") |
---|
109 | |
---|
110 | |
---|
111 | req=urllib2.Request(HOME_CONTENT_URL,headers=header) |
---|
112 | res=urllib2.urlopen(req) |
---|
113 | |
---|
114 | f=open(TMP_STORE_DIR+"home_content.json","w") |
---|
115 | f.write(res.read().decode("utf-8")) |
---|
116 | f.close() |
---|
117 | |
---|
118 | |
---|
119 | f=open(TMP_STORE_DIR+"home_content.json") |
---|
120 | self.home_info=json.load(f) |
---|
121 | |
---|
122 | ''' |
---|
123 | for pkg in self.home_info["large"]: |
---|
124 | data=self.core.store.search_package(pkg["package"]) |
---|
125 | if len(data)>0: |
---|
126 | data=data[0] |
---|
127 | for key in data: |
---|
128 | pkg[key]=data[key] |
---|
129 | |
---|
130 | for pkg in self.home_info["small"]: |
---|
131 | data=self.core.store.search_package(pkg["package"]) |
---|
132 | if len(data)>0: |
---|
133 | data=data[0] |
---|
134 | for key in data: |
---|
135 | pkg[key]=data[key] |
---|
136 | ''' |
---|
137 | |
---|
138 | f.close() |
---|
139 | |
---|
140 | except Exception as e: |
---|
141 | |
---|
142 | print(e) |
---|
143 | |
---|
144 | |
---|
145 | #def download_home_info |
---|
146 | |
---|
147 | def build_banners(self): |
---|
148 | |
---|
149 | # Main banners |
---|
150 | |
---|
151 | spacing=5 |
---|
152 | count=1 |
---|
153 | |
---|
154 | for pkg in self.home_info["large"]: |
---|
155 | s=Screenshot.ScreenshotNeo() |
---|
156 | info={} |
---|
157 | info["image_url"]=pkg["banner_large"] |
---|
158 | info["image_id"]=pkg["package"]+"_banner_large" |
---|
159 | info["x"]=self.banner_large_x |
---|
160 | info["y"]=self.banner_large_y |
---|
161 | info["aspect_ratio"]=True |
---|
162 | info["name"]=pkg["name"] |
---|
163 | info["package"]=pkg["package"] |
---|
164 | s.download_image(info) |
---|
165 | s.set_size_request(self.banner_large_x,self.banner_large_y) |
---|
166 | b=Gtk.Button() |
---|
167 | b.set_name("RELATED_BUTTON") |
---|
168 | b.add(s) |
---|
169 | b.show_all() |
---|
170 | b.set_size_request(self.banner_large_x,self.banner_large_y) |
---|
171 | b.connect("clicked",self.banner_clicked,pkg) |
---|
172 | self.image_stack.add_titled(b,"image%s"%count,"Image %s"%count) |
---|
173 | count+=1 |
---|
174 | |
---|
175 | |
---|
176 | # Smaller banners |
---|
177 | |
---|
178 | |
---|
179 | banner_range=range(0,len(self.home_info["small"])) |
---|
180 | sample=random.sample(banner_range,5) |
---|
181 | |
---|
182 | for b_id in banner_range: |
---|
183 | |
---|
184 | pkg=self.home_info["small"][b_id] |
---|
185 | s=Screenshot.ScreenshotNeo() |
---|
186 | info={} |
---|
187 | if pkg["banner_small"]!=None: |
---|
188 | info["image_url"]=pkg["banner_small"] |
---|
189 | info["aspect_ratio"]=False |
---|
190 | else: |
---|
191 | info["image_path"]=self.core.resources.get_icon(pkg) |
---|
192 | info["aspect_ratio"]=True |
---|
193 | info["custom_frame"]=True |
---|
194 | |
---|
195 | info["image_id"]=pkg["package"]+"_banner_small" |
---|
196 | info["x"]=self.banner_small |
---|
197 | info["y"]=self.banner_small |
---|
198 | info["name"]=pkg["name"] |
---|
199 | info["package"]=pkg["package"] |
---|
200 | |
---|
201 | if pkg["banner_small"]!=None: |
---|
202 | s.download_image(info) |
---|
203 | else: |
---|
204 | s.create_banner_from_file(info) |
---|
205 | b=Gtk.Button() |
---|
206 | b.set_name("RELATED_BUTTON") |
---|
207 | b.add(s) |
---|
208 | b.connect("clicked",self.banner_clicked,pkg) |
---|
209 | self.featured_extra_box.pack_start(b,True,False,spacing) |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | self.show_all() |
---|
214 | |
---|
215 | |
---|
216 | #def build_related |
---|
217 | |
---|
218 | def build_categories(self): |
---|
219 | |
---|
220 | max_width=7 |
---|
221 | w_counter=0 |
---|
222 | h_counter=0 |
---|
223 | |
---|
224 | button_size=97 |
---|
225 | |
---|
226 | |
---|
227 | for item in sorted(self.core.categories_manager.categories): |
---|
228 | |
---|
229 | |
---|
230 | |
---|
231 | icon_name=self.core.categories_manager.categories[item]["icon"] |
---|
232 | label=item |
---|
233 | |
---|
234 | b=Gtk.Button() |
---|
235 | b.set_name("RELATED_BUTTON") |
---|
236 | hbox=Gtk.HBox() |
---|
237 | hbox.set_halign(Gtk.Align.START) |
---|
238 | |
---|
239 | s=Screenshot.ScreenshotNeo() |
---|
240 | i={} |
---|
241 | i["image_path"]=icon_name |
---|
242 | i["x"]=button_size |
---|
243 | i["y"]=button_size |
---|
244 | i["custom_frame"]=True |
---|
245 | i["name"]=label |
---|
246 | |
---|
247 | s.create_banner_from_file(i) |
---|
248 | b.add(s) |
---|
249 | b.connect("clicked",self.category_clicked,item) |
---|
250 | |
---|
251 | |
---|
252 | #self.categories_flowbox.add(b) |
---|
253 | |
---|
254 | self.categories_grid.attach(b,w_counter,h_counter,1,1) |
---|
255 | w_counter+=1 |
---|
256 | if w_counter ==max_width: |
---|
257 | w_counter=0 |
---|
258 | h_counter+=1 |
---|
259 | |
---|
260 | |
---|
261 | ''' |
---|
262 | |
---|
263 | icon_name=self.core.categories_manager.categories[item]["icon"] |
---|
264 | label=item |
---|
265 | |
---|
266 | b=Gtk.Button() |
---|
267 | b.set_name("RELATED_BUTTON") |
---|
268 | hbox=Gtk.HBox() |
---|
269 | hbox.set_halign(Gtk.Align.START) |
---|
270 | |
---|
271 | s=Screenshot.ScreenshotNeo() |
---|
272 | i={} |
---|
273 | i["image_path"]=icon_name |
---|
274 | i["x"]=button_size |
---|
275 | i["y"]=button_size |
---|
276 | i["custom_frame"]=True |
---|
277 | i["name"]=label |
---|
278 | |
---|
279 | s.create_banner_from_file(i) |
---|
280 | b.add(s) |
---|
281 | b.connect("clicked",self.category_clicked,item) |
---|
282 | |
---|
283 | b.set_halign(Gtk.Align.CENTER) |
---|
284 | b.set_valign(Gtk.Align.CENTER) |
---|
285 | |
---|
286 | self.categories_flowbox.add(b) |
---|
287 | |
---|
288 | ''' |
---|
289 | |
---|
290 | self.categories_grid.show_all() |
---|
291 | #self.categories_flowbox.show_all() |
---|
292 | |
---|
293 | |
---|
294 | |
---|
295 | |
---|
296 | |
---|
297 | #def build_categories |
---|
298 | |
---|
299 | |
---|
300 | def set_css_names(self): |
---|
301 | |
---|
302 | self.main_view_box.set_name("DETAILS_BOX") |
---|
303 | self.divider1.set_name("DIVIDER") |
---|
304 | self.divider2.set_name("DIVIDER") |
---|
305 | self.divider3.set_name("DIVIDER") |
---|
306 | self.featured_label.set_name("RELATED_LABEL") |
---|
307 | self.categories_label.set_name("RELATED_LABEL") |
---|
308 | self.rewind_button.set_name("MEDIA_BUTTON") |
---|
309 | self.play_button.set_name("MEDIA_BUTTON") |
---|
310 | self.forward_button.set_name("MEDIA_BUTTON") |
---|
311 | |
---|
312 | |
---|
313 | #def set_css_info |
---|
314 | |
---|
315 | |
---|
316 | def banner_clicked(self,widget,pkg): |
---|
317 | |
---|
318 | p=Package.Package(pkg) |
---|
319 | |
---|
320 | self.core.main_window.load_pkg_data(p["package"]) |
---|
321 | |
---|
322 | |
---|
323 | #def banner_clicked |
---|
324 | |
---|
325 | def category_clicked(self,widget,category_tag): |
---|
326 | |
---|
327 | self.core.search_box.current_category=category_tag |
---|
328 | self.core.main_window.search_category(category_tag) |
---|
329 | |
---|
330 | #def category_clicked |
---|
331 | |
---|
332 | |
---|
333 | def next_image(self,force=False,add=True): |
---|
334 | |
---|
335 | tmp=self.image_stack.get_visible_child_name() |
---|
336 | if tmp!=None: |
---|
337 | id=int(tmp.split("image")[1]) |
---|
338 | |
---|
339 | if add: |
---|
340 | |
---|
341 | if id < self.max_image_id: |
---|
342 | id+=1 |
---|
343 | else: |
---|
344 | id=1 |
---|
345 | else: |
---|
346 | |
---|
347 | if id <= 1: |
---|
348 | id=self.max_image_id |
---|
349 | else: |
---|
350 | id-=1 |
---|
351 | |
---|
352 | id="image%s"%id |
---|
353 | |
---|
354 | if not self.paused or force: |
---|
355 | if not self.image_stack.get_transition_running() or force: |
---|
356 | self.image_stack.set_visible_child_name(id) |
---|
357 | |
---|
358 | return True |
---|
359 | |
---|
360 | #def next_image |
---|
361 | |
---|
362 | def rewind_clicked(self,widget): |
---|
363 | |
---|
364 | self.image_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_RIGHT) |
---|
365 | self.next_image(True,False) |
---|
366 | self.image_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT) |
---|
367 | |
---|
368 | #def rewind_clicked |
---|
369 | |
---|
370 | def play_clicked(self,widget): |
---|
371 | |
---|
372 | if self.paused: |
---|
373 | self.media_play_image.set_from_file(RSRC_DIR + "media_pause.svg") |
---|
374 | else: |
---|
375 | self.media_play_image.set_from_file(RSRC_DIR + "media_play.svg") |
---|
376 | |
---|
377 | self.paused=not self.paused |
---|
378 | |
---|
379 | #def rewind_clicked |
---|
380 | |
---|
381 | def forward_clicked(self,widget): |
---|
382 | |
---|
383 | self.next_image(True) |
---|
384 | |
---|
385 | #def rewind_clicked |
---|
386 | |
---|
387 | #class MainMenu |
---|