From 3a1a639931344a5e009361e931b09a71e50f0b18 Mon Sep 17 00:00:00 2001 From: Willem Mulder Date: Tue, 7 Sep 2021 15:55:52 +0200 Subject: [PATCH] Clean up code, explicitly require GI versions --- bin/argon | 17 ++-- bin/argon-notifier-config | 163 +++++++++++++++----------------------- 2 files changed, 76 insertions(+), 104 deletions(-) diff --git a/bin/argon b/bin/argon index b21d3ff..f963378 100755 --- a/bin/argon +++ b/bin/argon @@ -1,8 +1,13 @@ #!/usr/bin/python +import os +import gi + +gi.require_version('Gtk', '3.0') +gi.require_version('Vte', '2.91') + from gi.repository import Gtk, Vte, Gdk from gi.repository import GLib -import os from os.path import expanduser topaddpath = os.path.expanduser('~/.config/argon/top-add') @@ -30,22 +35,22 @@ class GridWindow(Gtk.Window): self.entry1 = Gtk.Entry() self.entry1.connect("activate", self.button1sig) - self.button1 = Gtk.Button("Install") + self.button1 = Gtk.Button(label="Install") self.button1.connect("clicked", self.button1sig) self.entry2 = Gtk.Entry() self.entry2.connect("activate", self.button2sig) - self.button2 = Gtk.Button("Remove") + self.button2 = Gtk.Button(label="Remove") self.button2.connect("clicked", self.button2sig) - self.button5 = Gtk.Button("Top-level Packages") + self.button5 = Gtk.Button(label="Top-level Packages") self.button5.connect("clicked", self.button5sig) - self.button3 = Gtk.Button("Configure Notifier") + self.button3 = Gtk.Button(label="Configure Notifier") self.button3.connect("clicked", self.button3sig) - self.button4 = Gtk.Button("Update System") + self.button4 = Gtk.Button(label="Update System") self.button4.connect("clicked", self.button4sig) grid.add(self.entry1) diff --git a/bin/argon-notifier-config b/bin/argon-notifier-config index 2c0e218..0894a02 100755 --- a/bin/argon-notifier-config +++ b/bin/argon-notifier-config @@ -1,13 +1,16 @@ #!/usr/bin/python +import os +import gi + +gi.require_version('Gtk', '3.0') + +from gi.repository import Gtk config = [] for line in open('/etc/argon/config'): line = line.rstrip() config.append(line) -from gi.repository import Gtk -import os -from os.path import expanduser class GridWindow(Gtk.Window): @@ -16,11 +19,11 @@ class GridWindow(Gtk.Window): self.set_border_width(8) self.set_position(Gtk.WindowPosition.CENTER) self.set_icon_from_file('/usr/share/argon/argon.png') - grid = Gtk.Grid(column_homogeneous=True,column_spacing=8,row_spacing=8) - self.add(grid) + grid = Gtk.Grid(column_homogeneous=True, column_spacing=8, row_spacing=8) + self.add(grid) - self.label1 = Gtk.Label("seconds from login to first update check", xalign=0) - adjustment = Gtk.Adjustment(0, 0, 999999999, 1, 10, 0) + self.label1 = Gtk.Label(label="seconds from login to first update check", xalign=0) + adjustment = Gtk.Adjustment.new(0, 0, 999999999, 1, 10, 0) policy = Gtk.SpinButtonUpdatePolicy.IF_VALID delayonevalue = eval(config[0]) self.spinbutton1 = Gtk.SpinButton() @@ -28,8 +31,8 @@ class GridWindow(Gtk.Window): self.spinbutton1.set_update_policy(policy) self.spinbutton1.set_value(delayonevalue) - self.label2 = Gtk.Label("seconds between subsequent update checks", xalign=0) - adjustment = Gtk.Adjustment(0, 0, 999999999, 1, 10, 0) + self.label2 = Gtk.Label(label="seconds between subsequent update checks", xalign=0) + adjustment = Gtk.Adjustment.new(0, 0, 999999999, 1, 10, 0) policy = Gtk.SpinButtonUpdatePolicy.IF_VALID delaytwovalue = eval(config[1]) self.spinbutton2 = Gtk.SpinButton() @@ -37,112 +40,75 @@ class GridWindow(Gtk.Window): self.spinbutton2.set_update_policy(policy) self.spinbutton2.set_value(delaytwovalue) - self.label3 = Gtk.Label("notification text when updates are available", xalign=0) + self.label3 = Gtk.Label(label="notification text when updates are available", xalign=0) self.entry1 = Gtk.Entry() self.entry1.set_text("%s" % config[2]) - self.label4 = Gtk.Label("notification text when system is up to date", xalign=0) + self.label4 = Gtk.Label(label="notification text when system is up to date", xalign=0) self.entry2 = Gtk.Entry() self.entry2.set_text("%s" % config[3]) - self.label5 = Gtk.Label("notification icon when updates are available", xalign=0) - self.button1 = Gtk.Button("%s" % (config[4])) - self.button1.connect("clicked", self.button1sig) - - self.label6 = Gtk.Label("notification icon when system is up to date", xalign=0) - self.button2 = Gtk.Button("%s" % (config[5])) - self.button2.connect("clicked", self.button2sig) - - self.label7 = Gtk.Label("show notifications when system is up to date", xalign=0) - self.check = Gtk.CheckButton() - if config[6] == "True": - self.check.set_active(True) - self.spinbutton2.set_sensitive(True) - self.entry2.set_sensitive(True) - elif config[6] == "False": - self.check.set_active(False) - self.spinbutton2.set_sensitive(False) - self.entry2.set_sensitive(False) - self.check.connect("toggled", self.checksig) - - self.link = Gtk.LinkButton("http://code.google.com/p/arch-argon/", "Argon Project Page") - - autofile = os.path.exists(os.path.expanduser('~/.config/autostart/argon-update-notifier.desktop')) - if autofile == False: - self.button3 = Gtk.Button("Enable Autostart") - elif autofile == True: - self.button3 = Gtk.Button("Disable Autostart") + self.label5 = Gtk.Label(label="notification icon when updates are available", xalign=0) + self.button1 = Gtk.FileChooserButton.new("Choose Icon", Gtk.FileChooserAction.OPEN) + self.button1.set_filename("%s" % config[4]) + + self.label6 = Gtk.Label(label="notification icon when system is up to date", xalign=0) + self.button2 = Gtk.FileChooserButton.new("Choose Icon", Gtk.FileChooserAction.OPEN) + self.button2.set_filename("%s" % config[5]) + + self.label7 = Gtk.Label(label="show notifications when system is up to date", xalign=0) + self.check = Gtk.CheckButton(active=config[6] == "True") + self.check.bind_property("active", self.spinbutton2, "sensitive") + self.check.bind_property("active", self.entry2, "sensitive") + self.check.notify("active") + + self.link = Gtk.LinkButton.new_with_label("https://github.com/14mRh4X0r/arch-argon", "Argon Project Page") + + if os.path.exists(os.path.expanduser('~/.config/autostart/argon-update-notifier.desktop')): + self.button3 = Gtk.Button.new_with_label("Enable Autostart") + else: + self.button3 = Gtk.Button.new_with_label("Disable Autostart") + self.button3.connect("clicked", self.autostart) - self.button4 = Gtk.Button("Restore Defaults") + self.button4 = Gtk.Button.new_with_label("Restore Defaults") self.button4.connect("clicked", self.default) - self.button5 = Gtk.Button("Cancel") + self.button5 = Gtk.Button.new_with_label("Cancel") self.button5.connect("clicked", self.cancel) - self.button6 = Gtk.Button("Done") + self.button6 = Gtk.Button.new_with_label("Done") self.button6.connect("clicked", self.done) - grid.attach(self.label1,0,0,2,1) - grid.attach(self.spinbutton1,2,0,2,1) - grid.attach(self.label2,0,1,2,1) - grid.attach(self.spinbutton2,2,1,2,1) - grid.attach(self.label3,0,2,2,1) - grid.attach(self.entry1,2,2,2,1) - grid.attach(self.label4,0,3,2,1) - grid.attach(self.entry2,2,3,2,1) - grid.attach(self.label5,0,4,2,1) - grid.attach(self.button1,2,4,2,1) - grid.attach(self.label6,0,5,2,1) - grid.attach(self.button2,2,5,2,1) - grid.attach(self.label7,0,6,2,1) - grid.attach(self.check,2,6,1,1) - grid.attach(self.link,3,6,1,1) - grid.attach(self.button3,0,7,1,1) - grid.attach(self.button4,1,7,1,1) - grid.attach(self.button5,2,7,1,1) - grid.attach(self.button6,3,7,1,1) - - def button1sig(self, configalter): - dialog = Gtk.FileChooserDialog("Choose Icon", self, - Gtk.FileChooserAction.OPEN, - (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, - Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) - response = dialog.run() - if response == Gtk.ResponseType.OK: - configalter.set_label(dialog.get_filename()) - iconfile1 = dialog.get_filename() - dialog.destroy() - - def button2sig(self, configalter): - dialog = Gtk.FileChooserDialog("Choose Icon", self, - Gtk.FileChooserAction.OPEN, - (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, - Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) - response = dialog.run() - if response == Gtk.ResponseType.OK: - configalter.set_label(dialog.get_filename()) - iconfile2 = dialog.get_filename() - dialog.destroy() - - def checksig(self, configalter): - if self.check.get_active() == True: - self.spinbutton2.set_sensitive(True) - self.entry2.set_sensitive(True) - elif self.check.get_active() == False: - self.spinbutton2.set_sensitive(False) - self.entry2.set_sensitive(False) + grid.attach(self.label1, 0, 0, 2, 1) + grid.attach(self.spinbutton1, 2, 0, 2, 1) + grid.attach(self.label2, 0, 1, 2, 1) + grid.attach(self.spinbutton2, 2, 1, 2, 1) + grid.attach(self.label3, 0, 2, 2, 1) + grid.attach(self.entry1, 2, 2, 2, 1) + grid.attach(self.label4, 0, 3, 2, 1) + grid.attach(self.entry2, 2, 3, 2, 1) + grid.attach(self.label5, 0, 4, 2, 1) + grid.attach(self.button1, 2, 4, 2, 1) + grid.attach(self.label6, 0, 5, 2, 1) + grid.attach(self.button2, 2, 5, 2, 1) + grid.attach(self.label7, 0, 6, 2, 1) + grid.attach(self.check, 2, 6, 1, 1) + grid.attach(self.link, 3, 6, 1, 1) + grid.attach(self.button3, 0, 7, 1, 1) + grid.attach(self.button4, 1, 7, 1, 1) + grid.attach(self.button5, 2, 7, 1, 1) + grid.attach(self.button6, 3, 7, 1, 1) def autostart(self, button): - autofile = os.path.exists((os.path.expanduser('~/.config/autostart/argon-update-notifier.desktop'))) - if autofile == False: + if os.path.exists((os.path.expanduser('~/.config/autostart/argon-update-notifier.desktop'))): + os.remove(os.path.expanduser('~/.config/autostart/argon-update-notifier.desktop')) + self.button3.set_label("Enable Autostart") + else: if not os.path.exists(os.path.expanduser('~/.config/autostart')): os.makedirs(os.path.expanduser('~/.config/autostart')) - os.symlink('/usr/share/argon/argon-update-notifier.desktop',os.path.expanduser('~/.config/autostart/argon-update-notifier.desktop')) + os.symlink('/usr/share/argon/argon-update-notifier.desktop', os.path.expanduser('~/.config/autostart/argon-update-notifier.desktop')) self.button3.set_label("Disable Autostart") - elif autofile == True: - os.remove(os.path.expanduser('~/.config/autostart/argon-update-notifier.desktop')) - self.button3.set_label("Enable Autostart") def default(self, button): config = ["60", "28800", "NUM system UPD available", "Arch Linux is up to date", "/usr/share/argon/arch-stale.png", "/usr/share/argon/arch-fresh.png", "True"] @@ -169,8 +135,8 @@ class GridWindow(Gtk.Window): config[3] = self.entry2.get_text() if config[3] == "": config[3] = " " - config[4] = self.button1.get_label() - config[5] = self.button2.get_label() + config[4] = self.button1.get_filename() + config[5] = self.button2.get_filename() config[6] = self.check.get_active() configfile = open("/etc/argon/config", "w") @@ -178,6 +144,7 @@ class GridWindow(Gtk.Window): configfile.write("%s\n" % item) Gtk.main_quit() + win = GridWindow() win.connect("delete-event", Gtk.main_quit) win.show_all()