7
7
from gettext import gettext as _
9
9
from appview import AppViewFilter
10
from softwarecenter.ui.gtk3.widgets.containers import FlowableGrid
11
from softwarecenter.ui.gtk3.widgets.buttons import CategoryTile
10
from softwarecenter.enums import NonAppVisibility
11
from softwarecenter.ui.gtk3.models.appstore2 import AppEnquire, AppPropertiesHelper
12
from softwarecenter.ui.gtk3.widgets.containers import *
13
from softwarecenter.ui.gtk3.widgets.exhibits import ExhibitBanner
14
from softwarecenter.ui.gtk3.widgets.buttons import (LabelTile,
17
from softwarecenter.ui.gtk3.em import StockEms
12
18
from softwarecenter.db.categories import (Category,
14
21
categories_sorted_by_name)
16
23
LOG_ALLOCATION = logging.getLogger("softwarecenter.ui.gtk.allocation")
17
24
LOG=logging.getLogger(__name__)
29
for (i, (title, url)) in enumerate([
30
("1 some title", "https://wiki.ubuntu.com/Brand?action=AttachFile&do=get&target=orangeubuntulogo.png"),
31
("2 another title", "https://wiki.ubuntu.com/Brand?action=AttachFile&do=get&target=blackeubuntulogo.png"),
32
("3 yet another title", "https://wiki.ubuntu.com/Brand?action=AttachFile&do=get&target=xubuntu.png"),
35
exhibit.background_color = "#000000"
36
exhibit.banner_url = url
37
exhibit.date_created = "2011-07-20 08:49:15"
38
exhibit.font_color = "#000000"
39
exhibit.font_name = ""
40
exhibit.font_size = 24
42
exhibit.package_names = "apt,2vcard"
43
exhibit.published = True
44
exhibit.title_coords = [10, 10]
45
exhibit.title_translated = title
46
exhibits_list.append(exhibit)
20
50
class CategoriesViewGtk(Gtk.Viewport, CategoriesParser):
93
126
self._poster_sigs = []
94
127
self._allocation = None
129
assets = self._cache_art_assets()
130
self.vbox.connect("draw", self.on_draw, assets)
131
self._prev_alloc = None
132
self.connect("size-allocate", self.on_size_allocate)
135
def on_size_allocate(self, widget, _):
136
a = widget.get_allocation()
137
prev = self._prev_alloc
138
if prev is None or a.width != prev.width or a.height != prev.height:
143
def _cache_art_assets(self):
145
if _asset_cache: return _asset_cache
146
assets = _asset_cache
147
# cache the bg pattern
148
surf = cairo.ImageSurface.create_from_png(self.STIPPLE)
149
ptrn = cairo.SurfacePattern(surf)
150
ptrn.set_extend(cairo.EXTEND_REPEAT)
151
assets["stipple"] = ptrn
154
def on_app_clicked(self, btn, app):
155
"""emit the category-selected signal when a category was clicked"""
157
self.emit("application-selected", app)
158
self.emit("application-activated", app)
161
GObject.timeout_add(50, idle_emit)
164
def on_category_clicked(self, btn, cat):
165
"""emit the category-selected signal when a category was clicked"""
167
self.emit("category-selected", cat)
170
GObject.timeout_add(50, idle_emit)
97
173
def build(self, desktopdir):
100
#~ def _on_app_clicked(self, btn):
102
#~ appname = app[AppStore.COL_APP_NAME]
103
#~ pkgname = app[AppStore.COL_PKGNAME]
104
#~ rating = app[AppStore.COL_RATING]
105
#~ self.emit("application-selected", Application(appname, pkgname, "", rating))
106
#~ self.emit("application-activated", Application(appname, pkgname, "", rating))
109
def _on_category_clicked(self, cat_btn, cat):
110
"""emit the category-selected signal when a category was clicked"""
111
LOG.debug("on_category_changed: %s" % cat.name)
112
self.emit("category-selected", cat)
176
def on_draw(self, widget, cr, assets):
177
cr.set_source(assets["stipple"])
115
181
def set_section(self, section):
154
220
# these methods add sections to the page
155
221
# changing order of methods changes order that they appear in the page
156
222
#~ self._append_recommendations()
223
self._append_banner_ads()
225
self.top_hbox = Gtk.HBox(spacing=self.SPACING)
226
top_hbox_alignment = Gtk.Alignment()
227
top_hbox_alignment.set_padding(0, 0, self.PADDING, self.PADDING)
228
top_hbox_alignment.add(self.top_hbox)
229
self.vbox.pack_start(top_hbox_alignment, False, False, 0)
157
231
self._append_departments()
158
#~ self._append_featured()
159
#~ self._append_whatsnew()
233
self.right_column = Gtk.Box.new(Gtk.Orientation.VERTICAL, self.SPACING)
234
self.top_hbox.pack_start(self.right_column, True, True, 0)
236
self._append_featured()
237
self._append_recommendations()
239
self._append_video_clips()
240
self._append_top_of_the_pops()
243
def _append_top_of_the_pops(self):
244
self.totp_hbox = Gtk.HBox(spacing=self.SPACING)
246
alignment = Gtk.Alignment()
247
alignment.set_padding(0, 0, self.PADDING, self.PADDING)
248
alignment.add(self.totp_hbox)
250
frame = FramedHeaderBox()
251
frame.header_implements_more_button()
252
frame.set_header_label(_("Most Popular"))
254
label = Gtk.Label.new("Soda pop!!!")
255
label.set_name("placeholder")
256
label.set_size_request(-1, 200)
259
self.totp_hbox.add(frame)
261
frame = FramedHeaderBox()
262
frame.header_implements_more_button()
263
frame.set_header_label(_("Top Rated"))
265
label = Gtk.Label.new("Demos ftw(?)")
266
label.set_name("placeholder")
267
label.set_size_request(-1, 200)
270
self.totp_hbox.add(frame)
272
self.vbox.pack_start(alignment, False, False, 0)
275
def _append_video_clips(self):
276
frame = FramedHeaderBox()
277
frame.set_header_expand(False)
278
frame.set_header_position(HeaderPosition.LEFT)
279
frame.set_header_label(_("Latest Demo Videos"))
281
label = Gtk.Label.new("Videos go here")
282
label.set_name("placeholder")
283
label.set_size_request(-1, 200)
287
alignment = Gtk.Alignment()
288
alignment.set_padding(0, 0, self.PADDING, self.PADDING)
291
self.vbox.pack_start(alignment, False, False, 0)
294
def _append_banner_ads(self):
295
exhibit_banner = ExhibitBanner()
296
#~ exhibit_banner.set_exhibits(exhibits_list)
297
exhibit_banner.set_size_request(-1, 200)
298
self.vbox.pack_start(exhibit_banner, False, False, 0)
162
301
def _append_departments(self):
163
# # set the departments section to use the label markup we have just defined
165
label.set_markup("<b><big>%s</big></b>" % self.header)
166
label.set_alignment(0, 0.5)
167
self.vbox.pack_start(label, False, False, 0)
169
self.departments = FlowableGrid()
170
self.departments.set_row_spacing(6)
171
self.departments.set_column_spacing(6)
172
self.vbox.pack_start(self.departments, True, True, 0)
302
# set the departments section to use the label markup we have just defined
303
cat_vbox = FramedBox(Gtk.Orientation.VERTICAL)
304
self.top_hbox.pack_start(cat_vbox, False, False, 0)
174
306
# sort Category.name's alphabetically
175
307
sorted_cats = categories_sorted_by_name(self.categories)
176
#layout = self.create_pango_layout('')
309
mrkup = "<small>%s</small>"
178
310
for cat in sorted_cats:
179
311
if 'carousel-only' in cat.flags: continue
181
tile = CategoryTile(cat.name, cat.iconname)
182
tile.set_name("tile")
183
tile.connect('clicked', self._on_category_clicked, cat)
184
self.departments.add_child(tile)
312
category_name = mrkup % GObject.markup_escape_text(cat.name)
313
label = LabelTile(category_name, None)
314
label.label.set_alignment(0.0, 0.5)
315
label.label.set_use_markup(True)
316
label.connect('clicked', self.on_category_clicked, cat)
317
cat_vbox.pack_start(label, False, False, 0)
320
def _append_featured(self):
321
#~ featured_cat = get_category_by_name(self.categories,
322
#~ u"What\u2019s New") # unstranslated name
323
featured_cat = get_category_by_name(self.categories,
324
u"Featured") # unstranslated name
327
enq = AppEnquire(self.cache, self.db)
328
app_filter = AppViewFilter(self.db, self.cache)
329
enq.set_query(featured_cat.query,
332
nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE,
333
nonblocking_load=False)
335
self.featured = FlowableGrid()
336
#~ self.featured.row_spacing = StockEms.SMALL
338
frame.set_corner_label(_("New"))
339
frame.add(self.featured)
340
self.right_column.pack_start(frame, True, True, 0)
342
helper = AppPropertiesHelper(self.db, self.cache, self.icons)
343
for doc in enq.get_documents()[15:21]:
344
name = helper.get_appname(doc)
345
icon_pb = helper.get_icon_at_size(doc, 48, 48)
346
stats = helper.get_review_stats(doc)
347
tile = FeaturedTile(name, icon_pb, stats)
348
tile.connect('clicked', self.on_app_clicked,
349
helper.get_application(doc))
350
self.featured.add_child(tile)
353
def _append_recommendations(self):
354
featured_cat = get_category_by_name(self.categories,
355
u"Featured") # unstranslated name
357
enq = AppEnquire(self.cache, self.db)
358
app_filter = AppViewFilter(self.db, self.cache)
359
enq.set_query(featured_cat.query,
362
nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE,
363
nonblocking_load=False)
365
self.featured = FlowableGrid()
366
frame = FramedHeaderBox(Gtk.Orientation.VERTICAL)
367
frame.add(self.featured)
368
frame.set_header_label(_("Recommended For You"))
369
frame.header_implements_more_button()
370
self.right_column.pack_start(frame, True, True, 0)
372
helper = AppPropertiesHelper(self.db, self.cache, self.icons)
373
for doc in enq.get_documents():
374
name = helper.get_appname(doc)
375
icon_pb = helper.get_icon_at_size(doc, 48, 48)
376
stats = helper.get_review_stats(doc)
377
tile = FeaturedTile(name, icon_pb, stats)
378
tile.connect('clicked', self.on_app_clicked,
379
helper.get_application(doc))
380
self.featured.add_child(tile)
187
383
def build(self, desktopdir):