Finish PyGtk upgrade (7 years in the making)
This commit is contained in:
parent
f68ea6e9c4
commit
01ad187150
|
@ -2,15 +2,12 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
import platform
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
if(os.environ.get('TRAVIS') != 'true'):
|
if(os.environ.get('TRAVIS') != 'true'):
|
||||||
import pygtk
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
pygtk.require('2.0')
|
from gi.repository import Gtk,GLib
|
||||||
import gtk
|
|
||||||
|
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -53,40 +50,40 @@ class HackerNewsApp:
|
||||||
self.ind.set_icon(get_icon_filename("hacker-tray.png"))
|
self.ind.set_icon(get_icon_filename("hacker-tray.png"))
|
||||||
|
|
||||||
# create a menu
|
# create a menu
|
||||||
self.menu = gtk.Menu()
|
self.menu = Gtk.Menu()
|
||||||
|
|
||||||
# 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
|
||||||
|
|
||||||
# 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.menu.append(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.connect("activate", self.toggleComments)
|
btnComments.connect("activate", self.toggleComments)
|
||||||
self.menu.append(btnComments)
|
self.menu.append(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.menu.append(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.menu.append(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.menu.append(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.menu.append(btnQuit)
|
||||||
|
@ -95,18 +92,6 @@ class HackerNewsApp:
|
||||||
|
|
||||||
self.ind.set_menu(self.menu)
|
self.ind.set_menu(self.menu)
|
||||||
self.refresh(chrome_data_directory=args.chrome, firefox_data_directory=args.firefox)
|
self.refresh(chrome_data_directory=args.chrome, firefox_data_directory=args.firefox)
|
||||||
self.launch_analytics(args)
|
|
||||||
|
|
||||||
def launch_analytics(self, args):
|
|
||||||
# Now that we're all done with the boot, send a beacone home
|
|
||||||
launch_data = vars(args)
|
|
||||||
launch_data['version'] = Version.current()
|
|
||||||
launch_data['platform'] = platform.linux_distribution()
|
|
||||||
try:
|
|
||||||
launch_data['browser'] = subprocess.check_output(["xdg-settings", "get", "default-web-browser"]).strip()
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
launch_data['browser'] = "unknown"
|
|
||||||
|
|
||||||
|
|
||||||
def toggleComments(self, widget):
|
def toggleComments(self, widget):
|
||||||
"""Whether comments page is opened or not"""
|
"""Whether comments page is opened or not"""
|
||||||
|
@ -132,11 +117,11 @@ class HackerNewsApp:
|
||||||
with open(home + '/.hackertray.json', 'w+') as file:
|
with open(home + '/.hackertray.json', 'w+') as file:
|
||||||
file.write(json.dumps(l))
|
file.write(json.dumps(l))
|
||||||
|
|
||||||
gtk.main_quit()
|
Gtk.main_quit()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
signal.signal(signal.SIGINT, self.quit)
|
signal.signal(signal.SIGINT, self.quit)
|
||||||
gtk.main()
|
Gtk.main()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def open(self, widget, event=None, data=None):
|
def open(self, widget, event=None, data=None):
|
||||||
|
@ -160,7 +145,7 @@ class HackerNewsApp:
|
||||||
if item['points'] == 0 or item['points'] is None:
|
if item['points'] == 0 or item['points'] is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
i = gtk.CheckMenuItem(
|
i = Gtk.CheckMenuItem(
|
||||||
"(" + str(item['points']).zfill(3) + "/" + str(item['comments_count']).zfill(3) + ") " + item['title'])
|
"(" + str(item['points']).zfill(3) + "/" + str(item['comments_count']).zfill(3) + ") " + item['title'])
|
||||||
|
|
||||||
visited = item['history'] or item['id'] in self.db
|
visited = item['history'] or item['id'] in self.db
|
||||||
|
@ -206,7 +191,7 @@ class HackerNewsApp:
|
||||||
finally:
|
finally:
|
||||||
# Call every 10 minutes
|
# Call every 10 minutes
|
||||||
if not no_timer:
|
if not no_timer:
|
||||||
gtk.timeout_add(10 * 30 * 1000, self.refresh, widget, no_timer, chrome_data_directory)
|
GLib.timeout_add(10 * 30 * 1000, self.refresh, widget, no_timer, chrome_data_directory)
|
||||||
|
|
||||||
# Merges two boolean arrays, using OR operation against each pair
|
# Merges two boolean arrays, using OR operation against each pair
|
||||||
def mergeBoolArray(self, original, patch):
|
def mergeBoolArray(self, original, patch):
|
||||||
|
@ -220,7 +205,7 @@ def main():
|
||||||
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', 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")
|
parser.add_argument('--firefox', default=self.default_firefox_profile(), dest='firefox', help="Specify a Firefox Profile directory to use for matching firefox history")
|
||||||
parser.set_defaults(comments=False)
|
parser.set_defaults(comments=False)
|
||||||
parser.set_defaults(dnt=False)
|
parser.set_defaults(dnt=False)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
|
@ -9,8 +9,7 @@
|
||||||
#=========================
|
#=========================
|
||||||
|
|
||||||
# We require PyGTK
|
# We require PyGTK
|
||||||
import gtk
|
from gi.repository import Gtk,GLib
|
||||||
import gobject
|
|
||||||
|
|
||||||
# We also need os and sys
|
# We also need os and sys
|
||||||
import os
|
import os
|
||||||
|
@ -42,7 +41,7 @@ class Indicator:
|
||||||
self.active_icon = "" # Blank until the user calls set_attention_icon
|
self.active_icon = "" # Blank until the user calls set_attention_icon
|
||||||
|
|
||||||
# Create the status icon
|
# Create the status icon
|
||||||
self.icon = gtk.StatusIcon()
|
self.icon = Gtk.StatusIcon()
|
||||||
|
|
||||||
# Initialize to the default icon
|
# Initialize to the default icon
|
||||||
self.icon.set_from_file(self.inactive_icon)
|
self.icon.set_from_file(self.inactive_icon)
|
||||||
|
@ -81,7 +80,7 @@ class Indicator:
|
||||||
|
|
||||||
def show_menu(self, widget):
|
def show_menu(self, widget):
|
||||||
# Show the menu
|
# Show the menu
|
||||||
self.menu.popup(None, None, None, 0, 0)
|
self.menu.popup(None, None, None, 0, 0, Gtk.get_current_event_time())
|
||||||
|
|
||||||
# Get the location and size of the window
|
# Get the location and size of the window
|
||||||
mouse_rect = self.menu.get_window().get_frame_extents()
|
mouse_rect = self.menu.get_window().get_frame_extents()
|
||||||
|
@ -92,7 +91,7 @@ class Indicator:
|
||||||
self.bottom = self.y + mouse_rect.height
|
self.bottom = self.y + mouse_rect.height
|
||||||
|
|
||||||
# Set a timer to poll the menu
|
# Set a timer to poll the menu
|
||||||
self.timer = gobject.timeout_add(100, self.check_mouse)
|
self.timer = GLib.timeout_add(100, self.check_mouse)
|
||||||
|
|
||||||
def check_mouse(self):
|
def check_mouse(self):
|
||||||
if not self.menu.get_window().is_visible():
|
if not self.menu.get_window().is_visible():
|
||||||
|
@ -101,9 +100,9 @@ class Indicator:
|
||||||
# Now check the global mouse coords
|
# Now check the global mouse coords
|
||||||
root = self.menu.get_screen().get_root_window()
|
root = self.menu.get_screen().get_root_window()
|
||||||
|
|
||||||
x, y, z = root.get_pointer()
|
_,x,y,_ = root.get_pointer()
|
||||||
|
|
||||||
if x < self.x or x > self.right or y < self.y or y > self.bottom:
|
if (x < (self.x-10)) or (x > self.right) or (y < (self.y+10)) or (y > self.bottom):
|
||||||
self.hide_menu()
|
self.hide_menu()
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue