Big portion of doc-string refactoring

This commit is contained in:
Alexander Cherniuk 2009-11-25 22:59:43 +02:00
parent 7316d00766
commit a23961fbf6
16 changed files with 856 additions and 496 deletions

View File

@ -43,23 +43,25 @@ constants = Constants()
# Completion dict # Completion dict
( (
C_INFO_JID, C_INFO_JID,
C_INFO_ACCOUNT, C_INFO_ACCOUNT,
C_INFO_NAME, C_INFO_NAME,
C_INFO_COMPLETION C_INFO_COMPLETION
) = range(4) ) = range(4)
# contact_name, date, message, time # contact_name, date, message, time
( (
C_LOG_JID, C_LOG_JID,
C_CONTACT_NAME, C_CONTACT_NAME,
C_UNIXTIME, C_UNIXTIME,
C_MESSAGE, C_MESSAGE,
C_TIME C_TIME
) = range(5) ) = range(5)
class HistoryWindow: 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): def __init__(self, jid = None, account = None):
xml = gtkgui_helpers.get_glade('history_window.glade') xml = gtkgui_helpers.get_glade('history_window.glade')
@ -132,15 +134,16 @@ class HistoryWindow:
self.window.show_all() self.window.show_all()
def _fill_completion_dict(self): 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 Key will be either jid or full_completion_name (contact name or long
(contact name or long description like "pm-contact from groupchat....") description like "pm-contact from groupchat....").
{key : (jid, account, nick_name, full_completion_name} {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) liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry)
# Add all jids in logs.db: # Add all jids in logs.db:
@ -208,8 +211,10 @@ class HistoryWindow:
yield False yield False
def _get_account_for_jid(self, jid): 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() accounts = gajim.contacts.get_accounts()
account = None account = None
for acc in accounts: for acc in accounts:
@ -247,7 +252,9 @@ class HistoryWindow:
widget.select_region(0, -1) # select text widget.select_region(0, -1) # select text
def _load_history(self, jid_or_name, account = None): 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: if jid_or_name and jid_or_name in self.completion_dict:
# a full qualified jid or a contact name was entered # a full qualified jid or a contact name was entered
info_jid, info_account, info_name, info_completion = self.completion_dict[jid_or_name] 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) self._add_lines_for_date(year, month, day)
def on_calendar_month_changed(self, widget): 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: if not self.jid:
return return
year, month, day = widget.get_date() # integers year, month, day = widget.get_date() # integers
@ -362,7 +369,9 @@ class HistoryWindow:
return show return show
def _add_lines_for_date(self, year, month, day): 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.history_buffer.set_text('') # clear the buffer first
self.last_time_printout = 0 self.last_time_printout = 0
@ -376,7 +385,9 @@ class HistoryWindow:
line[5]) line[5])
def _add_new_line(self, contact_name, tim, kind, show, message, subject): 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, if not message and kind not in (constants.KIND_STATUS,
constants.KIND_GCSTATUS): constants.KIND_GCSTATUS):
return return
@ -538,8 +549,10 @@ class HistoryWindow:
self.jids_to_search = gajim.logger.get_jids_in_db() self.jids_to_search = gajim.logger.get_jids_in_db()
def on_results_treeview_row_activated(self, widget, path, column): 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 # get currently selected date
cur_year, cur_month = self.calendar.get_date()[0:2] cur_year, cur_month = self.calendar.get_date()[0:2]
cur_month = gtkgui_helpers.make_gtk_month_python_month(cur_month) cur_month = gtkgui_helpers.make_gtk_month_python_month(cur_month)
@ -568,7 +581,9 @@ class HistoryWindow:
# and highlight all that # and highlight all that
def _scroll_to_result(self, unix_time): 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() start_iter = self.history_buffer.get_start_iter()
local_time = time.localtime(float(unix_time)) local_time = time.localtime(float(unix_time))
tim = time.strftime('%X', local_time) tim = time.strftime('%X', local_time)
@ -602,7 +617,9 @@ class HistoryWindow:
' '.join(no_log_for)) ' '.join(no_log_for))
def open_history(self, jid, account): 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) self.jid_entry.set_text(jid)
if account and account not in self.accounts_seen_online: if account and account not in self.accounts_seen_online:
# Update dict to not only show bare jid # Update dict to not only show bare jid

View File

