class Sidebar(Gtk.EventBox): def __init__(self): Gtk.EventBox.__init__(self) self.set_size_request(20, -1) # Take care of the background first white = Gdk.color_parse("white") self.modify_bg(Gtk.StateType.NORMAL, white) self.box = Gtk.VButtonBox() self.box.set_layout(Gtk.ButtonBoxStyle.CENTER) self.add(self.box) self.box.show() self.show() self.bookmark_icon = Icon(icon_name = 'emblem-favorite', \ pixel_size = 18) tooltip_text = _('Bookmark') self.bookmark_icon.set_tooltip_text(tooltip_text) self.box.pack_start(self.bookmark_icon, False, False, 0) def show_bookmark_icon(self, state): if state: self.bookmark_icon.show_all() else: self.bookmark_icon.hide()
class ButtonWithImage(Gtk.Button): def __init__(self, label_text): GObject.GObject.__init__(self, ) self.icon_move_up = Icon(icon_name='go-up') # self.remove(self.get_children()[0]) self.hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self.add(self.hbox) self.hbox.add(self.icon_move_up) self.label = Gtk.Label(label=label_text) self.hbox.add(self.label) self.show_all() def hide_image(self): self.icon_move_up.hide() def show_image(self): self.icon_move_up.show() def set_label(self, text): self.label.set_text(text)
class ButtonWithImage(Gtk.Button): def __init__(self, label_text): GObject.GObject.__init__(self,) self.icon_move_up = Icon(icon_name='go-up') # self.remove(self.get_children()[0]) self.hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self.add(self.hbox) self.hbox.add(self.icon_move_up) self.label = Gtk.Label(label=label_text) self.hbox.add(self.label) self.show_all() def hide_image(self): self.icon_move_up.hide() def show_image(self): self.icon_move_up.show() def set_label(self, text): self.label.set_text(text)
class SlideView(Gtk.EventBox): def __init__(self, activity): Gtk.EventBox.__init__(self) self._area = Gtk.DrawingArea() self._area.connect('draw', self._area_draw_cb) self._boxes = [] self._current_box = None self._timeout_id = None prev_btn = Gtk.EventBox() prev_btn.connect('button-press-event', self._prev_slide) self._prev_icon = Icon(pixel_size=100) self._prev_icon.props.icon_name = 'go-previous' prev_btn.add(self._prev_icon) next_btn = Gtk.EventBox() next_btn.connect('button-press-event', self._next_slide) self._next_icon = Icon(pixel_size=100) self._next_icon.props.icon_name = 'go-next' next_btn.add(self._next_icon) hbox = Gtk.Box() hbox.set_border_width(10) hbox.pack_start(prev_btn, True, False, 0) hbox.pack_start(self._area, False, False, 0) hbox.pack_end(next_btn, True, False, 0) self.add(hbox) self.show_all() def _area_draw_cb(self, widget, context): if self._current_box is None: return box = self._boxes[self._current_box] self._area.set_size_request(box.width + 1, box.height + 1) context.move_to(box.width - style.zoom(40), box.height + style.zoom(25)) context.set_font_size(style.zoom(20)) context.show_text('%s/%s' % (self._current_box + 1, str(len(self._boxes)))) if self._current_box == len(self._boxes) - 1: self._next_icon.set_fill_color(style.COLOR_BUTTON_GREY.get_html()) else: self._next_icon.set_fill_color(None) if self._current_box == 0: self._prev_icon.set_fill_color(style.COLOR_BUTTON_GREY.get_html()) else: self._prev_icon.set_fill_color(None) box.draw_in_context(context) def set_boxes(self, boxes): # Discard the title box self._boxes = boxes[1:] def set_current_box(self, box): self._current_box = box self._area.queue_draw() def start(self, use_timings): if not use_timings: self._prev_icon.show() self._next_icon.show() return self._prev_icon.hide() self._next_icon.hide() box = self._boxes[self._current_box] duration = box.slideshow_duration self._timeout_id = \ GObject.timeout_add_seconds(duration, self.__slideshow_timeout_cb) def stop(self): if self._timeout_id: GObject.source_remove(self._timeout_id) def __slideshow_timeout_cb(self, *args): if self._current_box + 1 > len(self._boxes) - 1: return False self._current_box += 1 self._area.queue_draw() box = self._boxes[self._current_box] duration = box.slideshow_duration self._timeout_id = \ GObject.timeout_add_seconds(duration, self.__slideshow_timeout_cb) return False def _next_slide(self, widget, event): self._current_box += 1 if self._current_box > len(self._boxes) - 1: self._current_box -= 1 self._area.queue_draw() def _prev_slide(self, widget, event): self._current_box -= 1 if self._current_box < 0: self._current_box += 1 self._area.queue_draw() def key_press_cb(self, widget, event): if event.keyval == 65361: self._prev_slide(None, None) elif event.keyval == 65363: self._next_slide(None, None)
class Sidebar(Gtk.EventBox): def __init__(self): Gtk.EventBox.__init__(self) self.set_size_request(20, -1) # Take care of the background first white = Gdk.color_parse("white") self.modify_bg(Gtk.StateType.NORMAL, white) self._box = Gtk.VButtonBox() self._box.set_layout(Gtk.ButtonBoxStyle.CENTER) self.add(self._box) self._box.show() self.show() self._view = None self._bookmark_icon = None self._bookmark_manager = None self._is_showing_local_bookmark = False self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK) def _add_bookmark_icon(self, bookmark): xocolor = XoColor(bookmark.color) self._bookmark_icon = Icon(icon_name='emblem-favorite', pixel_size=18, xo_color=xocolor) self._bookmark_icon.props.has_tooltip = True self.__bookmark_icon_query_tooltip_cb_id = \ self._bookmark_icon.connect('query_tooltip', self.__bookmark_icon_query_tooltip_cb, bookmark) self.__event_cb_id = \ self.connect('event', self.__event_cb, bookmark) self._box.pack_start(self._bookmark_icon, False, False, 0) self._bookmark_icon.show_all() if bookmark.is_local(): self._is_showing_local_bookmark = True def __bookmark_icon_query_tooltip_cb(self, widget, x, y, keyboard_mode, tip, bookmark): tooltip_header = bookmark.get_note_title() tooltip_body = bookmark.get_note_body() #TRANS: This goes like Bookmark added by User 5 days ago #TRANS: (the elapsed string gets translated automatically) tooltip_footer = (_('Bookmark added by %(user)s %(time)s') \ % {'user': bookmark.nick, 'time': timestamp_to_elapsed_string(bookmark.timestamp)}) vbox = Gtk.VBox() l = Gtk.Label('<big>%s</big>' % tooltip_header) l.set_use_markup(True) l.set_width_chars(40) l.set_line_wrap(True) vbox.pack_start(l, False, False, 0) l.show() l = Gtk.Label('%s' % tooltip_body) l.set_use_markup(True) l.set_alignment(0, 0) l.set_padding(2, 6) l.set_width_chars(40) l.set_line_wrap(True) l.set_justify(Gtk.Justification.FILL) vbox.pack_start(l, True, True, 0) l.show() l = Gtk.Label('<small><i>%s</i></small>' % tooltip_footer) l.set_use_markup(True) l.set_width_chars(40) l.set_line_wrap(True) vbox.pack_start(l, False, False, 0) l.show() tip.set_custom(vbox) return True def __event_cb(self, widget, event, bookmark): if event.type == Gdk.EventType.BUTTON_PRESS and \ self._bookmark_icon is not None: bookmark_title = bookmark.get_note_title() bookmark_content = bookmark.get_note_body() dialog = BookmarkEditDialog( parent_xid=self.get_toplevel().window.xid, dialog_title=_("Add notes for bookmark: "), bookmark_title=bookmark_title, bookmark_content=bookmark_content, page=bookmark.page_no, sidebarinstance=self) dialog.show_all() return False def _clear_bookmarks(self): if self._bookmark_icon is not None: self._bookmark_icon.disconnect( self.__bookmark_icon_query_tooltip_cb_id) self.disconnect(self.__event_cb_id) self._bookmark_icon.hide() # XXX: Is this needed?? self._bookmark_icon.destroy() self._bookmark_icon = None self._is_showing_local_bookmark = False def set_bookmarkmanager(self, bookmark_manager): self._bookmark_manager = bookmark_manager def get_bookmarkmanager(self): return (self._bookmark_manager) def update_for_page(self, page): self._clear_bookmarks() if self._bookmark_manager is None: return bookmarks = self._bookmark_manager.get_bookmarks_for_page(page) for bookmark in bookmarks: self._add_bookmark_icon(bookmark) def add_bookmark(self, number_of_times_zoomed): self._real_add_bookmark(number_of_times_zoomed) def _real_add_bookmark(self, number_of_times_zoomed): self._bookmark_manager.add_bookmark(number_of_times_zoomed) def del_bookmark(self, page): self._bookmark_manager.del_bookmark(page) def is_showing_local_bookmark(self): return self._is_showing_local_bookmark def set_view(self, view): self._view = view
class ForecastScreen(Gtk.Box): def __init__(self, activity): Gtk.Box.__init__(self) self.activity = activity self.name_label = Gtk.Label() self.name_label.set_alignment(0, 0) self.name_label.show() self.icon = Icon(pixel_size=SCREEN_HEIGHT / 4, fill_color=style.COLOR_TOOLBAR_GREY.get_svg()) self.icon.show() self.temp_label = Gtk.Label() self.temp_label.show() self.temp_scale_label = Gtk.Label() self.temp_scale_label.set_alignment(0.33, 0.41) self.temp_scale_label.show() separator = Gtk.Separator() separator.set_property('expand', True) separator.modify_fg(Gtk.StateType.NORMAL, Gdk.Color.parse(GREY)[1]) separator.show() self.info_label = Gtk.Label() self.info_label.set_alignment(0, 0) self.info_label.set_margin_right(20) self.info_label.show() grid = Gtk.Grid() grid.attach(self.name_label, left=0, top=0, width=5, height=1) grid.attach(self.icon, left=0, top=1, width=1, height=2) grid.attach(self.temp_label, left=1, top=1, width=1, height=2) grid.attach(self.temp_scale_label, left=2, top=1, width=1, height=1) grid.attach(separator, left=3, top=1, width=1, height=1) grid.attach(self.info_label, left=4, top=1, width=1, height=2) grid.show() self.forecast_daily_treeview = ForecastDailyTreeView(self.activity) self.scroll = Gtk.ScrolledWindow() self.scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.scroll.add(self.forecast_daily_treeview) self.scroll.set_size_request(-1, SCREEN_HEIGHT / 2.2) self.scroll.show() self.set_orientation(Gtk.Orientation.VERTICAL) self.pack_start(grid, expand=True, fill=False, padding=0) self.pack_start(self.scroll, expand=False, fill=False, padding=0) self.show() def get_daily_forecast(self): city = self.activity.selected_city source = 'forecast/daily?id=%s&mode=json&cnt=7' % (city.id) dest = os.path.join(self.activity.get_activity_root(), 'tmp', '', str(city.id) + '.json') self.activity.add_download(source, dest) def download_complete(self, downloader, file_path, file_name): forecast = self.activity.read_file(file_path)['list'] self.activity.selected_city.load_forecast_daily(forecast) self.activity.set_canvas(self) def refresh(self): self.activity.search_entry.set_text(self.activity.input) self.get_daily_forecast() def update_current(self, city): font_size = 28 if len(city.name + city.country) > 20: font_size = 28 - (len(city.name + city.country) - 20) name = '<span font="Sans Bold %d">%s, %s\n</span>' % ( font_size, city.name, city.country) timestamp = datetime.fromtimestamp(city.date) day = timestamp.weekday() time = '%02d:%02d' % (timestamp.hour, timestamp.minute) desc = '<span font="Sans 16">%s %s\n%s</span>' % (week[day], time, city.weather) file_name = 'icons/%s.svg' % (city.icon[:3]) self.icon.hide() self.icon.set_file(file_name) self.icon.show() temp = self.activity.convert(city.temp) degree = '<span stretch="ultracondensed" font="Sans 40"> %s</span>'\ % (temp) scale = '<span font="Sans 16">%s</span>' % (self.activity.temp_scale) wind = _('Wind') + ': ' if city.wind_speed != None: wind = wind + '%s %s' % (city.wind_speed, self.activity.wind_scale) clouds = _('Clouds') + ': ' if city.clouds != None: clouds = clouds + '%s %s' % (int( city.clouds), self.activity.cloud_scale) pressure = _('Pressure') + ': ' if city.pressure != None: pressure = pressure + '%s %s' % (city.pressure, self.activity.pressure_scale) humidity = _('Humidity') + ': ' if city.humidity != None: humidity = humidity + '%s %s' % (int( city.humidity), self.activity.humidity_scale) info = '<span font="Sans 16">%s\n%s\n%s\n%s</span>' % ( wind, clouds, pressure, humidity) self.name_label.set_markup(name + desc) self.temp_label.set_markup(degree) self.temp_scale_label.set_markup(scale) self.info_label.set_markup(info) def display_results(self): city = self.activity.selected_city if city: self.update_current(city) self.forecast_daily_treeview.update(city)