diff --git a/src/tab.py b/src/tab.py index 6828a3a4..60c8094f 100644 --- a/src/tab.py +++ b/src/tab.py @@ -147,15 +147,17 @@ class InfoTab(Tab): """ def __init__(self, core, name): Tab.__init__(self, core) - self.tab_win = windows.GlobalInfoBar(1, self.width, self.height-2, 0, self.core.stdscr, self.visible) - self.text_win = windows.TextWin(self.height-2, self.width, 0, 0, self.core.stdscr, self.visible) - self.input = windows.Input(1, self.width, self.height-1, 0, self.core.stdscr, self.visible) + self.tab_win = windows.GlobalInfoBar() + self.text_win = windows.TextWin() + self.input = windows.Input() self.name = name self.color_state = theme.COLOR_TAB_NORMAL + self.resize() 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) @@ -240,16 +242,17 @@ class MucTab(ChatTab): """ def __init__(self, core, room): ChatTab.__init__(self, core, room) - self.topic_win = windows.Topic(1, self.width, 0, 0, self.core.stdscr, self.visible) - self.text_win = windows.TextWin(self.height-4-self.core.information_win_size, (self.width//10)*9, 1, 0, self.core.stdscr, self.visible) - self.v_separator = windows.VerticalSeparator(self.height-3, 1, 1, 9*(self.width//10), self.core.stdscr, self.visible) - self.user_win = windows.UserList(self.height-3, (self.width//10), 1, 9*(self.width//10)+1, self.core.stdscr, self.visible) - self.info_header = windows.MucInfoWin(1, (self.width//10)*9, self.height-3-self.core.information_win_size, 0, self.core.stdscr, self.visible) - self.info_win = windows.TextWin(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 = windows.GlobalInfoBar(1, self.width, self.height-2, 0, self.core.stdscr, self.visible) - self.input = windows.MessageInput(1, self.width, self.height-1, 0, self.core.stdscr, self.visible) + self.topic_win = windows.Topic() + self.text_win = windows.TextWin() + self.v_separator = windows.VerticalSeparator() + self.user_win = windows.UserList() + self.info_header = windows.MucInfoWin() + self.info_win = windows.TextWin() + self.tab_win = windows.GlobalInfoBar() + self.input = windows.MessageInput() self.key_func['^I'] = self.completion self.key_func['M-i'] = self.completion + self.resize() def resize(self): """ @@ -341,11 +344,12 @@ class PrivateTab(ChatTab): """ def __init__(self, core, room): ChatTab.__init__(self, core, room) - self.text_win = windows.TextWin(self.height-3-self.core.information_win_size, self.width, 0, 0, self.core.stdscr, self.visible) - self.info_header = windows.PrivateInfoWin(1, self.width, self.height-3-self.core.information_win_size, 0, self.core.stdscr, self.visible) - self.info_win = windows.TextWin(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, self.core.stdscr, self.visible) - self.tab_win = windows.GlobalInfoBar(1, self.width, self.height-2, 0, self.core.stdscr, self.visible) - self.input = windows.MessageInput(1, self.width, self.height-1, 0, self.core.stdscr, self.visible) + self.text_win = windows.TextWin() + self.info_header = windows.PrivateInfoWin() + self.info_win = windows.TextWin() + self.tab_win = windows.GlobalInfoBar() + self.input = windows.MessageInput() + self.resize() def resize(self): Tab.resize(self) @@ -422,16 +426,15 @@ class RosterInfoTab(Tab): def __init__(self, core): Tab.__init__(self, core) self.name = "Roster" - roster_width = self.width//2 - info_width = self.width-roster_width-1 - self.v_separator = windows.VerticalSeparator(self.height-2, 1, 0, roster_width, self.core.stdscr, self.visible) - self.tab_win = windows.GlobalInfoBar(1, self.width, self.height-2, 0, self.core.stdscr, self.visible) - self.info_win = windows.TextWin(self.height-2, info_width, 0, roster_width+1, self.core.stdscr, self.visible) - self.roster_win = windows.RosterWin(self.height-2-3, roster_width, 0, 0, self.core.stdscr, self.visible) - self.contact_info_win = windows.ContactInfoWin(3, roster_width, self.height-2-3, 0, self.core.stdscr, self.visible) - self.default_help_message = windows.HelpText(1, self.width, self.height-1, 0, self.core.stdscr, self.visible, "Enter commands with “/”. “o”: toggle offline show") + self.v_separator = windows.VerticalSeparator() + self.tab_win = windows.GlobalInfoBar() + self.info_win = windows.TextWin() + self.roster_win = windows.RosterWin() + self.contact_info_win = windows.ContactInfoWin() + self.default_help_message = windows.HelpText("Enter commands with “/”. “o”: toggle offline show") self.input = self.default_help_message self.set_color_state(theme.COLOR_TAB_NORMAL) + self.resize() def resize(self): Tab.resize(self) @@ -581,12 +584,13 @@ class ConversationTab(ChatTab): ChatTab.__init__(self, core, text_buffer) self.color_state = theme.COLOR_TAB_NORMAL self._name = jid # a conversation tab is linked to one specific full jid OR bare jid - self.text_win = windows.TextWin(self.height-4-self.core.information_win_size, self.width, 1, 0, self.core.stdscr, self.visible) - self.upper_bar = windows.ConversationStatusMessageWin(1, self.width, 0, 0, self.core.stdscr, self.visible) - self.info_header = windows.ConversationInfoWin(1, self.width, self.height-3-self.core.information_win_size, 0, self.core.stdscr, self.visible) - self.info_win = windows.TextWin(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, self.core.stdscr, self.visible) - self.tab_win = windows.GlobalInfoBar(1, self.width, self.height-2, 0, self.core.stdscr, self.visible) - self.input = windows.MessageInput(1, self.width, self.height-1, 0, self.core.stdscr, self.visible) + self.text_win = windows.TextWin() + self.upper_bar = windows.ConversationStatusMessageWin() + self.info_header = windows.ConversationInfoWin() + self.info_win = windows.TextWin() + self.tab_win = windows.GlobalInfoBar() + self.input = windows.MessageInput() + self.resize() def resize(self): Tab.resize(self) diff --git a/src/windows.py b/src/windows.py index dee1aa9d..aa505afa 100644 --- a/src/windows.py +++ b/src/windows.py @@ -50,8 +50,8 @@ import theme g_lock = Lock() class Win(object): - def __init__(self, height, width, y, x, parent_win): - self._resize(height, width, y, x, parent_win, True) + def __init__(self): + pass def _resize(self, height, width, y, x, parent_win, visible): if not visible: @@ -99,9 +99,8 @@ class Win(object): self.addnstr(' '*size, size, curses.color_pair(color)) class UserList(Win): - def __init__(self, height, width, y, x, parent_win, visible): - Win.__init__(self, height, width, y, x, parent_win) - self.visible = visible + def __init__(self): + Win.__init__(self) self.color_role = {'moderator': theme.COLOR_USER_MODERATOR, 'participant':theme.COLOR_USER_PARTICIPANT, 'visitor':theme.COLOR_USER_VISITOR, @@ -117,8 +116,8 @@ class UserList(Win): } def refresh(self, users): - if not self.visible: - return + # if not self.visible: + # return with g_lock: self._win.erase() y = 0 @@ -148,16 +147,15 @@ class UserList(Win): self._win.attroff(curses.color_pair(theme.COLOR_VERTICAL_SEPARATOR)) class Topic(Win): - def __init__(self, height, width, y, x, parent_win, visible): - self.visible = visible - Win.__init__(self, height, width, y, x, parent_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 refresh(self, topic): - if not self.visible: - return + # 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)) @@ -169,16 +167,15 @@ class Topic(Win): self._refresh() class GlobalInfoBar(Win): - def __init__(self, height, width, y, x, parent_win, visible): - self.visible = visible - Win.__init__(self, height, width, y, x, parent_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 refresh(self, tabs, current): - if not self.visible: - return + # if not self.visible: + # return def compare_room(a): # return a.nb - b.nb return a.nb @@ -207,9 +204,8 @@ class InfoWin(Win): Base class for all the *InfoWin, used in various tabs. For example MucInfoWin, etc. Provides some useful methods. """ - def __init__(self, height, width, y, x, parent_win, visible): - self.visible = visible - Win.__init__(self, height, width, y, x, parent_win) + def __init__(self): + Win.__init__(self) def print_scroll_position(self, text_buffer): """ @@ -226,15 +222,15 @@ class PrivateInfoWin(InfoWin): The live above the information window, displaying informations about the MUC user we are talking to """ - def __init__(self, height, width, y, x, parent_win, visible): - InfoWin.__init__(self, height, width, y, x, parent_win, visible) + def __init__(self): + InfoWin.__init__(self) def resize(self, height, width, y, x, stdscr, visible): self._resize(height, width, y, x, stdscr, visible) def refresh(self, room): - if not self.visible: - return + # if not self.visible: + # return with g_lock: self._win.erase() self.write_room_name(room) @@ -263,15 +259,15 @@ class ConversationInfoWin(InfoWin): 'unavailable':theme.COLOR_STATUS_UNAVAILABLE } - def __init__(self, height, width, y, x, parent_win, visible): - InfoWin.__init__(self, height, width, y, x, parent_win, visible) + def __init__(self): + InfoWin.__init__(self) def resize(self, height, width, y, x, stdscr, visible): self._resize(height, width, y, x, stdscr, visible) def refresh(self, jid, contact, text_buffer): - if not self.visible: - return + # 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. @@ -332,15 +328,15 @@ class ConversationStatusMessageWin(InfoWin): """ The upper bar displaying the status message of the contact """ - def __init__(self, height, width, y, x, parent_win, visible): - InfoWin.__init__(self, height, width, y, x, parent_win, visible) + def __init__(self): + InfoWin.__init__(self) def resize(self, height, width, y, x, stdscr, visible): self._resize(height, width, y, x, stdscr, visible) def refresh(self, jid, contact): - if not self.visible: - return + # if not self.visible: + # return jid = JID(jid) if contact: if jid.resource: @@ -364,15 +360,15 @@ class MucInfoWin(InfoWin): The line just above the information window, displaying informations about the MUC we are viewing """ - def __init__(self, height, width, y, x, parent_win, visible): - InfoWin.__init__(self, height, width, y, x, parent_win, visible) + def __init__(self): + InfoWin.__init__(self) def resize(self, height, width, y, x, stdscr, visible): self._resize(height, width, y, x, stdscr, visible) def refresh(self, room): - if not self.visible: - return + # if not self.visible: + # return with g_lock: self._win.erase() self.write_room_name(room) @@ -430,9 +426,8 @@ class TextWin(Win): Just keep ONE single window for the text area and rewrite EVERYTHING on each change. (thanks weechat :o) """ - def __init__(self, height, width, y, x, parent_win, visible): - Win.__init__(self, height, width, y, x, parent_win) - self.visible = visible + def __init__(self): + Win.__init__(self) def build_lines_from_messages(self, messages): """ @@ -498,8 +493,8 @@ class TextWin(Win): Build the Line objects from the messages, and then write them in the text area """ - if not self.visible: - return + # if not self.visible: + # return if self.height <= 0: return with g_lock: @@ -611,17 +606,16 @@ class HelpText(Win): Usually used to replace an Input when the tab is in command mode. """ - def __init__(self, height, width, y, x, parent_win, visible, text=''): - self.visible = visible - Win.__init__(self, height, width, y, x, parent_win) + def __init__(self, text=''): + Win.__init__(self) self.txt = text def resize(self, height, width, y, x, stdscr, visible): self._resize(height, width, y, x, stdscr, visible) def refresh(self): - if not self.visible: - return + # 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)) @@ -645,7 +639,7 @@ class Input(Win): """ clipboard = '' # A common clipboard for all the inputs, this makes # it easy cut and paste text between various input - def __init__(self, height, width, y, x, stdscr, visible): + def __init__(self): self.key_func = { "KEY_LEFT": self.key_left, "M-D": self.key_left, @@ -667,8 +661,7 @@ class Input(Win): '^?': self.key_backspace, } - Win.__init__(self, height, width, y, x, stdscr) - self.visible = visible + Win.__init__(self) self.text = '' self.pos = 0 # cursor position self.line_pos = 0 # position (in self.text) of @@ -970,8 +963,8 @@ class Input(Win): self._refresh() def refresh(self): - if not self.visible: - return + # if not self.visible: + # return self.rewrite_text() def clear_text(self): @@ -987,8 +980,8 @@ class MessageInput(Input): """ history = list() # The history is common to all MessageInput - def __init__(self, height, width, y, x, stdscr, visible): - Input.__init__(self, height, width, y, x, stdscr, visible) + def __init__(self): + Input.__init__(self) self.last_completion = None self.histo_pos = 0 self.key_func["KEY_UP"] = self.key_up @@ -1044,9 +1037,8 @@ class CommandInput(Input): HelpMessage when a command is started The on_input callback """ - def __init__(self, height, width, y, x, stdscr, visible, - help_message, on_abort, on_success, on_input=None): - Input.__init__(self, height, width, y, x, stdscr, visible) + def __init__(self, help_message, on_abort, on_success, on_input=None): + Input.__init__(self) self.on_abort = on_abort self.on_success = on_success self.on_input = on_input @@ -1098,9 +1090,8 @@ class VerticalSeparator(Win): Just a one-column window, with just a line in it, that is refreshed only on resize, but never on refresh, for efficiency """ - def __init__(self, height, width, y, x, parent_win, visible): - Win.__init__(self, height, width, y, x, parent_win) - self.visible = visible + def __init__(self): + Win.__init__(self) def rewrite_line(self): with g_lock: @@ -1114,8 +1105,8 @@ class VerticalSeparator(Win): return def refresh(self): - if not self.visible: - return + # if not self.visible: + # return self.rewrite_line() class RosterWin(Win): @@ -1129,9 +1120,8 @@ class RosterWin(Win): 'unavailable':theme.COLOR_STATUS_UNAVAILABLE } - def __init__(self, height, width, y, x, parent_win, visible): - self.visible = visible - Win.__init__(self, height, width, y, x, parent_win) + def __init__(self): + Win.__init__(self) self.pos = 0 # cursor position in the contact list self.start_pos = 1 # position of the start of the display self.roster_len = 0 @@ -1163,8 +1153,8 @@ class RosterWin(Win): """ We get the roster object """ - if not self.visible: - return + # if not self.visible: + # return with g_lock: self.roster_len = len(roster) while self.roster_len and self.pos >= self.roster_len: @@ -1285,9 +1275,8 @@ class RosterWin(Win): return self.selected_row class ContactInfoWin(Win): - def __init__(self, height, width, y, x, parent_win, visible): - self.visible = visible - Win.__init__(self, height, width, y, x, parent_win) + def __init__(self): + Win.__init__(self) def resize(self, height, width, y, x, stdscr, visible): self._resize(height, width, y, x, stdscr, visible) @@ -1314,8 +1303,8 @@ class ContactInfoWin(Win): self.finish_line(theme.COLOR_INFORMATION_BAR) def refresh(self, selected_row): - if not self.visible: - return + # if not self.visible: + # return with g_lock: self._win.erase() if isinstance(selected_row, RosterGroup):