def run(): parser = ArgumentParser( description='Something For Reddit - a Gtk+ Reddit Client') parser.add_argument('uri', help='Reddit.com URI to open, or None', default=None, nargs='?') parser.add_argument('--dark', help='Force Gtk+ dark theme', action='store_true') args = parser.parse_args() settings = Gtk.Settings.get_default() theme = get_settings()['theme'] if theme == 'dark': settings.props.gtk_application_prefer_dark_theme = True elif theme == 'light': settings.props.gtk_application_prefer_dark_theme = False if args.dark: settings.props.gtk_application_prefer_dark_theme = True a = Application() if args.uri is not None: a.goto_reddit_uri(args.uri) status = a.run() get_read_controller().save() sys.exit(status)
def __row_selected_cb(self, listbox, row): if row is None: return row.grab_focus() # For keyboard shortcuts to work if hasattr(row, 'read'): row.read() if isinstance(row, sublistrows.MessageRow): if 'context' not in row.data: row.data['context'] = '/r/{}/comments/{}/slug/{}/'.format( row.data['subreddit'], row.data['link_id'][len('t4_'):], row.data['id']) get_read_controller().read(row.data['name']) self._handle_activate(permalink=row.data['context'], link_first=False) elif isinstance(row, sublistrows.LinkRow): self._handle_activate(row.data) elif isinstance(row, sublistrows.MoreItemsRow): row.activate() elif isinstance(row, aboutrow.AboutRow): pass else: raise Exception('Unknown type of row activated: {}'.format(row))
def _handle_activate(self, data, comments=None): link = None get_read_controller().read(data['name']) if not data.get('is_self') and 'url' in data: link = data['url'] comments = CommentsView(data, comments=comments) self.new_other_pane.emit(link, comments)
def _handle_activate(self, data=None, permalink=None, link_first=True): link = None if data is not None: get_read_controller().read(data['name']) if not data.get('is_self') and 'url' in data: link = data['url'] comments = CommentsView(data, permalink=permalink) self.new_other_pane.emit(link, comments, link_first)
def __row_selected_cb(self, listbox, row): if row is None: return row.grab_focus() # For keyboard shortcuts to work if hasattr(row, 'read'): row.read() if isinstance(row, MessageRow): if 'context' not in row.data: row.data['context'] = '/r/{}/comments/{}/slug/{}/'.format( row.data['subreddit'], row.data['link_id'][len('t4_'):], row.data['id']) get_read_controller().read(row.data['name']) self._handle_activate(permalink=row.data['context'], link_first=False) else: self._handle_activate(row.data)
def __init__(self, api: RedditAPI, data): Gtk.ListBoxRow.__init__(self) self.add_events(Gdk.EventMask.KEY_PRESS_MASK) self.get_style_context().add_class('link-row') self.data = data['data'] self._msg = None self._api = api self._builder = Gtk.Builder.new_from_resource( '/today/sam/reddit-is-gtk/row-link.ui') self._g = self._builder.get_object self.add(self._g('box')) read = get_read_controller().is_read(self.data['name']) if read: self.read() # Keep a reference so the GC doesn't collect them self._sbb = ScoreButtonBehaviour(self._api, self._g('score'), self.data) self._abb = AuthorButtonBehaviour(self._g('author'), self.data) self._srbb = SubButtonBehaviour(self._g('subreddit'), self.data) self._tbb = TimeButtonBehaviour(self._g('time'), self.data) self._g('nsfw').props.visible = self.data.get('over_18') self._g('saved').props.visible = self.data.get('saved') self._g('sticky').props.visible = self.data.get('stickied') if self.data.get('stickied'): self.get_style_context().add_class('sticky') if self.data['num_comments']: self._g('comments').props.label = \ '{}c'.format(self.data['num_comments']) else: self._g('comments').props.label = 'no c' self._g('comments').connect('clicked', self.__comments_clicked_cb) self._g('title').props.label = self.data['title'] self._g('domain').props.label = self.data['domain'] self._fetch_thumbnail() self._preview_palette = None
def __init__(self, api: RedditAPI, data): Gtk.ListBoxRow.__init__(self) self.add_events(Gdk.EventMask.KEY_PRESS_MASK) self.get_style_context().add_class('link-row') self.data = data['data'] self._msg = None self._api = api self._builder = Gtk.Builder.new_from_resource( '/today/sam/reddit-is-gtk/row-link.ui') self._g = self._builder.get_object self.add(self._g('box')) read = get_read_controller().is_read(self.data['name']) if read: self.read() # Keep a reference so the GC doesn't collect them self._sbb = ScoreButtonBehaviour( self._api, self._g('score'), self.data) self._abb = AuthorButtonBehaviour(self._g('author'), self.data) self._srbb = SubButtonBehaviour(self._g('subreddit'), self.data) self._tbb = TimeButtonBehaviour(self._g('time'), self.data) self._g('nsfw').props.visible = self.data.get('over_18') self._g('saved').props.visible = self.data.get('saved') self._g('sticky').props.visible = self.data.get('stickied') if self.data.get('stickied'): self.get_style_context().add_class('sticky') if self.data['num_comments']: self._g('comments').props.label = \ '{}c'.format(self.data['num_comments']) else: self._g('comments').props.label = 'no c' self._g('comments').connect('clicked', self.__comments_clicked_cb) self._g('title').props.label = self.data['title'] self._g('domain').props.label = self.data['domain'] self._fetch_thumbnail() self._preview_palette = None
def run(): a = Application() status = a.run() get_read_controller().save() sys.exit(status)
def __init__(self, data): Gtk.ListBoxRow.__init__(self) self.data = data['data'] self._pbl = None self._msg = None if get_read_controller().is_read(self.data['name']): self.get_style_context().add_class('read') box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self.add(box) box.show() l = Gtk.Label() l.props.xalign = 0 l.props.justify = Gtk.Justification.LEFT l.set_line_wrap(True) self.data['score'] = self.data['score'] if 'score' in self.data else '' self.data['num_comments'] = self.data.get('num_comments') or 'no' edited_string = '' if self.data.get('edited'): edited_string = '(edited {})'.format( arrow.get(self.data['edited']).humanize()) score_color = {True: 'color="darkorange"', False: 'color="darkorchid"'}.get( self.data.get('likes'), '') nsfw_tag = '' if self.data.get('over18'): # One day, we will pipe this through gettext nsfw_tag = ' <span color="red">{}</span>'.format('NSFW') gilded_tag = '' if self.data.get('gilded') > 0: gilded_tag = ('<span bgcolor="darkorange" color="white"><b>' '★{}</b></span> ').format(self.data['gilded']) author_color = '' if not self.data['distinguished'] else \ 'bgcolor="{}"'.format(AUTHOR_COLORS[self.data['distinguished']]) l.set_markup( '<span {color}><big>{gilded_tag}' '<span weight="heavy" {score_color}>{score}</span></big>' ' <span {author_color}>{author}</span> in' ' /r/{subreddit}{nsfw_tag}\n' '<big>{title}</big>\n' '{num_comments} comments · {domain}' ' · {created_string} {edited_string}' '</span>'.format( color='color="green"' if self.data.get('stickied') else '', score_color=score_color, edited_string=edited_string, created_string=arrow.get(self.data['created_utc']).humanize(), nsfw_tag=nsfw_tag, gilded_tag=gilded_tag, author_color=author_color, **self.data)) box.add(l) l.show() self._fetch_thumbnail(self.data.get('thumbnail')) self._image_button = Gtk.Button() self._image = Gtk.Image() self._image_button.set_image(self._image) box.add(self._image_button) self._preview_palette = None