@ -25,7 +25,7 @@
## along with Gajim. If not, see <http://www.gnu.org/licenses/>. ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
## ##
''' """
A gtk.TextView-based renderer for XHTML-IM, as described in: A gtk.TextView-based renderer for XHTML-IM, as described in:
http://www.jabber.org/jeps/jep-0071.html 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 I (Santiago Gala) am trying to make it more compatible
with the markup that docutils generate, and also more with the markup that docutils generate, and also more
modular. modular.
"""
'''
import gobject import gobject
import pango import pango
@ -187,7 +186,6 @@ for name in BLOCK_HEAD:
) )
def _parse_css_color(color): def _parse_css_color(color):
'''_parse_css_color(css_color) -> gtk.gdk.Color'''
if color.startswith('rgb(') and color.endswith(')'): if color.startswith('rgb(') and color.endswith(')'):
r, g, b = [int(c)*257 for c in color[4:-1].split(',')] r, g, b = [int(c)*257 for c in color[4:-1].split(',')]
return gtk.gdk.Color(r, g, b) return gtk.gdk.Color(r, g, b)
@ -200,10 +198,11 @@ def style_iter(style):
class HtmlHandler(xml.sax.handler.ContentHandler): 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) It keeps a stack of "style spans" (start/end element pairs) and a stack of
and a stack of list counters, for nested lists. list counters, for nested lists.
""" """
def __init__(self, conv_textview, startiter): def __init__(self, conv_textview, startiter):
xml.sax.handler.ContentHandler.__init__(self) xml.sax.handler.ContentHandler.__init__(self)
@ -240,8 +239,10 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
callback(allocation.width*frac, *args) callback(allocation.width*frac, *args)
def _parse_length(self, value, font_relative, block_relative, minl, maxl, callback, *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('%'): if value.endswith('%'):
val = float(value[:-1]) val = float(value[:-1])
sign = cmp(val,0) sign = cmp(val,0)
@ -556,11 +557,11 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
if h: if h:
self._parse_length(h, False, False, 1, 1000, height_cb) self._parse_length(h, False, False, 1, 1000, height_cb)
def set_size(pixbuf, w, h, dims): def set_size(pixbuf, w, h, dims):
'''FIXME: floats should be relative to the whole """
textview, and resize with it. This needs new FIXME: Floats should be relative to the whole textview, and
pifbufs for every resize, gtk.gdk.Pixbuf.scale_simple resize with it. This needs new pifbufs for every resize,
or similar. gtk.gdk.Pixbuf.scale_simple or similar.
''' """
if isinstance(dims[0], float): if isinstance(dims[0], float):
dims[0] = int(dims[0]*w) dims[0] = int(dims[0]*w)
elif not dims[0]: elif not dims[0]:
@ -945,7 +946,9 @@ if __name__ == '__main__':
tooltip = tooltips.BaseTooltip() tooltip = tooltips.BaseTooltip()
def on_textview_motion_notify_event(widget, event): 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 global change_cursor
pointer_x, pointer_y = htmlview.tv.window.get_pointer()[0:2] 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, x, y = htmlview.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, pointer_x,

View File

@ -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. ## 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 @author: Eitan Isaacson
@organization: IBM Corporation @organization: IBM Corporation
@ -40,7 +40,7 @@ Provides IPython console widget.
All rights reserved. This program and the accompanying materials are made All rights reserved. This program and the accompanying materials are made
available under the terms of the BSD which accompanies this distribution, and available under the terms of the BSD which accompanies this distribution, and
is available at U{http://www.opensource.org/licenses/bsd-license.php} is available at U{http://www.opensource.org/licenses/bsd-license.php}
''' """
import gtk, gobject import gtk, gobject
import re import re
@ -55,10 +55,10 @@ except ImportError:
IPython = None IPython = None
class IterableIPShell: class IterableIPShell:
''' """
Create an IPython instance. Does not start a blocking event loop, Create an IPython instance. Does not start a blocking event loop,
instead allow single iterations. This allows embedding in GTK+ instead allow single iterations. This allows embedding in GTK+
without blockage. without blockage
@ivar IP: IPython instance. @ivar IP: IPython instance.
@type IP: IPython.iplib.InteractiveShell @type IP: IPython.iplib.InteractiveShell
@ -70,12 +70,10 @@ class IterableIPShell:
@type history_level: integer @type history_level: integer
@ivar complete_sep: Seperation delimeters for completion function. @ivar complete_sep: Seperation delimeters for completion function.
@type complete_sep: _sre.SRE_Pattern @type complete_sep: _sre.SRE_Pattern
''' """
def __init__(self,argv=[],user_ns=None,user_global_ns=None, def __init__(self,argv=[],user_ns=None,user_global_ns=None, cin=None,
cin=None, cout=None,cerr=None, input_func=None): cout=None,cerr=None, input_func=None):
''' """
@param argv: Command line options for IPython @param argv: Command line options for IPython
@type argv: list @type argv: list
@param user_ns: User namespace. @param user_ns: User namespace.
@ -90,7 +88,7 @@ class IterableIPShell:
@type cerr: IO stream @type cerr: IO stream
@param input_func: Replacement for builtin raw_input() @param input_func: Replacement for builtin raw_input()
@type input_func: function @type input_func: function
''' """
if input_func: if input_func:
IPython.iplib.raw_input_original = input_func IPython.iplib.raw_input_original = input_func
if cin: if cin:
@ -121,9 +119,9 @@ class IterableIPShell:
self.complete_sep = re.compile('[\s\{\}\[\]\(\)]') self.complete_sep = re.compile('[\s\{\}\[\]\(\)]')
def execute(self): 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 self.history_level = 0
orig_stdout = sys.stdout orig_stdout = sys.stdout
sys.stdout = IPython.Shell.Term.cout sys.stdout = IPython.Shell.Term.cout
@ -156,32 +154,32 @@ class IterableIPShell:
sys.stdout = orig_stdout sys.stdout = orig_stdout
def historyBack(self): def historyBack(self):
''' """
Provides one history command back. Provide one history command back
@return: The command string. @return: The command string.
@rtype: string @rtype: string
''' """
self.history_level -= 1 self.history_level -= 1
return self._getHistory() return self._getHistory()
def historyForward(self): def historyForward(self):
''' """
Provides one history command forward. Provide one history command forward
@return: The command string. @return: The command string.
@rtype: string @rtype: string
''' """
self.history_level += 1 self.history_level += 1
return self._getHistory() return self._getHistory()
def _getHistory(self): 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. @return: Historic command string.
@rtype: string @rtype: string
''' """
try: try:
rv = self.IP.user_ns['In'][self.history_level].strip('\n') rv = self.IP.user_ns['In'][self.history_level].strip('\n')
except IndexError: except IndexError:
@ -190,17 +188,17 @@ class IterableIPShell:
return rv return rv
def updateNamespace(self, ns_dict): 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. @param ns_dict: A dictionary of symbol-values.
@type ns_dict: dictionary @type ns_dict: dictionary
''' """
self.IP.user_ns.update(ns_dict) self.IP.user_ns.update(ns_dict)
def complete(self, line): 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. @param line: Given line so far.
@type line: string @type line: string
@ -208,7 +206,7 @@ class IterableIPShell:
@return: Line completed as for as possible, @return: Line completed as for as possible,
and possible further completions. and possible further completions.
@rtype: tuple @rtype: tuple
''' """
split_line = self.complete_sep.split(line) split_line = self.complete_sep.split(line)
possibilities = self.IP.complete(split_line[-1]) possibilities = self.IP.complete(split_line[-1])
@ -222,7 +220,9 @@ class IterableIPShell:
return True return True
def common_prefix(seq): 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]) return "".join(c for i, c in enumerate(seq[0])
if all(s.startswith(c, i) for s in seq)) if all(s.startswith(c, i) for s in seq))
if possibilities: if possibilities:
@ -233,8 +233,8 @@ class IterableIPShell:
def shell(self, cmd,verbose=0,debug=0,header=''): 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. @param cmd: Shell command to execute.
@type cmd: string @type cmd: string
@ -244,7 +244,7 @@ class IterableIPShell:
@type debug: integer @type debug: integer
@param header: Header to be printed before output @param header: Header to be printed before output
@type header: string @type header: string
''' """
if verbose or debug: print header+cmd if verbose or debug: print header+cmd
# flush stdout so we don't mangle python's buffering # flush stdout so we don't mangle python's buffering
if not debug: if not debug:
@ -254,8 +254,8 @@ class IterableIPShell:
input_.close() input_.close()
class ConsoleView(gtk.TextView): 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. @cvar ANSI_COLORS: Mapping of terminal colors to X11 names.
@type ANSI_COLORS: dictionary @type ANSI_COLORS: dictionary
@ -268,7 +268,8 @@ class ConsoleView(gtk.TextView):
@type mark: gtk.TextMark @type mark: gtk.TextMark
@ivar line_start: Start of command line mark. @ivar line_start: Start of command line mark.
@type line_start: gtk.TextMark @type line_start: gtk.TextMark
''' """
ANSI_COLORS = {'0;30': 'Black', '0;31': 'Red', ANSI_COLORS = {'0;30': 'Black', '0;31': 'Red',
'0;32': 'Green', '0;33': 'Brown', '0;32': 'Green', '0;33': 'Brown',
'0;34': 'Blue', '0;35': 'Purple', '0;34': 'Blue', '0;35': 'Purple',
@ -279,9 +280,9 @@ class ConsoleView(gtk.TextView):
'1;36': 'LightCyan', '1;37': 'White'} '1;36': 'LightCyan', '1;37': 'White'}
def __init__(self): def __init__(self):
''' """
Initialize console view. Initialize console view
''' """
gtk.TextView.__init__(self) gtk.TextView.__init__(self)
self.modify_font(pango.FontDescription('Mono')) self.modify_font(pango.FontDescription('Mono'))
self.set_cursor_visible(True) self.set_cursor_visible(True)
@ -305,14 +306,14 @@ class ConsoleView(gtk.TextView):
gobject.idle_add(self._write, text, editable) gobject.idle_add(self._write, text, editable)
def _write(self, text, editable=False): def _write(self, text, editable=False):
''' """
Write given text to buffer. Write given text to buffer
@param text: Text to append. @param text: Text to append.
@type text: string @type text: string
@param editable: If true, added text is editable. @param editable: If true, added text is editable.
@type editable: boolean @type editable: boolean
''' """
segments = self.color_pat.split(text) segments = self.color_pat.split(text)
segment = segments.pop(0) segment = segments.pop(0)
start_mark = self.text_buffer.create_mark(None, start_mark = self.text_buffer.create_mark(None,
@ -339,12 +340,12 @@ class ConsoleView(gtk.TextView):
gobject.idle_add(self._showPrompt, prompt) gobject.idle_add(self._showPrompt, prompt)
def _showPrompt(self, prompt): def _showPrompt(self, prompt):
''' """
Prints prompt at start of line. Print prompt at start of line
@param prompt: Prompt to print. @param prompt: Prompt to print.
@type prompt: string @type prompt: string
''' """
self._write(prompt) self._write(prompt)
self.text_buffer.move_mark(self.line_start, self.text_buffer.move_mark(self.line_start,
self.text_buffer.get_end_iter()) self.text_buffer.get_end_iter())
@ -353,24 +354,24 @@ class ConsoleView(gtk.TextView):
gobject.idle_add(self._changeLine, text) gobject.idle_add(self._changeLine, text)
def _changeLine(self, 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. @param text: Text to use as replacement.
@type text: string @type text: string
''' """
iter_ = self.text_buffer.get_iter_at_mark(self.line_start) iter_ = self.text_buffer.get_iter_at_mark(self.line_start)
iter_.forward_to_line_end() iter_.forward_to_line_end()
self.text_buffer.delete(self.text_buffer.get_iter_at_mark(self.line_start), iter_) self.text_buffer.delete(self.text_buffer.get_iter_at_mark(self.line_start), iter_)
self._write(text, True) self._write(text, True)
def getCurrentLine(self): def getCurrentLine(self):
''' """
Get text in current command line. Get text in current command line
@return: Text of current command line. @return: Text of current command line.
@rtype: string @rtype: string
''' """
rv = self.text_buffer.get_slice( rv = self.text_buffer.get_slice(
self.text_buffer.get_iter_at_mark(self.line_start), self.text_buffer.get_iter_at_mark(self.line_start),
self.text_buffer.get_end_iter(), False) self.text_buffer.get_end_iter(), False)
@ -380,12 +381,12 @@ class ConsoleView(gtk.TextView):
gobject.idle_add(self._showReturned, text) gobject.idle_add(self._showReturned, text)
def _showReturned(self, 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. @param text: Text to show.
@type text: string @type text: string
''' """
iter_ = self.text_buffer.get_iter_at_mark(self.line_start) iter_ = self.text_buffer.get_iter_at_mark(self.line_start)
iter_.forward_to_line_end() iter_.forward_to_line_end()
self.text_buffer.apply_tag_by_name( 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()) self.text_buffer.place_cursor(self.text_buffer.get_end_iter())
def onKeyPress(self, widget, event): def onKeyPress(self, widget, event):
''' """
Key press callback used for correcting behavior for console-like Key press callback used for correcting behavior for console-like
interfaces. For example 'home' should go to prompt, not to begining of interfaces. For example 'home' should go to prompt, not to begining of
line. line
@param widget: Widget that key press accored in. @param widget: Widget that key press accored in.
@type widget: gtk.Widget @type widget: gtk.Widget
@ -412,7 +413,7 @@ class ConsoleView(gtk.TextView):
@return: Return True if event should not trickle. @return: Return True if event should not trickle.
@rtype: boolean @rtype: boolean
''' """
insert_mark = self.text_buffer.get_insert() insert_mark = self.text_buffer.get_insert()
insert_iter = self.text_buffer.get_iter_at_mark(insert_mark) insert_iter = self.text_buffer.get_iter_at_mark(insert_mark)
selection_mark = self.text_buffer.get_selection_bound() selection_mark = self.text_buffer.get_selection_bound()
@ -445,9 +446,9 @@ class ConsoleView(gtk.TextView):
return self.onKeyPressExtend(event) return self.onKeyPressExtend(event)
def onKeyPressExtend(self, 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 pass
class IPythonView(ConsoleView, IterableIPShell): class IPythonView(ConsoleView, IterableIPShell):
@ -456,9 +457,9 @@ class IPythonView(ConsoleView, IterableIPShell):
a GTK+ IPython console. a GTK+ IPython console.
''' '''
def __init__(self): def __init__(self):
''' """
Initialize. Redirect I/O to console. Initialize. Redirect I/O to console
''' """
ConsoleView.__init__(self) ConsoleView.__init__(self)
self.cout = StringIO() self.cout = StringIO()
IterableIPShell.__init__(self, cout=self.cout,cerr=self.cout, IterableIPShell.__init__(self, cout=self.cout,cerr=self.cout,
@ -470,24 +471,24 @@ class IPythonView(ConsoleView, IterableIPShell):
self.interrupt = False self.interrupt = False
def raw_input(self, prompt=''): 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. @param prompt: Prompt to print. Here for compatability as replacement.
@type prompt: string @type prompt: string
@return: The current command line text. @return: The current command line text.
@rtype: string @rtype: string
''' """
if self.interrupt: if self.interrupt:
self.interrupt = False self.interrupt = False
raise KeyboardInterrupt raise KeyboardInterrupt
return self.getCurrentLine() return self.getCurrentLine()
def onKeyPressExtend(self, event): def onKeyPressExtend(self, event):
''' """
Key press callback with plenty of shell goodness, like history, Key press callback with plenty of shell goodness, like history,
autocompletions, etc. autocompletions, etc
@param widget: Widget that key press occured in. @param widget: Widget that key press occured in.
@type widget: gtk.Widget @type widget: gtk.Widget
@ -496,7 +497,7 @@ class IPythonView(ConsoleView, IterableIPShell):
@return: True if event should not trickle. @return: True if event should not trickle.
@rtype: boolean @rtype: boolean
''' """
if event.state & gtk.gdk.CONTROL_MASK and event.keyval == 99: if event.state & gtk.gdk.CONTROL_MASK and event.keyval == 99:
self.interrupt = True self.interrupt = True
self._processLine() self._processLine()
@ -524,9 +525,9 @@ class IPythonView(ConsoleView, IterableIPShell):
return True return True
def _processLine(self): def _processLine(self):
''' """
Process current command line. Process current command line
''' """
self.history_pos = 0 self.history_pos = 0
self.execute() self.execute()
rv = self.cout.getvalue() rv = self.cout.getvalue()

View File

@ -39,7 +39,10 @@ TYPE_PM = 'pm'
#################### ####################
class MessageControl: 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): def __init__(self, type_id, parent_win, widget_name, contact, account, resource = None):
# dict { cb id : widget} # dict { cb id : widget}
@ -67,57 +70,87 @@ class MessageControl:
return fjid return fjid
def set_control_active(self, state): 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 pass # Derived classes MUST implement this method
def minimizable(self): 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 return False
def safe_shutdown(self): 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''' Called to check if control can be closed without loosing data.
# NOTE: Derived classes MAY implement this returns True if control can be closed safely else False
Derived classes MAY implement this.
"""
return True return True
def allow_shutdown(self, method, on_response_yes, on_response_no, def allow_shutdown(self, method, on_response_yes, on_response_no,
on_response_minimize): on_response_minimize):
'''Called to check is a control is allowed to shutdown. """
Called to check is a control is allowed to shutdown.
If a control is not in a suitable shutdown state this method If a control is not in a suitable shutdown state this method
should call on_response_no, else on_response_yes or should call on_response_no, else on_response_yes or
on_response_minimize ''' on_response_minimize
# NOTE: Derived classes MAY implement this
Derived classes MAY implement this.
"""
on_response_yes(self) on_response_yes(self)
def shutdown(self): def shutdown(self):
# NOTE: Derived classes MUST implement this """
Derived classes MUST implement this
"""
pass pass
def repaint_themed_widgets(self): def repaint_themed_widgets(self):
pass # NOTE: Derived classes SHOULD implement this """
Derived classes SHOULD implement this
"""
pass
def update_ui(self): def update_ui(self):
pass # NOTE: Derived classes SHOULD implement this """
Derived classes SHOULD implement this
"""
pass
def toggle_emoticons(self): def toggle_emoticons(self):
pass # NOTE: Derived classes MAY implement this """
Derived classes MAY implement this
"""
pass
def update_font(self): def update_font(self):
pass # NOTE: Derived classes SHOULD implement this """
Derived classes SHOULD implement this
"""
pass
def update_tags(self): def update_tags(self):
pass # NOTE: Derived classes SHOULD implement this """
Derived classes SHOULD implement this
"""
pass
def get_tab_label(self, chatstate): 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 Return a suitable tab label string. Returns a tuple such as: (label_str,
if chatstate is given that means we have HE SENT US a chatstate and color) either of which can be None if chatstate is given that means we
we want it displayed''' have HE SENT US a chatstate and we want it displayed
# NOTE: Derived classes MUST implement this
Derivded classes MUST implement this.
"""
# Return a markup'd label and optional gtk.Color in a tupple like: # Return a markup'd label and optional gtk.Color in a tupple like:
#return (label_str, None) # return (label_str, None)
pass pass
def get_tab_image(self, count_unread=True): def get_tab_image(self, count_unread=True):
@ -126,11 +159,15 @@ class MessageControl:
return None return None
def prepare_context_menu(self): def prepare_context_menu(self):
# NOTE: Derived classes SHOULD implement this """
Derived classes SHOULD implement this
"""
return None return None
def chat_buttons_set_visible(self, state): def chat_buttons_set_visible(self, state):
# NOTE: Derived classes MAY implement this """
Derived classes MAY implement this
"""
self.hide_chat_buttons = state self.hide_chat_buttons = state
def got_connected(self): def got_connected(self):
@ -170,8 +207,8 @@ class MessageControl:
self.print_esession_details() self.print_esession_details()
def send_message(self, message, keyID='', type_='chat', chatstate=None, def send_message(self, message, keyID='', type_='chat', chatstate=None,
msg_id=None, composing_xep=None, resource=None, user_nick=None, xhtml=None, msg_id=None, composing_xep=None, resource=None, user_nick=None,
callback=None, callback_args=[]): xhtml=None, callback=None, callback_args=[]):
# Send the given message to the active tab. # Send the given message to the active tab.
# Doesn't return None if error # Doesn't return None if error
jid = self.contact.jid jid = self.contact.jid

View File

@ -42,8 +42,9 @@ from common import gajim
#################### ####################
class MessageWindow(object): 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 is the targets needed by drag_source_set and drag_dest_set
DND_TARGETS = [('GAJIM_TAB', 0, 81)] DND_TARGETS = [('GAJIM_TAB', 0, 81)]
@ -160,7 +161,9 @@ class MessageWindow(object):
self.account = new_name self.account = new_name
def change_jid(self, account, old_jid, new_jid): 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: if account not in self._controls:
return return
if old_jid not in self._controls[account]: if old_jid not in self._controls[account]:
@ -417,7 +420,9 @@ class MessageWindow(object):
return True return True
def _on_close_button_clicked(self, button, control): 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) self.remove_tab(control, self.CLOSE_CLOSE_BUTTON)
def show_icon(self): def show_icon(self):
@ -444,7 +449,9 @@ class MessageWindow(object):
self.window.set_icon(icon.get_pixbuf()) self.window.set_icon(icon.get_pixbuf())
def show_title(self, urgent=True, control=None): def show_title(self, urgent=True, control=None):
'''redraw the window's title''' """
Redraw the window's title
"""
if not control: if not control:
control = self.get_active_control() control = self.get_active_control()
if not control: if not control:
@ -512,8 +519,10 @@ class MessageWindow(object):
self.window.present() self.window.present()
def remove_tab(self, ctrl, method, reason = None, force = False): 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): def close(ctrl):
if reason is not None: # We are leaving gc with a status message if reason is not None: # We are leaving gc with a status message
ctrl.shutdown(reason) ctrl.shutdown(reason)
@ -616,7 +625,9 @@ class MessageWindow(object):
self.show_icon() self.show_icon()
def repaint_themed_widgets(self): 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 # iterate through controls and repaint
for ctrl in self.controls(): for ctrl in self.controls():
ctrl.repaint_themed_widgets() ctrl.repaint_themed_widgets()
@ -663,8 +674,10 @@ class MessageWindow(object):
ctrl.update_tags() ctrl.update_tags()
def get_control(self, key, acct): 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): if isinstance(key, str):
key = unicode(key, 'utf-8') key = unicode(key, 'utf-8')
@ -686,7 +699,9 @@ class MessageWindow(object):
return (acct in self._controls and jid in self._controls[acct]) return (acct in self._controls and jid in self._controls[acct])
def change_key(self, old_jid, new_jid, 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: try:
# Check if controls exists # Check if controls exists
ctrl = self._controls[acct][old_jid] ctrl = self._controls[acct][old_jid]
@ -814,10 +829,10 @@ class MessageWindow(object):
control.msg_textview.grab_focus() control.msg_textview.grab_focus()
def get_tab_at_xy(self, x, y): def get_tab_at_xy(self, x, y):
'''Thanks to Gaim """
Return the tab under xy and Return the tab under xy and if its nearer from left or right side of the
if its nearer from left or right side of the tab tab
''' """
page_num = -1 page_num = -1
to_right = False to_right = False
horiz = self.notebook.get_tab_pos() == gtk.POS_TOP or \ horiz = self.notebook.get_tab_pos() == gtk.POS_TOP or \
@ -844,7 +859,9 @@ class MessageWindow(object):
return (page_num, to_right) return (page_num, to_right)
def find_page_num_according_to_tab_label(self, tab_label): 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 page_num = -1
for i in xrange(self.notebook.get_n_pages()): for i in xrange(self.notebook.get_n_pages()):
page = self.notebook.get_nth_page(i) page = self.notebook.get_nth_page(i)
@ -856,18 +873,21 @@ class MessageWindow(object):
################################################################################ ################################################################################
class MessageWindowMgr(gobject.GObject): class MessageWindowMgr(gobject.GObject):
'''A manager and factory for MessageWindow objects''' """
A manager and factory for MessageWindow objects
"""
__gsignals__ = { __gsignals__ = {
'window-delete': (gobject.SIGNAL_RUN_LAST, None, (object,)), 'window-delete': (gobject.SIGNAL_RUN_LAST, None, (object,)),
} }
# These constants map to common.config.opt_one_window_types indices # These constants map to common.config.opt_one_window_types indices
( (
ONE_MSG_WINDOW_NEVER, ONE_MSG_WINDOW_NEVER,
ONE_MSG_WINDOW_ALWAYS, ONE_MSG_WINDOW_ALWAYS,
ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER, ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER,
ONE_MSG_WINDOW_PERACCT, ONE_MSG_WINDOW_PERACCT,
ONE_MSG_WINDOW_PERTYPE, ONE_MSG_WINDOW_PERTYPE,
) = range(5) ) = range(5)
# A key constant for the main window in ONE_MSG_WINDOW_ALWAYS mode # A key constant for the main window in ONE_MSG_WINDOW_ALWAYS mode
MAIN_WIN = 'main' MAIN_WIN = 'main'
@ -875,12 +895,14 @@ class MessageWindowMgr(gobject.GObject):
ROSTER_MAIN_WIN = 'roster' ROSTER_MAIN_WIN = 'roster'
def __init__(self, parent_window, parent_paned): 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 A dictionary of windows; the key depends on the config:
ONE_MSG_WINDOW_ALWAYS: The key is MessageWindowMgr.MAIN_WIN ONE_MSG_WINDOW_NEVER: The key is the contact JID
ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: The key is MessageWindowMgr.MAIN_WIN ONE_MSG_WINDOW_ALWAYS: The key is MessageWindowMgr.MAIN_WIN
ONE_MSG_WINDOW_PERACCT: The key is the account name ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: The key is MessageWindowMgr.MAIN_WIN
ONE_MSG_WINDOW_PERTYPE: The key is a message type constant''' 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) gobject.GObject.__init__(self)
self._windows = {} self._windows = {}
@ -931,7 +953,9 @@ class MessageWindowMgr(gobject.GObject):
return False return False
def _resize_window(self, win, acct, type_): 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, if self.mode in (self.ONE_MSG_WINDOW_ALWAYS,
self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER): self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER):
size = (gajim.config.get('msgwin-width'), size = (gajim.config.get('msgwin-width'),
@ -958,7 +982,9 @@ class MessageWindowMgr(gobject.GObject):
win.parent_paned.set_position(parent_size[0]) win.parent_paned.set_position(parent_size[0])
def _position_window(self, win, acct, type_): 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, if (self.mode in [self.ONE_MSG_WINDOW_NEVER,
self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER]): self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER]):
return return
@ -1054,15 +1080,19 @@ class MessageWindowMgr(gobject.GObject):
return return
def get_control(self, jid, acct): 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) win = self.get_window(jid, acct)
if win: if win:
return win.get_control(jid, acct) return win.get_control(jid, acct)
return None return None
def get_gc_control(self, jid, acct): 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) ctrl = self.get_control(jid, acct)
if ctrl and ctrl.type_id == message_control.TYPE_GC: if ctrl and ctrl.type_id == message_control.TYPE_GC:
return ctrl return ctrl

