summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-11-22 02:39:56 +0000
committerlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-11-22 02:39:56 +0000
commit6ffafadbdd6c19bb01438478794b64fd307b1d72 (patch)
tree8f46424b136b2fdb15fd447a81c1115b4ce9dd2f /src
parent0eeb6a871dabde1af29c490e1c4bee8da853226c (diff)
downloadpoezio-6ffafadbdd6c19bb01438478794b64fd307b1d72.tar.gz
poezio-6ffafadbdd6c19bb01438478794b64fd307b1d72.tar.bz2
poezio-6ffafadbdd6c19bb01438478794b64fd307b1d72.tar.xz
poezio-6ffafadbdd6c19bb01438478794b64fd307b1d72.zip
re-use the resize_timer and better handle the size of the term to decide if we refresh. Everything seems fine on refresh now \o/
Diffstat (limited to 'src')
-rw-r--r--src/core.py18
-rw-r--r--src/tab.py90
-rw-r--r--src/windows.py96
3 files changed, 88 insertions, 116 deletions
diff --git a/src/core.py b/src/core.py
index 62011994..5b390c84 100644
--- a/src/core.py
+++ b/src/core.py
@@ -535,15 +535,15 @@ class Core(object):
This is to avoid multiple unnecessary software resizes (this
can be heavy on resource on slow computers or networks)
"""
- # with resize_lock:
- # if self.resize_timer:
- # # a recent terminal resize occured.
- # # Cancel the programmed software resize
- # self.resize_timer.cancel()
- # # add the new timer
- # self.resize_timer = threading.Timer(0.15, self.resize_window)
- # self.resize_timer.start()
- self.resize_window()
+ with resize_lock:
+ if self.resize_timer:
+ # a recent terminal resize occured.
+ # Cancel the programmed software resize
+ self.resize_timer.cancel()
+ # add the new timer
+ self.resize_timer = threading.Timer(0.1, self.resize_window)
+ self.resize_timer.start()
+ # self.resize_window()
def resize_window(self):
"""
diff --git a/src/tab.py b/src/tab.py
index 60c8094f..3bbbeee8 100644
--- a/src/tab.py
+++ b/src/tab.py
@@ -156,12 +156,14 @@ class InfoTab(Tab):
def resize(self):
Tab.resize(self)
- self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr, self.visible)
- self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr, self.visible)
- self.text_win.resize(self.height-2, self.width, 0, 0, self.core.stdscr, self.visible)
- self.input.resize(1, self.width, self.height-1, 0, self.core.stdscr, self.visible)
+ self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr)
+ self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr)
+ self.text_win.resize(self.height-2, self.width, 0, 0, self.core.stdscr)
+ self.input.resize(1, self.width, self.height-1, 0, self.core.stdscr)
def refresh(self, tabs, informations, _):
+ if not self.visible:
+ return
self.text_win.refresh(informations)
self.tab_win.refresh(tabs, tabs[0])
self.input.refresh()
@@ -260,16 +262,18 @@ class MucTab(ChatTab):
"""
Tab.resize(self)
text_width = (self.width//10)*9
- self.topic_win.resize(1, self.width, 0, 0, self.core.stdscr, self.visible)
- self.text_win.resize(self.height-4-self.core.information_win_size, text_width, 1, 0, self.core.stdscr, self.visible)
- self.v_separator.resize(self.height-3, 1, 1, 9*(self.width//10), self.core.stdscr, self.visible)
- self.user_win.resize(self.height-3, self.width-text_width-1, 1, text_width+1, self.core.stdscr, self.visible)
- self.info_header.resize(1, (self.width//10)*9, self.height-3-self.core.information_win_size, 0, self.core.stdscr, self.visible)
- self.info_win.resize(self.core.information_win_size, (self.width//10)*9, self.height-2-self.core.information_win_size, 0, self.core.stdscr, self.visible)
- self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr, self.visible)
- self.input.resize(1, self.width, self.height-1, 0, self.core.stdscr, self.visible)
+ self.topic_win.resize(1, self.width, 0, 0, self.core.stdscr)
+ self.text_win.resize(self.height-4-self.core.information_win_size, text_width, 1, 0, self.core.stdscr)
+ self.v_separator.resize(self.height-3, 1, 1, 9*(self.width//10), self.core.stdscr)
+ self.user_win.resize(self.height-3, self.width-text_width-1, 1, text_width+1, self.core.stdscr)
+ self.info_header.resize(1, (self.width//10)*9, self.height-3-self.core.information_win_size, 0, self.core.stdscr)
+ self.info_win.resize(self.core.information_win_size, (self.width//10)*9, self.height-2-self.core.information_win_size, 0, self.core.stdscr)
+ self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr)
+ self.input.resize(1, self.width, self.height-1, 0, self.core.stdscr)
def refresh(self, tabs, informations, _):
+ if not self.visible:
+ return
self.topic_win.refresh(self._room.topic)
self.text_win.refresh(self._room)
self.v_separator.refresh()
@@ -328,9 +332,9 @@ class MucTab(ChatTab):
def on_info_win_size_changed(self):
text_width = (self.width//10)*9
- self.text_win.resize(self.height-4-self.core.information_win_size, text_width, 1, 0, self.core.stdscr, self.visible)
- self.info_header.resize(1, (self.width//10)*9, self.height-3-self.core.information_win_size, 0, self.core.stdscr, self.visible)
- self.info_win.resize(self.core.information_win_size, (self.width//10)*9, self.height-2-self.core.information_win_size, 0, self.core.stdscr, self.visible)
+ self.text_win.resize(self.height-4-self.core.information_win_size, text_width, 1, 0, self.core.stdscr)
+ self.info_header.resize(1, (self.width//10)*9, self.height-3-self.core.information_win_size, 0, self.core.stdscr)
+ self.info_win.resize(self.core.information_win_size, (self.width//10)*9, self.height-2-self.core.information_win_size, 0, self.core.stdscr)
def just_before_refresh(self):
return
@@ -353,13 +357,15 @@ class PrivateTab(ChatTab):
def resize(self):
Tab.resize(self)
- self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0, self.core.stdscr, self.visible)
- self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0, self.core.stdscr, self.visible)
- self.info_win.resize(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, self.core.stdscr, self.visible)
- self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr, self.visible)
- self.input.resize(1, self.width, self.height-1, 0, self.core.stdscr, self.visible)
+ self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0, self.core.stdscr)
+ self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0, self.core.stdscr)
+ self.info_win.resize(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, self.core.stdscr)
+ self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr)
+ self.input.resize(1, self.width, self.height-1, 0, self.core.stdscr)
def refresh(self, tabs, informations, _):
+ if not self.visible:
+ return
self.text_win.refresh(self._room)
self.info_header.refresh(self._room)
self.info_win.refresh(informations)
@@ -406,9 +412,9 @@ class PrivateTab(ChatTab):
self._room.scroll_down(self.text_win.height-1)
def on_info_win_size_changed(self):
- self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0, self.core.stdscr, self.visible)
- self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0, self.core.stdscr, self.visible)
- self.info_win.resize(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, self.core.stdscr, self.visible)
+ self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0, self.core.stdscr)
+ self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0, self.core.stdscr)
+ self.info_win.resize(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, self.core.stdscr)
def get_room(self):
return self._room
@@ -440,14 +446,16 @@ class RosterInfoTab(Tab):
Tab.resize(self)
roster_width = self.width//2
info_width = self.width-roster_width-1
- self.v_separator.resize(self.height-2, 1, 0, roster_width, self.core.stdscr, self.visible)
- self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr, self.visible)
- self.info_win.resize(self.height-2, info_width, 0, roster_width+1, self.core.stdscr, self.visible)
- self.roster_win.resize(self.height-2-3, roster_width, 0, 0, self.core.stdscr, self.visible)
- self.contact_info_win.resize(3, roster_width, self.height-2-3, 0, self.core.stdscr, self.visible)
- self.input.resize(1, self.width, self.height-1, 0, self.core.stdscr, self.visible)
+ self.v_separator.resize(self.height-2, 1, 0, roster_width, self.core.stdscr)
+ self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr)
+ self.info_win.resize(self.height-2, info_width, 0, roster_width+1, self.core.stdscr)
+ self.roster_win.resize(self.height-2-3, roster_width, 0, 0, self.core.stdscr)
+ self.contact_info_win.resize(3, roster_width, self.height-2-3, 0, self.core.stdscr)
+ self.input.resize(1, self.width, self.height-1, 0, self.core.stdscr)
def refresh(self, tabs, informations, roster):
+ if not self.visible:
+ return
self.v_separator.refresh()
self.roster_win.refresh(roster)
self.contact_info_win.refresh(self.roster_win.get_selected_row())
@@ -498,7 +506,7 @@ class RosterInfoTab(Tab):
'/' is pressed, we enter "input mode"
"""
curses.curs_set(1)
- self.input = windows.CommandInput(1, self.width, self.height-1, 0, self.default_help_message, self.visible, "", self.reset_help_message, self.execute_slash_command)
+ self.input = windows.CommandInput(1, self.width, self.height-1, 0, self.default_help_message, "", self.reset_help_message, self.execute_slash_command)
self.input.do_command("/") # we add the slash
def reset_help_message(self, _=None):
@@ -558,7 +566,7 @@ class RosterInfoTab(Tab):
in it.
"""
curses.curs_set(1)
- self.input = windows.CommandInput(1, self.width, self.height-1, 0, self.default_help_message, self.visible, "[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter)
+ self.input = windows.CommandInput(1, self.width, self.height-1, 0, self.default_help_message, "[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter)
return True
def set_roster_filter(self, txt):
@@ -594,14 +602,16 @@ class ConversationTab(ChatTab):
def resize(self):
Tab.resize(self)
- self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0, self.core.stdscr, self.visible)
- self.upper_bar.resize(1, self.width, 0, 0, self.core.stdscr, self.visible)
- self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0, self.core.stdscr, self.visible)
- self.info_win.resize(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, self.core.stdscr, self.visible)
- self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr, self.visible)
- self.input.resize(1, self.width, self.height-1, 0, self.core.stdscr, self.visible)
+ self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0, self.core.stdscr)
+ self.upper_bar.resize(1, self.width, 0, 0, self.core.stdscr)
+ self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0, self.core.stdscr)
+ self.info_win.resize(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, self.core.stdscr)
+ self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr)
+ self.input.resize(1, self.width, self.height-1, 0, self.core.stdscr)
def refresh(self, tabs, informations, roster):
+ if not self.visible:
+ return
self.text_win.refresh(self._room)
self.upper_bar.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()))
self.info_header.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()), self._room)
@@ -650,9 +660,9 @@ class ConversationTab(ChatTab):
self._room.scroll_down(self.text_win.height-1)
def on_info_win_size_changed(self):
- self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0, self.core.stdscr, self.visible)
- self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0, self.core.stdscr, self.visible)
- self.info_win.resize(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, self.core.stdscr, self.visible)
+ self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0, self.core.stdscr)
+ self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0, self.core.stdscr)
+ self.info_win.resize(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, self.core.stdscr)
def get_room(self):
return self._room
diff --git a/src/windows.py b/src/windows.py
index aa505afa..0356c813 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -53,9 +53,7 @@ class Win(object):
def __init__(self):
pass
- def _resize(self, height, width, y, x, parent_win, visible):
- if not visible:
- return
+ def _resize(self, height, width, y, x, parent_win):
self.height, self.width, self.x, self.y = height, width, x, y
# try:
self._win = curses.newwin(height, width, y, x)
@@ -116,8 +114,6 @@ class UserList(Win):
}
def refresh(self, users):
- # if not self.visible:
- # return
with g_lock:
self._win.erase()
y = 0
@@ -137,11 +133,8 @@ class UserList(Win):
break
self._refresh()
- def resize(self, height, width, y, x, stdscr, visible):
- self.visible = visible
- if not visible:
- return
- self._resize(height, width, y, x, stdscr, visible)
+ def resize(self, height, width, y, x, stdscr):
+ self._resize(height, width, y, x, stdscr)
self._win.attron(curses.color_pair(theme.COLOR_VERTICAL_SEPARATOR))
self._win.vline(0, 0, curses.ACS_VLINE, self.height)
self._win.attroff(curses.color_pair(theme.COLOR_VERTICAL_SEPARATOR))
@@ -150,12 +143,10 @@ class Topic(Win):
def __init__(self):
Win.__init__(self)
- def resize(self, height, width, y, x, stdscr, visible):
- self._resize(height, width, y, x, stdscr, visible)
+ def resize(self, height, width, y, x, stdscr):
+ self._resize(height, width, y, x, stdscr)
def refresh(self, topic):
- # if not self.visible:
- # return
with g_lock:
self._win.erase()
self.addstr(0, 0, topic[:self.width-1], curses.color_pair(theme.COLOR_TOPIC_BAR))
@@ -170,12 +161,10 @@ class GlobalInfoBar(Win):
def __init__(self):
Win.__init__(self)
- def resize(self, height, width, y, x, stdscr, visible):
- self._resize(height, width, y, x, stdscr, visible)
+ def resize(self, height, width, y, x, stdscr):
+ self._resize(height, width, y, x, stdscr)
def refresh(self, tabs, current):
- # if not self.visible:
- # return
def compare_room(a):
# return a.nb - b.nb
return a.nb
@@ -225,12 +214,11 @@ class PrivateInfoWin(InfoWin):
def __init__(self):
InfoWin.__init__(self)
- def resize(self, height, width, y, x, stdscr, visible):
- self._resize(height, width, y, x, stdscr, visible)
+ def resize(self, height, width, y, x, stdscr):
+ self._resize(height, width, y, x, stdscr)
def refresh(self, room):
- # if not self.visible:
- # return
+
with g_lock:
self._win.erase()
self.write_room_name(room)
@@ -262,12 +250,10 @@ class ConversationInfoWin(InfoWin):
def __init__(self):
InfoWin.__init__(self)
- def resize(self, height, width, y, x, stdscr, visible):
- self._resize(height, width, y, x, stdscr, visible)
+ def resize(self, height, width, y, x, stdscr):
+ self._resize(height, width, y, x, stdscr)
def refresh(self, jid, contact, text_buffer):
- # if not self.visible:
- # return
# contact can be None, if we receive a message
# from someone not in our roster. In this case, we display
# only the maximum information from the message we can get.
@@ -331,12 +317,10 @@ class ConversationStatusMessageWin(InfoWin):
def __init__(self):
InfoWin.__init__(self)
- def resize(self, height, width, y, x, stdscr, visible):
- self._resize(height, width, y, x, stdscr, visible)
+ def resize(self, height, width, y, x, stdscr):
+ self._resize(height, width, y, x, stdscr)
def refresh(self, jid, contact):
- # if not self.visible:
- # return
jid = JID(jid)
if contact:
if jid.resource:
@@ -363,12 +347,10 @@ class MucInfoWin(InfoWin):
def __init__(self):
InfoWin.__init__(self)
- def resize(self, height, width, y, x, stdscr, visible):
- self._resize(height, width, y, x, stdscr, visible)
+ def resize(self, height, width, y, x, stdscr):
+ self._resize(height, width, y, x, stdscr)
def refresh(self, room):
- # if not self.visible:
- # return
with g_lock:
self._win.erase()
self.write_room_name(room)
@@ -493,8 +475,6 @@ class TextWin(Win):
Build the Line objects from the messages, and then write
them in the text area
"""
- # if not self.visible:
- # return
if self.height <= 0:
return
with g_lock:
@@ -596,9 +576,8 @@ class TextWin(Win):
self.addnstr(theme.CHAR_TIME_RIGHT, curses.color_pair(theme.COLOR_TIME_LIMITER))
self.addstr(' ')
- def resize(self, height, width, y, x, stdscr, visible):
- self.visible = visible
- self._resize(height, width, y, x, stdscr, visible)
+ def resize(self, height, width, y, x, stdscr):
+ self._resize(height, width, y, x, stdscr)
class HelpText(Win):
"""
@@ -610,12 +589,10 @@ class HelpText(Win):
Win.__init__(self)
self.txt = text
- def resize(self, height, width, y, x, stdscr, visible):
- self._resize(height, width, y, x, stdscr, visible)
+ def resize(self, height, width, y, x, stdscr):
+ self._resize(height, width, y, x, stdscr)
def refresh(self):
- # if not self.visible:
- # return
with g_lock:
self._win.erase()
self.addstr(0, 0, self.txt[:self.width-1], curses.color_pair(theme.COLOR_INFORMATION_BAR))
@@ -669,11 +646,9 @@ class Input(Win):
def is_empty(self):
return len(self.text) == 0
- def resize(self, height, width, y, x, stdscr, visible):
- self.visible = visible
- if not visible:
- return
- self._resize(height, width, y, x, stdscr, visible)
+ def resize(self, height, width, y, x, stdscr):
+
+ self._resize(height, width, y, x, stdscr)
self._win.erase()
self.addnstr(0, 0, self.text, self.width-1)
@@ -963,8 +938,6 @@ class Input(Win):
self._refresh()
def refresh(self):
- # if not self.visible:
- # return
self.rewrite_text()
def clear_text(self):
@@ -1098,15 +1071,10 @@ class VerticalSeparator(Win):
self._win.vline(0, 0, curses.ACS_VLINE, self.height, curses.color_pair(theme.COLOR_VERTICAL_SEPARATOR))
self._refresh()
- def resize(self, height, width, y, x, stdscr, visible):
- self.visible = visible
- self._resize(height, width, y, x, stdscr, visible)
- if not visible:
- return
+ def resize(self, height, width, y, x, stdscr):
+ self._resize(height, width, y, x, stdscr)
def refresh(self):
- # if not self.visible:
- # return
self.rewrite_line()
class RosterWin(Win):
@@ -1127,9 +1095,8 @@ class RosterWin(Win):
self.roster_len = 0
self.selected_row = None
- def resize(self, height, width, y, x, stdscr, visible):
- self._resize(height, width, y, x, stdscr, visible)
- self.visible = visible
+ def resize(self, height, width, y, x, stdscr):
+ self._resize(height, width, y, x, stdscr)
def move_cursor_down(self):
if self.pos < self.roster_len-1:
@@ -1153,8 +1120,6 @@ class RosterWin(Win):
"""
We get the roster object
"""
- # if not self.visible:
- # return
with g_lock:
self.roster_len = len(roster)
while self.roster_len and self.pos >= self.roster_len:
@@ -1278,9 +1243,8 @@ class ContactInfoWin(Win):
def __init__(self):
Win.__init__(self)
- def resize(self, height, width, y, x, stdscr, visible):
- self._resize(height, width, y, x, stdscr, visible)
- self.visible = visible
+ def resize(self, height, width, y, x, stdscr):
+ self._resize(height, width, y, x, stdscr)
def draw_contact_info(self, resource, jid=None):
"""
@@ -1303,8 +1267,6 @@ class ContactInfoWin(Win):
self.finish_line(theme.COLOR_INFORMATION_BAR)
def refresh(self, selected_row):
- # if not self.visible:
- # return
with g_lock:
self._win.erase()
if isinstance(selected_row, RosterGroup):