More doc-string refactoring
This commit is contained in:
parent
8c82c35654
commit
0ee0ade03a
|
@ -35,17 +35,22 @@ import dialogs
|
||||||
import dataforms_widget
|
import dataforms_widget
|
||||||
|
|
||||||
class CommandWindow:
|
class CommandWindow:
|
||||||
'''Class for a window for single ad-hoc commands session. Note, that
|
"""
|
||||||
there might be more than one for one account/jid pair in one moment.
|
Class for a window for single ad-hoc commands session
|
||||||
|
|
||||||
TODO: maybe put this window into MessageWindow? consider this when
|
Note, that there might be more than one for one account/jid pair in one
|
||||||
TODO: it will be possible to manage more than one window of one
|
moment.
|
||||||
TODO: account/jid pair in MessageWindowMgr.
|
|
||||||
|
|
||||||
TODO: gtk 2.10 has a special wizard-widget, consider using it...'''
|
TODO: Maybe put this window into MessageWindow? consider this when it will
|
||||||
|
be possible to manage more than one window of one.
|
||||||
|
TODO: Account/jid pair in MessageWindowMgr.
|
||||||
|
TODO: GTK 2.10 has a special wizard-widget, consider using it...
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, account, jid, commandnode=None):
|
def __init__(self, account, jid, commandnode=None):
|
||||||
'''Create new window.'''
|
"""
|
||||||
|
Create new window
|
||||||
|
"""
|
||||||
|
|
||||||
# an account object
|
# an account object
|
||||||
self.account = gajim.connections[account]
|
self.account = gajim.connections[account]
|
||||||
|
@ -89,16 +94,29 @@ class CommandWindow:
|
||||||
self.xml.signal_autoconnect(self)
|
self.xml.signal_autoconnect(self)
|
||||||
self.window.show_all()
|
self.window.show_all()
|
||||||
|
|
||||||
# these functions are set up by appropriate stageX methods
|
# These functions are set up by appropriate stageX methods.
|
||||||
def stage_finish(self, *anything): pass
|
def stage_finish(self, *anything):
|
||||||
def stage_back_button_clicked(self, *anything): assert False
|
pass
|
||||||
def stage_forward_button_clicked(self, *anything): assert False
|
|
||||||
def stage_execute_button_clicked(self, *anything): assert False
|
|
||||||
def stage_close_button_clicked(self, *anything): assert False
|
|
||||||
def stage_adhoc_commands_window_delete_event(self, *anything): assert False
|
|
||||||
def do_nothing(self, *anything): return False
|
|
||||||
|
|
||||||
# widget callbacks
|
def stage_back_button_clicked(self, *anything):
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def stage_forward_button_clicked(self, *anything):
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def stage_execute_button_clicked(self, *anything):
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def stage_close_button_clicked(self, *anything):
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def stage_adhoc_commands_window_delete_event(self, *anything):
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def do_nothing(self, *anything):
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Widget callbacks...
|
||||||
def on_back_button_clicked(self, *anything):
|
def on_back_button_clicked(self, *anything):
|
||||||
return self.stage_back_button_clicked(*anything)
|
return self.stage_back_button_clicked(*anything)
|
||||||
|
|
||||||
|
@ -123,8 +141,10 @@ class CommandWindow:
|
||||||
|
|
||||||
# stage 1: waiting for command list
|
# stage 1: waiting for command list
|
||||||
def stage1(self):
|
def stage1(self):
|
||||||
'''Prepare the first stage. Request command list,
|
"""
|
||||||
set appropriate state of widgets.'''
|
Prepare the first stage. Request command list, set appropriate state of
|
||||||
|
widgets
|
||||||
|
"""
|
||||||
# close old stage...
|
# close old stage...
|
||||||
self.stage_finish()
|
self.stage_finish()
|
||||||
|
|
||||||
|
@ -164,9 +184,12 @@ class CommandWindow:
|
||||||
|
|
||||||
# stage 2: choosing the command to execute
|
# stage 2: choosing the command to execute
|
||||||
def stage2(self):
|
def stage2(self):
|
||||||
'''Populate the command list vbox with radiobuttons
|
"""
|
||||||
(FIXME: if there is more commands, maybe some kind of list?),
|
Populate the command list vbox with radiobuttons
|
||||||
set widgets' state.'''
|
|
||||||
|
FIXME: If there is more commands, maybe some kind of list, set widgets
|
||||||
|
state
|
||||||
|
"""
|
||||||
# close old stage
|
# close old stage
|
||||||
self.stage_finish()
|
self.stage_finish()
|
||||||
|
|
||||||
|
@ -198,7 +221,9 @@ class CommandWindow:
|
||||||
self.stage_adhoc_commands_window_delete_event = self.do_nothing
|
self.stage_adhoc_commands_window_delete_event = self.do_nothing
|
||||||
|
|
||||||
def stage2_finish(self):
|
def stage2_finish(self):
|
||||||
'''Remove widgets we created. Not needed when the window is destroyed.'''
|
"""
|
||||||
|
Remove widgets we created. Not needed when the window is destroyed
|
||||||
|
"""
|
||||||
def remove_widget(widget):
|
def remove_widget(widget):
|
||||||
self.command_list_vbox.remove(widget)
|
self.command_list_vbox.remove(widget)
|
||||||
self.command_list_vbox.foreach(remove_widget)
|
self.command_list_vbox.foreach(remove_widget)
|
||||||
|
@ -247,8 +272,10 @@ class CommandWindow:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def stage3_close_button_clicked(self, widget):
|
def stage3_close_button_clicked(self, widget):
|
||||||
''' We are in the middle of executing command. Ask user if he really want to cancel
|
"""
|
||||||
the process, then... cancel it. '''
|
We are in the middle of executing command. Ask user if he really want to
|
||||||
|
cancel the process, then cancel it
|
||||||
|
"""
|
||||||
# this works also as a handler for window_delete_event, so we have to return appropriate
|
# this works also as a handler for window_delete_event, so we have to return appropriate
|
||||||
# values
|
# values
|
||||||
if self.form_status == 'completed':
|
if self.form_status == 'completed':
|
||||||
|
@ -362,7 +389,9 @@ class CommandWindow:
|
||||||
|
|
||||||
# stage 4: no commands are exposed
|
# stage 4: no commands are exposed
|
||||||
def stage4(self):
|
def stage4(self):
|
||||||
'''Display the message. Wait for user to close the window'''
|
"""
|
||||||
|
Display the message. Wait for user to close the window
|
||||||
|
"""
|
||||||
# close old stage
|
# close old stage
|
||||||
self.stage_finish()
|
self.stage_finish()
|
||||||
|
|
||||||
|
@ -387,7 +416,9 @@ class CommandWindow:
|
||||||
|
|
||||||
# stage 5: an error has occured
|
# stage 5: an error has occured
|
||||||
def stage5(self, error=None, errorid=None, senderror=False):
|
def stage5(self, error=None, errorid=None, senderror=False):
|
||||||
'''Display the error message. Wait for user to close the window'''
|
"""
|
||||||
|
Display the error message. Wait for user to close the window
|
||||||
|
"""
|
||||||
# FIXME: sending error to responder
|
# FIXME: sending error to responder
|
||||||
# close old stage
|
# close old stage
|
||||||
self.stage_finish()
|
self.stage_finish()
|
||||||
|
@ -430,8 +461,10 @@ class CommandWindow:
|
||||||
|
|
||||||
# helpers to handle pulsing in progressbar
|
# helpers to handle pulsing in progressbar
|
||||||
def setup_pulsing(self, progressbar):
|
def setup_pulsing(self, progressbar):
|
||||||
'''Set the progressbar to pulse. Makes a custom
|
"""
|
||||||
function to repeatedly call progressbar.pulse() method.'''
|
Set the progressbar to pulse. Makes a custom function to repeatedly call
|
||||||
|
progressbar.pulse() method
|
||||||
|
"""
|
||||||
assert not self.pulse_id
|
assert not self.pulse_id
|
||||||
assert isinstance(progressbar, gtk.ProgressBar)
|
assert isinstance(progressbar, gtk.ProgressBar)
|
||||||
|
|
||||||
|
@ -443,14 +476,18 @@ class CommandWindow:
|
||||||
self.pulse_id = gobject.timeout_add(80, callback)
|
self.pulse_id = gobject.timeout_add(80, callback)
|
||||||
|
|
||||||
def remove_pulsing(self):
|
def remove_pulsing(self):
|
||||||
'''Stop pulsing, useful when especially when removing widget.'''
|
"""
|
||||||
|
Stop pulsing, useful when especially when removing widget
|
||||||
|
"""
|
||||||
if self.pulse_id:
|
if self.pulse_id:
|
||||||
gobject.source_remove(self.pulse_id)
|
gobject.source_remove(self.pulse_id)
|
||||||
self.pulse_id=None
|
self.pulse_id=None
|
||||||
|
|
||||||
# handling xml stanzas
|
# handling xml stanzas
|
||||||
def request_command_list(self):
|
def request_command_list(self):
|
||||||
'''Request the command list. Change stage on delivery.'''
|
"""
|
||||||
|
Request the command list. Change stage on delivery
|
||||||
|
"""
|
||||||
query = xmpp.Iq(typ='get', to=xmpp.JID(self.jid), queryNS=xmpp.NS_DISCO_ITEMS)
|
query = xmpp.Iq(typ='get', to=xmpp.JID(self.jid), queryNS=xmpp.NS_DISCO_ITEMS)
|
||||||
query.setQuerynode(xmpp.NS_COMMANDS)
|
query.setQuerynode(xmpp.NS_COMMANDS)
|
||||||
|
|
||||||
|
@ -481,7 +518,9 @@ class CommandWindow:
|
||||||
self.account.connection.SendAndCallForResponse(query, callback)
|
self.account.connection.SendAndCallForResponse(query, callback)
|
||||||
|
|
||||||
def send_command(self, action='execute'):
|
def send_command(self, action='execute'):
|
||||||
'''Send the command with data form. Wait for reply.'''
|
"""
|
||||||
|
Send the command with data form. Wait for reply
|
||||||
|
"""
|
||||||
# create the stanza
|
# create the stanza
|
||||||
assert isinstance(self.commandnode, unicode)
|
assert isinstance(self.commandnode, unicode)
|
||||||
assert action in ('execute', 'prev', 'next', 'complete')
|
assert action in ('execute', 'prev', 'next', 'complete')
|
||||||
|
@ -510,7 +549,9 @@ class CommandWindow:
|
||||||
self.account.connection.SendAndCallForResponse(stanza, callback)
|
self.account.connection.SendAndCallForResponse(stanza, callback)
|
||||||
|
|
||||||
def send_cancel(self):
|
def send_cancel(self):
|
||||||
'''Send the command with action='cancel'. '''
|
"""
|
||||||
|
Send the command with action='cancel'
|
||||||
|
"""
|
||||||
assert self.commandnode
|
assert self.commandnode
|
||||||
if self.sessionid and self.account.connection:
|
if self.sessionid and self.account.connection:
|
||||||
# we already have sessionid, so the service sent at least one reply.
|
# we already have sessionid, so the service sent at least one reply.
|
||||||
|
|
Loading…
Reference in New Issue