[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 <calumlind+deluge@gmail.com>
This commit is contained in:
parent
c51e01ac46
commit
ed1b2a50fa
Binary file not shown.
Before Width: | Height: | Size: 792 B |
|
@ -0,0 +1 @@
|
|||
<?xml version="1.0" standalone="no"?><!-- Generator: Gravit.io --><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="isolation:isolate" viewBox="0 0 16 16" width="16" height="16"><defs><clipPath id="_clipPath_Ng8EWXQF95Gs7ywflmaKe8f73244LGgx"><rect width="16" height="16"/></clipPath></defs><g clip-path="url(#_clipPath_Ng8EWXQF95Gs7ywflmaKe8f73244LGgx)"><clipPath id="_clipPath_fEKXMbJwavdXcwSIsEYpsxFyYERCnK2c"><rect x="0" y="0" width="16" height="16" transform="matrix(1,0,0,1,0,0)" fill="rgb(255,255,255)"/></clipPath><g clip-path="url(#_clipPath_fEKXMbJwavdXcwSIsEYpsxFyYERCnK2c)"><g><g><radialGradient id="_rgradient_9" fx="0.5" fy="0.5" cx="0.5" cy="0.5" r="0.5" gradientTransform="matrix(12,0,0,12,1.5,1.5)" gradientUnits="userSpaceOnUse"><stop offset="0%" stop-opacity="1" style="stop-color:rgb(22,200,22)"/><stop offset="100%" stop-opacity="1" style="stop-color:rgb(22,200,22)"/></radialGradient><circle vector-effect="non-scaling-stroke" cx="7.5" cy="7.5" r="6" fill="url(#_rgradient_9)"/><path d=" M 7.5 0.013 C 3.37 0.013 0.013 3.37 0.013 7.5 C 0.013 11.63 3.37 14.987 7.5 14.987 C 11.63 14.987 14.987 11.63 14.987 7.5 C 14.987 3.37 11.63 0.013 7.5 0.013 Z M 7.5 1.987 C 10.549 1.987 13.013 4.451 13.013 7.5 C 13.013 10.549 10.549 13.013 7.5 13.013 C 4.451 13.013 1.987 10.549 1.987 7.5 C 1.987 4.451 4.451 1.987 7.5 1.987 Z " fill="rgb(18,155,0)"/><path d=" M 10.406 4 C 10.309 4.026 10.222 4.08 10.156 4.156 L 7.5 6.813 L 5.844 5.156 C 5.736 4.98 5.53 4.888 5.326 4.925 C 5.123 4.963 4.963 5.123 4.925 5.326 C 4.888 5.53 4.98 5.736 5.156 5.844 L 7.156 7.844 C 7.349 8.026 7.651 8.026 7.844 7.844 L 10.844 4.844 C 10.995 4.689 11.03 4.455 10.931 4.263 C 10.831 4.071 10.62 3.965 10.406 4 Z " fill="rgb(43,46,57)"/></g></g></g></g></svg>
|
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
Before Width: | Height: | Size: 759 B |
|
@ -0,0 +1 @@
|
|||
<?xml version="1.0" standalone="no"?><!-- Generator: Gravit.io --><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="isolation:isolate" viewBox="0 0 16 16" width="16" height="16"><defs><clipPath id="_clipPath_b9idtDkK5ON8Jka415AjKueNrp89rRRq"><rect width="16" height="16"/></clipPath></defs><g clip-path="url(#_clipPath_b9idtDkK5ON8Jka415AjKueNrp89rRRq)"><clipPath id="_clipPath_vxaOVU0QEXAkOxrpA9AlU4ChkMqnhw1h"><rect x="0" y="0" width="16" height="16" transform="matrix(1,0,0,1,0,0)" fill="rgb(255,255,255)"/></clipPath><g clip-path="url(#_clipPath_vxaOVU0QEXAkOxrpA9AlU4ChkMqnhw1h)"><g><g><g style="opacity:0.98;"><g opacity="0.98"><circle vector-effect="non-scaling-stroke" cx="7.5" cy="7.5" r="6" fill="rgb(230,56,31)"/></g></g><path d=" M 7.5 0.013 C 3.37 0.013 0.013 3.37 0.013 7.5 C 0.013 11.63 3.37 14.987 7.5 14.987 C 11.63 14.987 14.987 11.63 14.987 7.5 C 14.987 3.37 11.63 0.013 7.5 0.013 Z M 7.5 1.987 C 10.549 1.987 13.013 4.451 13.013 7.5 C 13.013 10.549 10.549 13.013 7.5 13.013 C 4.451 13.013 1.987 10.549 1.987 7.5 C 1.987 4.451 4.451 1.987 7.5 1.987 Z " fill="rgb(166,14,14)"/><path d=" M 10.406 4 C 10.309 4.026 10.222 4.08 10.156 4.156 L 7.5 6.813 L 5.844 5.156 C 5.736 4.98 5.53 4.888 5.326 4.925 C 5.123 4.963 4.963 5.123 4.925 5.326 C 4.888 5.53 4.98 5.736 5.156 5.844 L 7.156 7.844 C 7.349 8.026 7.651 8.026 7.844 7.844 L 10.844 4.844 C 10.995 4.689 11.03 4.455 10.931 4.263 C 10.831 4.071 10.62 3.965 10.406 4 Z " fill="rgb(43,46,57)"/></g></g></g></g></svg>
|
After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 770 B |
|
@ -0,0 +1 @@
|
|||
<?xml version="1.0" standalone="no"?><!-- Generator: Gravit.io --><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="isolation:isolate" viewBox="0 0 16 16" width="16" height="16"><defs><clipPath id="_clipPath_FTEVJ02JqQbaAkGq0zxCClZ8ovSf28LF"><rect width="16" height="16"/></clipPath></defs><g clip-path="url(#_clipPath_FTEVJ02JqQbaAkGq0zxCClZ8ovSf28LF)"><clipPath id="_clipPath_kMUc2qeZPnpfemB5VN1mID2bTbctQK6V"><rect x="0" y="0" width="16" height="16" transform="matrix(1,0,0,1,0,0)" fill="rgb(255,255,255)"/></clipPath><g clip-path="url(#_clipPath_kMUc2qeZPnpfemB5VN1mID2bTbctQK6V)"><g><clipPath id="_clipPath_O3gUc8WX8CfJdh8CMbdOfLtRtmBkIQPk"><rect x="0" y="0" width="16" height="16" transform="matrix(1,0,0,1,0,0)" fill="rgb(255,255,255)"/></clipPath><g clip-path="url(#_clipPath_O3gUc8WX8CfJdh8CMbdOfLtRtmBkIQPk)"><g><g><g><path d=" M 7.5 0.013 C 3.37 0.013 0.013 3.37 0.013 7.5 C 0.013 11.63 3.37 14.987 7.5 14.987 C 11.63 14.987 14.987 11.63 14.987 7.5 C 14.987 3.37 11.63 0.013 7.5 0.013 Z M 7.5 1.987 C 10.549 1.987 13.013 4.451 13.013 7.5 C 13.013 10.549 10.549 13.013 7.5 13.013 C 4.451 13.013 1.987 10.549 1.987 7.5 C 1.987 4.451 4.451 1.987 7.5 1.987 Z " fill="rgb(180,180,0)"/><g style="opacity:0.99;"><g style="opacity:0.99;"><g opacity="0.99"><circle vector-effect="non-scaling-stroke" cx="7.5" cy="7.5" r="6" fill="rgb(220,220,0)"/></g></g></g><path d=" M 10.406 4 C 10.309 4.026 10.222 4.08 10.156 4.156 L 7.5 6.813 L 5.844 5.156 C 5.736 4.98 5.53 4.888 5.326 4.925 C 5.123 4.963 4.963 5.123 4.925 5.326 C 4.888 5.53 4.98 5.736 5.156 5.844 L 7.156 7.844 C 7.349 8.026 7.651 8.026 7.844 7.844 L 10.844 4.844 C 10.995 4.689 11.03 4.455 10.931 4.263 C 10.831 4.071 10.62 3.965 10.406 4 Z " fill="rgb(43,46,57)"/></g></g></g></g></g></g></g></svg>
|
After Width: | Height: | Size: 1.8 KiB |
|
@ -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('<b>Schedule</b>')
|
||||
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(_('<b>Schedule</b>'))
|
||||
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(_('<b>Slow Settings</b>'))
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue