InputDialog can be non modal with parameters
is_modal=True and callback ok_handler
This commit is contained in:
parent
e7952867d2
commit
98460f0f35
|
@ -693,7 +693,7 @@ class RosterTooltip(gtk.Window):
|
||||||
|
|
||||||
class InputDialog:
|
class InputDialog:
|
||||||
'''Class for Input dialog'''
|
'''Class for Input dialog'''
|
||||||
def __init__(self, title, label_str, input_str = None):
|
def __init__(self, title, label_str, input_str = None, is_modal = True, ok_handler = None):
|
||||||
xml = gtk.glade.XML(GTKGUI_GLADE, 'input_dialog', APP)
|
xml = gtk.glade.XML(GTKGUI_GLADE, 'input_dialog', APP)
|
||||||
self.dialog = xml.get_widget('input_dialog')
|
self.dialog = xml.get_widget('input_dialog')
|
||||||
label = xml.get_widget('label')
|
label = xml.get_widget('label')
|
||||||
|
@ -703,10 +703,23 @@ class InputDialog:
|
||||||
if input_str:
|
if input_str:
|
||||||
self.input_entry.set_text(input_str)
|
self.input_entry.set_text(input_str)
|
||||||
self.input_entry.select_region(0, -1) # select all
|
self.input_entry.select_region(0, -1) # select all
|
||||||
|
|
||||||
def get_response(self):
|
self.is_modal = is_modal
|
||||||
response = self.dialog.run()
|
if not is_modal and ok_handler is not None:
|
||||||
|
self.ok_handler = ok_handler
|
||||||
|
okbutton = xml.get_widget('okbutton')
|
||||||
|
okbutton.connect('clicked', self.on_okbutton_clicked)
|
||||||
|
self.dialog.show_all()
|
||||||
|
|
||||||
|
def on_okbutton_clicked(self, widget):
|
||||||
|
response = self.input_entry.get_text()
|
||||||
self.dialog.destroy()
|
self.dialog.destroy()
|
||||||
|
self.ok_handler(response)
|
||||||
|
|
||||||
|
def get_response(self):
|
||||||
|
if self.is_modal:
|
||||||
|
response = self.dialog.run()
|
||||||
|
self.dialog.destroy()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
class ErrorDialog(HigDialog):
|
class ErrorDialog(HigDialog):
|
||||||
|
@ -855,17 +868,16 @@ class NewMessageDialog:
|
||||||
title = _('New Message')
|
title = _('New Message')
|
||||||
prompt_text = _('Fill in the contact ID of the contact you would like\nto send a chat message to:')
|
prompt_text = _('Fill in the contact ID of the contact you would like\nto send a chat message to:')
|
||||||
|
|
||||||
instance = InputDialog(title, prompt_text)
|
instance = InputDialog(title, prompt_text, is_modal = False, ok_handler = self.new_message_response)
|
||||||
response = instance.get_response()
|
|
||||||
if response == gtk.RESPONSE_OK:
|
def new_message_response(self, jid):
|
||||||
jid = instance.input_entry.get_text()
|
''' called when ok button is clicked '''
|
||||||
|
if jid.find('@') == -1: # if no @ was given
|
||||||
|
ErrorDialog(_('Invalid contact ID'),
|
||||||
|
_('Contact ID must be of the form "username@servername".')).get_response()
|
||||||
|
return
|
||||||
|
|
||||||
if jid.find('@') == -1: # if no @ was given
|
self.plugin.roster.new_chat_from_jid(self.account, jid)
|
||||||
ErrorDialog(_('Invalid contact ID'),
|
|
||||||
_('Contact ID must be of the form "username@servername".')).get_response()
|
|
||||||
return
|
|
||||||
|
|
||||||
self.plugin.roster.new_chat_from_jid(self.account, jid)
|
|
||||||
|
|
||||||
class ChangePasswordDialog:
|
class ChangePasswordDialog:
|
||||||
def __init__(self, plugin, account):
|
def __init__(self, plugin, account):
|
||||||
|
|
Loading…
Reference in New Issue