From ed1b2a50fadb542420a53e0f3d9949ae23be2d30 Mon Sep 17 00:00:00 2001 From: kbdserver Date: Thu, 11 Oct 2018 15:58:30 +0100 Subject: [PATCH] [Scheduler] Migrate plugin code to GTK3 - Added new svg icons for cleaner look. - Use widget get_allocated_width and get_allocated_height instead of window size. - Tweaked margins to fix spacing issues. - Removed yellow background from 'slow settings' and applied only to label. Co-authored-by: Calum Lind --- .../deluge/plugins/scheduler/data/green.png | Bin 792 -> 0 bytes .../deluge/plugins/scheduler/data/green.svg | 1 + .../deluge/plugins/scheduler/data/red.png | Bin 759 -> 0 bytes .../deluge/plugins/scheduler/data/red.svg | 1 + .../deluge/plugins/scheduler/data/yellow.png | Bin 770 -> 0 bytes .../deluge/plugins/scheduler/data/yellow.svg | 1 + .../deluge/plugins/scheduler/gtkui.py | 128 +++++++++--------- 7 files changed, 68 insertions(+), 63 deletions(-) delete mode 100644 deluge/plugins/Scheduler/deluge/plugins/scheduler/data/green.png create mode 100644 deluge/plugins/Scheduler/deluge/plugins/scheduler/data/green.svg delete mode 100644 deluge/plugins/Scheduler/deluge/plugins/scheduler/data/red.png create mode 100644 deluge/plugins/Scheduler/deluge/plugins/scheduler/data/red.svg delete mode 100644 deluge/plugins/Scheduler/deluge/plugins/scheduler/data/yellow.png create mode 100644 deluge/plugins/Scheduler/deluge/plugins/scheduler/data/yellow.svg diff --git a/deluge/plugins/Scheduler/deluge/plugins/scheduler/data/green.png b/deluge/plugins/Scheduler/deluge/plugins/scheduler/data/green.png deleted file mode 100644 index 3118c7430b770f32baf670fcde22328290acead1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 792 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s77>k44ofy`glX=O&z`&N| z?e4GY~bkAZ=K zzr;17#5q4VH#M(>Au~lGCqF&E?O6Fv1_q{DPZ!4!i_>c-pY{$Z6gh5R{M_uZO+rnq zq^z6t6$urul^1-~To$fg5W0nfv+z`GcUkUheU6~cf{V+<@{G8&H#90Ko|NNQWcG8$ zmBO4oWzWyOzIT7Ut7h8nS8Mp%KijhJ<7fZ9s(!_0*%z$48cwV)WSYU?)|UM7o+t88r6M~^bzYX185>%;C- zomuKDzFY}dPIr(#H8uY^y%>NMFx;H%VJ? z#W`k^kZlWoI=$G*oAu`_LoAoT$KBc|qSco#8-T4)rhLRw|<{Ws!pOvNmm(TG)Io&hL)peeyK85DfwfM3k{bN7bIW67uD&BS3GcYhPc)I$ztaD0e0szY0VU7R* diff --git a/deluge/plugins/Scheduler/deluge/plugins/scheduler/data/green.svg b/deluge/plugins/Scheduler/deluge/plugins/scheduler/data/green.svg new file mode 100644 index 000000000..ff3f5d6f3 --- /dev/null +++ b/deluge/plugins/Scheduler/deluge/plugins/scheduler/data/green.svg @@ -0,0 +1 @@ + diff --git a/deluge/plugins/Scheduler/deluge/plugins/scheduler/data/red.png b/deluge/plugins/Scheduler/deluge/plugins/scheduler/data/red.png deleted file mode 100644 index 90f532609384bd206181d546b89e053edf5c4fce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 759 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s77>k44ofy`glX=O&z`&N| z?e4KqD%)B( z_8rXVk)0#w;&N8um}^kD<1J72_G|SEVt=vk*kN(y(WCeWDVb~&C+MwZnW8XLrPGt^ zB8#%2%9Fo8_VKM;cx&z3R_^JiEx#YKeePw`y*VI5?gq=F15ehMF?ukz7eD><{r<;G z#-H3nr``WiB3rJ~WMjnCu;RMmr^;D3b#xWKJwNqydp(Z@ck8~4$B#P~x-hMdII=2C zaIF}_rd5kFq`WMAtYgjZbb;r-%`tf7+!KbOaX7X?}YD*kh{90r2VvD(a z-|otWEp0LvJA6B1PX+HS$IU-)mWpwmUA<|~`}p|fvrj(YVhOl@ZNux*UE<<5wr~Hj zeS6{0zc~Y6W6(7!>F)%Q^ zc-T#ep-^(h6n8g)wPIb%zH;tg}#YeyWKaiz-RK*#mXw4Nk5&_t>hCfJ2G1Zt5IZ_=-a zu7H)vV^T|Lt?% diff --git a/deluge/plugins/Scheduler/deluge/plugins/scheduler/data/yellow.png b/deluge/plugins/Scheduler/deluge/plugins/scheduler/data/yellow.png deleted file mode 100644 index 11146b996f51c4197f6c019bdce64c49e5c09fe9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 770 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s77>k44ofy`glX=O&z`&N| z?e4Kpc0*{U^@}A(h<*n9> zP5*AW%q>kXOWS{6Pb+HsE6crm_PqbRZ_oMP8h_eOK3v9^!0>|cQT0pK1U3oJWt-&r zuWRo&wKr{kwKu|)^Jn`PF7ow+* zy2e=df6!qFIqSmj^08g&<~je5$%&7Bji$b3{_xg6ug^U%Wd5!*@6P)xu+9=(xN4iI zZ9xB;DIZR;-nnFywuC!4KKI@3lq>zdIeuD`5Btid1^g{o_EqiZA(>hKEsiH$*ARQQ zVf!;ii^^|;-_Dt@`5M`hF1YITli$w+*TfbEva%)d>Q3qI)>!3OYI5?eb@|7iuQ}$v zaN{>y!0s=+>a~hQ9=oQ7xOk`O76zUb4*iL01#fK{XML7PYr6PRQqHEP=EWW+S5uC* z+aKDc3g6na&185H*tjFjMPOcQoG7b<*U1+@bk@i58U8Jk(u{Ff@X9pgYMevGwS7*7 zUptm{@h@@UV%LmmVNrY-R&RcOevECv69bckgT-d&R?g~7U$2IHh;{r>2ay^U@fHFfRq$335R@BC_9WPM`L%UFxLnQbxC$WZ~I6U+>-eRZ;hP zp4+a1H74i$q#j28_><_cFec_mRBij-zf%)-^v<1{8FsB36oWVI_ka3teEI&ZpW diff --git a/deluge/plugins/Scheduler/deluge/plugins/scheduler/gtkui.py b/deluge/plugins/Scheduler/deluge/plugins/scheduler/gtkui.py index 8aa68b345..b802aa666 100644 --- a/deluge/plugins/Scheduler/deluge/plugins/scheduler/gtkui.py +++ b/deluge/plugins/Scheduler/deluge/plugins/scheduler/gtkui.py @@ -15,7 +15,7 @@ from __future__ import division, unicode_literals import logging -import gtk +from gi.repository import Gdk, Gtk import deluge.component as component from deluge.plugins.pluginbase import Gtk3PluginBase @@ -28,17 +28,17 @@ log = logging.getLogger(__name__) DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] -class SchedulerSelectWidget(gtk.DrawingArea): +class SchedulerSelectWidget(Gtk.DrawingArea): def __init__(self, hover): super(SchedulerSelectWidget, self).__init__() self.set_events( - gtk.gdk.BUTTON_PRESS_MASK - | gtk.gdk.BUTTON_RELEASE_MASK - | gtk.gdk.POINTER_MOTION_MASK - | gtk.gdk.LEAVE_NOTIFY_MASK + Gdk.EventMask.BUTTON_PRESS_MASK + | Gdk.EventMask.BUTTON_RELEASE_MASK + | Gdk.EventMask.POINTER_MOTION_MASK + | Gdk.EventMask.LEAVE_NOTIFY_MASK ) - self.connect('expose_event', self.expose) + self.connect('draw', self.draw) self.connect('button_press_event', self.mouse_down) self.connect('button_release_event', self.mouse_up) self.connect('motion_notify_event', self.mouse_hover) @@ -65,39 +65,37 @@ class SchedulerSelectWidget(gtk.DrawingArea): log.debug(self.button_state) # redraw the whole thing - def expose(self, widget, event): - context = self.window.cairo_create() - context.rectangle( - event.area.x, event.area.y, event.area.width, event.area.height - ) + def draw(self, widget, context): + width = widget.get_allocated_width() + height = widget.get_allocated_height() + context.rectangle(0, 0, width, height) context.clip() - width = self.window.get_size()[0] - height = self.window.get_size()[1] - for y in range(7): for x in range(24): context.set_source_rgba( self.colors[self.button_state[x][y]][0], self.colors[self.button_state[x][y]][1], self.colors[self.button_state[x][y]][2], - 0.7, + 0.5, ) context.rectangle( width * (6 * x / 145 + 1 / 145), height * (6 * y / 43 + 1 / 43), - 5 * width / 145, + 6 * width / 145, 5 * height / 43, ) context.fill_preserve() - context.set_source_rgba(0.5, 0.5, 0.5, 0.5) + context.set_source_rgba(0, 0, 0, 0.7) + context.set_line_width(1) context.stroke() # coordinates --> which box def get_point(self, event): - size = self.window.get_size() - x = int((event.x - size[0] * 0.5 / 145) / (6 * size[0] / 145)) - y = int((event.y - size[1] * 0.5 / 43) / (6 * size[1] / 43)) + width = self.get_allocated_width() + height = self.get_allocated_height() + x = int((event.x - width * 0.5 / 145) / (6 * width / 145)) + y = int((event.y - height * 0.5 / 43) / (6 * height / 43)) if x > 23: x = 23 @@ -179,7 +177,7 @@ class GtkUI(Gtk3PluginBase): ) self.statusbar = component.get('StatusBar') self.status_item = self.statusbar.add_item( - image=get_resource('green.png'), + image=get_resource('green.svg'), text='', callback=self.on_status_item_clicked, tooltip='Scheduler', @@ -189,6 +187,8 @@ class GtkUI(Gtk3PluginBase): self.state = state self.on_scheduler_event(state) + self.on_show_prefs() + client.scheduler.get_state().addCallback(on_state_deferred) client.register_event_handler('SchedulerEvent', self.on_scheduler_event) @@ -237,7 +237,7 @@ class GtkUI(Gtk3PluginBase): def on_scheduler_event(self, state): self.state = state - self.status_item.set_image_from_file(get_resource(self.state.lower() + '.png')) + self.status_item.set_image_from_file(get_resource(self.state.lower() + '.svg')) if self.state == 'Yellow': # Prevent func calls in Statusbar if the config changes. self.statusbar.config_value_changed_dict.pop('max_download_speed', None) @@ -274,84 +274,86 @@ class GtkUI(Gtk3PluginBase): # Configuration dialog def create_prefs_page(self): # Select Widget - hover = gtk.Label() + hover = Gtk.Label() self.scheduler_select = SchedulerSelectWidget(hover) - vbox = gtk.VBox(False, 5) - hbox = gtk.HBox(False, 5) - vbox_days = gtk.VBox() + vbox = Gtk.VBox(False, 5) + hbox = Gtk.HBox(False, 5) + vbox_days = Gtk.VBox() for day in DAYS: - vbox_days.pack_start(gtk.Label(day)) - hbox.pack_start(vbox_days, False, False) - hbox.pack_start(self.scheduler_select, True, True) - frame = gtk.Frame() - label = gtk.Label() - label.set_markup('Schedule') + vbox_days.pack_start(Gtk.Label(day, xalign=0), True, False, 0) + hbox.pack_start(vbox_days, False, False, 15) + hbox.pack_start(self.scheduler_select, True, True, 0) + frame = Gtk.Frame() + label = Gtk.Label() + label.set_markup(_('Schedule')) frame.set_label_widget(label) - frame.set_shadow_type(gtk.SHADOW_NONE) + frame.set_shadow_type(Gtk.ShadowType.NONE) + frame.set_margin_left(15) frame.add(hbox) - vbox.pack_start(frame, True, True) - vbox.pack_start(hover) + vbox.pack_start(frame, False, False, 0) + vbox.pack_start(hover, False, False, 0) - table = gtk.Table(3, 4) + table = Gtk.Table(5, 2) + table.set_margin_left(15) - label = gtk.Label(_('Download Limit:')) + label = Gtk.Label(_('Download Limit:')) label.set_alignment(0.0, 0.6) - table.attach(label, 0, 1, 0, 1, gtk.FILL) - self.spin_download = gtk.SpinButton() + table.attach_defaults(label, 0, 1, 0, 1) + self.spin_download = Gtk.SpinButton() self.spin_download.set_numeric(True) self.spin_download.set_range(-1.0, 99999.0) self.spin_download.set_increments(1, 10) - table.attach(self.spin_download, 1, 2, 0, 1, gtk.FILL) + table.attach_defaults(self.spin_download, 1, 2, 0, 1) - label = gtk.Label(_('Upload Limit:')) + label = Gtk.Label(_('Upload Limit:')) label.set_alignment(0.0, 0.6) - table.attach(label, 0, 1, 1, 2, gtk.FILL) - self.spin_upload = gtk.SpinButton() + table.attach_defaults(label, 0, 1, 1, 2) + self.spin_upload = Gtk.SpinButton() self.spin_upload.set_numeric(True) self.spin_upload.set_range(-1.0, 99999.0) self.spin_upload.set_increments(1, 10) - table.attach(self.spin_upload, 1, 2, 1, 2, gtk.FILL) + table.attach_defaults(self.spin_upload, 1, 2, 1, 2) - label = gtk.Label(_('Active Torrents:')) + label = Gtk.Label(_('Active Torrents:')) label.set_alignment(0.0, 0.6) - table.attach(label, 2, 3, 0, 1, gtk.FILL) - self.spin_active = gtk.SpinButton() + table.attach_defaults(label, 0, 1, 2, 3) + self.spin_active = Gtk.SpinButton() self.spin_active.set_numeric(True) self.spin_active.set_range(-1, 9999) self.spin_active.set_increments(1, 10) - table.attach(self.spin_active, 3, 4, 0, 1, gtk.FILL) + table.attach_defaults(self.spin_active, 1, 2, 2, 3) - label = gtk.Label(_('Active Downloading:')) + label = Gtk.Label(_('Active Downloading:')) label.set_alignment(0.0, 0.6) - table.attach(label, 2, 3, 1, 2, gtk.FILL) - self.spin_active_down = gtk.SpinButton() + table.attach_defaults(label, 0, 1, 3, 4) + self.spin_active_down = Gtk.SpinButton() self.spin_active_down.set_numeric(True) self.spin_active_down.set_range(-1, 9999) self.spin_active_down.set_increments(1, 10) - table.attach(self.spin_active_down, 3, 4, 1, 2, gtk.FILL) + table.attach_defaults(self.spin_active_down, 1, 2, 3, 4) - label = gtk.Label(_('Active Seeding:')) + label = Gtk.Label(_('Active Seeding:')) label.set_alignment(0.0, 0.6) - table.attach(label, 2, 3, 2, 3, gtk.FILL) - self.spin_active_up = gtk.SpinButton() + table.attach_defaults(label, 0, 1, 4, 5) + self.spin_active_up = Gtk.SpinButton() self.spin_active_up.set_numeric(True) self.spin_active_up.set_range(-1, 9999) self.spin_active_up.set_increments(1, 10) - table.attach(self.spin_active_up, 3, 4, 2, 3, gtk.FILL) + table.attach_defaults(self.spin_active_up, 1, 2, 4, 5) - eventbox = gtk.EventBox() - eventbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#EDD400')) + eventbox = Gtk.EventBox() eventbox.add(table) - frame = gtk.Frame() - label = gtk.Label() + frame = Gtk.Frame() + label = Gtk.Label() label.set_markup(_('Slow Settings')) + label.modify_bg(Gtk.StateFlags.NORMAL, Gdk.color_parse('#EDD400')) frame.set_label_widget(label) - frame.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#CDB400')) + frame.set_margin_left(15) frame.set_border_width(2) frame.add(eventbox) - vbox.pack_start(frame, False, False) + vbox.pack_start(frame, False, False, 0) vbox.show_all() component.get('Preferences').add_page(_('Scheduler'), vbox)