Adds a --reverse flag for users with status bar at bottom

This commit is contained in:
Nemo 2020-06-15 18:04:57 +05:30
parent a78796e029
commit 30a38bd769
1 changed files with 19 additions and 10 deletions

View File

@ -54,40 +54,41 @@ class HackerNewsApp:
# The default state is false, and it toggles when you click on it # The default state is false, and it toggles when you click on it
self.commentState = args.comments self.commentState = args.comments
self.reverse = args.reverse
# create items for the menu - refresh, quit and a separator # create items for the menu - refresh, quit and a separator
menuSeparator = Gtk.SeparatorMenuItem() menuSeparator = Gtk.SeparatorMenuItem()
menuSeparator.show() menuSeparator.show()
self.menu.append(menuSeparator) self.add(menuSeparator)
btnComments = Gtk.CheckMenuItem("Show Comments") btnComments = Gtk.CheckMenuItem("Show Comments")
btnComments.show() btnComments.show()
btnComments.set_active(args.comments) btnComments.set_active(args.comments)
btnComments.set_draw_as_radio(True) btnComments.set_draw_as_radio(True)
btnComments.connect("activate", self.toggleComments) btnComments.connect("activate", self.toggleComments)
self.menu.append(btnComments) self.add(btnComments)
btnAbout = Gtk.MenuItem("About") btnAbout = Gtk.MenuItem("About")
btnAbout.show() btnAbout.show()
btnAbout.connect("activate", self.showAbout) btnAbout.connect("activate", self.showAbout)
self.menu.append(btnAbout) self.add(btnAbout)
btnRefresh = Gtk.MenuItem("Refresh") btnRefresh = Gtk.MenuItem("Refresh")
btnRefresh.show() btnRefresh.show()
# the last parameter is for not running the timer # the last parameter is for not running the timer
btnRefresh.connect("activate", self.refresh, True, args.chrome) btnRefresh.connect("activate", self.refresh, True, args.chrome)
self.menu.append(btnRefresh) self.add(btnRefresh)
if Version.new_available(): if Version.new_available():
btnUpdate = Gtk.MenuItem("New Update Available") btnUpdate = Gtk.MenuItem("New Update Available")
btnUpdate.show() btnUpdate.show()
btnUpdate.connect('activate', self.showUpdate) btnUpdate.connect('activate', self.showUpdate)
self.menu.append(btnUpdate) self.add(btnUpdate)
btnQuit = Gtk.MenuItem("Quit") btnQuit = Gtk.MenuItem("Quit")
btnQuit.show() btnQuit.show()
btnQuit.connect("activate", self.quit) btnQuit.connect("activate", self.quit)
self.menu.append(btnQuit) self.add(btnQuit)
self.menu.show() self.menu.show()
self.ind.set_menu(self.menu) self.ind.set_menu(self.menu)
@ -95,6 +96,12 @@ class HackerNewsApp:
args.firefox = Firefox.default_firefox_profile_path() args.firefox = Firefox.default_firefox_profile_path()
self.refresh(chrome_data_directory=args.chrome, firefox_data_directory=args.firefox) self.refresh(chrome_data_directory=args.chrome, firefox_data_directory=args.firefox)
def add(self, item):
if self.reverse:
self.menu.prepend(item)
else:
self.menu.append(item)
def toggleComments(self, widget): def toggleComments(self, widget):
"""Whether comments page is opened or not""" """Whether comments page is opened or not"""
self.commentState = not self.commentState self.commentState = not self.commentState
@ -161,7 +168,10 @@ class HackerNewsApp:
i.signal_id = i.connect('activate', self.open) i.signal_id = i.connect('activate', self.open)
i.hn_id = item['id'] i.hn_id = item['id']
i.item_id = item['id'] i.item_id = item['id']
self.menu.prepend(i) if self.reverse:
self.menu.append(i)
else:
self.menu.prepend(i)
i.show() i.show()
def refresh(self, widget=None, no_timer=False, chrome_data_directory=None, firefox_data_directory=None): def refresh(self, widget=None, no_timer=False, chrome_data_directory=None, firefox_data_directory=None):
@ -207,11 +217,10 @@ class HackerNewsApp:
def main(): def main():
parser = argparse.ArgumentParser(description='Hacker News in your System Tray') parser = argparse.ArgumentParser(description='Hacker News in your System Tray')
parser.add_argument('-v', '--version', action='version', version=Version.current()) parser.add_argument('-v', '--version', action='version', version=Version.current())
parser.add_argument('-c', '--comments', dest='comments', action='store_true', help="Load the HN comments link for the article as well") parser.add_argument('-c', '--comments', dest='comments', default=False, action='store_true', help="Load the HN comments link for the article as well")
parser.add_argument('--chrome', dest='chrome', help="Specify a Google Chrome Profile directory to use for matching chrome history") parser.add_argument('--chrome', dest='chrome', help="Specify a Google Chrome Profile directory to use for matching chrome history")
parser.add_argument('--firefox', dest='firefox', help="Specify a Firefox Profile directory to use for matching firefox history. Pass auto to automatically pick the default profile") parser.add_argument('--firefox', dest='firefox', help="Specify a Firefox Profile directory to use for matching firefox history. Pass auto to automatically pick the default profile")
parser.set_defaults(comments=False) parser.add_argument('-r', '--reverse', dest='reverse', default=False, action='store_true', help="Reverse the order of items. Use if your status bar is at the bottom of the screen")
parser.set_defaults(dnt=False)
args = parser.parse_args() args = parser.parse_args()
indicator = HackerNewsApp(args) indicator = HackerNewsApp(args)
indicator.run() indicator.run()