Ticket #97: scheduler_additional_prefs.patch
File scheduler_additional_prefs.patch, 12.3 KB (added by ben@…, 15 years ago) |
---|
-
plugins/Scheduler/plugin.py
diff --git a/plugins/Scheduler/plugin.py b/plugins/Scheduler/plugin.py index 869fe0f..c43bd28 100644
a b class plugin_Scheduler: 13 13 self.config = deluge.pref.Preferences() 14 14 self.button_state_temp = [[0] * 7 for dummy in xrange(24)] 15 15 self.status = -1 16 self.prevact = None17 16 18 17 #Load config 19 18 self.button_state = None 20 self.dllimit = self.ullimit = None 21 self.dlmax = self.ulmax = None 19 self.settings_structure = [["low_down", "max_download_speed", float], 20 ["low_up", "max_upload_speed", float], 21 ["high_down", "max_download_speed", float], 22 ["high_up", "max_upload_speed", float], 23 ["low_activetorrents", "max_active_torrents", float], 24 ["low_numslots", "max_upload_slots_global", float], 25 ["low_maxconns", "max_connections_global", float], 26 ["high_activetorrents", "max_active_torrents", float], 27 ["high_numslots", "max_upload_slots_global", float], 28 ["high_maxconns", "max_connections_global", float]] 29 30 self.settings = {} 31 22 32 try: 23 33 reader = open(self.conf_file, "rb") 24 34 data = pickle.load(reader) 35 25 36 self.button_state = data[0] 26 self.dllimit = float(data[1][0]) 27 self.ullimit = float(data[1][1]) 28 self.dlmax = float(data[1][2]) 29 self.ulmax = float(data[1][3]) 37 for i, item in enumerate(self.settings_structure): 38 self.settings[item[0]] = data[1][i] 39 30 40 reader.close() 31 41 except: 32 42 if self.button_state is None: 33 43 self.button_state = [[0] * 7 for dummy in xrange(24)] 34 gdl = self.config.get("max_download_speed") 35 gul = self.config.get("max_upload_speed") 36 if self.dllimit is None: 37 self.dllimit = float(gdl) 38 if self.ullimit is None: 39 self.ullimit = float(gul) 40 if self.dlmax is None: 41 self.dlmax = float(gdl) 42 if self.ulmax is None: 43 self.ulmax = float(gul) 44 45 for item in self.settings_structure: 46 if item[0] not in self.settings: 47 temp = self.config.get(item[1]) 48 49 if item[2] is not None: 50 temp = item[2](temp) 51 52 self.settings[item[0]] = temp 44 53 45 54 now = time.localtime(time.time()) 46 55 self.status = self.button_state[now[3]][now[6]] … … class plugin_Scheduler: 48 57 49 58 # Force speed changes when the plugin loads 50 59 self._state(self.status) 51 60 52 61 def unload(self): 53 62 self.status = -1 54 self.resume()55 63 self.unlimit() 56 64 57 def _state(self, state):65 def _state(self, state): 58 66 if state == 0: 59 67 self.unlimit() 60 68 elif state == 1: 61 69 self.limit() 62 70 elif state == 2: 63 71 self.pause() 64 # If we're moving from paused 65 if state < 2 and self.status == 2: 66 self.resume() 67 self.status = state 72 68 73 # Update the settings 69 self. interface.apply_prefs()74 self.status = state 70 75 71 76 def update(self): 72 77 # Only do stuff if the status is valid … … class plugin_Scheduler: 80 85 self._state(self.button_state[now[3]][now[6]]) 81 86 82 87 def pause(self): 83 self.prevact = self.config.get("max_active_torrents")84 88 self.config.set("max_active_torrents", 0) 85 self.core.apply_queue()86 87 def resume(self):88 if self.prevact != None:89 self.config.set("max_active_torrents", self.prevact)90 self.core.apply_queue()91 89 92 90 def limit(self): 93 self.config.set("max_download_speed", float(self.dllimit)) 94 self.config.set("max_upload_speed", float(self.ullimit)) 91 self.apply_configuration("low") 95 92 96 93 def unlimit(self): 97 self.config.set("max_download_speed", float(self.dlmax)) 98 self.config.set("max_upload_speed", float(self.ulmax)) 94 self.apply_configuration("high") 99 95 96 def apply_configuration(self, type): 97 for item in self.settings_structure: 98 if item[0].find(type) == 0: 99 self.config.set(item[1], self.settings[item[0]]) 100 101 self.core.apply_queue() 102 self.interface.apply_prefs() 103 100 104 #Configuration dialog 101 105 def configure(self, window): 102 106 global scheduler_select 103 107 104 108 self.button_state_temp = copy.deepcopy(self.button_state) 105 109 110 #data 111 spin = {} 112 boxen = [ 113 ["down", _("Download limit:"), -1, 2048], 114 ["up", _("Upload limit:"), -1, 1024], 115 ["activetorrents", _("Active torrents:"), 0, 128], 116 ["numslots", _("Upload Slots:"), 0, 128], 117 ["maxconns", _("Max Connections:"), 0, 1024]] 118 106 119 #dialog 107 120 dialog = gtk.Dialog(_("Scheduler Settings")) 108 121 dialog.set_default_size(600, 270) … … class plugin_Scheduler: 114 127 #text 115 128 hover_text = gtk.Label() 116 129 117 dlmax_label = gtk.Label(_("High download limit:"))118 ulmax_label = gtk.Label(_("High upload limit:"))119 dllimit_label = gtk.Label(_("Low download limit:"))120 ullimit_label = gtk.Label(_("Low upload limit:"))121 122 130 #Select Widget 123 131 drawing = scheduler_select(self.button_state_temp, hover_text, self.days) 124 132 … … class plugin_Scheduler: 128 136 vbox_sub = gtk.VBox() 129 137 hbox_key = gtk.HBox() 130 138 hbox_info = gtk.HBox() 131 # max boxen 132 hbox_max = gtk.HBox() 133 ebox_max = gtk.EventBox() 134 ebox_max.add(hbox_max) 135 ebrd_max = gtk.Frame() 136 ebrd_max.add(ebox_max) 137 ebrd_max.set_border_width(2) 138 hbox_max.set_border_width(2) 139 ebox_max.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse("#73D716")) 140 ebrd_max.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse("#53B700")) 141 # limit boxen 142 hbox_limit = gtk.HBox() 143 ebox_limit = gtk.EventBox() 144 ebox_limit.add(hbox_limit) 145 ebrd_limit = gtk.Frame() 146 ebrd_limit.add(ebox_limit) 147 ebrd_limit.set_border_width(2) 148 hbox_limit.set_border_width(2) 139 hbox_settings = gtk.HBox() 140 # high boxen 141 tbl_high = gtk.Table(len(boxen), 2) 142 ebox_high = gtk.EventBox() 143 ebox_high.add(tbl_high) 144 ebrd_high = gtk.Frame() 145 ebrd_high.add(ebox_high) 146 ebrd_high.set_border_width(2) 147 tbl_high.set_border_width(2) 148 ebox_high.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse("#73D716")) 149 ebrd_high.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse("#53B700")) 150 # low boxen 151 tbl_low = gtk.Table(len(boxen), 2) 152 ebox_low = gtk.EventBox() 153 ebox_low.add(tbl_low) 154 ebrd_low = gtk.Frame() 155 ebrd_low.add(ebox_low) 156 ebrd_low.set_border_width(2) 157 tbl_low.set_border_width(2) 149 158 # Green 150 159 # Yellow 151 ebox_l imit.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse("#EDD400"))152 ebrd_l imit.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse("#CDB400"))160 ebox_low.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse("#EDD400")) 161 ebrd_low.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse("#CDB400")) 153 162 154 163 #seperator 155 164 sep = gtk.HSeparator() 156 157 # max spinbuttons 158 dminput = gtk.SpinButton() 159 dminput.set_numeric(True) 160 dminput.set_range(-1, 2048) 161 dminput.set_increments(1, 10) 162 dminput.set_value(float(self.dlmax)) 163 uminput = gtk.SpinButton() 164 uminput.set_numeric(True) 165 uminput.set_range(-1, 1024) 166 uminput.set_increments(1, 10) 167 uminput.set_value(float(self.ulmax)) 168 169 # limit spinbuttons 170 dlinput = gtk.SpinButton() 171 dlinput.set_numeric(True) 172 dlinput.set_range(-1, 2048) 173 dlinput.set_increments(1, 10) 174 dlinput.set_value(float(self.dllimit)) 175 ulinput = gtk.SpinButton() 176 ulinput.set_numeric(True) 177 ulinput.set_range(-1, 1024) 178 ulinput.set_increments(1, 10) 179 ulinput.set_value(float(self.ullimit)) 180 165 181 166 #pack 182 167 dialog.vbox.pack_start(vbox_main) 183 168 … … class plugin_Scheduler: 186 171 vbox_main.pack_start(hbox_key, False, True) 187 172 vbox_main.pack_start(hbox_info, False, True) 188 173 vbox_main.pack_start(sep, False, True) 189 vbox_main.pack_start(ebrd_max, False, True, 5) 190 vbox_main.pack_start(ebrd_limit, False, True, 5) 174 vbox_main.pack_start(hbox_settings) 191 175 192 176 hbox_main.pack_start(vbox_sub, False, True, 5) 193 177 hbox_main.pack_start(drawing) 194 178 195 179 hbox_key.pack_start(gtk.Label(_("Green is the high limits, yellow is the low limits and red is stopped")), True, False) 196 180 hbox_info.pack_start(gtk.Label(_("If a limit is set to -1, it is unlimitted.")), True, False) 197 198 hbox_max.pack_start(dlmax_label, True, False) 199 hbox_max.pack_start(dminput, True, False) 200 hbox_max.pack_start(ulmax_label, True, False) 201 hbox_max.pack_start(uminput, True, False) 202 203 hbox_limit.pack_start(dllimit_label, True, False) 204 hbox_limit.pack_start(dlinput, True, False) 205 hbox_limit.pack_start(ullimit_label, True, False) 206 hbox_limit.pack_start(ulinput, True, False) 181 182 hbox_settings.pack_start(ebrd_high, True, True, 5) 183 hbox_settings.pack_start(gtk.Label()) 184 hbox_settings.pack_start(ebrd_low, True, True, 5) 185 186 for box in [tbl_high, tbl_low]: 187 for y, val in enumerate(boxen): 188 if box is tbl_high: type = "high" 189 else: type = "low" 190 key = type + "_" + val[0] 191 192 label = gtk.Label(val[1]) 193 label.set_alignment(0.0, 0.6) 194 spin[key] = gtk.SpinButton() 195 spin[key].set_numeric(True) 196 spin[key].set_range(val[2], val[3]) 197 spin[key].set_increments(1, 10) 198 spin[key].set_value(self.settings[key]) 199 200 box.attach(label, 0, 1, y, y + 1) 201 box.attach(spin[key], 1, 2, y, y + 1, False, False) 207 202 208 203 for index in xrange(len(self.days)): 209 204 vbox_sub.pack_start(gtk.Label(self.days[index])) … … class plugin_Scheduler: 219 214 self.button_state = copy.deepcopy(drawing.button_state) 220 215 changed = True 221 216 222 if not self.dlmax == float(dminput.get_value()): 223 self.dlmax = float(dminput.get_value()) 224 changed = True 225 226 if not self.ulmax == float(uminput.get_value()): 227 self.ulmax = float(uminput.get_value()) 228 changed = True 229 230 if not self.dllimit == float(dlinput.get_value()): 231 self.dllimit = float(dlinput.get_value()) 232 changed = True 233 234 if not self.ullimit == float(ulinput.get_value()): 235 self.ullimit = float(ulinput.get_value()) 236 changed = True 217 for key in spin.keys(): 218 if not self.settings[key] == spin[key].get_value(): 219 self.settings[key] = spin[key].get_value() 220 changed = True 237 221 238 222 now = time.localtime(time.time()) 239 223 if changed: 240 224 self._state(self.button_state[now[3]][now[6]]) 241 225 242 226 writer = open(self.conf_file, "wb") 243 pickle.dump([drawing.button_state,[self.dllimit, self.ullimit, self.dlmax, self.ulmax]], writer) 227 228 out = [] 229 230 for item in self.settings_structure: 231 out.append(self.settings[item[0]]) 232 233 pickle.dump([drawing.button_state, out], writer) 244 234 writer.close() 245 235 246 236 dialog.destroy() 247 237 248 238 class scheduler_select(gtk.DrawingArea):