View File

@ -27,14 +27,15 @@ from common import gajim
from common import xmpp from common import xmpp
def describe_features(features): 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': if features['logging'] == 'may':
return _('- messages will be logged') return _('- messages will be logged')
elif features['logging'] == 'mustnot': elif features['logging'] == 'mustnot':
return _('- messages will not be logged') return _('- messages will not be logged')
class FeatureNegotiationWindow: class FeatureNegotiationWindow:
'''FeatureNegotiotionWindow class'''
def __init__(self, account, jid, session, form): def __init__(self, account, jid, session, form):
self.account = account self.account = account
self.jid = jid self.jid = jid

View File

@ -26,21 +26,27 @@ from common import gajim
def device_now_active(self, *args): def device_now_active(self, *args):
'''For Network Manager 0.6''' """
For Network Manager 0.6
"""
for connection in gajim.connections.itervalues(): for connection in gajim.connections.itervalues():
if gajim.config.get_per('accounts', connection.name, if gajim.config.get_per('accounts', connection.name,
'listen_to_network_manager') and connection.time_to_reconnect: 'listen_to_network_manager') and connection.time_to_reconnect:
connection._reconnect() connection._reconnect()
def device_no_longer_active(self, *args): def device_no_longer_active(self, *args):
'''For Network Manager 0.6''' """
For Network Manager 0.6
"""
for connection in gajim.connections.itervalues(): for connection in gajim.connections.itervalues():
if gajim.config.get_per('accounts', connection.name, if gajim.config.get_per('accounts', connection.name,
'listen_to_network_manager') and connection.connected > 1: 'listen_to_network_manager') and connection.connected > 1:
connection._disconnectedReconnCB() connection._disconnectedReconnCB()
def state_changed(state): def state_changed(state):
'''For Network Manager 0.7''' """
For Network Manager 0.7
"""
if props.Get("org.freedesktop.NetworkManager", "State") == 3: if props.Get("org.freedesktop.NetworkManager", "State") == 3:
for connection in gajim.connections.itervalues(): for connection in gajim.connections.itervalues():
if gajim.config.get_per('accounts', connection.name, if gajim.config.get_per('accounts', connection.name,

View File

@ -69,7 +69,9 @@ def server_display(server):
win.present() win.present()
def get_show_in_roster(event, account, contact, session=None): 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': if event == 'gc_message_received':
return True return True
num = get_advanced_notification(event, account, contact) num = get_advanced_notification(event, account, contact)
@ -84,7 +86,9 @@ def get_show_in_roster(event, account, contact, session=None):
return True return True
def get_show_in_systray(event, account, contact, type_=None): 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) num = get_advanced_notification(event, account, contact)
if num is not None: if num is not None:
if gajim.config.get_per('notifications', str(num), 'systray') == 'yes': 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') return gajim.config.get('trayicon_notification_on_events')
def get_advanced_notification(event, account, contact): 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 num = 0
notif = gajim.config.get_per('notifications', str(num)) notif = gajim.config.get_per('notifications', str(num))
while notif: while notif:
@ -146,10 +151,11 @@ def get_advanced_notification(event, account, contact):
notif = gajim.config.get_per('notifications', str(num)) notif = gajim.config.get_per('notifications', str(num))
def notify(event, jid, account, parameters, advanced_notif_num=None): 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; Check what type of notifications we want, depending on basic and the advanced
advanced_notif_num holds the number of the first (top most) advanced configuration of notifications and do these notifications; advanced_notif_num
notification''' holds the number of the first (top most) advanced notification
"""
# First, find what notifications we want # First, find what notifications we want
do_popup = False do_popup = False
do_sound = False do_sound = False
@ -327,12 +333,13 @@ def notify(event, jid, account, parameters, advanced_notif_num=None):
except Exception: except Exception:
pass pass
def popup(event_type, jid, account, msg_type='', path_to_image=None, def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None,
title=None, text=None): text=None):
'''Notifies a user of an event. It first tries to a valid implementation of """
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 Desktop Notification Specification. If that fails, then we fall back to
the older style PopupNotificationWindow method.''' the older style PopupNotificationWindow method
"""
# default image # default image
if not path_to_image: if not path_to_image:
path_to_image = os.path.abspath( 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) gajim.interface.handle_event(account, jid, msg_type)
class NotificationResponseManager: 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 Collect references to pending DesktopNotifications and manages there
a signal from an interface once it's connected.''' 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): def __init__(self):
self.pending = {} self.pending = {}
self.received = [] self.received = []
@ -464,8 +474,11 @@ class NotificationResponseManager:
notification_response_manager = NotificationResponseManager() notification_response_manager = NotificationResponseManager()
class DesktopNotification: 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='', def __init__(self, event_type, jid, account, msg_type='',
path_to_image=None, title=None, text=None): path_to_image=None, title=None, text=None):
self.path_to_image = path_to_image self.path_to_image = path_to_image

