Commit 7316d007 authored by Alexander Cherniuk's avatar Alexander Cherniuk

New portion of doc-string refactoring

parent 18fc83c1
This diff is collapsed.
......@@ -33,7 +33,9 @@ from common import helpers
from common import kwalletbinding
class FeaturesWindow:
'''Class for features window'''
"""
Class for features window
"""
def __init__(self):
self.xml = gtkgui_helpers.get_glade('features_window.glade')
......
......@@ -134,7 +134,9 @@ class FileTransfersWindow:
self.xml.signal_autoconnect(self)
def find_transfer_by_jid(self, account, jid):
''' find all transfers with peer 'jid' that belong to 'account' '''
"""
Find all transfers with peer 'jid' that belong to 'account'
"""
active_transfers = [[],[]] # ['senders', 'receivers']
# 'account' is the sender
......@@ -155,7 +157,9 @@ class FileTransfersWindow:
return active_transfers
def show_completed(self, jid, file_props):
''' show a dialog saying that file (file_props) has been transferred'''
"""
Show a dialog saying that file (file_props) has been transferred
"""
def on_open(widget, file_props):
dialog.destroy()
if 'file-name' not in file_props:
......@@ -207,14 +211,16 @@ class FileTransfersWindow:
dialog.show_all()
def show_request_error(self, file_props):
''' show error dialog to the recipient saying that transfer
has been canceled'''
"""
Show error dialog to the recipient saying that transfer has been canceled
"""
dialogs.InformationDialog(_('File transfer cancelled'), _('Connection with peer cannot be established.'))
self.tree.get_selection().unselect_all()
def show_send_error(self, file_props):
''' show error dialog to the sender saying that transfer
has been canceled'''
"""
Show error dialog to the sender saying that transfer has been canceled
"""
dialogs.InformationDialog(_('File transfer cancelled'),
_('Connection with peer cannot be established.'))
self.tree.get_selection().unselect_all()
......@@ -273,7 +279,9 @@ _('Connection with peer cannot be established.'))
desc_hbox.show_all()
def send_file(self, account, contact, file_path, file_desc=''):
''' start the real transfer(upload) of the file '''
"""
Start the real transfer(upload) of the file
"""
if gtkgui_helpers.file_is_locked(file_path):
pritext = _('Gajim cannot access this file')
sextext = _('This file is being used by another process.')
......@@ -303,8 +311,10 @@ _('Connection with peer cannot be established.'))
gajim.connections[account].send_file_approval(file_props)
def show_file_request(self, account, contact, file_props):
''' show dialog asking for comfirmation and store location of new
file requested by a contact'''
"""
Show dialog asking for comfirmation and store location of new file
requested by a contact
"""
if file_props is None or 'name' not in file_props:
return
sec_text = '\t' + _('File: %s') % gobject.markup_escape_text(
......@@ -394,7 +404,9 @@ _('Connection with peer cannot be established.'))
self.window.render_icon(self.icons[ident], gtk.ICON_SIZE_MENU))
def set_status(self, typ, sid, status):
''' change the status of a transfer to state 'status' '''
"""
Change the status of a transfer to state 'status'
"""
iter_ = self.get_iter_by_sid(typ, sid)
if iter_ is None:
return
......@@ -409,8 +421,10 @@ _('Connection with peer cannot be established.'))
self.select_func(path)
def _format_percent(self, percent):
''' add extra spaces from both sides of the percent, so that
progress string has always a fixed size'''
"""
Add extra spaces from both sides of the percent, so that progress string
has always a fixed size
"""
_str = ' '
if percent != 100.:
_str += ' '
......@@ -481,7 +495,9 @@ _('Connection with peer cannot be established.'))
del(file_props)
def set_progress(self, typ, sid, transfered_size, iter_ = None):
''' change the progress of a transfer with new transfered size'''
"""
Change the progress of a transfer with new transfered size
"""
if sid not in self.files_props[typ]:
return
file_props = self.files_props[typ][sid]
......@@ -546,8 +562,10 @@ _('Connection with peer cannot be established.'))
self.select_func(path)
def get_iter_by_sid(self, typ, sid):
'''returns iter to the row, which holds file transfer, identified by the
session id'''
"""
Return iter to the row, which holds file transfer, identified by the
session id
"""
iter_ = self.model.get_iter_root()
while iter_:
if typ + sid == self.model[iter_][C_SID].decode('utf-8'):
......@@ -555,9 +573,10 @@ _('Connection with peer cannot be established.'))
iter_ = self.model.iter_next(iter_)
def get_send_file_props(self, account, contact, file_path, file_name,
file_desc=''):
''' create new file_props dict and set initial file transfer
properties in it'''
file_desc=''):
"""
Create new file_props dict and set initial file transfer properties in it
"""
file_props = {'file-name' : file_path, 'name' : file_name,
'type' : 's', 'desc' : file_desc}
if os.path.isfile(file_path):
......@@ -582,7 +601,9 @@ _('Connection with peer cannot be established.'))
return file_props
def add_transfer(self, account, contact, file_props):
''' add new transfer to FT window and show the FT window '''
"""
Add new transfer to FT window and show the FT window
"""
self.on_transfers_list_leave_notify_event(None)
if file_props is None:
return
......@@ -686,15 +707,19 @@ _('Connection with peer cannot be established.'))
return True
def set_cleanup_sensitivity(self):
''' check if there are transfer rows and set cleanup_button
sensitive, or insensitive if model is empty'''
"""
Check if there are transfer rows and set cleanup_button sensitive, or
insensitive if model is empty
"""
if len(self.model) == 0:
self.cleanup_button.set_sensitive(False)
else:
self.cleanup_button.set_sensitive(True)
def set_all_insensitive(self):
''' make all buttons/menuitems insensitive '''
"""
Make all buttons/menuitems insensitive
"""
self.pause_button.set_sensitive(False)
self.pause_menuitem.set_sensitive(False)
self.continue_menuitem.set_sensitive(False)
......@@ -705,8 +730,10 @@ _('Connection with peer cannot be established.'))
self.set_cleanup_sensitivity()
def set_buttons_sensitive(self, path, is_row_selected):
''' make buttons/menuitems sensitive as appropriate to
the state of file transfer located at path 'path' '''
"""
Make buttons/menuitems sensitive as appropriate to the state of file
transfer located at path 'path'
"""
if path is None:
self.set_all_insensitive()
return
......@@ -743,8 +770,9 @@ _('Connection with peer cannot be established.'))
return True
def selection_changed(self, args):
''' selection has changed - change the sensitivity of the
buttons/menuitems'''
"""
Selection has changed - change the sensitivity of the buttons/menuitems
"""
selection = args
selected = selection.get_selected_rows()
if selected[1] != []:
......@@ -881,7 +909,9 @@ _('Connection with peer cannot be established.'))
event_button, event.time)
def on_transfers_list_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()
iter_ = None
try:
......@@ -963,5 +993,4 @@ _('Connection with peer cannot be established.'))
if event.keyval == gtk.keysyms.Escape: # ESCAPE
self.window.hide()
# vim: se ts=3:
......@@ -60,7 +60,6 @@ INTERFACE = 'org.gajim.dbus.RemoteInterface'
SERVICE = 'org.gajim.dbus'
BASENAME = 'gajim-remote'
class GajimRemote:
def __init__(self):
......@@ -327,7 +326,9 @@ class GajimRemote:
self.print_result(res)
def print_result(self, res):
''' Print retrieved result to the output '''
"""
Print retrieved result to the output
"""
if res is not None:
if self.command in ('open_chat', 'send_chat_message', 'send_single_message', 'start_chat'):
if self.command in ('send_message', 'send_single_message'):
......@@ -382,8 +383,9 @@ class GajimRemote:
return test
def init_connection(self):
''' create the onnection to the session dbus,
or exit if it is not possible '''
"""
Create the onnection to the session dbus, or exit if it is not possible
"""
try:
self.sbus = dbus.SessionBus()
except Exception:
......@@ -398,8 +400,10 @@ class GajimRemote:
self.method = interface.__getattr__(self.command)
def make_arguments_row(self, args):
''' return arguments list. Mandatory arguments are enclosed with:
'<', '>', optional arguments - with '[', ']' '''
"""
Return arguments list. Mandatory arguments are enclosed with:
'<', '>', optional arguments - with '[', ']'
"""
s = ''
for arg in args:
if arg[2]:
......@@ -409,7 +413,9 @@ class GajimRemote:
return s
def help_on_command(self, command):
''' return help message for a given command '''
"""
Return help message for a given command
"""
if command in self.commands:
command_props = self.commands[command]
arguments_str = self.make_arguments_row(command_props[1])
......@@ -424,7 +430,9 @@ class GajimRemote:
send_error(_('%s not found') % command)
def compose_help(self):
''' print usage, and list available commands '''
"""
Print usage, and list available commands
"""
s = _('Usage: %s command [arguments]\nCommand is one of:\n' ) % BASENAME
for command in sorted(self.commands):
s += ' ' + command
......@@ -437,7 +445,9 @@ class GajimRemote:
return s
def print_info(self, level, prop_dict, encode_return = False):
''' return formated string from data structure '''
"""
Return formated string from data structure
"""
if prop_dict is None or not isinstance(prop_dict, (dict, list, tuple)):
return ''
ret_str = ''
......@@ -486,7 +496,9 @@ class GajimRemote:
return ret_str
def check_arguments(self):
''' Make check if all necessary arguments are given '''
"""
Make check if all necessary arguments are given
"""
argv_len = self.argv_len - 2
args = self.commands[self.command][1]
if len(args) < argv_len:
......@@ -559,7 +571,9 @@ class GajimRemote:
sys.exit(0)
def call_remote_method(self):
''' calls self.method with arguments from sys.argv[2:] '''
"""
Calls self.method with arguments from sys.argv[2:]
"""
args = [i.decode(PREFERRED_ENCODING) for i in self.arguments]
args = [dbus.String(i) for i in args]
try:
......
......@@ -275,7 +275,9 @@ class GajimThemesWindow:
self._set_font()
def _set_color(self, state, widget, option):
''' set color value in prefs and update the UI '''
"""
Set color value in prefs and update the UI
"""
if state:
color = widget.get_color()
color_string = gtkgui_helpers.make_color_string(color)
......@@ -297,7 +299,9 @@ class GajimThemesWindow:
gajim.interface.save_config()
def _set_font(self):
''' set font value in prefs and update the UI '''
"""
Set font value in prefs and update the UI
"""
state = self.textfont_checkbutton.get_active()
if state:
font_string = self.text_fontbutton.get_font_name()
......@@ -317,13 +321,16 @@ class GajimThemesWindow:
gajim.interface.save_config()
def _toggle_font_widgets(self, font_props):
''' toggle font buttons with the bool values of font_props tuple'''
"""
Toggle font buttons with the bool values of font_props tuple
"""
self.bold_togglebutton.set_active(font_props[0])
self.italic_togglebutton.set_active(font_props[1])
def _get_font_description(self):
''' return a FontDescription from togglebuttons
states'''
"""
Return a FontDescription from togglebuttons states
"""
fd = pango.FontDescription()
if self.bold_togglebutton.get_active():
fd.set_weight(pango.WEIGHT_BOLD)
......@@ -332,8 +339,10 @@ class GajimThemesWindow:
return fd
def _set_font_widgets(self, font_attrs):
''' set the correct toggle state of font style buttons by
a font string of type 'BI' '''
"""
Set the correct toggle state of font style buttons by a font string of
type 'BI'
"""
font_props = [False, False, False]
if font_attrs:
if font_attrs.find('B') != -1:
......@@ -343,7 +352,9 @@ class GajimThemesWindow:
self._toggle_font_widgets(font_props)
def _get_font_attrs(self):
''' get a string with letters of font attribures: 'BI' '''
"""
Get a string with letters of font attribures: 'BI'
"""
attrs = ''
if self.bold_togglebutton.get_active():
attrs += 'B'
......@@ -353,7 +364,9 @@ class GajimThemesWindow:
def _get_font_props(self, font_name):
''' get tuple of font properties: Weight, Style '''
"""
Get tuple of font properties: weight, style
"""
font_props = [False, False, False]
font_description = pango.FontDescription(font_name)
if font_description.get_weight() != pango.WEIGHT_NORMAL:
......
......@@ -26,7 +26,10 @@ import gtkgui_helpers
class GroupsPostWindow:
def __init__(self, account, servicejid, groupid):
'''Open new 'create post' window to create message for groupid on servicejid service.'''
"""
Open new 'create post' window to create message for groupid on servicejid
service
"""
assert isinstance(servicejid, basestring)
assert isinstance(groupid, basestring)
......@@ -43,11 +46,15 @@ class GroupsPostWindow:
self.window.show_all()
def on_cancel_button_clicked(self, w):
'''Close window.'''
"""
Close window
"""
self.window.destroy()
def on_send_button_clicked(self, w):
'''Gather info from widgets and send it as a message.'''
"""
Gather info from widgets and send it as a message
"""
# constructing item to publish... that's atom:entry element
item = xmpp.Node('entry', {'xmlns':'http://www.w3.org/2005/Atom'})
author = item.addChild('author')
......
This diff is collapsed.
......@@ -54,7 +54,6 @@ if dbus_support.supported:
import gtkgui_helpers
import dialogs
import notify
import message_control
......@@ -92,7 +91,6 @@ config_filename = gajimpaths['CONFIG_FILE']
from common import optparser
parser = optparser.OptionsParser(config_filename)
import logging
log = logging.getLogger('gajim.interface')
......@@ -265,10 +263,10 @@ class Interface:
def handle_event_new_jid(self, account, data):
#('NEW_JID', account, (old_jid, new_jid))
'''
"""
This event is raised when our JID changed (most probably because we use
anonymous account. We update contact and roster entry in this case.
'''
anonymous account. We update contact and roster entry in this case
"""
self.roster.rename_self_contact(data[0], data[1], account)
def edit_own_details(self, account):
......@@ -1521,7 +1519,9 @@ class Interface:
contact.resource)
def handle_event_signed_in(self, account, empty):
'''SIGNED_IN event is emitted when we sign in, so handle it'''
"""
SIGNED_IN event is emitted when we sign in, so handle it
"""
# ('SIGNED_IN', account, ())
# block signed in notifications for 30 seconds
gajim.block_signed_in_notifications[account] = True
......@@ -1828,7 +1828,9 @@ class Interface:
dialogs.RosterItemExchangeWindow(account, data[0], data[1], data[2])
def handle_event_unique_room_id_supported(self, account, data):
'''Receive confirmation that unique_room_id are supported'''
"""
Receive confirmation that unique_room_id are supported
"""
# ('UNIQUE_ROOM_ID_SUPPORTED', server, instance, room_id)
instance = data[1]
instance.unique_room_id_supported(data[0], data[2])
......@@ -2114,12 +2116,11 @@ class Interface:
'PEP_RECEIVED': [self.handle_event_pep_received]
}
def dispatch(self, event, account, data):
'''
Dispatches an network event to the event handlers of this class.
Return true if it could be dispatched to alteast one handler.
'''
def dispatch(self, event, account, data):
"""
Dispatch an network event to the event handlers of this class. Return
true if it could be dispatched to alteast one handler
"""
if event not in self.handlers:
log.warning('Unknown event %s dispatched to GUI: %s' % (event, data))
return False
......@@ -2135,7 +2136,9 @@ class Interface:
################################################################################
def add_event(self, account, jid, type_, event_args):
'''add an event to the gajim.events var'''
"""
Add an event to the gajim.events var
"""
# We add it to the gajim.events queue
# Do we have a queue?
jid = gajim.get_jid_without_resource(jid)
......@@ -2464,7 +2467,9 @@ class Interface:
self.invalid_XML_chars = u'[\x00-\x08]|[\x0b-\x0c]|[\x0e-\x19]|[\ud800-\udfff]|[\ufffe-\uffff]'
def popup_emoticons_under_button(self, button, parent_win):
''' pops emoticons menu under button, located in parent_win'''
"""
Popup the emoticons menu under button, located in parent_win
"""
gtkgui_helpers.popup_emoticons_under_button(self.emoticons_menu,
button, parent_win)
......@@ -2572,8 +2577,10 @@ class Interface:
################################################################################
def join_gc_room(self, account, room_jid, nick, password, minimize=False,
is_continued=False):
'''joins the room immediately'''
is_continued=False):
"""
Join the room immediately
"""
if not nick:
nick = gajim.nicks[account]
......@@ -2841,7 +2848,9 @@ class Interface:
return (bg_str, fg_str)
def read_sleepy(self):
'''Check idle status and change that status if needed'''
"""
Check idle status and change that status if needed
"""
if not self.sleeper.poll():
# idle detection is not supported in that OS
return False # stop looping in vain
......@@ -2895,7 +2904,9 @@ class Interface:
return True # renew timeout (loop for ever)
def autoconnect(self):
'''auto connect at startup'''
"""
Auto connect at startup
"""
# dict of account that want to connect sorted by status
shows = {}
for a in gajim.connections:
......@@ -2934,7 +2945,9 @@ class Interface:
helpers.launch_browser_mailer(kind, url)
def process_connections(self):
''' Called each foo (200) miliseconds. Check for idlequeue timeouts. '''
"""
Called each foo (200) miliseconds. Check for idlequeue timeouts
"""
try:
gajim.idlequeue.process()
except Exception:
......@@ -2958,7 +2971,11 @@ class Interface:
sys.exit()
def save_avatar_files(self, jid, photo, puny_nick = None, local = False):
'''Saves an avatar to a separate file, and generate files for dbus notifications. An avatar can be given as a pixmap directly or as an decoded image.'''
"""
Save an avatar to a separate file, and generate files for dbus
notifications. An avatar can be given as a pixmap directly or as an
decoded image
"""
puny_jid = helpers.sanitize_filename(jid)
path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid)
if puny_nick:
......@@ -3011,7 +3028,9 @@ class Interface:
(path_to_original_file, str(e)))
def remove_avatar_files(self, jid, puny_nick = None, local = False):
'''remove avatar files of a jid'''
"""
Remove avatar files of a jid
"""
puny_jid = helpers.sanitize_filename(jid)
path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid)
if puny_nick:
......@@ -3028,7 +3047,9 @@ class Interface:
os.remove(path_to_file + '_notif_size_bw' + ext)
def auto_join_bookmarks(self, account):
'''autojoin bookmarked GCs that have 'auto join' on for this account'''
"""
Autojoin bookmarked GCs that have 'auto join' on for this account
"""
for bm in gajim.connections[account].bookmarks:
if bm['autojoin'] in ('1', 'true'):
jid = bm['jid']
......@@ -3046,8 +3067,10 @@ class Interface:
self.roster.add_groupchat(jid, account)
def add_gc_bookmark(self, account, name, jid, autojoin, minimize, password,
nick):
'''add a bookmark for this account, sorted in bookmark list'''
nick):
"""
Add a bookmark for this account, sorted in bookmark list
"""
bm = {
'name': name,
'jid': jid,
......@@ -3475,13 +3498,9 @@ class PassphraseRequest:
class ThreadInterface:
def __init__(self, func, func_args, callback, callback_args):
'''Call a function in a thread
:param func: the function to call in the thread
:param func_args: list or arguments for this function
:param callback: callback to call once function is finished
:param callback_args: list of arguments for this callback
'''
"""
Call a function in a thread
"""
def thread_function(func, func_args, callback, callback_args):
output = func(*func_args)
gobject.idle_add(callback, output, *callback_args)
......
......@@ -28,9 +28,11 @@ from common import helpers
from common.xmpp.protocol import NS_COMMANDS, NS_FILE, NS_MUC, NS_ESESSION
def build_resources_submenu(contacts, account, action, room_jid=None,
room_account=None, cap=None):
''' Build a submenu with contact's resources.
room_jid and room_account are for action self.on_invite_to_room '''
room_account=None, cap=None):
"""
Build a submenu with contact's resources. room_jid and room_account are for
action self.on_invite_to_room
"""
roster = gajim.interface.roster
sub_menu = gtk.Menu()
......@@ -61,7 +63,9 @@ room_account=None, cap=None):
return sub_menu
def build_invite_submenu(invite_menuitem, list_):
'''list_ in a list of (contact, account)'''
"""
list_ in a list of (contact, account)
"""
roster = gajim.interface.roster
# used if we invite only one contact with several resources
contact_list = []
......@@ -145,10 +149,12 @@ def build_invite_submenu(invite_menuitem, list_):
invite_to_submenu.append(menuitem)
def get_contact_menu(contact, account, use_multiple_contacts=True,
show_start_chat=True, show_encryption=False, show_buttonbar_items=True,
control=None):
''' Build contact popup menu for roster and chat window.
If control is not set, we hide invite_contacts_menuitem'''
show_start_chat=True, show_encryption=False, show_buttonbar_items=True,
control=None):
"""
Build contact popup menu for roster and chat window. If control is not set,
we hide invite_contacts_menuitem
"""
if not contact:
return
......
......@@ -290,11 +290,13 @@ class HistoryManager:
self._fill_logs_listview(jid)
def _get_jid_id(self, jid):
'''jids table has jid and jid_id
"""
jids table has jid and jid_id
logs table has log_id, jid_id, contact_name, time, kind, show, message
so to ask logs we need jid_id that matches our jid in jids table
this method wants jid and returns the jid_id for later sql-ing on logs
'''
So to ask logs we need jid_id that matches our jid in jids table this
method wants jid and returns the jid_id for later sql-ing on logs
"""
if jid.find('/') != -1: # if it has a /
jid_is_from_pm = self._jid_is_from_pm(jid)
if not jid_is_from_pm: # it's normal jid with resource
......@@ -304,22 +306,24 @@ class HistoryManager:
return str(jid_id)
def _get_jid_from_jid_id(self, jid_id):
'''jids table has jid and jid_id
this method accepts jid_id and returns the jid for later sql-ing on logs
'''
"""
jids table has jid and jid_id
This method accepts jid_id and returns the jid for later sql-ing on logs
"""
self.cur.execute('SELECT jid FROM jids WHERE jid_id = ?', (jid_id,))
jid = self.cur.fetchone()[0]
return jid
def _jid_is_from_pm(self, jid):
'''if jid is gajim@conf/nkour it's likely a pm one, how we know
gajim@conf is not a normal guy and nkour is not his resource?
we ask if gajim@conf is already in jids (with type room jid)
this fails if user disables logging for room and only enables for
pm (so higly unlikely) and if we fail we do not go chaos
(user will see the first pm as if it was message in room's public chat)
and after that all okay'''
"""
If jid is gajim@conf/nkour it's likely a pm one, how we know gajim@conf
is not a normal guy and nkour is not his resource? We ask if gajim@conf
is already in jids (with type room jid). This fails if user disables
logging for room and only enables for pm (so higly unlikely) and if we
fail we do not go chaos (user will see the first pm as if it was message
in room's public chat) and after that everything is ok
"""
possible_room_jid = jid.split('/', 1)[0]
self.cur.execute('SELECT jid_id FROM jids WHERE jid = ? AND type = ?',
......@@ -331,8 +335,9 @@ class HistoryManager:
return True
def _jid_is_room_type(self, jid):
'''returns True/False if given id is room type or not
eg. if it is room'''
"""
Return True/False if given id is room type or not eg. if it is room
"""
self.cur.execute('SELECT type FROM jids WHERE jid = ?', (jid,))
row = self.cur.fetchone()
if row is None:
......@@ -343,8 +348,10 @@ class HistoryManager:
return False
def _fill_logs_listview(self, jid):
'''fill the listview with all messages that user sent to or
received from JID'''
"""
Fill the listview with all messages that user sent to or received from
JID
"""
# no need to lower jid in this context as jid is already lowered
# as we use those jids from db
jid_id = self._get_jid_id(jid)
......@@ -403,7 +410,9 @@ class HistoryManager:
subject, nickname))
def _fill_search_results_listview(self, text):
'''ask db and fill listview with results that match text'''
"""
Ask db and fill listview with results that match text
"""
self.search_results_liststore.clear()
like_sql = '%' + text + '%'
self.cur.execute('''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment