mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-03 07:03:39 +00:00
Merge branch 'master' of deluge-torrent.org:deluge
This commit is contained in:
commit
6694ac7a58
@ -418,10 +418,13 @@ class AllTorrents(BaseMode, component.Component):
|
||||
|
||||
|
||||
def show_torrent_details(self,tid):
|
||||
component.stop(["AllTorrents"])
|
||||
def dodeets(arg):
|
||||
if arg and True in arg[0]:
|
||||
self.stdscr.clear()
|
||||
td = TorrentDetail(self,tid,self.stdscr,self.encoding)
|
||||
component.get("ConsoleUI").set_mode(td)
|
||||
component.get("ConsoleUI").set_mode(TorrentDetail(self,tid,self.stdscr,self.encoding))
|
||||
else:
|
||||
self.messages.append(("Error","An error occured trying to display torrent details"))
|
||||
component.stop(["AllTorrents"]).addCallback(dodeets)
|
||||
|
||||
def show_preferences(self):
|
||||
def _on_get_config(config):
|
||||
@ -431,28 +434,38 @@ class AllTorrents(BaseMode, component.Component):
|
||||
client.core.get_cache_status().addCallback(_on_get_cache_status,port,config)
|
||||
|
||||
def _on_get_cache_status(status,port,config):
|
||||
component.stop(["AllTorrents"])
|
||||
def doprefs(arg):
|
||||
if arg and True in arg[0]:
|
||||
self.stdscr.clear()
|
||||
prefs = Preferences(self,config,self.config,port,status,self.stdscr,self.encoding)
|
||||
component.get("ConsoleUI").set_mode(prefs)
|
||||
component.get("ConsoleUI").set_mode(Preferences(self,config,self.config,port,status,self.stdscr,self.encoding))
|
||||
else:
|
||||
self.messages.append(("Error","An error occured trying to display preferences"))
|
||||
component.stop(["AllTorrents"]).addCallback(doprefs)
|
||||
|
||||
client.core.get_config().addCallback(_on_get_config)
|
||||
|
||||
|
||||
def __show_events(self):
|
||||
component.stop(["AllTorrents"])
|
||||
def doevents(arg):
|
||||
if arg and True in arg[0]:
|
||||
self.stdscr.clear()
|
||||
ev = EventView(self,self.stdscr,self.encoding)
|
||||
component.get("ConsoleUI").set_mode(ev)
|
||||
component.get("ConsoleUI").set_mode(EventView(self,self.stdscr,self.encoding))
|
||||
else:
|
||||
self.messages.append(("Error","An error occured trying to display events"))
|
||||
component.stop(["AllTorrents"]).addCallback(doevents)
|
||||
|
||||
def __legacy_mode(self):
|
||||
component.stop(["AllTorrents"])
|
||||
def dolegacy(arg):
|
||||
if arg and True in arg[0]:
|
||||
self.stdscr.clear()
|
||||
if not self.legacy_mode:
|
||||
self.legacy_mode = Legacy(self.stdscr,self.encoding)
|
||||
component.get("ConsoleUI").set_mode(self.legacy_mode)
|
||||
self.legacy_mode.refresh()
|
||||
curses.curs_set(2)
|
||||
else:
|
||||
self.messages.append(("Error","An error occured trying to switch to legacy mode"))
|
||||
component.stop(["AllTorrents"]).addCallback(dolegacy)
|
||||
|
||||
def _torrent_filter(self, idx, data):
|
||||
if data==FILTER.ALL:
|
||||
|
@ -77,7 +77,11 @@ def format_priority(prio):
|
||||
return pstring
|
||||
|
||||
def trim_string(string, w, have_dbls):
|
||||
if have_dbls:
|
||||
if w <= 0:
|
||||
return ""
|
||||
elif w == 1:
|
||||
return "…"
|
||||
elif have_dbls:
|
||||
# have to do this the slow way
|
||||
chrs = []
|
||||
width = 4
|
||||
@ -92,9 +96,9 @@ def trim_string(string, w, have_dbls):
|
||||
if width != w:
|
||||
chrs.pop()
|
||||
chrs.append('.')
|
||||
return "%s... "%("".join(chrs))
|
||||
return "%s… "%("".join(chrs))
|
||||
else:
|
||||
return "%s... "%(string[0:w-4])
|
||||
return "%s… "%(string[0:w-2])
|
||||
|
||||
def format_column(col, lim):
|
||||
dbls = 0
|
||||
|
@ -185,18 +185,27 @@ class IntSpinInput(InputField):
|
||||
self.move_func = move_func
|
||||
self.min_val = min_val
|
||||
self.max_val = max_val
|
||||
self.need_update = False
|
||||
|
||||
def render(self, screen, row, width, active, col=1, cursor_offset=0):
|
||||
if not active and not self.valstr:
|
||||
if not active and self.need_update:
|
||||
if not self.valstr or self.valstr == '-':
|
||||
self.value = self.initvalue
|
||||
else:
|
||||
self.value = int(self.valstr)
|
||||
if self.value < self.min_val:
|
||||
self.value = self.min_val
|
||||
if self.value > self.max_val:
|
||||
self.value = self.max_val
|
||||
self.valstr = "%d"%self.value
|
||||
self.cursor = len(self.valstr)
|
||||
self.need_update = False
|
||||
if not self.valstr:
|
||||
self.parent.add_string(row,"%s [ ]"%self.message,screen,col,False,True)
|
||||
elif active:
|
||||
self.parent.add_string(row,"%s [ {!black,white,bold!}%d{!white,black!} ]"%(self.message,self.value),screen,col,False,True)
|
||||
self.parent.add_string(row,"%s [ {!black,white,bold!}%s{!white,black!} ]"%(self.message,self.valstr),screen,col,False,True)
|
||||
else:
|
||||
self.parent.add_string(row,"%s [ %d ]"%(self.message,self.value),screen,col,False,True)
|
||||
self.parent.add_string(row,"%s [ %s ]"%(self.message,self.valstr),screen,col,False,True)
|
||||
|
||||
if active:
|
||||
self.move_func(row,self.cursor+self.cursoff+cursor_offset)
|
||||
@ -204,10 +213,14 @@ class IntSpinInput(InputField):
|
||||
return 1
|
||||
|
||||
def handle_read(self, c):
|
||||
if c == curses.KEY_PPAGE:
|
||||
if c == curses.KEY_PPAGE and self.value < self.max_val:
|
||||
self.value+=1
|
||||
elif c == curses.KEY_NPAGE:
|
||||
self.valstr = "%d"%self.value
|
||||
self.cursor = len(self.valstr)
|
||||
elif c == curses.KEY_NPAGE and self.value > self.min_val:
|
||||
self.value-=1
|
||||
self.valstr = "%d"%self.value
|
||||
self.cursor = len(self.valstr)
|
||||
elif c == curses.KEY_LEFT:
|
||||
self.cursor = max(0,self.cursor-1)
|
||||
elif c == curses.KEY_RIGHT:
|
||||
@ -215,25 +228,32 @@ class IntSpinInput(InputField):
|
||||
elif c == curses.KEY_HOME:
|
||||
self.cursor = 0
|
||||
elif c == curses.KEY_END:
|
||||
self.cursor = len(self.value)
|
||||
self.cursor = len(self.valstr)
|
||||
elif c == curses.KEY_BACKSPACE or c == 127:
|
||||
if self.valstr and self.cursor > 0:
|
||||
self.valstr = self.valstr[:self.cursor - 1] + self.valstr[self.cursor:]
|
||||
self.cursor-=1
|
||||
if self.valstr:
|
||||
self.value = int(self.valstr)
|
||||
self.need_update = True
|
||||
elif c == curses.KEY_DC:
|
||||
if self.valstr and self.cursor < len(self.valstr):
|
||||
self.valstr = self.valstr[:self.cursor] + self.valstr[self.cursor+1:]
|
||||
self.need_update = True
|
||||
elif c == 45 and self.cursor == 0 and self.min_val < 0:
|
||||
minus_place = self.valstr.find('-')
|
||||
if minus_place >= 0: return
|
||||
self.valstr = chr(c)+self.valstr
|
||||
self.cursor += 1
|
||||
self.need_update = True
|
||||
elif c > 47 and c < 58:
|
||||
if c == 48 and self.cursor == 0: return
|
||||
minus_place = self.valstr.find('-')
|
||||
if self.cursor <= minus_place: return
|
||||
if self.cursor == len(self.valstr):
|
||||
self.valstr += chr(c)
|
||||
self.value = int(self.valstr)
|
||||
else:
|
||||
# Insert into string
|
||||
self.valstr = self.valstr[:self.cursor] + chr(c) + self.valstr[self.cursor:]
|
||||
self.value = int(self.valstr)
|
||||
self.need_update = True
|
||||
# Move the cursor forward
|
||||
self.cursor+=1
|
||||
|
||||
@ -265,15 +285,22 @@ class FloatSpinInput(InputField):
|
||||
self.max_val = max_val
|
||||
self.need_update = False
|
||||
|
||||
def __limit_value(self):
|
||||
if self.value < self.min_val:
|
||||
self.value = self.min_val
|
||||
if self.value > self.max_val:
|
||||
self.value = self.max_val
|
||||
|
||||
def render(self, screen, row, width, active, col=1, cursor_offset=0):
|
||||
if not active and not self.valstr:
|
||||
if not active and self.need_update:
|
||||
try:
|
||||
self.value = round(float(self.valstr),self.precision)
|
||||
self.__limit_value()
|
||||
except ValueError:
|
||||
self.value = self.initvalue
|
||||
self.valstr = self.fmt%self.value
|
||||
self.cursor = len(self.valstr)
|
||||
if not active and self.need_update:
|
||||
self.value = round(float(self.valstr),self.precision)
|
||||
self.valstr = self.fmt%self.value
|
||||
self.cursor = len(self.valstr)
|
||||
self.need_update = False
|
||||
if not self.valstr:
|
||||
self.parent.add_string(row,"%s [ ]"%self.message,screen,col,False,True)
|
||||
elif active:
|
||||
@ -288,10 +315,12 @@ class FloatSpinInput(InputField):
|
||||
def handle_read(self, c):
|
||||
if c == curses.KEY_PPAGE:
|
||||
self.value+=self.inc_amt
|
||||
self.__limit_value()
|
||||
self.valstr = self.fmt%self.value
|
||||
self.cursor = len(self.valstr)
|
||||
elif c == curses.KEY_NPAGE:
|
||||
self.value-=self.inc_amt
|
||||
self.__limit_value()
|
||||
self.valstr = self.fmt%self.value
|
||||
self.cursor = len(self.valstr)
|
||||
elif c == curses.KEY_LEFT:
|
||||
@ -301,7 +330,7 @@ class FloatSpinInput(InputField):
|
||||
elif c == curses.KEY_HOME:
|
||||
self.cursor = 0
|
||||
elif c == curses.KEY_END:
|
||||
self.cursor = len(self.value)
|
||||
self.cursor = len(self.valstr)
|
||||
elif c == curses.KEY_BACKSPACE or c == 127:
|
||||
if self.valstr and self.cursor > 0:
|
||||
self.valstr = self.valstr[:self.cursor - 1] + self.valstr[self.cursor:]
|
||||
|
Loading…
x
Reference in New Issue
Block a user