View File

@ -36,7 +36,9 @@ from common import gajim
class ProfileWindow: class ProfileWindow:
'''Class for our information window''' """
Class for our information window
"""
def __init__(self, account): def __init__(self, account):
self.xml = gtkgui_helpers.get_glade('profile_window.glade') 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) on_response_cancel = on_cancel, on_response_clear = on_clear)
def on_PHOTO_button_press_event(self, widget, event): 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 if event.button == 3 and self.avatar_encoded: # right click
menu = gtk.Menu() menu = gtk.Menu()
@ -257,7 +261,9 @@ class ProfileWindow:
self.update_progressbar_timeout_id = None self.update_progressbar_timeout_id = None
def add_to_vcard(self, vcard_, entry, txt): 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('_') entries = entry.split('_')
loc = vcard_ loc = vcard_
if len(entries) == 3: # We need to use lists if len(entries) == 3: # We need to use lists
@ -280,7 +286,9 @@ class ProfileWindow:
return vcard_ return vcard_
def make_vcard(self): def make_vcard(self):
'''make the vCard dictionary''' """
Make the vCard dictionary
"""
entries = ['FN', 'NICKNAME', 'BDAY', 'EMAIL_HOME_USERID', 'URL', entries = ['FN', 'NICKNAME', 'BDAY', 'EMAIL_HOME_USERID', 'URL',
'TEL_HOME_NUMBER', 'N_FAMILY', 'N_GIVEN', 'N_MIDDLE', 'N_PREFIX', 'TEL_HOME_NUMBER', 'N_FAMILY', 'N_GIVEN', 'N_MIDDLE', 'N_PREFIX',
'N_SUFFIX', 'ADR_HOME_STREET', 'ADR_HOME_EXTADR', 'ADR_HOME_LOCALITY', 'N_SUFFIX', 'ADR_HOME_STREET', 'ADR_HOME_EXTADR', 'ADR_HOME_LOCALITY',

View File

@ -64,9 +64,10 @@ DBUS_DICT_SS = lambda : dbus.Dictionary({}, signature="ss")
DBUS_NONE = lambda : dbus.Int32(0) DBUS_NONE = lambda : dbus.Int32(0)
def get_dbus_struct(obj): 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: if obj is None:
return DBUS_NONE() return DBUS_NONE()
if isinstance(obj, (unicode, str)): if isinstance(obj, (unicode, str)):
@ -110,8 +111,12 @@ class Remote:
class SignalObject(dbus.service.Object): 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): def __init__(self, bus_name):
self.first_show = True self.first_show = True
@ -193,14 +198,18 @@ class SignalObject(dbus.service.Object):
pass pass
def raise_signal(self, signal, arg): 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) getattr(self, signal)(arg)
@dbus.service.method(INTERFACE, in_signature='s', out_signature='s') @dbus.service.method(INTERFACE, in_signature='s', out_signature='s')
def get_status(self, account): 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 not account:
# If user did not ask for account, returns the global status # If user did not ask for account, returns the global status
return DBUS_STRING(helpers.get_global_show()) 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') @dbus.service.method(INTERFACE, in_signature='s', out_signature='s')
def get_status_message(self, account): 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 not account:
# If user did not ask for account, returns the global status # If user did not ask for account, returns the global status
return DBUS_STRING(str(helpers.get_global_status())) return DBUS_STRING(str(helpers.get_global_status()))
@ -220,7 +230,9 @@ class SignalObject(dbus.service.Object):
return DBUS_STRING(status) return DBUS_STRING(status)
def _get_account_and_contact(self, account, jid): 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 connected_account = None
contact = None contact = None
accounts = gajim.contacts.get_accounts() accounts = gajim.contacts.get_accounts()
@ -247,8 +259,10 @@ class SignalObject(dbus.service.Object):
return connected_account, contact return connected_account, contact
def _get_account_for_groupchat(self, account, room_jid): 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 connected_account = None
accounts = gajim.contacts.get_accounts() accounts = gajim.contacts.get_accounts()
# if there is only one account in roster, take it as default # 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') @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b')
def send_file(self, file_path, jid, account): 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) jid = self._get_real_jid(jid, account)
connected_account, contact = self._get_account_and_contact(account, jid) 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', def _send_message(self, jid, message, keyID, account, type_ = 'chat',
subject = None): 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: if not jid or not message:
return DBUS_BOOLEAN(False) return DBUS_BOOLEAN(False)
if not keyID: if not keyID:
@ -305,22 +323,27 @@ class SignalObject(dbus.service.Object):
@dbus.service.method(INTERFACE, in_signature='ssss', out_signature='b') @dbus.service.method(INTERFACE, in_signature='ssss', out_signature='b')
def send_chat_message(self, jid, message, keyID, account): 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) jid = self._get_real_jid(jid, account)
return self._send_message(jid, message, keyID, account) return self._send_message(jid, message, keyID, account)
@dbus.service.method(INTERFACE, in_signature='sssss', out_signature='b') @dbus.service.method(INTERFACE, in_signature='sssss', out_signature='b')
def send_single_message(self, jid, subject, message, keyID, account): 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) jid = self._get_real_jid(jid, account)
return self._send_message(jid, message, keyID, account, type, subject) return self._send_message(jid, message, keyID, account, type, subject)
@dbus.service.method(INTERFACE, in_signature='sss', out_signature='b') @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b')
def send_groupchat_message(self, room_jid, message, account): 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: if not room_jid or not message:
return DBUS_BOOLEAN(False) return DBUS_BOOLEAN(False)
connected_account = self._get_account_for_groupchat(account, room_jid) 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') @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b')
def open_chat(self, jid, account, message): 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: if not jid:
raise dbus_support.MissingArgument() raise dbus_support.MissingArgument()
jid = self._get_real_jid(jid, account) 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') @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b')
def change_status(self, status, message, account): 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', if status not in ('offline', 'online', 'chat',
'away', 'xa', 'dnd', 'invisible'): 'away', 'xa', 'dnd', 'invisible'):
return DBUS_BOOLEAN(False) return DBUS_BOOLEAN(False)
@ -404,9 +431,10 @@ class SignalObject(dbus.service.Object):
@dbus.service.method(INTERFACE, in_signature='ss', out_signature='') @dbus.service.method(INTERFACE, in_signature='ss', out_signature='')
def set_priority(self, prio, account): 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 set_priority(prio, account). Account is optional - if not specified
with global status''' priority is changed for all accounts. That are synced with global status
"""
if account: if account:
gajim.config.set_per('accounts', account, 'priority', prio) gajim.config.set_per('accounts', account, 'priority', prio)
show = gajim.SHOW_LIST[gajim.connections[account].connected] 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='') @dbus.service.method(INTERFACE, in_signature='', out_signature='')
def show_next_pending_event(self): 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(): if gajim.events.get_nb_events():
gajim.interface.systray.handle_first_event() gajim.interface.systray.handle_first_event()
@dbus.service.method(INTERFACE, in_signature='s', out_signature='a{sv}') @dbus.service.method(INTERFACE, in_signature='s', out_signature='a{sv}')
def contact_info(self, jid): 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): if not isinstance(jid, unicode):
jid = unicode(jid) jid = unicode(jid)
if not jid: if not jid:
@ -452,7 +483,9 @@ class SignalObject(dbus.service.Object):
@dbus.service.method(INTERFACE, in_signature='', out_signature='as') @dbus.service.method(INTERFACE, in_signature='', out_signature='as')
def list_accounts(self): def list_accounts(self):
'''list register accounts''' """
List register accounts
"""
result = gajim.contacts.get_accounts() result = gajim.contacts.get_accounts()
result_array = dbus.Array([], signature='s') result_array = dbus.Array([], signature='s')
if result and len(result) > 0: 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}') @dbus.service.method(INTERFACE, in_signature='s', out_signature='a{ss}')
def account_info(self, account): 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() result = DBUS_DICT_SS()
if account in gajim.connections: if account in gajim.connections:
# account is valid # account is valid
@ -479,8 +514,10 @@ class SignalObject(dbus.service.Object):
@dbus.service.method(INTERFACE, in_signature='s', out_signature='aa{sv}') @dbus.service.method(INTERFACE, in_signature='s', out_signature='aa{sv}')
def list_contacts(self, account): 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}') result = dbus.Array([], signature='aa{sv}')
accounts = gajim.contacts.get_accounts() accounts = gajim.contacts.get_accounts()
if len(accounts) == 0: if len(accounts) == 0:
@ -500,7 +537,9 @@ class SignalObject(dbus.service.Object):
@dbus.service.method(INTERFACE, in_signature='', out_signature='') @dbus.service.method(INTERFACE, in_signature='', out_signature='')
def toggle_roster_appearance(self): def toggle_roster_appearance(self):
''' shows/hides the roster window ''' """
Show/hide the roster window
"""
win = gajim.interface.roster.window win = gajim.interface.roster.window
if win.get_property('visible'): if win.get_property('visible'):
gobject.idle_add(win.hide) gobject.idle_add(win.hide)
@ -514,7 +553,9 @@ class SignalObject(dbus.service.Object):
@dbus.service.method(INTERFACE, in_signature='', out_signature='') @dbus.service.method(INTERFACE, in_signature='', out_signature='')
def toggle_ipython(self): def toggle_ipython(self):
''' shows/hides the ipython window ''' """
Show/hide the ipython window
"""
win = gajim.ipython_window win = gajim.ipython_window
if win: if win:
if win.window.is_visible(): if win.window.is_visible():
@ -615,9 +656,10 @@ class SignalObject(dbus.service.Object):
return False return False
def _get_real_jid(self, jid, account = None): 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: if account:
accounts = [account] accounts = [account]
else: else:
@ -643,7 +685,9 @@ class SignalObject(dbus.service.Object):
return jid return jid
def _contacts_as_dbus_structure(self, contacts): 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: if not contacts:
return None return None
prim_contact = None # primary contact prim_contact = None # primary contact

File diff suppressed because it is too large Load Diff

View File

@ -32,8 +32,9 @@ import dataforms_widget
class SearchWindow: class SearchWindow:
def __init__(self, account, jid): def __init__(self, account, jid):
'''Create new window.''' """
Create new window
"""
# an account object # an account object
self.account = account self.account = account
self.jid = jid self.jid = jid
@ -231,5 +232,4 @@ class SearchWindow:
self.window.set_title('%s - Search - Gajim' % \ self.window.set_title('%s - Search - Gajim' % \
self.data_form_widget.title) self.data_form_widget.title)
# vim: se ts=3: # vim: se ts=3:

View File

@ -57,7 +57,9 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
self.detach_from_control() self.detach_from_control()
def get_chatstate(self, msg, msgtxt): def get_chatstate(self, msg, msgtxt):
'''extracts chatstate from a <message/> stanza''' """
Extract chatstate from a <message/> stanza
"""
composing_xep = None composing_xep = None
chatstate = None chatstate = None
@ -83,7 +85,9 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
return (composing_xep, chatstate) return (composing_xep, chatstate)
def received(self, full_jid_with_resource, msgtxt, tim, encrypted, msg): def received(self, full_jid_with_resource, msgtxt, tim, encrypted, msg):
'''dispatch a received <message> stanza''' """
Dispatch a received <message> stanza
"""
msg_type = msg.getType() msg_type = msg.getType()
subject = msg.getSubject() subject = msg.getSubject()
resource = gajim.get_resource_from_jid(full_jid_with_resource) 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])) chatstate, msg_id, composing_xep, user_nick, xhtml, form_node]))
def roster_message(self, jid, msg, tim, encrypted=False, msg_type='', def roster_message(self, jid, msg, tim, encrypted=False, msg_type='',
subject=None, resource='', msg_id=None, user_nick='', subject=None, resource='', msg_id=None, user_nick='',
advanced_notif_num=None, xhtml=None, form_node=None): advanced_notif_num=None, xhtml=None, form_node=None):
'''display the message or show notification in the roster''' """
Display the message or show notification in the roster
"""
contact = None contact = None
# if chat window will be for specific resource # if chat window will be for specific resource
resource_for_chat = resource resource_for_chat = resource

View File

@ -39,7 +39,10 @@ from common import helpers
from common import pep from common import pep
class StatusIcon: class StatusIcon:
'''Class for the notification area icon''' """
Class for the notification area icon
"""
def __init__(self): def __init__(self):
self.single_message_handler_id = None self.single_message_handler_id = None
self.new_chat_handler_id = None self.new_chat_handler_id = None
@ -54,22 +57,30 @@ class StatusIcon:
self.tooltip = tooltips.NotificationAreaTooltip() self.tooltip = tooltips.NotificationAreaTooltip()
def subscribe_events(self): 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_added_subscribe(self.on_event_added)
gajim.events.event_removed_subscribe(self.on_event_removed) gajim.events.event_removed_subscribe(self.on_event_removed)
def unsubscribe_events(self): 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_added_unsubscribe(self.on_event_added)
gajim.events.event_removed_unsubscribe(self.on_event_removed) gajim.events.event_removed_unsubscribe(self.on_event_removed)
def on_event_added(self, event): 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: if event.show_in_systray:
self.set_img() self.set_img()
def on_event_removed(self, event_list): 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() self.set_img()
def show_icon(self): def show_icon(self):
@ -102,7 +113,9 @@ class StatusIcon:
self.on_left_click() self.on_left_click()
def set_img(self): 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: if not gajim.interface.systray_enabled:
return return
if gajim.events.get_nb_systray_events(): if gajim.events.get_nb_systray_events():
@ -122,7 +135,9 @@ class StatusIcon:
# self.img_tray.set_from_animation(image.get_animation()) # self.img_tray.set_from_animation(image.get_animation())
def change_status(self, global_status): 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 # change image and status, only if it is different
if global_status is not None and self.status != global_status: if global_status is not None and self.status != global_status:
self.status = global_status self.status = global_status
@ -145,7 +160,9 @@ class StatusIcon:
dialogs.NewChatDialog(account) dialogs.NewChatDialog(account)
def make_menu(self, event_button, event_time): 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: for m in self.popup_menus:
m.destroy() m.destroy()
@ -366,8 +383,10 @@ class StatusIcon:
gajim.interface.handle_event(account, jid, event.type_) gajim.interface.handle_event(account, jid, event.type_)
def on_middle_click(self): 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 win = gajim.interface.roster.window
if win.is_active(): # is it fully raised? (eg does it receive kbd events?) if win.is_active(): # is it fully raised? (eg does it receive kbd events?)
win.hide() win.hide()

View File

@ -41,7 +41,9 @@ from common import helpers
from common.pep import MOODS, ACTIVITIES from common.pep import MOODS, ACTIVITIES
class BaseTooltip: class BaseTooltip:
''' Base Tooltip class; """
Base Tooltip class
Usage: Usage:
tooltip = BaseTooltip() tooltip = BaseTooltip()
.... ....
@ -57,7 +59,8 @@ class BaseTooltip:
Tooltip is displayed aligned centered to the mouse poiner and 4px below the widget. 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. In case tooltip goes below the visible area it is shown above the widget.
''' """
def __init__(self): def __init__(self):
self.timeout = 0 self.timeout = 0
self.preferred_position = [0, 0] self.preferred_position = [0, 0]
@ -65,14 +68,17 @@ class BaseTooltip:
self.id = None self.id = None
def populate(self, data): 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.create_window()
self.win.add(gtk.Label(data)) self.win.add(gtk.Label(data))
def create_window(self): 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 = gtk.Window(gtk.WINDOW_POPUP)
self.win.set_border_width(3) self.win.set_border_width(3)
self.win.set_resizable(False) self.win.set_resizable(False)
@ -86,10 +92,12 @@ class BaseTooltip:
self.screen = self.win.get_screen() self.screen = self.win.get_screen()
def _get_icon_name_for_tooltip(self, contact): 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 Tooltip on account has fake contact with sub == '', in this case we show
real status of the account real status of the account
''' """
if contact.ask == 'subscribe': if contact.ask == 'subscribe':
return 'requested' return 'requested'
elif contact.sub in ('both', 'to', ''): elif contact.sub in ('both', 'to', ''):
@ -133,11 +141,13 @@ class BaseTooltip:
return True return True
def show_tooltip(self, data, widget_height, widget_y_position): def show_tooltip(self, data, widget_height, widget_y_position):
''' show tooltip on widget. """
data contains needed data for tooltip contents Show tooltip on widget
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 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 # set tooltip contents
self.populate(data) self.populate(data)
@ -163,8 +173,11 @@ class BaseTooltip:
self.id = None self.id = None
class StatusTable: 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): def __init__(self):
self.current_row = 1 self.current_row = 1
self.table = None self.table = None
@ -201,8 +214,10 @@ class StatusTable:
return str_status return str_status
def add_status_row(self, file_path, show, str_status, status_time=None, def add_status_row(self, file_path, show, str_status, status_time=None,
show_lock=False, indent=True): show_lock=False, indent=True):
''' appends a new row with status icon to the table ''' """
Append a new row with status icon to the table
"""
self.current_row += 1 self.current_row += 1
state_file = show.replace(' ', '_') state_file = show.replace(' ', '_')
files = [] files = []
@ -235,7 +250,10 @@ class StatusTable:
self.current_row + 1, 0, 0, 0, 0) self.current_row + 1, 0, 0, 0, 0)
class NotificationAreaTooltip(BaseTooltip, StatusTable): class NotificationAreaTooltip(BaseTooltip, StatusTable):
''' Tooltip that is shown in the notification area ''' """
Tooltip that is shown in the notification area
"""
def __init__(self): def __init__(self):
BaseTooltip.__init__(self) BaseTooltip.__init__(self)
StatusTable.__init__(self) StatusTable.__init__(self)
@ -283,7 +301,10 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
self.hbox.show_all() self.hbox.show_all()
class GCTooltip(BaseTooltip): class GCTooltip(BaseTooltip):
''' Tooltip that is shown in the GC treeview ''' """
Tooltip that is shown in the GC treeview
"""
def __init__(self): def __init__(self):
self.account = None self.account = None
self.text_label = gtk.Label() self.text_label = gtk.Label()
@ -378,7 +399,10 @@ class GCTooltip(BaseTooltip):
self.win.add(vcard_table) self.win.add(vcard_table)
class RosterTooltip(NotificationAreaTooltip): class RosterTooltip(NotificationAreaTooltip):
''' Tooltip that is shown in the roster treeview ''' """
Tooltip that is shown in the roster treeview
"""
def __init__(self): def __init__(self):
self.account = None self.account = None
self.image = gtk.Image() self.image = gtk.Image()
@ -561,7 +585,7 @@ class RosterTooltip(NotificationAreaTooltip):
vcard_current_row + 1, gtk.EXPAND | gtk.FILL, vcard_current_row + 1, gtk.EXPAND | gtk.FILL,
vertical_fill, 0, 0) vertical_fill, 0, 0)
else: 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_markup(property_[0])
label.set_line_wrap(True) label.set_line_wrap(True)
else: else:
@ -575,10 +599,10 @@ class RosterTooltip(NotificationAreaTooltip):
self.win.add(vcard_table) self.win.add(vcard_table)
def _append_pep_info(self, contact, properties): def _append_pep_info(self, contact, properties):
''' """
Append Tune, Mood, Activity information of the specified contact Append Tune, Mood, Activity information of the specified contact
to the given property list. to the given property list.
''' """
if 'mood' in contact.pep: if 'mood' in contact.pep:
mood = contact.pep['mood'].asMarkupText() mood = contact.pep['mood'].asMarkupText()
mood_string = _('Mood:') + ' %s' % mood mood_string = _('Mood:') + ' %s' % mood
@ -586,7 +610,7 @@ class RosterTooltip(NotificationAreaTooltip):
if 'activity' in contact.pep: if 'activity' in contact.pep:
activity = contact.pep['activity'].asMarkupText() activity = contact.pep['activity'].asMarkupText()
activity_string = _('Activity:') + ' %s' % activity activity_string = _('Activity:') + ' %s' % activity
properties.append((activity_string, None)) properties.append((activity_string, None))
if 'tune' in contact.pep: if 'tune' in contact.pep:
@ -596,7 +620,10 @@ class RosterTooltip(NotificationAreaTooltip):
class FileTransfersTooltip(BaseTooltip): class FileTransfersTooltip(BaseTooltip):
''' Tooltip that is shown in the notification area ''' """
Tooltip that is shown in the notification area
"""
def __init__(self): def __init__(self):
BaseTooltip.__init__(self) BaseTooltip.__init__(self)
@ -680,7 +707,9 @@ class FileTransfersTooltip(BaseTooltip):
class ServiceDiscoveryTooltip(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): def populate(self, status):
self.create_window() self.create_window()
label = gtk.Label() label = gtk.Label()

View File

@ -45,8 +45,11 @@ from common import gajim
from common.i18n import Q_ from common.i18n import Q_
def get_avatar_pixbuf_encoded_mime(photo): 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): if not isinstance(photo, dict):
return None, None, None return None, None, None
img_decoded = None img_decoded = None
@ -71,7 +74,9 @@ def get_avatar_pixbuf_encoded_mime(photo):
return pixbuf, avatar_encoded, avatar_mime_type return pixbuf, avatar_encoded, avatar_mime_type
class VcardWindow: class VcardWindow:
'''Class for contact's information window''' """
Class for contact's information window
"""
def __init__(self, contact, account, gc_contact = None): def __init__(self, contact, account, gc_contact = None):
# the contact variable is the jid if vcard is true # the contact variable is the jid if vcard is true
@ -151,7 +156,9 @@ class VcardWindow:
self.window.destroy() self.window.destroy()
def on_PHOTO_eventbox_button_press_event(self, widget, event): 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 if event.button == 3: # right click
menu = gtk.Menu() menu = gtk.Menu()
menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS) menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS)
@ -465,7 +472,9 @@ class ZeroconfVcardWindow:
self.window.destroy() self.window.destroy()
def on_PHOTO_eventbox_button_press_event(self, widget, event): 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 if event.button == 3: # right click
menu = gtk.Menu() menu = gtk.Menu()
menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS) menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS)