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