Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 420 lines (363 sloc) 16.076 kb
2108419 initial commit
Stephen Sugden authored
1 #!/usr/bin/python -d
2
b4ce749 Fix docstrings
Stephen Sugden authored
3 '''
c53265f Moved settings into dialog
Stephen Sugden authored
4 File: wrTc.py
b4ce749 Fix docstrings
Stephen Sugden authored
5 Author: Stephen Sugden (grncdr)
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
6 Description: This is a little app that connects to and monitors a remote
7 rTorrent via xmlrpc. It can also upload local torrent files to a
8 remote machine
b4ce749 Fix docstrings
Stephen Sugden authored
9 '''
2108419 initial commit
Stephen Sugden authored
10
614bc3b Use with statement again, get rid of a silly function
Stephen Sugden authored
11 from __future__ import with_statement
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
12 import os, sys, threading, wx, time, math
652aa00 eww
Stephen Sugden authored
13 from ObjectListView import ObjectListView, ColumnDefn
82ef0cf Remove SettingsManager from main script
Stephen Sugden authored
14 from settings_manager import SettingsManager
754761a oh dear god
Stephen Sugden authored
15 import xmlrpcdaemon
16 from xmlrpclib import Binary
4624cb6 Added Callbacks to ListCtrl
Stephen Sugden authored
17 from multiqueue import MultiQueue
18
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
19 APP_NAME = 'wrTc'
20 WRTC_OSX = hasattr(os, 'uname') and (os.uname()[0] == 'Darwin')
21 VIEW_LIST = ["incomplete", "seeding", "stopped"]
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
22 MAX_REFRESH_CYCLE = 30
c53265f Moved settings into dialog
Stephen Sugden authored
23
652aa00 eww
Stephen Sugden authored
24 def format_bytes(bytes):
cd3dbee More doc strings, generalizing the SettingsManager class a bit
Stephen Sugden authored
25 ''' prettifies sizes given in bytes '''
8c447c7 Improved formatters
Stephen Sugden authored
26 units = ("B", "KB", "MB", "GB", "TB")
4624cb6 Added Callbacks to ListCtrl
Stephen Sugden authored
27 bytes = float(bytes)
8c447c7 Improved formatters
Stephen Sugden authored
28 for unit in units:
5dd376c switch to deque, some 2.5 fixes, and a lot of other weird changes
Stephen Sugden authored
29 if abs(bytes) < 1024:
4624cb6 Added Callbacks to ListCtrl
Stephen Sugden authored
30 break
8c447c7 Improved formatters
Stephen Sugden authored
31 bytes /= 1024
32 return str(round(bytes,2))+unit
2108419 initial commit
Stephen Sugden authored
33
d95b37a Add 'speed' formatter
Stephen Sugden authored
34 def format_speed(bytes):
35 return format_bytes(bytes)+"/S"
36
9f06f0b Removed rTorrent specific bits from rTDaemon and renamed to XMLRPCDaemon
Stephen Sugden authored
37 def make_hash(tdata):
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
38 ''' Create an infohash for the given torrent data '''
9f06f0b Removed rTorrent specific bits from rTDaemon and renamed to XMLRPCDaemon
Stephen Sugden authored
39 from bencode import bdecode, bencode
40 from hashlib import sha1
41 return sha1(bencode(bdecode(tdata)['info'])).hexdigest().upper()
42
620d688 Some OSX compatibility
Stephen Sugden authored
43 class wrtcApp(wx.App):
44 def __init__(self, *args, **kwargs):
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
45 def settings_save_callback(*args, **kwargs):
fd77cee Rename settings_manager to cfg
Stephen Sugden authored
46 self.rtorrent.open(self.cfg.get("DEFAULT",'rTorrent URL'))
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
47
fd77cee Rename settings_manager to cfg
Stephen Sugden authored
48 self.cfg = SettingsManager(APP_NAME+'.cfg', {
cd3dbee More doc strings, generalizing the SettingsManager class a bit
Stephen Sugden authored
49 'rtorrent url': 'http://localhost/RPC2',
50 'remote root': '/'
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
51 }, settings_save_callback)
52
53 self.rtorrent = xmlrpcdaemon.XMLRPCDaemon( # Can't shorten this one!
fd77cee Rename settings_manager to cfg
Stephen Sugden authored
54 self.cfg.get("rTorrent URL"))
754761a oh dear god
Stephen Sugden authored
55 self.rtorrent.start()
620d688 Some OSX compatibility
Stephen Sugden authored
56 wx.App.__init__(self, *args, **kwargs)
754761a oh dear god
Stephen Sugden authored
57 self.updater = UpdateScheduler(self)
58 self.updater.start()
620d688 Some OSX compatibility
Stephen Sugden authored
59 self.Bind(wx.EVT_ACTIVATE_APP, self.activate)
60
61 def OnInit(self):
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
62 self.frame = MainWindow(None, wx.ID_ANY,
63 APP_NAME+" - wxPython rTorrent client")
620d688 Some OSX compatibility
Stephen Sugden authored
64 self.frame.Show()
83ad54a Squish all bugs
Stephen Sugden authored
65 if len(sys.argv) > 1 and os.path.isfile(sys.argv[1]):
66 self.load_torrent(filename=sys.argv[1])
620d688 Some OSX compatibility
Stephen Sugden authored
67 return True
68
69 def raise_frame(self):
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
70 try: self.frame.Raise()
71 except: pass
620d688 Some OSX compatibility
Stephen Sugden authored
72
73 def activate(self, evt):
74 if evt.GetActive():
75 self.raise_frame()
76 evt.Skip()
77
78 def MacOpenFile(self, filename):
0350e1a Rewriting to move a lot of stuff into the new App class
Stephen Sugden authored
79 self.load_torrent(filename=filename)
620d688 Some OSX compatibility
Stephen Sugden authored
80
83ad54a Squish all bugs
Stephen Sugden authored
81 def MacReopenApp(self, *args, **kwargs):
620d688 Some OSX compatibility
Stephen Sugden authored
82 self.raise_frame()
83
0350e1a Rewriting to move a lot of stuff into the new App class
Stephen Sugden authored
84 def load_torrent(self,e=None,filename=None):
fd77cee Rename settings_manager to cfg
Stephen Sugden authored
85 dlg = LoadTorrentDialog(self.cfg.get('remote root'))
0350e1a Rewriting to move a lot of stuff into the new App class
Stephen Sugden authored
86 if filename:
87 dlg.filepath.SetValue(filename)
88 if dlg.ShowModal() == wx.ID_OK:
89 self.send_torrent(dlg)
90 dlg.Destroy()
620d688 Some OSX compatibility
Stephen Sugden authored
91
0350e1a Rewriting to move a lot of stuff into the new App class
Stephen Sugden authored
92 def send_torrent(self, dlg):
93 start = dlg.start_immediate.GetValue()
94 dest = dlg.browser.GetPyData(dlg.browser.GetSelection())['path']
95 if dlg.filepath.GetValue() != '':
96 torrent_file = open(dlg.filepath.GetValue(),'rb')
97 elif dlg.url.GetValue() != '':
98 import urllib2
99 torrent_file = urllib2.urlopen(dlg.url.GetValue())
100 torrent_data = torrent_file.read()
101 torrent_file.close()
102 infohash = make_hash(torrent_data)
83ad54a Squish all bugs
Stephen Sugden authored
103 torrent_data = Binary(torrent_data)
0350e1a Rewriting to move a lot of stuff into the new App class
Stephen Sugden authored
104 def dest_callback(rv):
105 def start_callback(rv):
106 if start:
754761a oh dear god
Stephen Sugden authored
107 self.rtorrent.put(('d.start', infohash))
108 self.rtorrent.put(('d.set_directory', (infohash, dest),
0350e1a Rewriting to move a lot of stuff into the new App class
Stephen Sugden authored
109 start_callback))
754761a oh dear god
Stephen Sugden authored
110 self.rtorrent.put(('load_raw', torrent_data, dest_callback))
620d688 Some OSX compatibility
Stephen Sugden authored
111
3b4307a refactoring and attempting to add filename argument support
Stephen Sugden authored
112 class MainWindow(wx.Frame):
dc594c7 Lots of little fixes, one new feature
Stephen Sugden authored
113 def __init__(self, parent, id, title):
3b4307a refactoring and attempting to add filename argument support
Stephen Sugden authored
114 wx.Frame.__init__(self, parent, id, title, size=(600,600))
c53265f Moved settings into dialog
Stephen Sugden authored
115
116 self.menu_bar = wx.MenuBar()
dc594c7 Lots of little fixes, one new feature
Stephen Sugden authored
117
118 self.file_menu = wx.Menu()
119 self.file_menu.Append(wx.ID_OPEN, "Add &Torrent")
0350e1a Rewriting to move a lot of stuff into the new App class
Stephen Sugden authored
120 self.Bind(wx.EVT_MENU, wx.GetApp().load_torrent, id=wx.ID_OPEN)
dc594c7 Lots of little fixes, one new feature
Stephen Sugden authored
121 self.file_menu.Append(wx.ID_PREFERENCES, "&Preferences")
fd77cee Rename settings_manager to cfg
Stephen Sugden authored
122 self.Bind(wx.EVT_MENU, wx.GetApp().cfg.show_dialog,
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
123 id=wx.ID_PREFERENCES)
dc594c7 Lots of little fixes, one new feature
Stephen Sugden authored
124 self.file_menu.Append(wx.ID_EXIT, "&Quit")
e882c9f Fixing torrent loading
Stephen Sugden authored
125 self.Bind(wx.EVT_MENU, self.on_exit, id=wx.ID_EXIT)
dc594c7 Lots of little fixes, one new feature
Stephen Sugden authored
126 self.menu_bar.Append(self.file_menu, "&File")
b8231c0 Removed silly buttons and put them in a menu
Stephen Sugden authored
127
c53265f Moved settings into dialog
Stephen Sugden authored
128 self.help_menu = wx.Menu()
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
129 self.help_menu.Append(wx.ID_ABOUT, "&About "+APP_NAME)
dc594c7 Lots of little fixes, one new feature
Stephen Sugden authored
130 self.Bind(wx.EVT_MENU, self.on_about_request, id=wx.ID_ABOUT)
c53265f Moved settings into dialog
Stephen Sugden authored
131 self.menu_bar.Append(self.help_menu, "&Help")
b8231c0 Removed silly buttons and put them in a menu
Stephen Sugden authored
132
c53265f Moved settings into dialog
Stephen Sugden authored
133 self.SetMenuBar(self.menu_bar)
134
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
135 self.notebook = rTorrentNotebook(self, VIEW_LIST)
40ddcfe Got rid of most global names
Stephen Sugden authored
136 main_sizer = wx.BoxSizer(wx.VERTICAL)
7d19f15 Settings saving/loading should be working now.
Stephen Sugden authored
137 main_sizer.Add(self.notebook, 1, wx.EXPAND | wx.ALL, 10)
40ddcfe Got rid of most global names
Stephen Sugden authored
138 self.SetSizer(main_sizer)
0350e1a Rewriting to move a lot of stuff into the new App class
Stephen Sugden authored
139 self.Bind(wx.EVT_CLOSE, self.on_exit)
e882c9f Fixing torrent loading
Stephen Sugden authored
140 # Icons = {}
141 # Icons['play'] = wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD, wx.ART_TOOLBAR)
142 # Icons['pause'] = wx.ArtProvider.GetBitmap(wx.ART_CROSS_MARK, wx.ART_TOOLBAR)
143 # Icons['add'] = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR)
144 # Icons['remove'] = wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_FRAME_ICON)
145 # ControlIcons = (Icons['play'], Icons['pause'])
01cf130 Settings saving/loading via dialog now works
Stephen Sugden authored
146
c53265f Moved settings into dialog
Stephen Sugden authored
147 def on_about_request(self, evt):
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
148 dlg = wx.MessageDialog(self, "wxPython rTorrent client", APP_NAME,
149 wx.OK | wx.ICON_INFORMATION)
c53265f Moved settings into dialog
Stephen Sugden authored
150 dlg.ShowModal()
151
cc7550f Stop threads before destroying SWIG objects
Stephen Sugden authored
152 def on_exit(self,e):
754761a oh dear god
Stephen Sugden authored
153 wx.GetApp().updater.proceed = False
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
154 wx.GetApp().rtorrent.proceed = False
cc7550f Stop threads before destroying SWIG objects
Stephen Sugden authored
155 self.Show(False)
754761a oh dear god
Stephen Sugden authored
156 wx.GetApp().updater.join()
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
157 wx.GetApp().rtorrent.join()
2108419 initial commit
Stephen Sugden authored
158 self.Destroy()
159
160
754761a oh dear god
Stephen Sugden authored
161 class rTorrentNotebook(wx.Notebook):
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
162 def __init__(self, parent, views, *args, **kwargs):
b090ed2 All globals should be gone now
Stephen Sugden authored
163 wx.Notebook.__init__(self, parent, *args, **kwargs)
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
164 self.load_views(views)
5dd376c switch to deque, some 2.5 fixes, and a lot of other weird changes
Stephen Sugden authored
165 self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.page_changed)
2108419 initial commit
Stephen Sugden authored
166
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
167 def load_views(self, views):
168 for view in views:
0619096 Renamed ViewPanel to rTorrentView
Stephen Sugden authored
169 self.AddPage(rTorrentView(self, view), view.capitalize());
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
170 self.GetCurrentPage().get_list()
2108419 initial commit
Stephen Sugden authored
171
3173cdd getting rid of long lines, removing old cruft from settings dialog, some...
Stephen Sugden authored
172 def page_changed(self, evt):
754761a oh dear god
Stephen Sugden authored
173 self.GetPage(evt.GetSelection()).get_list()
3173cdd getting rid of long lines, removing old cruft from settings dialog, some...
Stephen Sugden authored
174 evt.Skip()
81333f8 Added support for command line torrent loading
Stephen Sugden authored
175
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
176 class rTorrentView(wx.NotebookPage):
177 _columns = [
178 ColumnDefn("Name", valueGetter="name", isSpaceFilling=True,
179 minimumWidth=100, maximumWidth=300),
d95b37a Add 'speed' formatter
Stephen Sugden authored
180 ColumnDefn("Up", "right", 70, "up_rate", stringConverter=format_speed),
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
181 ColumnDefn("Down", "right", 70, "down_rate",
d95b37a Add 'speed' formatter
Stephen Sugden authored
182 stringConverter=format_speed),
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
183 ColumnDefn("Size", "right", 70, "size_bytes",
184 stringConverter=format_bytes),
185 ColumnDefn("Up Total", "right", 80, "up_total",
186 stringConverter=format_bytes),
187 ColumnDefn("Down Total", "right", 80, "bytes_done",
188 stringConverter=format_bytes),
189 ColumnDefn("Ratio", "right", fixedWidth=40, valueGetter="ratio",
190 stringConverter="%s%%"),
191 #ColumnDefn("S", "center", 25, "peers_complete"),
192 #ColumnDefn("P", "center", 25, "peers_accounted"),
51b1874 Removed custom controls, moved over to a list control
Stephen Sugden authored
193 ]
2108419 initial commit
Stephen Sugden authored
194 def __init__(self, parent, title="default"):
195 self.title = title
652aa00 eww
Stephen Sugden authored
196 self.torrents = []
e02f2bb Setting frequency of updates now possible
Stephen Sugden authored
197 self.joblist = MultiQueue()
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
198 wx.NotebookPage.__init__(self, parent)
199
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
200 self.olv = ObjectListView(self, style=wx.LC_REPORT)
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
201 self.olv.SetEmptyListMsg("No torrents")
202 self.olv.SetColumns(self._columns)
ff3d6c9 Fix scaling for total down/up. Add __setitem__ to Torrent class
Stephen Sugden authored
203 self.joblist.put(2, ("download_list", self.title, self.set_list))
e02f2bb Setting frequency of updates now possible
Stephen Sugden authored
204
205 def __repr__(self):
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
206 return "<rTorrentView '%s'>" % self.title.capitalize()
653e7f3 fix configuration bootstrap fail, start adding some doc strings
Stephen Sugden authored
207
754761a oh dear god
Stephen Sugden authored
208 def get_list(self):
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
209 ''' Clear the queue and update the current page.
210 Called on page change '''
754761a oh dear god
Stephen Sugden authored
211 self.joblist.put(0, ("download_list", self.title, self.set_list))
51b1874 Removed custom controls, moved over to a list control
Stephen Sugden authored
212
213 def set_list(self, hashlist):
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
214 ''' Given a list of infohashes, add and remove torrents
215 from the torrents list as necessary '''
216 self.torrents = [self.find_torrent(ih) for ih in hashlist]
0a429ee Split a long line
Stephen Sugden authored
217 self.olv.AddObjects(filter(lambda to: to not in self.olv.GetObjects(),
218 self.torrents))
4470e6c Remove non-existant torrents from the view in set_list, update check for...
Stephen Sugden authored
219 self.olv.RemoveObjects(filter(lambda to: to not in self.torrents,
220 self.olv.GetObjects()))
40ddcfe Got rid of most global names
Stephen Sugden authored
221
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
222 def find_torrent(self, infohash):
223 for t in self.torrents:
224 if t.infohash == infohash:
225 return t
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
226 # else make a new torrent object
227 t = Torrent(self, infohash)
228 for k in t.properties:
229 self.joblist.put(t.properties[k][2], t.properties[k][1])
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
230 return t
4624cb6 Added Callbacks to ListCtrl
Stephen Sugden authored
231
40ddcfe Got rid of most global names
Stephen Sugden authored
232 def on_erase(self, e):
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
233 dlg = wx.MessageDialog(self, "Remove this torrent?", "Delete torrent",
234 wx.OK | wx.CANCEL | wx.ICON_QUESTION)
2108419 initial commit
Stephen Sugden authored
235 if dlg.ShowModal() == wx.ID_OK:
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
236 print 'on_erase Not implemented'
2108419 initial commit
Stephen Sugden authored
237 dlg.Destroy()
238
652aa00 eww
Stephen Sugden authored
239 class Torrent(object):
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
240 def __init__(self, view, infohash):
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
241 self.view = view
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
242 self.infohash = infohash
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
243 self.dirty = False
244 self.properties = {
245 # 'property': [default_value, job_tuple, frequency]
246 'name': ["Loading torrent data...", None, 0],
247 'up_rate': [0, None, 0],
248 'down_rate': [0, None, 0],
249 'ratio': [0, None, 0],
250 'size_bytes': [0, None, 0],
251 'bytes_done': [0, None, 0],
252 'up_total': [0, None, 0],
253 }
254 for k in self.properties:
255 self.properties[k][1] = self.job(k)
256
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
257 # Don't update these properties after getting them initially
258 self.static = ['name', 'size_bytes']
259 self.new = True # Set to false when torrent is first refreshed
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
260 if view.title == 'stopped':
261 self.static.extend(self.properties.keys())
262 elif view.title == 'seeding':
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
263 self.static.append('down_rate')
264
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
265 def __getitem__(self, k):
266 """ We stick this in so that ObjectListView thinks it's got a normal dictionary """
267 if k in self.properties:
ff3d6c9 Fix scaling for total down/up. Add __setitem__ to Torrent class
Stephen Sugden authored
268 return self.properties[k][0]
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
269 else:
270 raise KeyError(k)
271
ff3d6c9 Fix scaling for total down/up. Add __setitem__ to Torrent class
Stephen Sugden authored
272 def __setitem__(self, k, v):
273 if k in self.properties:
ca22758 Fix Torrent.__setitem__
Stephen Sugden authored
274 self.properties[k][0] = v
ff3d6c9 Fix scaling for total down/up. Add __setitem__ to Torrent class
Stephen Sugden authored
275 else:
276 raise KeyError(k)
277
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
278 def job(self, key):
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
279 if not self.properties[key][1]:
280 self.properties[key][1] = ("d.get_"+key, self.infohash, self.callback(key))
281 return self.properties[key][1]
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
282
283 def callback(self, key):
284 def callback(rv):
7f49525 Use the self[] indexing notation inside Torrent class
Stephen Sugden authored
285 oldvalue = self[key]
286 self[key] = rv
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
287 self.dirty, self.new = True, False
288 f = self.new_frequency(key, rv, oldvalue)
289 if f:
290 self.view.joblist.move(self.properties[key][1], f)
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
291 return callback
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
292
293 def new_frequency(self, key, new, old):
294 """calculates the frequency at which the given key should be updated"""
295 if key in self.static:
296 return False # do not update this key again
297 old_frequency = self.properties[key][2]
298 if key[-4:] == "rate":
299 if new == 0: # No transfer happening
300 if old_frequency: # not the first time we've updated
301 # slow things down
79418a9 Fixing bugs in UpdateScheduler and Torrents refresh rate calculation
Stephen Sugden authored
302 return min(MAX_REFRESH_CYCLE, int(old_frequency * 1.3))
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
303 else:
304 return 5
305 else: # Transfer is happening, update more frequently
306 return 2
307 elif key == "bytes_done":
ff3d6c9 Fix scaling for total down/up. Add __setitem__ to Torrent class
Stephen Sugden authored
308 if self["down_rate"] > 0: # this torrent is transferring data
309 # How long we estimate it will take for a visible 0.01 increase
310 rate = max(1, int((1024**int(math.log(new, 1024)) / 10) / self["down_rate"]))
311 return rate
312 return 10
313 elif key == "up_total":
314 if self["up_rate"] > 0: # this torrent is transferring data
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
315 # How long we estimate it will take for a visible 0.01 increase
ff3d6c9 Fix scaling for total down/up. Add __setitem__ to Torrent class
Stephen Sugden authored
316 rate = max(1, int((1024**int(math.log(new, 1024)) / 10) / self["down_rate"]))
317 return rate
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
318 return 10
ff3d6c9 Fix scaling for total down/up. Add __setitem__ to Torrent class
Stephen Sugden authored
319 # Default for everything else
320 return 10
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
321
322 def __repr__(self):
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
323 return "<Torrent - %s>" % self.infohash
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
324
eb5d54f Set 'start on load' checkbox to checked by default
Stephen Sugden authored
325 def __eq__(self, other):
326 return (self.infohash == other.infohash)
652aa00 eww
Stephen Sugden authored
327
2108419 initial commit
Stephen Sugden authored
328 class UpdateScheduler(threading.Thread):
5dd376c switch to deque, some 2.5 fixes, and a lot of other weird changes
Stephen Sugden authored
329 ''' This thread reads the joblist for the current view,
330 and queues up jobs at an appropriate frequency '''
0350e1a Rewriting to move a lot of stuff into the new App class
Stephen Sugden authored
331 def __init__(self, app):
2108419 initial commit
Stephen Sugden authored
332 threading.Thread.__init__(self)
0350e1a Rewriting to move a lot of stuff into the new App class
Stephen Sugden authored
333 self.notebook = app.frame.notebook
754761a oh dear god
Stephen Sugden authored
334 self.rtorrent = app.rtorrent
cc7550f Stop threads before destroying SWIG objects
Stephen Sugden authored
335 self.proceed = True
2108419 initial commit
Stephen Sugden authored
336
337 def run(self):
cc7550f Stop threads before destroying SWIG objects
Stephen Sugden authored
338 while self.proceed:
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
339 page = self.notebook.GetCurrentPage()
ff3d6c9 Fix scaling for total down/up. Add __setitem__ to Torrent class
Stephen Sugden authored
340 now = int(time.time())
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
341 for i in page.joblist.keys():
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
342 if not i: # i == 0
53c80e2 Refresh Rate Scaling
Stephen Sugden authored
343 for job in page.joblist.get(i, clear=True):
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
344 self.rtorrent.put_first(job)
345 elif not (now % i):
ff3d6c9 Fix scaling for total down/up. Add __setitem__ to Torrent class
Stephen Sugden authored
346 jobs = page.joblist.get(i)
347 for job in jobs:
754761a oh dear god
Stephen Sugden authored
348 self.rtorrent.put(job)
79418a9 Fixing bugs in UpdateScheduler and Torrents refresh rate calculation
Stephen Sugden authored
349 for torrent in page.torrents:
350 if torrent.dirty:
351 page.olv.RefreshObject(torrent)
352 torrent.dirty = False
5dd376c switch to deque, some 2.5 fixes, and a lot of other weird changes
Stephen Sugden authored
353 time.sleep(1)
e02f2bb Setting frequency of updates now possible
Stephen Sugden authored
354
2108419 initial commit
Stephen Sugden authored
355 class LoadTorrentDialog(wx.Dialog):
cd3dbee More doc strings, generalizing the SettingsManager class a bit
Stephen Sugden authored
356 ''' Dialog that loads torrents from disk/URL '''
3173cdd getting rid of long lines, removing old cruft from settings dialog, some...
Stephen Sugden authored
357 def __init__(self, remote_root):
358 wx.Dialog.__init__(self, None, title="Load torrent", size=(400,400))
359 BORDER = 3
360 TEXT = wx.EXPAND|wx.ALL
361 LABEL = wx.ALIGN_CENTER_VERTICAL|wx.ALL
362 BUTTON = wx.ALIGN_RIGHT|wx.ALL
363
2108419 initial commit
Stephen Sugden authored
364 sizer = wx.BoxSizer(wx.VERTICAL)
365 self.SetSizer(sizer)
3173cdd getting rid of long lines, removing old cruft from settings dialog, some...
Stephen Sugden authored
366
2108419 initial commit
Stephen Sugden authored
367 file_sizer = wx.BoxSizer(wx.HORIZONTAL)
368 filepath_label = wx.StaticText(self, label="From file:")
3173cdd getting rid of long lines, removing old cruft from settings dialog, some...
Stephen Sugden authored
369 self.filepath = wx.TextCtrl(self, TEXT)
2108419 initial commit
Stephen Sugden authored
370 browse_button = wx.Button(self, label="Browse...")
7d9fdac move the torrent loading to MainWindow and callbacks work
Stephen Sugden authored
371 browse_button.Bind(wx.EVT_BUTTON, self.on_browse)
3173cdd getting rid of long lines, removing old cruft from settings dialog, some...
Stephen Sugden authored
372 file_sizer.Add(filepath_label, 0, LABEL, BORDER)
373 file_sizer.Add(self.filepath, 1, TEXT, BORDER)
374 file_sizer.Add(browse_button, 0, wx.ALL, BORDER)
375 sizer.Add(file_sizer, 0, wx.EXPAND)
2108419 initial commit
Stephen Sugden authored
376
377 url_sizer = wx.BoxSizer(wx.HORIZONTAL)
378 url_label = wx.StaticText(self, label="From URL:")
379 self.url = wx.TextCtrl(self)
3173cdd getting rid of long lines, removing old cruft from settings dialog, some...
Stephen Sugden authored
380 url_sizer.Add(url_label, 0, LABEL, BORDER)
381 url_sizer.Add(self.url, 1, TEXT, BORDER)
382 sizer.Add(url_sizer, 0, wx.EXPAND)
2108419 initial commit
Stephen Sugden authored
383
384 destpath_label = wx.StaticText(self, label="Save in:")
0458470 Remote filesystem browsing now implemented
Stephen Sugden authored
385 from browser import PathBrowser
3173cdd getting rid of long lines, removing old cruft from settings dialog, some...
Stephen Sugden authored
386 self.browser = PathBrowser(self, remote_root)
387 sizer.Add(destpath_label, 0, LABEL, BORDER)
388 sizer.Add(self.browser, 1, TEXT, BORDER)
3b4307a refactoring and attempting to add filename argument support
Stephen Sugden authored
389
2108419 initial commit
Stephen Sugden authored
390 start_sizer = wx.BoxSizer(wx.HORIZONTAL)
eb5d54f Set 'start on load' checkbox to checked by default
Stephen Sugden authored
391 self.start_immediate = wx.CheckBox(self, label="Start on load", )
392 self.start_immediate.SetValue(True)
3173cdd getting rid of long lines, removing old cruft from settings dialog, some...
Stephen Sugden authored
393 start_sizer.Add(self.start_immediate, 1, wx.ALL, BORDER)
2108419 initial commit
Stephen Sugden authored
394
395 buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
396 ok = wx.Button(self, id=wx.ID_OK)
397 cancel = wx.Button(self, id=wx.ID_CANCEL)
3173cdd getting rid of long lines, removing old cruft from settings dialog, some...
Stephen Sugden authored
398 buttons_sizer.Add(ok, 0, BUTTON, BORDER)
399 buttons_sizer.Add(cancel, 0, BUTTON, BORDER)
2108419 initial commit
Stephen Sugden authored
400
3173cdd getting rid of long lines, removing old cruft from settings dialog, some...
Stephen Sugden authored
401 sizer.Add(start_sizer, 0, wx.EXPAND)
402 sizer.Add(buttons_sizer, 0, wx.EXPAND)
2108419 initial commit
Stephen Sugden authored
403
7d9fdac move the torrent loading to MainWindow and callbacks work
Stephen Sugden authored
404 def on_browse(self,e):
b4ce749 Fix docstrings
Stephen Sugden authored
405 ''' Open a file'''
b473adf ObjectListView now working somewhat, need to figure out how/where to do ...
Stephen Sugden authored
406 dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "",
407 "*.torrent", wx.OPEN)
2108419 initial commit
Stephen Sugden authored
408 if dlg.ShowModal() == wx.ID_OK:
409 self.filename=dlg.GetFilename()
410 self.dirname=dlg.GetDirectory()
411 self.filepath.SetValue(self.dirname+"/"+self.filename)
412 dlg.Destroy()
413
e882c9f Fixing torrent loading
Stephen Sugden authored
414 if __name__ == "__main__":
0350e1a Rewriting to move a lot of stuff into the new App class
Stephen Sugden authored
415 app = wrtcApp(False)
cd3dbee More doc strings, generalizing the SettingsManager class a bit
Stephen Sugden authored
416 # Show configuration window on first run
4470e6c Remove non-existant torrents from the view in set_list, update check for...
Stephen Sugden authored
417 if not app.cfg.file_exists:
fd77cee Rename settings_manager to cfg
Stephen Sugden authored
418 app.cfg.show_dialog()
40ddcfe Got rid of most global names
Stephen Sugden authored
419 app.MainLoop()
Something went wrong with that request. Please try again.