diff --git a/src/history_window.py b/src/history_window.py index 2ad639fb7..1478720be 100644 --- a/src/history_window.py +++ b/src/history_window.py @@ -43,23 +43,25 @@ constants = Constants() # Completion dict ( -C_INFO_JID, -C_INFO_ACCOUNT, -C_INFO_NAME, -C_INFO_COMPLETION + C_INFO_JID, + C_INFO_ACCOUNT, + C_INFO_NAME, + C_INFO_COMPLETION ) = range(4) # contact_name, date, message, time ( -C_LOG_JID, -C_CONTACT_NAME, -C_UNIXTIME, -C_MESSAGE, -C_TIME + C_LOG_JID, + C_CONTACT_NAME, + C_UNIXTIME, + C_MESSAGE, + C_TIME ) = range(5) class HistoryWindow: - '''Class for browsing logs of conversations with contacts''' + """ + Class for browsing logs of conversations with contacts + """ def __init__(self, jid = None, account = None): xml = gtkgui_helpers.get_glade('history_window.glade') @@ -132,15 +134,16 @@ class HistoryWindow: self.window.show_all() def _fill_completion_dict(self): - '''Fill completion_dict for key auto completion. Then load history for - current jid (by calling another function). + """ + Fill completion_dict for key auto completion. Then load history for + current jid (by calling another function) - Key will be either jid or full_completion_name - (contact name or long description like "pm-contact from groupchat....") + Key will be either jid or full_completion_name (contact name or long + description like "pm-contact from groupchat...."). {key : (jid, account, nick_name, full_completion_name} - this is a generator and does pseudo-threading via idle_add() - ''' + This is a generator and does pseudo-threading via idle_add(). + """ liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry) # Add all jids in logs.db: @@ -208,8 +211,10 @@ class HistoryWindow: yield False def _get_account_for_jid(self, jid): - '''Return the corresponding account of the jid. - May be None if an account could not be found''' + """ + Return the corresponding account of the jid. May be None if an account + could not be found + """ accounts = gajim.contacts.get_accounts() account = None for acc in accounts: @@ -247,7 +252,9 @@ class HistoryWindow: widget.select_region(0, -1) # select text def _load_history(self, jid_or_name, account = None): - '''Load history for the given jid/name and show it''' + """ + Load history for the given jid/name and show it + """ if jid_or_name and jid_or_name in self.completion_dict: # a full qualified jid or a contact name was entered info_jid, info_account, info_name, info_completion = self.completion_dict[jid_or_name] @@ -324,9 +331,9 @@ class HistoryWindow: self._add_lines_for_date(year, month, day) def on_calendar_month_changed(self, widget): - '''asks for days in this month if they have logs it bolds them (marks - them) - ''' + """ + Ask for days in this month, if they have logs it bolds them (marks them) + """ if not self.jid: return year, month, day = widget.get_date() # integers @@ -362,7 +369,9 @@ class HistoryWindow: return show def _add_lines_for_date(self, year, month, day): - '''adds all the lines for given date in textbuffer''' + """ + Add all the lines for given date in textbuffer + """ self.history_buffer.set_text('') # clear the buffer first self.last_time_printout = 0 @@ -376,7 +385,9 @@ class HistoryWindow: line[5]) def _add_new_line(self, contact_name, tim, kind, show, message, subject): - '''add a new line in textbuffer''' + """ + Add a new line in textbuffer + """ if not message and kind not in (constants.KIND_STATUS, constants.KIND_GCSTATUS): return @@ -538,8 +549,10 @@ class HistoryWindow: self.jids_to_search = gajim.logger.get_jids_in_db() def on_results_treeview_row_activated(self, widget, path, column): - '''a row was double clicked, get date from row, and select it in calendar - which results to showing conversation logs for that date''' + """ + A row was double clicked, get date from row, and select it in calendar + which results to showing conversation logs for that date + """ # get currently selected date cur_year, cur_month = self.calendar.get_date()[0:2] cur_month = gtkgui_helpers.make_gtk_month_python_month(cur_month) @@ -568,7 +581,9 @@ class HistoryWindow: # and highlight all that def _scroll_to_result(self, unix_time): - '''scrolls to the result using unix_time and highlight line''' + """ + Scroll to the result using unix_time and highlight line + """ start_iter = self.history_buffer.get_start_iter() local_time = time.localtime(float(unix_time)) tim = time.strftime('%X', local_time) @@ -602,7 +617,9 @@ class HistoryWindow: ' '.join(no_log_for)) def open_history(self, jid, account): - '''Load chat history of the specified jid''' + """ + Load chat history of the specified jid + """ self.jid_entry.set_text(jid) if account and account not in self.accounts_seen_online: # Update dict to not only show bare jid diff --git a/src/htmltextview.py b/src/htmltextview.py index 5c12a049c..8b65d8f87 100644 --- a/src/htmltextview.py +++ b/src/htmltextview.py @@ -25,7 +25,7 @@ ## along with Gajim. If not, see . ## -''' +""" A gtk.TextView-based renderer for XHTML-IM, as described in: http://www.jabber.org/jeps/jep-0071.html @@ -33,8 +33,7 @@ Starting with the version posted by Gustavo Carneiro, I (Santiago Gala) am trying to make it more compatible with the markup that docutils generate, and also more modular. - -''' +""" import gobject import pango @@ -187,7 +186,6 @@ for name in BLOCK_HEAD: ) def _parse_css_color(color): - '''_parse_css_color(css_color) -> gtk.gdk.Color''' if color.startswith('rgb(') and color.endswith(')'): r, g, b = [int(c)*257 for c in color[4:-1].split(',')] return gtk.gdk.Color(r, g, b) @@ -200,10 +198,11 @@ def style_iter(style): class HtmlHandler(xml.sax.handler.ContentHandler): - """A handler to display html to a gtk textview. + """ + A handler to display html to a gtk textview - It keeps a stack of "style spans" (start/end element pairs) - and a stack of list counters, for nested lists. + It keeps a stack of "style spans" (start/end element pairs) and a stack of + list counters, for nested lists. """ def __init__(self, conv_textview, startiter): xml.sax.handler.ContentHandler.__init__(self) @@ -240,8 +239,10 @@ class HtmlHandler(xml.sax.handler.ContentHandler): callback(allocation.width*frac, *args) def _parse_length(self, value, font_relative, block_relative, minl, maxl, callback, *args): - '''Parse/calc length, converting to pixels, calls callback(length, *args) - when the length is first computed or changes''' + """ + Parse/calc length, converting to pixels, calls callback(length, *args) + when the length is first computed or changes + """ if value.endswith('%'): val = float(value[:-1]) sign = cmp(val,0) @@ -556,11 +557,11 @@ class HtmlHandler(xml.sax.handler.ContentHandler): if h: self._parse_length(h, False, False, 1, 1000, height_cb) def set_size(pixbuf, w, h, dims): - '''FIXME: floats should be relative to the whole - textview, and resize with it. This needs new - pifbufs for every resize, gtk.gdk.Pixbuf.scale_simple - or similar. - ''' + """ + FIXME: Floats should be relative to the whole textview, and + resize with it. This needs new pifbufs for every resize, + gtk.gdk.Pixbuf.scale_simple or similar. + """ if isinstance(dims[0], float): dims[0] = int(dims[0]*w) elif not dims[0]: @@ -945,7 +946,9 @@ if __name__ == '__main__': tooltip = tooltips.BaseTooltip() def on_textview_motion_notify_event(widget, event): - '''change the cursor to a hand when we are over a mail or an url''' + """ + Change the cursor to a hand when we are over a mail or an url + """ global change_cursor pointer_x, pointer_y = htmlview.tv.window.get_pointer()[0:2] x, y = htmlview.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, pointer_x, diff --git a/src/ipython_view.py b/src/ipython_view.py index 4bc8a9564..a901643f6 100644 --- a/src/ipython_view.py +++ b/src/ipython_view.py @@ -29,8 +29,8 @@ ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -''' -Provides IPython console widget. +""" +Provides IPython console widget @author: Eitan Isaacson @organization: IBM Corporation @@ -40,7 +40,7 @@ Provides IPython console widget. All rights reserved. This program and the accompanying materials are made available under the terms of the BSD which accompanies this distribution, and is available at U{http://www.opensource.org/licenses/bsd-license.php} -''' +""" import gtk, gobject import re @@ -55,10 +55,10 @@ except ImportError: IPython = None class IterableIPShell: - ''' + """ Create an IPython instance. Does not start a blocking event loop, instead allow single iterations. This allows embedding in GTK+ - without blockage. + without blockage @ivar IP: IPython instance. @type IP: IPython.iplib.InteractiveShell @@ -70,12 +70,10 @@ class IterableIPShell: @type history_level: integer @ivar complete_sep: Seperation delimeters for completion function. @type complete_sep: _sre.SRE_Pattern - ''' - def __init__(self,argv=[],user_ns=None,user_global_ns=None, - cin=None, cout=None,cerr=None, input_func=None): - ''' - - + """ + def __init__(self,argv=[],user_ns=None,user_global_ns=None, cin=None, + cout=None,cerr=None, input_func=None): + """ @param argv: Command line options for IPython @type argv: list @param user_ns: User namespace. @@ -90,7 +88,7 @@ class IterableIPShell: @type cerr: IO stream @param input_func: Replacement for builtin raw_input() @type input_func: function - ''' + """ if input_func: IPython.iplib.raw_input_original = input_func if cin: @@ -121,9 +119,9 @@ class IterableIPShell: self.complete_sep = re.compile('[\s\{\}\[\]\(\)]') def execute(self): - ''' - Executes the current line provided by the shell object. - ''' + """ + Execute the current line provided by the shell object + """ self.history_level = 0 orig_stdout = sys.stdout sys.stdout = IPython.Shell.Term.cout @@ -156,32 +154,32 @@ class IterableIPShell: sys.stdout = orig_stdout def historyBack(self): - ''' - Provides one history command back. + """ + Provide one history command back @return: The command string. @rtype: string - ''' + """ self.history_level -= 1 return self._getHistory() def historyForward(self): - ''' - Provides one history command forward. + """ + Provide one history command forward @return: The command string. @rtype: string - ''' + """ self.history_level += 1 return self._getHistory() def _getHistory(self): - ''' - Get's the command string of the current history level. + """ + Get the command string of the current history level @return: Historic command string. @rtype: string - ''' + """ try: rv = self.IP.user_ns['In'][self.history_level].strip('\n') except IndexError: @@ -190,17 +188,17 @@ class IterableIPShell: return rv def updateNamespace(self, ns_dict): - ''' - Add the current dictionary to the shell namespace. + """ + Add the current dictionary to the shell namespace @param ns_dict: A dictionary of symbol-values. @type ns_dict: dictionary - ''' + """ self.IP.user_ns.update(ns_dict) def complete(self, line): - ''' - Returns an auto completed line and/or posibilities for completion. + """ + Returns an auto completed line and/or posibilities for completion @param line: Given line so far. @type line: string @@ -208,7 +206,7 @@ class IterableIPShell: @return: Line completed as for as possible, and possible further completions. @rtype: tuple - ''' + """ split_line = self.complete_sep.split(line) possibilities = self.IP.complete(split_line[-1]) @@ -222,7 +220,9 @@ class IterableIPShell: return True def common_prefix(seq): - """Returns the common prefix of a sequence of strings""" + """ + Return the common prefix of a sequence of strings + """ return "".join(c for i, c in enumerate(seq[0]) if all(s.startswith(c, i) for s in seq)) if possibilities: @@ -233,8 +233,8 @@ class IterableIPShell: def shell(self, cmd,verbose=0,debug=0,header=''): - ''' - Replacement method to allow shell commands without them blocking. + """ + Replacement method to allow shell commands without them blocking @param cmd: Shell command to execute. @type cmd: string @@ -244,7 +244,7 @@ class IterableIPShell: @type debug: integer @param header: Header to be printed before output @type header: string - ''' + """ if verbose or debug: print header+cmd # flush stdout so we don't mangle python's buffering if not debug: @@ -254,8 +254,8 @@ class IterableIPShell: input_.close() class ConsoleView(gtk.TextView): - ''' - Specialized text view for console-like workflow. + """ + Specialized text view for console-like workflow @cvar ANSI_COLORS: Mapping of terminal colors to X11 names. @type ANSI_COLORS: dictionary @@ -268,7 +268,8 @@ class ConsoleView(gtk.TextView): @type mark: gtk.TextMark @ivar line_start: Start of command line mark. @type line_start: gtk.TextMark - ''' + """ + ANSI_COLORS = {'0;30': 'Black', '0;31': 'Red', '0;32': 'Green', '0;33': 'Brown', '0;34': 'Blue', '0;35': 'Purple', @@ -279,9 +280,9 @@ class ConsoleView(gtk.TextView): '1;36': 'LightCyan', '1;37': 'White'} def __init__(self): - ''' - Initialize console view. - ''' + """ + Initialize console view + """ gtk.TextView.__init__(self) self.modify_font(pango.FontDescription('Mono')) self.set_cursor_visible(True) @@ -305,14 +306,14 @@ class ConsoleView(gtk.TextView): gobject.idle_add(self._write, text, editable) def _write(self, text, editable=False): - ''' - Write given text to buffer. + """ + Write given text to buffer @param text: Text to append. @type text: string @param editable: If true, added text is editable. @type editable: boolean - ''' + """ segments = self.color_pat.split(text) segment = segments.pop(0) start_mark = self.text_buffer.create_mark(None, @@ -339,12 +340,12 @@ class ConsoleView(gtk.TextView): gobject.idle_add(self._showPrompt, prompt) def _showPrompt(self, prompt): - ''' - Prints prompt at start of line. + """ + Print prompt at start of line @param prompt: Prompt to print. @type prompt: string - ''' + """ self._write(prompt) self.text_buffer.move_mark(self.line_start, self.text_buffer.get_end_iter()) @@ -353,24 +354,24 @@ class ConsoleView(gtk.TextView): gobject.idle_add(self._changeLine, text) def _changeLine(self, text): - ''' - Replace currently entered command line with given text. + """ + Replace currently entered command line with given text @param text: Text to use as replacement. @type text: string - ''' + """ iter_ = self.text_buffer.get_iter_at_mark(self.line_start) iter_.forward_to_line_end() self.text_buffer.delete(self.text_buffer.get_iter_at_mark(self.line_start), iter_) self._write(text, True) def getCurrentLine(self): - ''' - Get text in current command line. + """ + Get text in current command line @return: Text of current command line. @rtype: string - ''' + """ rv = self.text_buffer.get_slice( self.text_buffer.get_iter_at_mark(self.line_start), self.text_buffer.get_end_iter(), False) @@ -380,12 +381,12 @@ class ConsoleView(gtk.TextView): gobject.idle_add(self._showReturned, text) def _showReturned(self, text): - ''' - Show returned text from last command and print new prompt. + """ + Show returned text from last command and print new prompt @param text: Text to show. @type text: string - ''' + """ iter_ = self.text_buffer.get_iter_at_mark(self.line_start) iter_.forward_to_line_end() self.text_buffer.apply_tag_by_name( @@ -400,10 +401,10 @@ class ConsoleView(gtk.TextView): self.text_buffer.place_cursor(self.text_buffer.get_end_iter()) def onKeyPress(self, widget, event): - ''' + """ Key press callback used for correcting behavior for console-like interfaces. For example 'home' should go to prompt, not to begining of - line. + line @param widget: Widget that key press accored in. @type widget: gtk.Widget @@ -412,7 +413,7 @@ class ConsoleView(gtk.TextView): @return: Return True if event should not trickle. @rtype: boolean - ''' + """ insert_mark = self.text_buffer.get_insert() insert_iter = self.text_buffer.get_iter_at_mark(insert_mark) selection_mark = self.text_buffer.get_selection_bound() @@ -445,9 +446,9 @@ class ConsoleView(gtk.TextView): return self.onKeyPressExtend(event) def onKeyPressExtend(self, event): - ''' - For some reason we can't extend onKeyPress directly (bug #500900). - ''' + """ + For some reason we can't extend onKeyPress directly (bug #500900) + """ pass class IPythonView(ConsoleView, IterableIPShell): @@ -456,9 +457,9 @@ class IPythonView(ConsoleView, IterableIPShell): a GTK+ IPython console. ''' def __init__(self): - ''' - Initialize. Redirect I/O to console. - ''' + """ + Initialize. Redirect I/O to console + """ ConsoleView.__init__(self) self.cout = StringIO() IterableIPShell.__init__(self, cout=self.cout,cerr=self.cout, @@ -470,24 +471,24 @@ class IPythonView(ConsoleView, IterableIPShell): self.interrupt = False def raw_input(self, prompt=''): - ''' - Custom raw_input() replacement. Get's current line from console buffer. + """ + Custom raw_input() replacement. Get's current line from console buffer @param prompt: Prompt to print. Here for compatability as replacement. @type prompt: string @return: The current command line text. @rtype: string - ''' + """ if self.interrupt: self.interrupt = False raise KeyboardInterrupt return self.getCurrentLine() def onKeyPressExtend(self, event): - ''' + """ Key press callback with plenty of shell goodness, like history, - autocompletions, etc. + autocompletions, etc @param widget: Widget that key press occured in. @type widget: gtk.Widget @@ -496,7 +497,7 @@ class IPythonView(ConsoleView, IterableIPShell): @return: True if event should not trickle. @rtype: boolean - ''' + """ if event.state & gtk.gdk.CONTROL_MASK and event.keyval == 99: self.interrupt = True self._processLine() @@ -524,9 +525,9 @@ class IPythonView(ConsoleView, IterableIPShell): return True def _processLine(self): - ''' - Process current command line. - ''' + """ + Process current command line + """ self.history_pos = 0 self.execute() rv = self.cout.getvalue() diff --git a/src/message_control.py b/src/message_control.py index 7ee724554..40d4beb07 100644 --- a/src/message_control.py +++ b/src/message_control.py @@ -39,7 +39,10 @@ TYPE_PM = 'pm' #################### class MessageControl: - '''An abstract base widget that can embed in the gtk.Notebook of a MessageWindow''' + """ + An abstract base widget that can embed in the gtk.Notebook of a + MessageWindow + """ def __init__(self, type_id, parent_win, widget_name, contact, account, resource = None): # dict { cb id : widget} @@ -67,57 +70,87 @@ class MessageControl: return fjid def set_control_active(self, state): - '''Called when the control becomes active (state is True) - or inactive (state is False)''' + """ + Called when the control becomes active (state is True) or inactive (state + is False) + """ pass # Derived classes MUST implement this method def minimizable(self): - '''Called to check if control can be minimized''' - # NOTE: Derived classes MAY implement this + """ + Called to check if control can be minimized + + Derived classes MAY implement this. + """ return False def safe_shutdown(self): - '''Called to check if control can be closed without loosing data. - returns True if control can be closed safely else False''' - # NOTE: Derived classes MAY implement this + """ + Called to check if control can be closed without loosing data. + returns True if control can be closed safely else False + + Derived classes MAY implement this. + """ return True def allow_shutdown(self, method, on_response_yes, on_response_no, - on_response_minimize): - '''Called to check is a control is allowed to shutdown. + on_response_minimize): + """ + Called to check is a control is allowed to shutdown. If a control is not in a suitable shutdown state this method should call on_response_no, else on_response_yes or - on_response_minimize ''' - # NOTE: Derived classes MAY implement this + on_response_minimize + + Derived classes MAY implement this. + """ on_response_yes(self) def shutdown(self): - # NOTE: Derived classes MUST implement this + """ + Derived classes MUST implement this + """ pass def repaint_themed_widgets(self): - pass # NOTE: Derived classes SHOULD implement this + """ + Derived classes SHOULD implement this + """ + pass def update_ui(self): - pass # NOTE: Derived classes SHOULD implement this + """ + Derived classes SHOULD implement this + """ + pass def toggle_emoticons(self): - pass # NOTE: Derived classes MAY implement this + """ + Derived classes MAY implement this + """ + pass def update_font(self): - pass # NOTE: Derived classes SHOULD implement this + """ + Derived classes SHOULD implement this + """ + pass def update_tags(self): - pass # NOTE: Derived classes SHOULD implement this + """ + Derived classes SHOULD implement this + """ + pass def get_tab_label(self, chatstate): - '''Return a suitable tab label string. Returns a tuple such as: - (label_str, color) either of which can be None - if chatstate is given that means we have HE SENT US a chatstate and - we want it displayed''' - # NOTE: Derived classes MUST implement this + """ + Return a suitable tab label string. Returns a tuple such as: (label_str, + color) either of which can be None if chatstate is given that means we + have HE SENT US a chatstate and we want it displayed + + Derivded classes MUST implement this. + """ # Return a markup'd label and optional gtk.Color in a tupple like: - #return (label_str, None) + # return (label_str, None) pass def get_tab_image(self, count_unread=True): @@ -126,11 +159,15 @@ class MessageControl: return None def prepare_context_menu(self): - # NOTE: Derived classes SHOULD implement this + """ + Derived classes SHOULD implement this + """ return None def chat_buttons_set_visible(self, state): - # NOTE: Derived classes MAY implement this + """ + Derived classes MAY implement this + """ self.hide_chat_buttons = state def got_connected(self): @@ -170,8 +207,8 @@ class MessageControl: self.print_esession_details() def send_message(self, message, keyID='', type_='chat', chatstate=None, - msg_id=None, composing_xep=None, resource=None, user_nick=None, xhtml=None, - callback=None, callback_args=[]): + msg_id=None, composing_xep=None, resource=None, user_nick=None, + xhtml=None, callback=None, callback_args=[]): # Send the given message to the active tab. # Doesn't return None if error jid = self.contact.jid diff --git a/src/message_window.py b/src/message_window.py index 8adb580d6..5e6fe5596 100644 --- a/src/message_window.py +++ b/src/message_window.py @@ -42,8 +42,9 @@ from common import gajim #################### class MessageWindow(object): - '''Class for windows which contain message like things; chats, - groupchats, etc.''' + """ + Class for windows which contain message like things; chats, groupchats, etc + """ # DND_TARGETS is the targets needed by drag_source_set and drag_dest_set DND_TARGETS = [('GAJIM_TAB', 0, 81)] @@ -160,7 +161,9 @@ class MessageWindow(object): self.account = new_name def change_jid(self, account, old_jid, new_jid): - ''' call then when the full jid of a contral change''' + """ + Called when the full jid of the control is changed + """ if account not in self._controls: return if old_jid not in self._controls[account]: @@ -417,7 +420,9 @@ class MessageWindow(object): return True def _on_close_button_clicked(self, button, control): - '''When close button is pressed: close a tab''' + """ + When close button is pressed: close a tab + """ self.remove_tab(control, self.CLOSE_CLOSE_BUTTON) def show_icon(self): @@ -444,7 +449,9 @@ class MessageWindow(object): self.window.set_icon(icon.get_pixbuf()) def show_title(self, urgent=True, control=None): - '''redraw the window's title''' + """ + Redraw the window's title + """ if not control: control = self.get_active_control() if not control: @@ -512,8 +519,10 @@ class MessageWindow(object): self.window.present() def remove_tab(self, ctrl, method, reason = None, force = False): - '''reason is only for gc (offline status message) - if force is True, do not ask any confirmation''' + """ + Reason is only for gc (offline status message) if force is True, do not + ask any confirmation + """ def close(ctrl): if reason is not None: # We are leaving gc with a status message ctrl.shutdown(reason) @@ -616,7 +625,9 @@ class MessageWindow(object): self.show_icon() def repaint_themed_widgets(self): - '''Repaint controls in the window with theme color''' + """ + Repaint controls in the window with theme color + """ # iterate through controls and repaint for ctrl in self.controls(): ctrl.repaint_themed_widgets() @@ -663,8 +674,10 @@ class MessageWindow(object): ctrl.update_tags() def get_control(self, key, acct): - '''Return the MessageControl for jid or n, where n is a notebook page index. - When key is an int index acct may be None''' + """ + Return the MessageControl for jid or n, where n is a notebook page index. + When key is an int index acct may be None + """ if isinstance(key, str): key = unicode(key, 'utf-8') @@ -686,7 +699,9 @@ class MessageWindow(object): return (acct in self._controls and jid in self._controls[acct]) def change_key(self, old_jid, new_jid, acct): - '''Change the JID key of a control''' + """ + Change the JID key of a control + """ try: # Check if controls exists ctrl = self._controls[acct][old_jid] @@ -814,10 +829,10 @@ class MessageWindow(object): control.msg_textview.grab_focus() def get_tab_at_xy(self, x, y): - '''Thanks to Gaim - Return the tab under xy and - if its nearer from left or right side of the tab - ''' + """ + Return the tab under xy and if its nearer from left or right side of the + tab + """ page_num = -1 to_right = False horiz = self.notebook.get_tab_pos() == gtk.POS_TOP or \ @@ -844,7 +859,9 @@ class MessageWindow(object): return (page_num, to_right) def find_page_num_according_to_tab_label(self, tab_label): - '''Find the page num of the tab label''' + """ + Find the page num of the tab label + """ page_num = -1 for i in xrange(self.notebook.get_n_pages()): page = self.notebook.get_nth_page(i) @@ -856,18 +873,21 @@ class MessageWindow(object): ################################################################################ class MessageWindowMgr(gobject.GObject): - '''A manager and factory for MessageWindow objects''' + """ + A manager and factory for MessageWindow objects + """ + __gsignals__ = { 'window-delete': (gobject.SIGNAL_RUN_LAST, None, (object,)), } # These constants map to common.config.opt_one_window_types indices ( - ONE_MSG_WINDOW_NEVER, - ONE_MSG_WINDOW_ALWAYS, - ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER, - ONE_MSG_WINDOW_PERACCT, - ONE_MSG_WINDOW_PERTYPE, + ONE_MSG_WINDOW_NEVER, + ONE_MSG_WINDOW_ALWAYS, + ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER, + ONE_MSG_WINDOW_PERACCT, + ONE_MSG_WINDOW_PERTYPE, ) = range(5) # A key constant for the main window in ONE_MSG_WINDOW_ALWAYS mode MAIN_WIN = 'main' @@ -875,12 +895,14 @@ class MessageWindowMgr(gobject.GObject): ROSTER_MAIN_WIN = 'roster' def __init__(self, parent_window, parent_paned): - ''' A dictionary of windows; the key depends on the config: - ONE_MSG_WINDOW_NEVER: The key is the contact JID - ONE_MSG_WINDOW_ALWAYS: The key is MessageWindowMgr.MAIN_WIN - ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: The key is MessageWindowMgr.MAIN_WIN - ONE_MSG_WINDOW_PERACCT: The key is the account name - ONE_MSG_WINDOW_PERTYPE: The key is a message type constant''' + """ + A dictionary of windows; the key depends on the config: + ONE_MSG_WINDOW_NEVER: The key is the contact JID + ONE_MSG_WINDOW_ALWAYS: The key is MessageWindowMgr.MAIN_WIN + ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: The key is MessageWindowMgr.MAIN_WIN + ONE_MSG_WINDOW_PERACCT: The key is the account name + ONE_MSG_WINDOW_PERTYPE: The key is a message type constant + """ gobject.GObject.__init__(self) self._windows = {} @@ -931,7 +953,9 @@ class MessageWindowMgr(gobject.GObject): return False def _resize_window(self, win, acct, type_): - '''Resizes window according to config settings''' + """ + Resizes window according to config settings + """ if self.mode in (self.ONE_MSG_WINDOW_ALWAYS, self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER): size = (gajim.config.get('msgwin-width'), @@ -958,7 +982,9 @@ class MessageWindowMgr(gobject.GObject): win.parent_paned.set_position(parent_size[0]) def _position_window(self, win, acct, type_): - '''Moves window according to config settings''' + """ + Moves window according to config settings + """ if (self.mode in [self.ONE_MSG_WINDOW_NEVER, self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER]): return @@ -1054,15 +1080,19 @@ class MessageWindowMgr(gobject.GObject): return def get_control(self, jid, acct): - '''Amongst all windows, return the MessageControl for jid''' + """ + Amongst all windows, return the MessageControl for jid + """ win = self.get_window(jid, acct) if win: return win.get_control(jid, acct) return None def get_gc_control(self, jid, acct): - '''Same as get_control. Was briefly required, is not any more. -May be useful some day in the future?''' + """ + Same as get_control. Was briefly required, is not any more. May be useful + some day in the future? + """ ctrl = self.get_control(jid, acct) if ctrl and ctrl.type_id == message_control.TYPE_GC: return ctrl diff --git a/src/negotiation.py b/src/negotiation.py index bd5a32123..a7cf5c043 100644 --- a/src/negotiation.py +++ b/src/negotiation.py @@ -27,14 +27,15 @@ from common import gajim from common import xmpp def describe_features(features): - '''a human-readable description of the features that have been negotiated''' + """ + A human-readable description of the features that have been negotiated + """ if features['logging'] == 'may': return _('- messages will be logged') elif features['logging'] == 'mustnot': return _('- messages will not be logged') class FeatureNegotiationWindow: - '''FeatureNegotiotionWindow class''' def __init__(self, account, jid, session, form): self.account = account self.jid = jid diff --git a/src/network_manager_listener.py b/src/network_manager_listener.py index 15a40bbf6..3f1f774ca 100644 --- a/src/network_manager_listener.py +++ b/src/network_manager_listener.py @@ -26,21 +26,27 @@ from common import gajim def device_now_active(self, *args): - '''For Network Manager 0.6''' + """ + For Network Manager 0.6 + """ for connection in gajim.connections.itervalues(): if gajim.config.get_per('accounts', connection.name, 'listen_to_network_manager') and connection.time_to_reconnect: connection._reconnect() def device_no_longer_active(self, *args): - '''For Network Manager 0.6''' + """ + For Network Manager 0.6 + """ for connection in gajim.connections.itervalues(): if gajim.config.get_per('accounts', connection.name, 'listen_to_network_manager') and connection.connected > 1: connection._disconnectedReconnCB() def state_changed(state): - '''For Network Manager 0.7''' + """ + For Network Manager 0.7 + """ if props.Get("org.freedesktop.NetworkManager", "State") == 3: for connection in gajim.connections.itervalues(): if gajim.config.get_per('accounts', connection.name, diff --git a/src/notify.py b/src/notify.py index 3d9eb6051..c155de29e 100644 --- a/src/notify.py +++ b/src/notify.py @@ -69,7 +69,9 @@ def server_display(server): win.present() def get_show_in_roster(event, account, contact, session=None): - '''Return True if this event must be shown in roster, else False''' + """ + Return True if this event must be shown in roster, else False + """ if event == 'gc_message_received': return True num = get_advanced_notification(event, account, contact) @@ -84,7 +86,9 @@ def get_show_in_roster(event, account, contact, session=None): return True def get_show_in_systray(event, account, contact, type_=None): - '''Return True if this event must be shown in systray, else False''' + """ + Return True if this event must be shown in systray, else False + """ num = get_advanced_notification(event, account, contact) if num is not None: if gajim.config.get_per('notifications', str(num), 'systray') == 'yes': @@ -98,8 +102,9 @@ def get_show_in_systray(event, account, contact, type_=None): return gajim.config.get('trayicon_notification_on_events') def get_advanced_notification(event, account, contact): - '''Returns the number of the first (top most) - advanced notification else None''' + """ + Returns the number of the first (top most) advanced notification else None + """ num = 0 notif = gajim.config.get_per('notifications', str(num)) while notif: @@ -146,10 +151,11 @@ def get_advanced_notification(event, account, contact): notif = gajim.config.get_per('notifications', str(num)) def notify(event, jid, account, parameters, advanced_notif_num=None): - '''Check what type of notifications we want, depending on basic - and the advanced configuration of notifications and do these notifications; - advanced_notif_num holds the number of the first (top most) advanced - notification''' + """ + Check what type of notifications we want, depending on basic and the advanced + configuration of notifications and do these notifications; advanced_notif_num + holds the number of the first (top most) advanced notification + """ # First, find what notifications we want do_popup = False do_sound = False @@ -327,12 +333,13 @@ def notify(event, jid, account, parameters, advanced_notif_num=None): except Exception: pass -def popup(event_type, jid, account, msg_type='', path_to_image=None, - title=None, text=None): - '''Notifies a user of an event. It first tries to a valid implementation of +def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None, + text=None): + """ + Notify a user of an event. It first tries to a valid implementation of the Desktop Notification Specification. If that fails, then we fall back to - the older style PopupNotificationWindow method.''' - + the older style PopupNotificationWindow method + """ # default image if not path_to_image: path_to_image = os.path.abspath( @@ -414,9 +421,12 @@ def on_pynotify_notification_clicked(notification, action): gajim.interface.handle_event(account, jid, msg_type) class NotificationResponseManager: - '''Collects references to pending DesktopNotifications and manages there - signalling. This is necessary due to a bug in DBus where you can't remove - a signal from an interface once it's connected.''' + """ + Collect references to pending DesktopNotifications and manages there + signalling. This is necessary due to a bug in DBus where you can't remove a + signal from an interface once it's connected + """ + def __init__(self): self.pending = {} self.received = [] @@ -464,8 +474,11 @@ class NotificationResponseManager: notification_response_manager = NotificationResponseManager() class DesktopNotification: - '''A DesktopNotification that interfaces with D-Bus via the Desktop - Notification specification''' + """ + A DesktopNotification that interfaces with D-Bus via the Desktop Notification + specification + """ + def __init__(self, event_type, jid, account, msg_type='', path_to_image=None, title=None, text=None): self.path_to_image = path_to_image diff --git a/src/profile_window.py b/src/profile_window.py index d00bfc335..a19623397 100644 --- a/src/profile_window.py +++ b/src/profile_window.py @@ -36,7 +36,9 @@ from common import gajim class ProfileWindow: - '''Class for our information window''' + """ + Class for our information window + """ def __init__(self, account): self.xml = gtkgui_helpers.get_glade('profile_window.glade') @@ -173,7 +175,9 @@ class ProfileWindow: on_response_cancel = on_cancel, on_response_clear = on_clear) def on_PHOTO_button_press_event(self, widget, event): - '''If right-clicked, show popup''' + """ + If right-clicked, show popup + """ if event.button == 3 and self.avatar_encoded: # right click menu = gtk.Menu() @@ -257,7 +261,9 @@ class ProfileWindow: self.update_progressbar_timeout_id = None def add_to_vcard(self, vcard_, entry, txt): - '''Add an information to the vCard dictionary''' + """ + Add an information to the vCard dictionary + """ entries = entry.split('_') loc = vcard_ if len(entries) == 3: # We need to use lists @@ -280,7 +286,9 @@ class ProfileWindow: return vcard_ def make_vcard(self): - '''make the vCard dictionary''' + """ + Make the vCard dictionary + """ entries = ['FN', 'NICKNAME', 'BDAY', 'EMAIL_HOME_USERID', 'URL', 'TEL_HOME_NUMBER', 'N_FAMILY', 'N_GIVEN', 'N_MIDDLE', 'N_PREFIX', 'N_SUFFIX', 'ADR_HOME_STREET', 'ADR_HOME_EXTADR', 'ADR_HOME_LOCALITY', diff --git a/src/remote_control.py b/src/remote_control.py index f50370708..87107cc0b 100644 --- a/src/remote_control.py +++ b/src/remote_control.py @@ -64,9 +64,10 @@ DBUS_DICT_SS = lambda : dbus.Dictionary({}, signature="ss") DBUS_NONE = lambda : dbus.Int32(0) def get_dbus_struct(obj): - ''' recursively go through all the items and replace - them with their casted dbus equivalents - ''' + """ + Recursively go through all the items and replace them with their casted dbus + equivalents + """ if obj is None: return DBUS_NONE() if isinstance(obj, (unicode, str)): @@ -110,8 +111,12 @@ class Remote: class SignalObject(dbus.service.Object): - ''' Local object definition for /org/gajim/dbus/RemoteObject. - (This docstring is not be visible, because the clients can access only the remote object.)''' + """ + Local object definition for /org/gajim/dbus/RemoteObject + + This docstring is not be visible, because the clients can access only the + remote object. + """ def __init__(self, bus_name): self.first_show = True @@ -193,14 +198,18 @@ class SignalObject(dbus.service.Object): pass def raise_signal(self, signal, arg): - '''raise a signal, with a single argument of unspecified type - Instead of obj.raise_signal("Foo", bar), use obj.Foo(bar).''' + """ + Raise a signal, with a single argument of unspecified type Instead of + obj.raise_signal("Foo", bar), use obj.Foo(bar) + """ getattr(self, signal)(arg) @dbus.service.method(INTERFACE, in_signature='s', out_signature='s') def get_status(self, account): - '''Returns status (show to be exact) which is the global one - unless account is given''' + """ + Return status (show to be exact) which is the global one unless account is + given + """ if not account: # If user did not ask for account, returns the global status return DBUS_STRING(helpers.get_global_show()) @@ -210,8 +219,9 @@ class SignalObject(dbus.service.Object): @dbus.service.method(INTERFACE, in_signature='s', out_signature='s') def get_status_message(self, account): - '''Returns status which is the global one - unless account is given''' + """ + Return status which is the global one unless account is given + """ if not account: # If user did not ask for account, returns the global status return DBUS_STRING(str(helpers.get_global_status())) @@ -220,7 +230,9 @@ class SignalObject(dbus.service.Object): return DBUS_STRING(status) def _get_account_and_contact(self, account, jid): - '''get the account (if not given) and contact instance from jid''' + """ + Get the account (if not given) and contact instance from jid + """ connected_account = None contact = None accounts = gajim.contacts.get_accounts() @@ -247,8 +259,10 @@ class SignalObject(dbus.service.Object): return connected_account, contact def _get_account_for_groupchat(self, account, room_jid): - '''get the account which is connected to groupchat (if not given) - or check if the given account is connected to the groupchat''' + """ + Get the account which is connected to groupchat (if not given) + or check if the given account is connected to the groupchat + """ connected_account = None accounts = gajim.contacts.get_accounts() # if there is only one account in roster, take it as default @@ -273,8 +287,10 @@ class SignalObject(dbus.service.Object): @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b') def send_file(self, file_path, jid, account): - '''send file, located at 'file_path' to 'jid', using account - (optional) 'account' ''' + """ + Send file, located at 'file_path' to 'jid', using account (optional) + 'account' + """ jid = self._get_real_jid(jid, account) connected_account, contact = self._get_account_and_contact(account, jid) @@ -289,8 +305,10 @@ class SignalObject(dbus.service.Object): def _send_message(self, jid, message, keyID, account, type_ = 'chat', subject = None): - '''can be called from send_chat_message (default when send_message) - or send_single_message''' + """ + Can be called from send_chat_message (default when send_message) or + send_single_message + """ if not jid or not message: return DBUS_BOOLEAN(False) if not keyID: @@ -305,22 +323,27 @@ class SignalObject(dbus.service.Object): @dbus.service.method(INTERFACE, in_signature='ssss', out_signature='b') def send_chat_message(self, jid, message, keyID, account): - '''Send chat 'message' to 'jid', using account (optional) 'account'. - if keyID is specified, encrypt the message with the pgp key ''' + """ + Send chat 'message' to 'jid', using account (optional) 'account'. If keyID + is specified, encrypt the message with the pgp key + """ jid = self._get_real_jid(jid, account) return self._send_message(jid, message, keyID, account) @dbus.service.method(INTERFACE, in_signature='sssss', out_signature='b') def send_single_message(self, jid, subject, message, keyID, account): - '''Send single 'message' to 'jid', using account (optional) 'account'. - if keyID is specified, encrypt the message with the pgp key ''' + """ + Send single 'message' to 'jid', using account (optional) 'account'. If + keyID is specified, encrypt the message with the pgp key + """ jid = self._get_real_jid(jid, account) return self._send_message(jid, message, keyID, account, type, subject) @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b') def send_groupchat_message(self, room_jid, message, account): - '''Send 'message' to groupchat 'room_jid', - using account (optional) 'account'.''' + """ + Send 'message' to groupchat 'room_jid', using account (optional) 'account' + """ if not room_jid or not message: return DBUS_BOOLEAN(False) connected_account = self._get_account_for_groupchat(account, room_jid) @@ -332,8 +355,10 @@ class SignalObject(dbus.service.Object): @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b') def open_chat(self, jid, account, message): - '''Shows the tabbed window for new message to 'jid', using account - (optional) 'account' ''' + """ + Shows the tabbed window for new message to 'jid', using account (optional) + 'account' + """ if not jid: raise dbus_support.MissingArgument() jid = self._get_real_jid(jid, account) @@ -384,8 +409,10 @@ class SignalObject(dbus.service.Object): @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b') def change_status(self, status, message, account): - ''' change_status(status, message, account). account is optional - - if not specified status is changed for all accounts. ''' + """ + change_status(status, message, account). Account is optional - if not + specified status is changed for all accounts + """ if status not in ('offline', 'online', 'chat', 'away', 'xa', 'dnd', 'invisible'): return DBUS_BOOLEAN(False) @@ -404,9 +431,10 @@ class SignalObject(dbus.service.Object): @dbus.service.method(INTERFACE, in_signature='ss', out_signature='') def set_priority(self, prio, account): - ''' set_priority(prio, account). account is optional - - if not specified priority is changed for all accounts. that are synced - with global status''' + """ + set_priority(prio, account). Account is optional - if not specified + priority is changed for all accounts. That are synced with global status + """ if account: gajim.config.set_per('accounts', account, 'priority', prio) show = gajim.SHOW_LIST[gajim.connections[account].connected] @@ -429,14 +457,17 @@ class SignalObject(dbus.service.Object): @dbus.service.method(INTERFACE, in_signature='', out_signature='') def show_next_pending_event(self): - '''Show the window(s) with next pending event in tabbed/group chats.''' + """ + Show the window(s) with next pending event in tabbed/group chats + """ if gajim.events.get_nb_events(): gajim.interface.systray.handle_first_event() @dbus.service.method(INTERFACE, in_signature='s', out_signature='a{sv}') def contact_info(self, jid): - '''get vcard info for a contact. Return cached value of the vcard. - ''' + """ + Get vcard info for a contact. Return cached value of the vcard + """ if not isinstance(jid, unicode): jid = unicode(jid) if not jid: @@ -452,7 +483,9 @@ class SignalObject(dbus.service.Object): @dbus.service.method(INTERFACE, in_signature='', out_signature='as') def list_accounts(self): - '''list register accounts''' + """ + List register accounts + """ result = gajim.contacts.get_accounts() result_array = dbus.Array([], signature='s') if result and len(result) > 0: @@ -462,7 +495,9 @@ class SignalObject(dbus.service.Object): @dbus.service.method(INTERFACE, in_signature='s', out_signature='a{ss}') def account_info(self, account): - '''show info on account: resource, jid, nick, prio, message''' + """ + Show info on account: resource, jid, nick, prio, message + """ result = DBUS_DICT_SS() if account in gajim.connections: # account is valid @@ -479,8 +514,10 @@ class SignalObject(dbus.service.Object): @dbus.service.method(INTERFACE, in_signature='s', out_signature='aa{sv}') def list_contacts(self, account): - '''list all contacts in the roster. If the first argument is specified, - then return the contacts for the specified account''' + """ + List all contacts in the roster. If the first argument is specified, then + return the contacts for the specified account + """ result = dbus.Array([], signature='aa{sv}') accounts = gajim.contacts.get_accounts() if len(accounts) == 0: @@ -500,7 +537,9 @@ class SignalObject(dbus.service.Object): @dbus.service.method(INTERFACE, in_signature='', out_signature='') def toggle_roster_appearance(self): - ''' shows/hides the roster window ''' + """ + Show/hide the roster window + """ win = gajim.interface.roster.window if win.get_property('visible'): gobject.idle_add(win.hide) @@ -514,7 +553,9 @@ class SignalObject(dbus.service.Object): @dbus.service.method(INTERFACE, in_signature='', out_signature='') def toggle_ipython(self): - ''' shows/hides the ipython window ''' + """ + Show/hide the ipython window + """ win = gajim.ipython_window if win: if win.window.is_visible(): @@ -615,9 +656,10 @@ class SignalObject(dbus.service.Object): return False def _get_real_jid(self, jid, account = None): - '''get the real jid from the given one: removes xmpp: or get jid from nick - if account is specified, search only in this account - ''' + """ + Get the real jid from the given one: removes xmpp: or get jid from nick if + account is specified, search only in this account + """ if account: accounts = [account] else: @@ -643,7 +685,9 @@ class SignalObject(dbus.service.Object): return jid def _contacts_as_dbus_structure(self, contacts): - ''' get info from list of Contact objects and create dbus dict ''' + """ + Get info from list of Contact objects and create dbus dict + """ if not contacts: return None prim_contact = None # primary contact diff --git a/src/roster_window.py b/src/roster_window.py index 344c4574a..7d84ace55 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -71,30 +71,31 @@ from common.pep import MOODS, ACTIVITIES #(icon, name, type, jid, account, editable, second pixbuf) ( -C_IMG, # image to show state (online, new message etc) -C_NAME, # cellrenderer text that holds contact nickame -C_TYPE, # account, group or contact? -C_JID, # the jid of the row -C_ACCOUNT, # cellrenderer text that holds account name -C_MOOD_PIXBUF, -C_ACTIVITY_PIXBUF, -C_TUNE_PIXBUF, -C_AVATAR_PIXBUF, # avatar_pixbuf -C_PADLOCK_PIXBUF, # use for account row only + C_IMG, # image to show state (online, new message etc) + C_NAME, # cellrenderer text that holds contact nickame + C_TYPE, # account, group or contact? + C_JID, # the jid of the row + C_ACCOUNT, # cellrenderer text that holds account name + C_MOOD_PIXBUF, + C_ACTIVITY_PIXBUF, + C_TUNE_PIXBUF, + C_AVATAR_PIXBUF, # avatar_pixbuf + C_PADLOCK_PIXBUF, # use for account row only ) = range(10) class RosterWindow: - '''Class for main window of the GTK+ interface''' + """ + Class for main window of the GTK+ interface + """ def _get_account_iter(self, name, model=None): - ''' - Return the gtk.TreeIter of the given account or None - if not found. + """ + Return the gtk.TreeIter of the given account or None if not found Keyword arguments: name -- the account name model -- the data model (default TreeFilterModel) - ''' + """ if not model: model = self.modelfilter if model is None: @@ -111,16 +112,15 @@ class RosterWindow: def _get_group_iter(self, name, account, account_iter=None, model=None): - ''' - Return the gtk.TreeIter of the given group or None if not found. + """ + Return the gtk.TreeIter of the given group or None if not found Keyword arguments: name -- the group name account -- the account name account_iter -- the iter of the account the model (default None) model -- the data model (default TreeFilterModel) - - ''' + """ if not model: model = self.modelfilter if not account_iter: @@ -136,14 +136,13 @@ class RosterWindow: def _get_self_contact_iter(self, account, model=None): - ''' Return the gtk.TreeIter of SelfContact or None if not found. + """ + Return the gtk.TreeIter of SelfContact or None if not found Keyword arguments: account -- the account of SelfContact model -- the data model (default TreeFilterModel) - - ''' - + """ if not model: model = self.modelfilter iterAcct = self._get_account_iter(account, model) @@ -161,15 +160,15 @@ class RosterWindow: def _get_contact_iter(self, jid, account, contact=None, model=None): - ''' Return a list of gtk.TreeIter of the given contact. + """ + Return a list of gtk.TreeIter of the given contact Keyword arguments: jid -- the jid without resource account -- the account contact -- the contact (default None) model -- the data model (default TreeFilterModel) - - ''' + """ if not model: model = self.modelfilter # when closing Gajim model can be none (async pbs?) @@ -227,23 +226,25 @@ class RosterWindow: def _iter_is_separator(self, model, titer): - ''' Return True if the given iter is a separator. + """ + Return True if the given iter is a separator Keyword arguments: model -- the data model iter -- the gtk.TreeIter to test - ''' + """ if model[titer][0] == 'SEPARATOR': return True return False def _iter_contact_rows(self, model=None): - '''Iterate over all contact rows in given model. + """ + Iterate over all contact rows in given model Keyword argument model -- the data model (default TreeFilterModel) - ''' + """ if not model: model = self.modelfilter account_iter = model.get_iter_root() @@ -264,10 +265,9 @@ class RosterWindow: ############################################################################# def add_account(self, account): - ''' - Add account to roster and draw it. Do nothing if it is - already in. - ''' + """ + Add account to roster and draw it. Do nothing if it is already in + """ if self._get_account_iter(account): # Will happen on reconnect or for merged accounts return @@ -300,9 +300,10 @@ class RosterWindow: def add_account_contacts(self, account): - '''Add all contacts and groups of the given account to roster, - draw them and account. - ''' + """ + Add all contacts and groups of the given account to roster, draw them and + account + """ self.starting = True jids = gajim.contacts.get_jid_list(account) @@ -324,11 +325,12 @@ class RosterWindow: def _add_entity(self, contact, account, groups=None, - big_brother_contact=None, big_brother_account=None): - '''Add the given contact to roster data model. + big_brother_contact=None, big_brother_account=None): + """ + Add the given contact to roster data model - Contact is added regardless if he is already in roster or not. - Return list of newly added iters. + Contact is added regardless if he is already in roster or not. Return + list of newly added iters. Keyword arguments: contact -- the contact to add @@ -338,7 +340,7 @@ class RosterWindow: Parameter ignored when big_brother_contact is specified. big_brother_contact -- if specified contact is added as child big_brother_contact. (default None) - ''' + """ added_iters = [] if big_brother_contact: # Add contact under big brother @@ -398,7 +400,8 @@ class RosterWindow: return added_iters def _remove_entity(self, contact, account, groups=None): - '''Remove the given contact from roster data model. + """ + Remove the given contact from roster data model Empty groups after contact removal are removed too. Return False if contact still has children and deletion was @@ -409,7 +412,7 @@ class RosterWindow: contact -- the contact to add account -- the contacts account groups -- list of groups to remove the contact from. - ''' + """ iters = self._get_contact_iter(contact.jid, account, contact, self.model) assert iters, '%s shall be removed but is not in roster' % contact.jid @@ -449,8 +452,8 @@ class RosterWindow: return True def _add_metacontact_family(self, family, account): - ''' - Add the give Metacontact family to roster data model. + """ + Add the give Metacontact family to roster data model Add Big Brother to his groups and all others under him. Return list of all added (contact, account) tuples with @@ -458,7 +461,7 @@ class RosterWindow: Keyword arguments: family -- the family, see Contacts.get_metacontacts_family() - ''' + """ nearby_family, big_brother_jid, big_brother_account = \ self._get_nearby_family_and_big_brother(family, account) @@ -496,12 +499,12 @@ class RosterWindow: return brothers def _remove_metacontact_family(self, family, account): - ''' - Remove the given Metacontact family from roster data model. + """ + Remove the given Metacontact family from roster data model See Contacts.get_metacontacts_family() and RosterWindow._remove_entity() - ''' + """ nearby_family = self._get_nearby_family_and_big_brother( family, account)[0] @@ -560,7 +563,9 @@ class RosterWindow: def _recalibrate_metacontact_family(self, family, account): - '''Regroup metacontact family if necessary.''' + """ + Regroup metacontact family if necessary + """ brothers = [] nearby_family, big_brother_jid, big_brother_account = \ @@ -608,10 +613,11 @@ class RosterWindow: return gajim.contacts.get_nearby_family_and_big_brother(family, account) def _add_self_contact(self, account): - '''Add account's SelfContact to roster and draw it and the account. + """ + Add account's SelfContact to roster and draw it and the account Return the SelfContact contact instance - ''' + """ jid = gajim.get_jid_from_account(account) contact = gajim.contacts.get_first_contact_from_jid(account, jid) @@ -633,7 +639,8 @@ class RosterWindow: self._recalibrate_metacontact_family(family, account) def add_contact(self, jid, account): - '''Add contact to roster and draw him. + """ + Add contact to roster and draw him Add contact to all its group and redraw the groups, the contact and the account. If it's a Metacontact, add and draw the whole family. @@ -645,8 +652,7 @@ class RosterWindow: Keyword arguments: jid -- the contact's jid or SelfJid to add SelfContact account -- the corresponding account. - - ''' + """ contact = gajim.contacts.get_contact_with_highest_priority(account, jid) if len(self._get_contact_iter(jid, account, contact, self.model)): # If contact already in roster, do nothing @@ -694,7 +700,8 @@ class RosterWindow: return contacts[0][0] # it's contact/big brother with highest priority def remove_contact(self, jid, account, force=False, backend=False): - '''Remove contact from roster. + """ + Remove contact from roster Remove contact from all its group. Remove empty groups or redraw otherwise. @@ -707,8 +714,7 @@ class RosterWindow: account -- the corresponding account. force -- remove contact even it has pending evens (Default False) backend -- also remove contact instance (Default False) - - ''' + """ contact = gajim.contacts.get_contact_with_highest_priority(account, jid) if not contact: return @@ -760,13 +766,14 @@ class RosterWindow: return True def rename_self_contact(self, old_jid, new_jid, account): - '''Rename the self_contact jid + """ + Rename the self_contact jid Keyword arguments: old_jid -- our old jid new_jid -- our new jid account -- the corresponding account. - ''' + """ gajim.contacts.change_contact_jid(old_jid, new_jid, account) self_iter = self._get_self_contact_iter(account, model=self.model) if not self_iter: @@ -775,9 +782,9 @@ class RosterWindow: self.draw_contact(new_jid, account) def add_groupchat(self, jid, account, status=''): - '''Add groupchat to roster and draw it. - Return the added contact instance. - ''' + """ + Add groupchat to roster and draw it. Return the added contact instance + """ contact = gajim.contacts.get_contact_with_highest_priority(account, jid) # Do not show gc if we are disconnected and minimize it if gajim.account_is_connected(account): @@ -816,7 +823,9 @@ class RosterWindow: def remove_groupchat(self, jid, account): - '''Remove groupchat from roster and redraw account and group.''' + """ + Remove groupchat from roster and redraw account and group + """ contact = gajim.contacts.get_contact_with_highest_priority(account, jid) if contact.is_groupchat(): if jid in gajim.interface.minimized_controls[account]: @@ -829,8 +838,9 @@ class RosterWindow: # FIXME: This function is yet unused! Port to new API def add_transport(self, jid, account): - '''Add transport to roster and draw it. - Return the added contact instance.''' + """ + Add transport to roster and draw it. Return the added contact instance + """ contact = gajim.contacts.get_contact_with_highest_priority(account, jid) if contact is None: #TRANSP @@ -842,57 +852,60 @@ class RosterWindow: return contact def remove_transport(self, jid, account): - '''Remove transport from roster and redraw account and group.''' + """ + Remove transport from roster and redraw account and group + """ self.remove_contact(jid, account, force=True, backend=True) return True - + def rename_group(self, old_name, new_name, account): """ - rename a roster group + Rename a roster group """ if old_name == new_name: return - + # Groups may not change name from or to a special groups for g in helpers.special_groups: if g in (new_name, old_name): return - + # update all contacts in the given group if self.regroup: accounts = gajim.connections.keys() else: accounts = [account,] - + for acc in accounts: changed_contacts = [] for jid in gajim.contacts.get_jid_list(acc): contact = gajim.contacts.get_first_contact_from_jid(acc, jid) if old_name not in contact.groups: continue - + self.remove_contact(jid, acc, force=True) - + contact.groups.remove(old_name) if new_name not in contact.groups: contact.groups.append(new_name) - - changed_contacts.append({'jid':jid, 'name':contact.name, + + changed_contacts.append({'jid':jid, 'name':contact.name, 'groups':contact.groups}) - - gajim.connections[acc].update_contacts(changed_contacts) - + + gajim.connections[acc].update_contacts(changed_contacts) + for c in changed_contacts: self.add_contact(c['jid'], acc) - + self._adjust_group_expand_collapse_state(new_name, acc) - + self.draw_group(old_name, acc) self.draw_group(new_name, acc) - + def add_contact_to_groups(self, jid, account, groups, update=True): - '''Add contact to given groups and redraw them. + """ + Add contact to given groups and redraw them Contact on server is updated too. When the contact has a family, the action will be performed for all members. @@ -902,8 +915,7 @@ class RosterWindow: account -- the corresponding account groups -- list of Groups to add the contact to. update -- update contact on the server - - ''' + """ self.remove_contact(jid, account, force=True) for contact in gajim.contacts.get_contacts(account, jid): for group in groups: @@ -920,7 +932,8 @@ class RosterWindow: self._adjust_group_expand_collapse_state(group, account) def remove_contact_from_groups(self, jid, account, groups, update=True): - '''Remove contact from given groups and redraw them. + """ + Remove contact from given groups and redraw them Contact on server is updated too. When the contact has a family, the action will be performed for all members. @@ -930,8 +943,7 @@ class RosterWindow: account -- the corresponding account groups -- list of Groups to remove the contact from update -- update contact on the server - - ''' + """ self.remove_contact(jid, account, force=True) for contact in gajim.contacts.get_contacts(account, jid): for group in groups: @@ -968,7 +980,7 @@ class RosterWindow: self._recalibrate_metacontact_family(family, account) self.draw_contact(jid, account) - #FIXME: integrate into add_contact() + # FIXME: integrate into add_contact() def add_to_not_in_the_roster(self, account, jid, nick='', resource=''): keyID = '' attached_keys = gajim.config.get_per('accounts', account, @@ -1075,7 +1087,9 @@ class RosterWindow: return False def draw_contact(self, jid, account, selected=False, focus=False): - '''draw the correct state image, name BUT not avatar''' + """ + Draw the correct state image, name BUT not avatar + """ # focus is about if the roster window has toplevel-focus or not # FIXME: We really need a custom cell_renderer @@ -1252,17 +1266,17 @@ class RosterWindow: return gajim.config.get('show_tunes_in_roster') else: return False - + def draw_all_pep_types(self, jid, account): for pep_type in self._pep_type_to_model_column: self.draw_pep(jid, account, pep_type) - + def draw_pep(self, jid, account, pep_type): if pep_type not in self._pep_type_to_model_column: return if not self._is_pep_shown_in_roster(pep_type): return - + model_column = self._pep_type_to_model_column[pep_type] iters = self._get_contact_iter(jid, account, model=self.model) if not iters: @@ -1298,9 +1312,10 @@ class RosterWindow: self.draw_avatar(jid, account) def adjust_and_draw_contact_context(self, jid, account): - '''Draw contact, account and groups of given jid - Show contact if it has pending events - ''' + """ + Draw contact, account and groups of given jid Show contact if it has + pending events + """ contact = gajim.contacts.get_first_contact_from_jid(account, jid) if not contact: # idle draw or just removed SelfContact @@ -1318,12 +1333,13 @@ class RosterWindow: self._adjust_group_expand_collapse_state(group, account) def _idle_draw_jids_of_account(self, jids, account): - '''Draw given contacts and their avatars in a lazy fashion. + """ + Draw given contacts and their avatars in a lazy fashion Keyword arguments: jids -- a list of jids to draw account -- the corresponding account - ''' + """ def _draw_all_contacts(jids, account): for jid in jids: family = gajim.contacts.get_metacontacts_family(account, jid) @@ -1342,7 +1358,9 @@ class RosterWindow: gobject.idle_add(task.next) def setup_and_draw_roster(self): - '''create new empty model and draw roster''' + """ + Create new empty model and draw roster + """ self.modelfilter = None # (icon, name, type, jid, account, editable, mood_pixbuf, # activity_pixbuf, tune_pixbuf avatar_pixbuf, padlock_pixbuf) @@ -1366,8 +1384,9 @@ class RosterWindow: def select_contact(self, jid, account): - '''Select contact in roster. If contact is hidden but has events, - show him.''' + """ + Select contact in roster. If contact is hidden but has events, show him + """ # Refiltering SHOULD NOT be needed: # When a contact gets a new event he will be redrawn and his # icon changes, so _visible_func WILL be called on him anyway @@ -1386,7 +1405,9 @@ class RosterWindow: def _adjust_account_expand_collapse_state(self, account): - '''Expand/collapse account row based on self.collapsed_rows''' + """ + Expand/collapse account row based on self.collapsed_rows + """ iterA = self._get_account_iter(account) if not iterA: # thank you modelfilter @@ -1400,7 +1421,9 @@ class RosterWindow: def _adjust_group_expand_collapse_state(self, group, account): - '''Expand/collapse group row based on self.collapsed_rows''' + """ + Expand/collapse group row based on self.collapsed_rows + """ iterG = self._get_group_iter(group, account) if not iterG: # Group not visible @@ -1427,7 +1450,9 @@ class RosterWindow: self.filtering = False def contact_has_pending_roster_events(self, contact, account): - '''Return True if the contact or one if it resources has pending events''' + """ + Return True if the contact or one if it resources has pending events + """ # jid has pending events if gajim.events.get_nb_roster_events(account, contact.jid) > 0: return True @@ -1452,7 +1477,9 @@ class RosterWindow: return True def _visible_func(self, model, titer): - '''Determine whether iter should be visible in the treeview''' + """ + Determine whether iter should be visible in the treeview + """ type_ = model[titer][C_TYPE] if not type_: return False @@ -1524,7 +1551,9 @@ class RosterWindow: return True def _compareIters(self, model, iter1, iter2, data=None): - '''Compare two iters to sort them''' + """ + Compare two iters to sort them + """ name1 = model[iter1][C_NAME] name2 = model[iter2][C_NAME] if not name1 or not name2: @@ -1632,8 +1661,10 @@ class RosterWindow: ################################################################################ def fire_up_unread_messages_events(self, account): - '''reads from db the unread messages, and fire them up, and - if we find very old unread messages, delete them from unread table''' + """ + Read from db the unread messages, and fire them up, and if we find very + old unread messages, delete them from unread table + """ results = gajim.logger.get_unread_msgs() for result in results: jid = result[4] @@ -1658,7 +1689,9 @@ class RosterWindow: gajim.logger.set_read_messages([result[0]]) def fill_contacts_and_groups_dicts(self, array, account): - '''fill gajim.contacts and gajim.groups''' + """ + Fill gajim.contacts and gajim.groups + """ # FIXME: This function needs to be splitted # Most of the logic SHOULD NOT be done at GUI level if account not in gajim.contacts.get_accounts(): @@ -1732,11 +1765,12 @@ class RosterWindow: return False def on_event_removed(self, event_list): - '''Remove contacts on last events removed. + """ + Remove contacts on last events removed - Only performed if removal was requested before but the contact - still had pending events - ''' + Only performed if removal was requested before but the contact still had + pending events + """ contact_list = ((event.jid.split('/')[0], event.account) for event in \ event_list) @@ -1752,7 +1786,9 @@ class RosterWindow: self.show_title() def open_event(self, account, jid, event): - '''If an event was handled, return True, else return False''' + """ + If an event was handled, return True, else return False + """ data = event.parameters ft = gajim.interface.instances['file_transfers'] event = gajim.events.get_first_event(account, jid, event.type_) @@ -1828,14 +1864,18 @@ class RosterWindow: def authorize(self, widget, jid, account): - '''Authorize a contact (by re-sending auth menuitem)''' + """ + Authorize a contact (by re-sending auth menuitem) + """ gajim.connections[account].send_authorization(jid) dialogs.InformationDialog(_('Authorization has been sent'), _('Now "%s" will know your status.') %jid) def req_sub(self, widget, jid, txt, account, groups=[], nickname=None, - auto_auth=False): - '''Request subscription to a contact''' + auto_auth=False): + """ + Request subscription to a contact + """ gajim.connections[account].request_subscription(jid, txt, nickname, groups, auto_auth, gajim.nicks[account]) contact = gajim.contacts.get_contact_with_highest_priority(account, jid) @@ -1862,7 +1902,9 @@ class RosterWindow: self.add_contact(jid, account) def revoke_auth(self, widget, jid, account): - '''Revoke a contact's authorization''' + """ + Revoke a contact's authorization + """ gajim.connections[account].refuse_authorization(jid) dialogs.InformationDialog(_('Authorization has been removed'), _('Now "%s" will always see you as offline.') %jid) @@ -1915,15 +1957,15 @@ class RosterWindow: connection.send_mood(mood, mood_text) else: connection.retract_mood() - + def delete_pep(self, jid, account): if jid == gajim.get_jid_from_account(account): gajim.connections[account].pep = {} self.draw_account(account) - + for contact in gajim.contacts.get_contacts(account, jid): contact.pep = {} - + self.draw_all_pep_types(jid, account) ctrl = gajim.interface.msg_win_mgr.get_control(jid, account) if ctrl: @@ -1969,7 +2011,9 @@ class RosterWindow: def chg_contact_status(self, contact, show, status, account): - '''When a contact changes his or her status''' + """ + When a contact changes his or her status + """ contact_instances = gajim.contacts.get_contacts(account, contact.jid) contact.show = show contact.status = status @@ -2027,7 +2071,9 @@ class RosterWindow: def on_status_changed(self, account, show): - '''the core tells us that our status has changed''' + """ + The core tells us that our status has changed + """ if account not in gajim.contacts.get_accounts(): return child_iterA = self._get_account_iter(account, self.model) @@ -2062,13 +2108,15 @@ class RosterWindow: self.update_status_combobox() def get_status_message(self, show, on_response, show_pep=True, - always_ask=False): - ''' get the status message by: + always_ask=False): + """ + Get the status message by: + 1/ looking in default status message 2/ asking to user if needed depending on ask_on(ff)line_status and always_ask show_pep can be False to hide pep things from status message or True - ''' + """ empty_pep = {'activity': '', 'subactivity': '', 'activity_text': '', 'mood': '', 'mood_text': ''} if show in gajim.config.get_per('defaultstatusmsg'): @@ -2150,7 +2198,9 @@ class RosterWindow: gajim.config.get('roster_height')) def close_all_from_dict(self, dic): - '''close all the windows in the given dictionary''' + """ + Close all the windows in the given dictionary + """ for w in dic.values(): if isinstance(w, dict): self.close_all_from_dict(w) @@ -2158,9 +2208,10 @@ class RosterWindow: w.window.destroy() def close_all(self, account, force=False): - '''close all the windows from an account - if force is True, do not ask confirmation before closing chat/gc windows - ''' + """ + Close all the windows from an account. If force is True, do not ask + confirmation before closing chat/gc windows + """ if account in gajim.interface.instances: self.close_all_from_dict(gajim.interface.instances[account]) for ctrl in gajim.interface.msg_win_mgr.get_controls(acct=account): @@ -2168,7 +2219,9 @@ class RosterWindow: force = force) def on_roster_window_delete_event(self, widget, event): - '''Main window X button was clicked''' + """ + Main window X button was clicked + """ if gajim.interface.systray_enabled and not gajim.config.get( 'quit_on_roster_x_button') and gajim.config.get('trayicon') != 'on_event': self.tooltip.hide_tooltip() @@ -2218,14 +2271,18 @@ class RosterWindow: gajim.interface.hide_systray() def quit_gtkgui_interface(self): - '''When we quit the gtk interface : exit gtk''' + """ + When we quit the gtk interface - exit gtk + """ self.prepare_quit() gtk.main_quit() def on_quit_request(self, widget=None): - ''' user want to quit. Check if he should be warned about messages - pending. Terminate all sessions and send offline to all connected - account. We do NOT really quit gajim here ''' + """ + User wants to quit. Check if he should be warned about messages pending. + Terminate all sessions and send offline to all connected account. We do + NOT really quit gajim here + """ accounts = gajim.connections.keys() get_msg = False for acct in accounts: @@ -2345,7 +2402,9 @@ class RosterWindow: helpers.exec_command('%s history_manager.py' % sys.executable) def on_info(self, widget, contact, account): - '''Call vcard_information_window class to display contact's information''' + """ + Call vcard_information_window class to display contact's information + """ if gajim.connections[account].is_zeroconf: self.on_info_zeroconf(widget, contact, account) return @@ -2474,16 +2533,22 @@ class RosterWindow: self.show_tooltip, contacts) def on_agent_logging(self, widget, jid, state, account): - '''When an agent is requested to log in or off''' + """ + When an agent is requested to log in or off + """ gajim.connections[account].send_agent_status(jid, state) def on_edit_agent(self, widget, contact, account): - '''When we want to modify the agent registration''' + """ + When we want to modify the agent registration + """ gajim.connections[account].request_register_agent_info(contact.jid) def on_remove_agent(self, widget, list_): - '''When an agent is requested to be removed. list_ is a list of - (contact, account) tuple''' + """ + When an agent is requested to be removed. list_ is a list of (contact, + account) tuple + """ for (contact, account) in list_: if gajim.config.get_per('accounts', account, 'hostname') == \ contact.jid: @@ -2527,8 +2592,10 @@ class RosterWindow: on_response_ok = (remove, list_)) def on_block(self, widget, list_, group=None): - ''' When clicked on the 'block' button in context menu. - list_ is a list of (contact, account)''' + """ + When clicked on the 'block' button in context menu. list_ is a list of + (contact, account) + """ def on_continue(msg, pep_dict): if msg is None: # user pressed Cancel to change status message dialog @@ -2591,7 +2658,9 @@ class RosterWindow: _('Do _not ask me again'), on_response_ok=_block_it) def on_unblock(self, widget, list_, group=None): - ''' When clicked on the 'unblock' button in context menu. ''' + """ + When clicked on the 'unblock' button in context menu. + """ accounts = [] if group is None: for (contact, account) in list_: @@ -2808,7 +2877,9 @@ class RosterWindow: dialogs.EditGroupsDialog(list_) def on_history(self, widget, contact, account): - '''When history menuitem is activated: call log window''' + """ + When history menuitem is activated: call log window + """ if 'logs' in gajim.interface.instances: gajim.interface.instances['logs'].window.present() gajim.interface.instances['logs'].open_history(contact.jid, account) @@ -2817,7 +2888,9 @@ class RosterWindow: HistoryWindow(contact.jid, account) def on_disconnect(self, widget, jid, account): - '''When disconnect menuitem is activated: disconect from room''' + """ + When disconnect menuitem is activated: disconect from room + """ if jid in gajim.interface.minimized_controls[account]: ctrl = gajim.interface.minimized_controls[account][jid] ctrl.shutdown() @@ -2825,7 +2898,9 @@ class RosterWindow: self.remove_groupchat(jid, account) def on_reconnect(self, widget, jid, account): - '''When disconnect menuitem is activated: disconect from room''' + """ + When disconnect menuitem is activated: disconect from room + """ if jid in gajim.interface.minimized_controls[account]: ctrl = gajim.interface.minimized_controls[account][jid] gajim.interface.join_gc_room(account, jid, ctrl.nick, @@ -2852,8 +2927,9 @@ class RosterWindow: dialogs.AddSpecialNotificationDialog(jid) def on_invite_to_new_room(self, widget, list_, resource=None): - ''' resource parameter MUST NOT be used if more than one contact in - list ''' + """ + Resource parameter MUST NOT be used if more than one contact in list + """ account_list = [] jid_list = [] for (contact, account) in list_: @@ -2882,9 +2958,10 @@ class RosterWindow: break def on_invite_to_room(self, widget, list_, room_jid, room_account, - resource=None): - ''' resource parameter MUST NOT be used if more than one contact in - list ''' + resource=None): + """ + Resource parameter MUST NOT be used if more than one contact in list + """ for e in list_: contact = e[0] contact_jid = contact.jid @@ -2897,7 +2974,9 @@ class RosterWindow: self.on_groupchat_maximized(widget, contact.jid, account) def on_groupchat_maximized(self, widget, jid, account): - '''When a groupchat is maximised''' + """ + When a groupchat is maximized + """ if not jid in gajim.interface.minimized_controls[account]: # Already opened? gc_control = gajim.interface.msg_win_mgr.get_gc_control(jid, account) @@ -2953,7 +3032,9 @@ class RosterWindow: self.tooltip.hide_tooltip() def on_roster_treeview_key_press_event(self, widget, event): - '''when a key is pressed in the treeviews''' + """ + When a key is pressed in the treeviews + """ self.tooltip.hide_tooltip() if event.keyval == gtk.keysyms.Escape: self.tree.get_selection().unselect_all() @@ -3100,7 +3181,9 @@ class RosterWindow: self.tree.expand_row(path, False) def on_req_usub(self, widget, list_): - '''Remove a contact. list_ is a list of (contact, account) tuples''' + """ + Remove a contact. list_ is a list of (contact, account) tuples + """ def on_ok(is_checked, list_): remove_auth = True if len(list_) == 1: @@ -3159,7 +3242,9 @@ class RosterWindow: on_response_ok = (on_ok2, list_)) def on_send_custom_status(self, widget, contact_list, show, group=None): - '''send custom status''' + """ + Send custom status + """ # contact_list has only one element except if group != None def on_response(message, pep_dict): if message is None: # None if user pressed Cancel @@ -3216,7 +3301,9 @@ class RosterWindow: _('Do _not ask me again'), on_response_ok=send_it) def on_status_combobox_changed(self, widget): - '''When we change our status via the combobox''' + """ + When we change our status via the combobox + """ model = self.status_combobox.get_model() active = self.status_combobox.get_active() if active == -1: # no active item @@ -3346,7 +3433,9 @@ class RosterWindow: dialogs.AddNewContactWindow(account) def on_join_gc_activate(self, widget, account): - '''when the join gc menuitem is clicked, show the join gc window''' + """ + When the join gc menuitem is clicked, show the join gc window + """ invisible_show = gajim.SHOW_LIST.index('invisible') if gajim.connections[account].connected == invisible_show: dialogs.ErrorDialog(_('You cannot join a group chat while you are ' @@ -3478,8 +3567,10 @@ class RosterWindow: self.show_treeview_menu(event) def on_row_activated(self, widget, path): - '''When an iter is activated (double-click or single click if gnome is - set this way)''' + """ + When an iter is activated (double-click or single click if gnome is set + this way) + """ model = self.modelfilter account = model[path][C_ACCOUNT].decode('utf-8') type_ = model[path][C_TYPE] @@ -3543,12 +3634,16 @@ class RosterWindow: resource=resource, session=session) def on_roster_treeview_row_activated(self, widget, path, col=0): - '''When an iter is double clicked: open the first event window''' + """ + When an iter is double clicked: open the first event window + """ if not gajim.single_click: self.on_row_activated(widget, path) def on_roster_treeview_row_expanded(self, widget, titer, path): - '''When a row is expanded change the icon of the arrow''' + """ + When a row is expanded change the icon of the arrow + """ self._toggeling_row = True model = widget.get_model() child_model = model.get_model() @@ -3608,7 +3703,9 @@ class RosterWindow: self._toggeling_row = False def on_roster_treeview_row_collapsed(self, widget, titer, path): - '''When a row is collapsed change the icon of the arrow''' + """ + When a row is collapsed change the icon of the arrow + """ self._toggeling_row = True model = widget.get_model() child_model = model.get_model() @@ -3652,10 +3749,11 @@ class RosterWindow: self._toggeling_row = False def on_modelfilter_row_has_child_toggled(self, model, path, titer): - '''Called when a row has gotten the first or lost its last child row. + """ + Called when a row has gotten the first or lost its last child row Expand Parent if necessary. - ''' + """ if self._toggeling_row: # Signal is emitted when we write to our model return @@ -3724,8 +3822,9 @@ class RosterWindow: pass def on_show_offline_contacts_menuitem_activate(self, widget): - '''when show offline option is changed: - redraw the treeview''' + """ + When show offline option is changed: redraw the treeview + """ gajim.config.set('showoffline', not gajim.config.get('showoffline')) self.refilter_shown_roster_items() w = self.xml.get_widget('show_only_active_contacts_menuitem') @@ -3738,8 +3837,9 @@ class RosterWindow: w.set_sensitive(True) def on_show_only_active_contacts_menuitem_activate(self, widget): - '''when show only active contact option is changed: - redraw the treeview''' + """ + When show only active contact option is changed: redraw the treeview + """ gajim.config.set('show_only_chat_and_online', not gajim.config.get( 'show_only_chat_and_online')) self.refilter_shown_roster_items() @@ -4148,10 +4248,12 @@ class RosterWindow: ################################################################################ def get_appropriate_state_images(self, jid, size='16', icon_name='online'): - '''check jid and return the appropriate state images dict for - the demanded size. icon_name is taken into account when jid is from - transport: transport iconset doesn't contain all icons, so we fall back - to jabber one''' + """ + Check jid and return the appropriate state images dict for the demanded + size. icon_name is taken into account when jid is from transport: + transport iconset doesn't contain all icons, so we fall back to jabber + one + """ transport = gajim.get_transport_name_from_jid(jid) if transport and size in self.transports_state_images: if transport not in self.transports_state_images[size]: @@ -4163,7 +4265,9 @@ class RosterWindow: return gajim.interface.jabber_state_images[size] def make_transport_state_images(self, transport): - '''initialise opened and closed 'transport' iconset dict''' + """ + Initialize opened and closed 'transport' iconset dict + """ if gajim.config.get('use_transports_iconsets'): folder = os.path.join(helpers.get_transport_path(transport), '16x16') @@ -4260,7 +4364,9 @@ class RosterWindow: win.repaint_themed_widgets() def repaint_themed_widgets(self): - '''Notify windows that contain themed widgets to repaint them''' + """ + Notify windows that contain themed widgets to repaint them + """ for win in gajim.interface.msg_win_mgr.windows(): win.repaint_themed_widgets() for account in gajim.connections: @@ -4279,13 +4385,17 @@ class RosterWindow: ctrl.show_avatar() def on_roster_treeview_style_set(self, treeview, style): - '''When style (theme) changes, redraw all contacts''' + """ + When style (theme) changes, redraw all contacts + """ for contact in self._iter_contact_rows(): self.draw_contact(contact[C_JID].decode('utf-8'), contact[C_ACCOUNT].decode('utf-8')) def set_renderer_color(self, renderer, style, set_background=True): - '''set style for treeview cell, using PRELIGHT system color''' + """ + Set style for treeview cell, using PRELIGHT system color + """ if set_background: bgcolor = self.tree.style.bg[style] renderer.set_property('cell-background-gdk', bgcolor) @@ -4294,7 +4404,9 @@ class RosterWindow: renderer.set_property('foreground-gdk', fgcolor) def _iconCellDataFunc(self, column, renderer, model, titer, data=None): - '''When a row is added, set properties for icon renderer''' + """ + When a row is added, set properties for icon renderer + """ theme = gajim.config.get('roster_theme') type_ = model[titer][C_TYPE] if type_ == 'account': @@ -4337,7 +4449,9 @@ class RosterWindow: renderer.set_property('width', 26) def _nameCellDataFunc(self, column, renderer, model, titer, data=None): - '''When a row is added, set properties for name renderer''' + """ + When a row is added, set properties for name renderer + """ theme = gajim.config.get('roster_theme') type_ = model[titer][C_TYPE] if type_ == 'account': @@ -4409,9 +4523,11 @@ class RosterWindow: renderer.set_property('xpad', 8) - def _fill_pep_pixbuf_renderer(self, column, renderer, model, titer, - data=None): - '''When a row is added, draw the respective pep icon''' + def _fill_pep_pixbuf_renderer(self, column, renderer, model, titer, + data=None): + """ + When a row is added, draw the respective pep icon + """ theme = gajim.config.get('roster_theme') type_ = model[titer][C_TYPE] if type_ == 'group': @@ -4450,9 +4566,11 @@ class RosterWindow: # align pixbuf to the right renderer.set_property('xalign', 1) - def _fill_avatar_pixbuf_renderer(self, column, renderer, model, titer, - data = None): - '''When a row is added, set properties for avatar renderer''' + def _fill_avatar_pixbuf_renderer(self, column, renderer, model, titer, data + = None): + """ + When a row is added, set properties for avatar renderer + """ theme = gajim.config.get('roster_theme') type_ = model[titer][C_TYPE] if type_ in ('group', 'account'): @@ -4489,9 +4607,11 @@ class RosterWindow: else: renderer.set_property('xalign', 1) # align pixbuf to the right - def _fill_padlock_pixbuf_renderer(self, column, renderer, model, titer, - data = None): - '''When a row is added, set properties for padlock renderer''' + def _fill_padlock_pixbuf_renderer(self, column, renderer, model, titer, data + = None): + """ + When a row is added, set properties for padlock renderer + """ theme = gajim.config.get('roster_theme') type_ = model[titer][C_TYPE] # allocate space for the icon only if needed @@ -4512,7 +4632,9 @@ class RosterWindow: ################################################################################ def make_menu(self, force=False): - '''create the main window\'s menus''' + """ + Create the main window's menus + """ if not force and not self.actions_menu_needs_rebuild: return new_chat_menuitem = self.xml.get_widget('new_chat_menuitem') @@ -4963,7 +5085,9 @@ class RosterWindow: return account_context_menu def make_account_menu(self, event, titer): - '''Make account's popup menu''' + """ + Make account's popup menu + """ model = self.modelfilter account = model[titer][C_ACCOUNT].decode('utf-8') @@ -4995,7 +5119,9 @@ class RosterWindow: menu.popup(None, None, None, event_button, event.time) def make_group_menu(self, event, titer): - '''Make group's popup menu''' + """ + Make group's popup menu + """ model = self.modelfilter path = model.get_path(titer) group = model[titer][C_JID].decode('utf-8') @@ -5152,7 +5278,9 @@ class RosterWindow: menu.popup(None, None, None, event_button, event.time) def make_contact_menu(self, event, titer): - '''Make contact\'s popup menu''' + """ + Make contact's popup menu + """ model = self.modelfilter jid = model[titer][C_JID].decode('utf-8') tree_path = model.get_path(titer) @@ -5164,7 +5292,9 @@ class RosterWindow: menu.popup(None, None, None, event_button, event.time) def make_multiple_contact_menu(self, event, iters): - '''Make group's popup menu''' + """ + Make group's popup menu + """ model = self.modelfilter list_ = [] # list of (jid, account) tuples one_account_offline = False @@ -5264,7 +5394,9 @@ class RosterWindow: menu.popup(None, None, None, event_button, event.time) def make_transport_menu(self, event, titer): - '''Make transport\'s popup menu''' + """ + Make transport's popup menu + """ model = self.modelfilter jid = model[titer][C_JID].decode('utf-8') path = model.get_path(titer) @@ -5451,7 +5583,9 @@ class RosterWindow: menu.popup(None, None, None, event_button, event.time) def get_and_connect_advanced_menuitem_menu(self, account): - '''adds FOR ACCOUNT options''' + """ + Add FOR ACCOUNT options + """ xml = gtkgui_helpers.get_glade('advanced_menuitem_menu.glade') advanced_menuitem_menu = xml.get_widget('advanced_menuitem_menu') @@ -5498,8 +5632,9 @@ class RosterWindow: return advanced_menuitem_menu def add_history_manager_menuitem(self, menu): - '''adds a seperator and History Manager menuitem BELOW for account - menuitems''' + """ + Add a seperator and History Manager menuitem BELOW for account menuitems + """ item = gtk.SeparatorMenuItem() # separator menu.append(item) @@ -5512,7 +5647,9 @@ class RosterWindow: item.connect('activate', self.on_history_manager_menuitem_activate) def add_bookmarks_list(self, gc_sub_menu, account): - '''Show join new group chat item and bookmarks list for an account''' + """ + Show join new group chat item and bookmarks list for an account + """ item = gtk.ImageMenuItem(_('_Join New Group Chat')) icon = gtk.image_new_from_stock(gtk.STOCK_NEW, gtk.ICON_SIZE_MENU) item.set_image(icon) @@ -5756,7 +5893,7 @@ class RosterWindow: col.add_attribute(render_pixbuf, 'pixbuf', C_TUNE_PIXBUF) col.set_cell_data_func(render_pixbuf, self._fill_pep_pixbuf_renderer, C_TUNE_PIXBUF) - + self._pep_type_to_model_column = {'mood': C_MOOD_PIXBUF, 'activity': C_ACTIVITY_PIXBUF, 'tune': C_TUNE_PIXBUF} diff --git a/src/search_window.py b/src/search_window.py index 3a21db543..bce009207 100644 --- a/src/search_window.py +++ b/src/search_window.py @@ -32,8 +32,9 @@ import dataforms_widget class SearchWindow: def __init__(self, account, jid): - '''Create new window.''' - + """ + Create new window + """ # an account object self.account = account self.jid = jid @@ -231,5 +232,4 @@ class SearchWindow: self.window.set_title('%s - Search - Gajim' % \ self.data_form_widget.title) - # vim: se ts=3: diff --git a/src/session.py b/src/session.py index 04f9241eb..1725cc593 100644 --- a/src/session.py +++ b/src/session.py @@ -57,7 +57,9 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): self.detach_from_control() def get_chatstate(self, msg, msgtxt): - '''extracts chatstate from a stanza''' + """ + Extract chatstate from a stanza + """ composing_xep = None chatstate = None @@ -83,7 +85,9 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): return (composing_xep, chatstate) def received(self, full_jid_with_resource, msgtxt, tim, encrypted, msg): - '''dispatch a received stanza''' + """ + Dispatch a received stanza + """ msg_type = msg.getType() subject = msg.getSubject() resource = gajim.get_resource_from_jid(full_jid_with_resource) @@ -265,9 +269,11 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): chatstate, msg_id, composing_xep, user_nick, xhtml, form_node])) def roster_message(self, jid, msg, tim, encrypted=False, msg_type='', - subject=None, resource='', msg_id=None, user_nick='', - advanced_notif_num=None, xhtml=None, form_node=None): - '''display the message or show notification in the roster''' + subject=None, resource='', msg_id=None, user_nick='', + advanced_notif_num=None, xhtml=None, form_node=None): + """ + Display the message or show notification in the roster + """ contact = None # if chat window will be for specific resource resource_for_chat = resource diff --git a/src/statusicon.py b/src/statusicon.py index e28b67cfd..556fb9fa1 100644 --- a/src/statusicon.py +++ b/src/statusicon.py @@ -39,7 +39,10 @@ from common import helpers from common import pep class StatusIcon: - '''Class for the notification area icon''' + """ + Class for the notification area icon + """ + def __init__(self): self.single_message_handler_id = None self.new_chat_handler_id = None @@ -54,22 +57,30 @@ class StatusIcon: self.tooltip = tooltips.NotificationAreaTooltip() def subscribe_events(self): - '''Register listeners to the events class''' + """ + Register listeners to the events class + """ gajim.events.event_added_subscribe(self.on_event_added) gajim.events.event_removed_subscribe(self.on_event_removed) def unsubscribe_events(self): - '''Unregister listeners to the events class''' + """ + Unregister listeners to the events class + """ gajim.events.event_added_unsubscribe(self.on_event_added) gajim.events.event_removed_unsubscribe(self.on_event_removed) def on_event_added(self, event): - '''Called when an event is added to the event list''' + """ + Called when an event is added to the event list + """ if event.show_in_systray: self.set_img() def on_event_removed(self, event_list): - '''Called when one or more events are removed from the event list''' + """ + Called when one or more events are removed from the event list + """ self.set_img() def show_icon(self): @@ -102,7 +113,9 @@ class StatusIcon: self.on_left_click() def set_img(self): - '''apart from image, we also update tooltip text here''' + """ + Apart from image, we also update tooltip text here + """ if not gajim.interface.systray_enabled: return if gajim.events.get_nb_systray_events(): @@ -122,7 +135,9 @@ class StatusIcon: # self.img_tray.set_from_animation(image.get_animation()) def change_status(self, global_status): - ''' set tray image to 'global_status' ''' + """ + Set tray image to 'global_status' + """ # change image and status, only if it is different if global_status is not None and self.status != global_status: self.status = global_status @@ -145,7 +160,9 @@ class StatusIcon: dialogs.NewChatDialog(account) def make_menu(self, event_button, event_time): - '''create chat with and new message (sub) menus/menuitems''' + """ + Create chat with and new message (sub) menus/menuitems + """ for m in self.popup_menus: m.destroy() @@ -366,8 +383,10 @@ class StatusIcon: gajim.interface.handle_event(account, jid, event.type_) def on_middle_click(self): - '''middle click raises window to have complete focus (fe. get kbd events) - but if already raised, it hides it''' + """ + Middle click raises window to have complete focus (fe. get kbd events) + but if already raised, it hides it + """ win = gajim.interface.roster.window if win.is_active(): # is it fully raised? (eg does it receive kbd events?) win.hide() diff --git a/src/tooltips.py b/src/tooltips.py index 5e55166c0..22f16874e 100644 --- a/src/tooltips.py +++ b/src/tooltips.py @@ -41,7 +41,9 @@ from common import helpers from common.pep import MOODS, ACTIVITIES class BaseTooltip: - ''' Base Tooltip class; + """ + Base Tooltip class + Usage: tooltip = BaseTooltip() .... @@ -57,7 +59,8 @@ class BaseTooltip: Tooltip is displayed aligned centered to the mouse poiner and 4px below the widget. In case tooltip goes below the visible area it is shown above the widget. - ''' + """ + def __init__(self): self.timeout = 0 self.preferred_position = [0, 0] @@ -65,14 +68,17 @@ class BaseTooltip: self.id = None def populate(self, data): - ''' this method must be overriden by all extenders - This is the most simple implementation: show data as value of a label - ''' + """ + This method must be overriden by all extenders. This is the most simple + implementation: show data as value of a label + """ self.create_window() self.win.add(gtk.Label(data)) def create_window(self): - ''' create a popup window each time tooltip is requested ''' + """ + Create a popup window each time tooltip is requested + """ self.win = gtk.Window(gtk.WINDOW_POPUP) self.win.set_border_width(3) self.win.set_resizable(False) @@ -86,10 +92,12 @@ class BaseTooltip: self.screen = self.win.get_screen() def _get_icon_name_for_tooltip(self, contact): - ''' helper function used for tooltip contacts/acounts + """ + Helper function used for tooltip contacts/acounts + Tooltip on account has fake contact with sub == '', in this case we show real status of the account - ''' + """ if contact.ask == 'subscribe': return 'requested' elif contact.sub in ('both', 'to', ''): @@ -133,11 +141,13 @@ class BaseTooltip: return True def show_tooltip(self, data, widget_height, widget_y_position): - ''' show tooltip on widget. - data contains needed data for tooltip contents - widget_height is the height of the widget on which we show the tooltip - widget_y_position is vertical position of the widget on the screen - ''' + """ + Show tooltip on widget + + Data contains needed data for tooltip contents. + widget_height is the height of the widget on which we show the tooltip. + widget_y_position is vertical position of the widget on the screen. + """ # set tooltip contents self.populate(data) @@ -163,8 +173,11 @@ class BaseTooltip: self.id = None class StatusTable: - ''' Contains methods for creating status table. This - is used in Roster and NotificationArea tooltips ''' + """ + Contains methods for creating status table. This is used in Roster and + NotificationArea tooltips + """ + def __init__(self): self.current_row = 1 self.table = None @@ -201,8 +214,10 @@ class StatusTable: return str_status def add_status_row(self, file_path, show, str_status, status_time=None, - show_lock=False, indent=True): - ''' appends a new row with status icon to the table ''' + show_lock=False, indent=True): + """ + Append a new row with status icon to the table + """ self.current_row += 1 state_file = show.replace(' ', '_') files = [] @@ -235,7 +250,10 @@ class StatusTable: self.current_row + 1, 0, 0, 0, 0) class NotificationAreaTooltip(BaseTooltip, StatusTable): - ''' Tooltip that is shown in the notification area ''' + """ + Tooltip that is shown in the notification area + """ + def __init__(self): BaseTooltip.__init__(self) StatusTable.__init__(self) @@ -283,7 +301,10 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable): self.hbox.show_all() class GCTooltip(BaseTooltip): - ''' Tooltip that is shown in the GC treeview ''' + """ + Tooltip that is shown in the GC treeview + """ + def __init__(self): self.account = None self.text_label = gtk.Label() @@ -378,7 +399,10 @@ class GCTooltip(BaseTooltip): self.win.add(vcard_table) class RosterTooltip(NotificationAreaTooltip): - ''' Tooltip that is shown in the roster treeview ''' + """ + Tooltip that is shown in the roster treeview + """ + def __init__(self): self.account = None self.image = gtk.Image() @@ -561,7 +585,7 @@ class RosterTooltip(NotificationAreaTooltip): vcard_current_row + 1, gtk.EXPAND | gtk.FILL, vertical_fill, 0, 0) else: - if isinstance(property_[0], (unicode, str)): #FIXME: rm unicode? + if isinstance(property_[0], (unicode, str)): # FIXME: rm unicode? label.set_markup(property_[0]) label.set_line_wrap(True) else: @@ -575,10 +599,10 @@ class RosterTooltip(NotificationAreaTooltip): self.win.add(vcard_table) def _append_pep_info(self, contact, properties): - ''' + """ Append Tune, Mood, Activity information of the specified contact to the given property list. - ''' + """ if 'mood' in contact.pep: mood = contact.pep['mood'].asMarkupText() mood_string = _('Mood:') + ' %s' % mood @@ -586,7 +610,7 @@ class RosterTooltip(NotificationAreaTooltip): if 'activity' in contact.pep: activity = contact.pep['activity'].asMarkupText() - activity_string = _('Activity:') + ' %s' % activity + activity_string = _('Activity:') + ' %s' % activity properties.append((activity_string, None)) if 'tune' in contact.pep: @@ -596,7 +620,10 @@ class RosterTooltip(NotificationAreaTooltip): class FileTransfersTooltip(BaseTooltip): - ''' Tooltip that is shown in the notification area ''' + """ + Tooltip that is shown in the notification area + """ + def __init__(self): BaseTooltip.__init__(self) @@ -680,7 +707,9 @@ class FileTransfersTooltip(BaseTooltip): class ServiceDiscoveryTooltip(BaseTooltip): - ''' Tooltip that is shown when hovering over a service discovery row ''' + """ + Tooltip that is shown when hovering over a service discovery row + """ def populate(self, status): self.create_window() label = gtk.Label() diff --git a/src/vcard.py b/src/vcard.py index 5ee86044b..88fd6acc8 100644 --- a/src/vcard.py +++ b/src/vcard.py @@ -45,8 +45,11 @@ from common import gajim from common.i18n import Q_ def get_avatar_pixbuf_encoded_mime(photo): - '''return the pixbuf of the image - photo is a dictionary containing PHOTO information''' + """ + Return the pixbuf of the image + + Photo is a dictionary containing PHOTO information. + """ if not isinstance(photo, dict): return None, None, None img_decoded = None @@ -71,7 +74,9 @@ def get_avatar_pixbuf_encoded_mime(photo): return pixbuf, avatar_encoded, avatar_mime_type class VcardWindow: - '''Class for contact's information window''' + """ + Class for contact's information window + """ def __init__(self, contact, account, gc_contact = None): # the contact variable is the jid if vcard is true @@ -151,7 +156,9 @@ class VcardWindow: self.window.destroy() def on_PHOTO_eventbox_button_press_event(self, widget, event): - '''If right-clicked, show popup''' + """ + If right-clicked, show popup + """ if event.button == 3: # right click menu = gtk.Menu() menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS) @@ -465,7 +472,9 @@ class ZeroconfVcardWindow: self.window.destroy() def on_PHOTO_eventbox_button_press_event(self, widget, event): - '''If right-clicked, show popup''' + """ + If right-clicked, show popup + """ if event.button == 3: # right click menu = gtk.Menu() menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS)