Change how scrolling is done
- All functions involved return a boolean, and the core function use that value to determine if a refresh is needed or not. (avoids useless refreshs) - Scrolling with PGUP/DOWN on the roster now only does _one_ action, an not a range corresponding to the screen size (should be way faster)
This commit is contained in:
parent
c4fcf3c71a
commit
d8623d1c50
3 changed files with 100 additions and 46 deletions
45
src/core.py
45
src/core.py
|
@ -934,34 +934,67 @@ class Core(object):
|
||||||
self.doupdate()
|
self.doupdate()
|
||||||
|
|
||||||
def refresh_tab_win(self):
|
def refresh_tab_win(self):
|
||||||
|
"""
|
||||||
|
Refresh the window containing the tab list
|
||||||
|
"""
|
||||||
self.current_tab().refresh_tab_win()
|
self.current_tab().refresh_tab_win()
|
||||||
if self.current_tab().input:
|
if self.current_tab().input:
|
||||||
self.current_tab().input.refresh()
|
self.current_tab().input.refresh()
|
||||||
self.doupdate()
|
self.doupdate()
|
||||||
|
|
||||||
def scroll_page_down(self, args=None):
|
def scroll_page_down(self, args=None):
|
||||||
self.current_tab().on_scroll_down()
|
"""
|
||||||
|
Scroll a page down, if possible.
|
||||||
|
Returns True on success, None on failure.
|
||||||
|
"""
|
||||||
|
if self.current_tab().on_scroll_down():
|
||||||
self.refresh_window()
|
self.refresh_window()
|
||||||
|
return True
|
||||||
|
|
||||||
def scroll_page_up(self, args=None):
|
def scroll_page_up(self, args=None):
|
||||||
self.current_tab().on_scroll_up()
|
"""
|
||||||
|
Scroll a page up, if possible.
|
||||||
|
Returns True on success, None on failure.
|
||||||
|
"""
|
||||||
|
if self.current_tab().on_scroll_up():
|
||||||
self.refresh_window()
|
self.refresh_window()
|
||||||
|
return True
|
||||||
|
|
||||||
def scroll_line_up(self, args=None):
|
def scroll_line_up(self, args=None):
|
||||||
self.current_tab().on_line_up()
|
"""
|
||||||
|
Scroll a line up, if possible.
|
||||||
|
Returns True on success, None on failure.
|
||||||
|
"""
|
||||||
|
if self.current_tab().on_line_up():
|
||||||
self.refresh_window()
|
self.refresh_window()
|
||||||
|
return True
|
||||||
|
|
||||||
def scroll_line_down(self, args=None):
|
def scroll_line_down(self, args=None):
|
||||||
self.current_tab().on_line_down()
|
"""
|
||||||
|
Scroll a line down, if possible.
|
||||||
|
Returns True on success, None on failure.
|
||||||
|
"""
|
||||||
|
if self.current_tab().on_line_down():
|
||||||
self.refresh_window()
|
self.refresh_window()
|
||||||
|
return True
|
||||||
|
|
||||||
def scroll_half_up(self, args=None):
|
def scroll_half_up(self, args=None):
|
||||||
self.current_tab().on_half_scroll_up()
|
"""
|
||||||
|
Scroll half a screen down, if possible.
|
||||||
|
Returns True on success, None on failure.
|
||||||
|
"""
|
||||||
|
if self.current_tab().on_half_scroll_up():
|
||||||
self.refresh_window()
|
self.refresh_window()
|
||||||
|
return True
|
||||||
|
|
||||||
def scroll_half_down(self, args=None):
|
def scroll_half_down(self, args=None):
|
||||||
self.current_tab().on_half_scroll_down()
|
"""
|
||||||
|
Scroll half a screen down, if possible.
|
||||||
|
Returns True on success, None on failure.
|
||||||
|
"""
|
||||||
|
if self.current_tab().on_half_scroll_down():
|
||||||
self.refresh_window()
|
self.refresh_window()
|
||||||
|
return True
|
||||||
|
|
||||||
def grow_information_win(self, nb=1):
|
def grow_information_win(self, nb=1):
|
||||||
if self.information_win_size >= self.current_tab().height -5 or \
|
if self.information_win_size >= self.current_tab().height -5 or \
|
||||||
|
|
28
src/tabs.py
28
src/tabs.py
|
@ -543,22 +543,22 @@ class ChatTab(Tab):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def on_line_up(self):
|
def on_line_up(self):
|
||||||
self.text_win.scroll_up(1)
|
return self.text_win.scroll_up(1)
|
||||||
|
|
||||||
def on_line_down(self):
|
def on_line_down(self):
|
||||||
self.text_win.scroll_down(1)
|
return self.text_win.scroll_down(1)
|
||||||
|
|
||||||
def on_scroll_up(self):
|
def on_scroll_up(self):
|
||||||
self.text_win.scroll_up(self.text_win.height-1)
|
return self.text_win.scroll_up(self.text_win.height-1)
|
||||||
|
|
||||||
def on_scroll_down(self):
|
def on_scroll_down(self):
|
||||||
self.text_win.scroll_down(self.text_win.height-1)
|
return self.text_win.scroll_down(self.text_win.height-1)
|
||||||
|
|
||||||
def on_half_scroll_up(self):
|
def on_half_scroll_up(self):
|
||||||
self.text_win.scroll_up((self.text_win.height-1) // 2)
|
return self.text_win.scroll_up((self.text_win.height-1) // 2)
|
||||||
|
|
||||||
def on_half_scroll_down(self):
|
def on_half_scroll_down(self):
|
||||||
self.text_win.scroll_down((self.text_win.height-1) // 2)
|
return self.text_win.scroll_down((self.text_win.height-1) // 2)
|
||||||
|
|
||||||
def scroll_separator(self):
|
def scroll_separator(self):
|
||||||
self.text_win.scroll_to_separator()
|
self.text_win.scroll_to_separator()
|
||||||
|
@ -2359,14 +2359,10 @@ class RosterInfoTab(Tab):
|
||||||
self.core.doupdate()
|
self.core.doupdate()
|
||||||
|
|
||||||
def on_scroll_down(self):
|
def on_scroll_down(self):
|
||||||
for i in range(self.height-1):
|
return self.roster_win.move_cursor_down(self.height // 2)
|
||||||
self.roster_win.move_cursor_down()
|
|
||||||
return True
|
|
||||||
|
|
||||||
def on_scroll_up(self):
|
def on_scroll_up(self):
|
||||||
for i in range(self.height-1):
|
return self.roster_win.move_cursor_up(self.height // 2)
|
||||||
self.roster_win.move_cursor_up()
|
|
||||||
return True
|
|
||||||
|
|
||||||
def on_space(self):
|
def on_space(self):
|
||||||
selected_row = self.roster_win.get_selected_row()
|
selected_row = self.roster_win.get_selected_row()
|
||||||
|
@ -2858,10 +2854,10 @@ class MucListTab(Tab):
|
||||||
curses.curs_set(0)
|
curses.curs_set(0)
|
||||||
|
|
||||||
def on_scroll_up(self):
|
def on_scroll_up(self):
|
||||||
self.listview.scroll_up()
|
return self.listview.scroll_up()
|
||||||
|
|
||||||
def on_scroll_down(self):
|
def on_scroll_down(self):
|
||||||
self.listview.scroll_down()
|
return self.listview.scroll_down()
|
||||||
|
|
||||||
class XMLTab(Tab):
|
class XMLTab(Tab):
|
||||||
|
|
||||||
|
@ -2943,10 +2939,10 @@ class XMLTab(Tab):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def on_scroll_up(self):
|
def on_scroll_up(self):
|
||||||
self.text_win.scroll_up(self.text_win.height-1)
|
return self.text_win.scroll_up(self.text_win.height-1)
|
||||||
|
|
||||||
def on_scroll_down(self):
|
def on_scroll_down(self):
|
||||||
self.text_win.scroll_down(self.text_win.height-1)
|
return self.text_win.scroll_down(self.text_win.height-1)
|
||||||
|
|
||||||
def command_clear(self, args):
|
def command_clear(self, args):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -212,11 +212,14 @@ class UserList(Win):
|
||||||
}
|
}
|
||||||
def scroll_up(self):
|
def scroll_up(self):
|
||||||
self.pos += self.height-1
|
self.pos += self.height-1
|
||||||
|
return True
|
||||||
|
|
||||||
def scroll_down(self):
|
def scroll_down(self):
|
||||||
|
pos = self.pos
|
||||||
self.pos -= self.height-1
|
self.pos -= self.height-1
|
||||||
if self.pos < 0:
|
if self.pos < 0:
|
||||||
self.pos = 0
|
self.pos = 0
|
||||||
|
return self.pos != pos
|
||||||
|
|
||||||
def draw_plus(self, y):
|
def draw_plus(self, y):
|
||||||
self.addstr(y, self.width-2, '++', to_curses_attr(get_theme().COLOR_MORE_INDICATOR))
|
self.addstr(y, self.width-2, '++', to_curses_attr(get_theme().COLOR_MORE_INDICATOR))
|
||||||
|
@ -714,16 +717,20 @@ class TextWin(Win):
|
||||||
self.pos = 0
|
self.pos = 0
|
||||||
|
|
||||||
def scroll_up(self, dist=14):
|
def scroll_up(self, dist=14):
|
||||||
|
pos = self.pos
|
||||||
self.pos += dist
|
self.pos += dist
|
||||||
if self.pos + self.height > len(self.built_lines):
|
if self.pos + self.height > len(self.built_lines):
|
||||||
self.pos = len(self.built_lines) - self.height
|
self.pos = len(self.built_lines) - self.height
|
||||||
if self.pos < 0:
|
if self.pos < 0:
|
||||||
self.pos = 0
|
self.pos = 0
|
||||||
|
return self.pos != pos
|
||||||
|
|
||||||
def scroll_down(self, dist=14):
|
def scroll_down(self, dist=14):
|
||||||
|
pos = self.pos
|
||||||
self.pos -= dist
|
self.pos -= dist
|
||||||
if self.pos <= 0:
|
if self.pos <= 0:
|
||||||
self.pos = 0
|
self.pos = 0
|
||||||
|
return self.pos != pos
|
||||||
|
|
||||||
def scroll_to_separator(self):
|
def scroll_to_separator(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1540,35 +1547,53 @@ class RosterWin(Win):
|
||||||
self.roster_len = 0
|
self.roster_len = 0
|
||||||
self.selected_row = None
|
self.selected_row = None
|
||||||
|
|
||||||
def move_cursor_down(self):
|
def move_cursor_down(self, number=1):
|
||||||
"""
|
"""
|
||||||
Return True if we scrolled, False otherwise
|
Return True if we scrolled, False otherwise
|
||||||
"""
|
"""
|
||||||
if self.pos < self.roster_len-1:
|
pos = self.pos
|
||||||
self.pos += 1
|
if self.pos < self.roster_len-number:
|
||||||
|
self.pos += number
|
||||||
else:
|
else:
|
||||||
return False
|
self.pos = self.roster_len - 1
|
||||||
if self.pos == self.start_pos-1 + self.height-1:
|
if self.pos >= self.start_pos-1 + self.height-1:
|
||||||
self.scroll_down()
|
if number == 1:
|
||||||
return True
|
self.scroll_down(8)
|
||||||
|
else:
|
||||||
|
self.scroll_down(self.pos-self.start_pos - self.height // 2)
|
||||||
|
return pos != self.pos
|
||||||
|
|
||||||
def move_cursor_up(self):
|
def move_cursor_up(self, number=1):
|
||||||
"""
|
"""
|
||||||
Return True if we scrolled, False otherwise
|
Return True if we scrolled, False otherwise
|
||||||
"""
|
"""
|
||||||
if self.pos > 0:
|
pos = self.pos
|
||||||
self.pos -= 1
|
if self.pos-number >= 0:
|
||||||
|
self.pos -= number
|
||||||
else:
|
else:
|
||||||
return False
|
self.pos = 0
|
||||||
if self.pos == self.start_pos-2:
|
if self.pos <= self.start_pos:
|
||||||
self.scroll_up()
|
if number == 1:
|
||||||
return True
|
self.scroll_up(8)
|
||||||
|
else:
|
||||||
|
self.scroll_up(self.start_pos-self.pos + self.height // 2)
|
||||||
|
return pos != self.pos
|
||||||
|
|
||||||
def scroll_down(self):
|
def scroll_down(self, number=8):
|
||||||
self.start_pos += 8
|
pos = self.start_pos
|
||||||
|
if self.start_pos + number <= self.roster_len-1:
|
||||||
|
self.start_pos += number
|
||||||
|
else:
|
||||||
|
self.start_pos = self.roster_len-1
|
||||||
|
return self.start_pos != pos
|
||||||
|
|
||||||
def scroll_up(self):
|
def scroll_up(self, number=8):
|
||||||
self.start_pos -= 8
|
pos = self.start_pos
|
||||||
|
if self.start_pos - number > 0:
|
||||||
|
self.start_pos -= number
|
||||||
|
else:
|
||||||
|
self.start_pos = 1
|
||||||
|
return self.start_pos != pos
|
||||||
|
|
||||||
def refresh(self, roster):
|
def refresh(self, roster):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue