filechooserdialog is no more blocking (no call to run() func). see #777

This commit is contained in:
Yann Leboulanger 2006-04-10 14:45:35 +00:00
parent eb8cc5b7ea
commit cf819d3835
2 changed files with 43 additions and 31 deletions

View File

@ -616,7 +616,7 @@ class HigDialog(gtk.MessageDialog):
else:
b.connect('clicked', possible_responses[response])
break
def just_destroy(self, widget):
self.destroy()
@ -638,25 +638,43 @@ class HigDialog(gtk.MessageDialog):
self.destroy()
return response
class FileChooserDialog(gtk.FileChooserDialog):
'''Non-blocking FileChooser Dialog around gtk.FileChooserDialog'''
def __init__(self, title_text, action, buttons, default_response,
select_multiple, current_folder, on_response_ok = None,
select_multiple, current_folder = None, on_response_ok = None,
on_response_cancel = None):
gtk.FileChooserDialog.__init__(self, title=title_text,
action=action, buttons=buttons)
gtk.FileChooserDialog.__init__(self, title = title_text,
action = action, buttons = buttons)
self.set_default_response(default_response)
self.set_select_multiple(select_multiple)
if current_folder and os.path.isdir(current_folder):
self.set_current_folder(current_folder)
else:
self.set_current_folder(helpers.get_documents_path())
buttons = self.action_area.get_children()
possible_responses = {gtk.STOCK_OK: on_response_ok,
gtk.STOCK_CANCEL: on_response_cancel}
for b in buttons:
for response in possible_responses:
if b.get_label() == response:
if not possible_responses[response]:
b.connect('clicked', self.just_destroy)
elif isinstance(possible_responses[response], tuple):
if len(possible_responses[response]) == 1:
b.connect('clicked', possible_responses[response][0])
else:
b.connect('clicked', *possible_responses[response])
else:
b.connect('clicked', possible_responses[response])
break
self.show_all()
def just_destroy(self, widget):
self.destroy()
class ConfirmationDialog(HigDialog):
'''HIG compliant confirmation dialog.'''
@ -666,7 +684,7 @@ class ConfirmationDialog(HigDialog):
gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, pritext, sectext,
on_response_ok, on_response_cancel)
self.popup()
class NonModalConfirmationDialog(HigDialog):
'''HIG compliant non modal confirmation dialog.'''
def __init__(self, pritext, sectext='', on_response_ok = None,

View File

@ -244,34 +244,28 @@ _('Connection with peer cannot be established.'))
self.tree.get_selection().unselect_all()
def show_file_send_request(self, account, contact):
dialog = dialogs.FileChooserDialog(_('Choose File to Send...'),
def on_ok(widget):
file_dir = None
files_path_list = self.dialog.get_filenames()
files_path_list = gtkgui_helpers.decode_filechooser_file_paths(
files_path_list)
for file_path in files_path_list:
if self.send_file(account, contact, file_path) and file_dir is None:
file_dir = os.path.dirname(file_path)
if file_dir:
gajim.config.set('last_send_dir', file_dir)
self.dialog.destroy()
self.dialog = dialogs.FileChooserDialog(_('Choose File to Send...'),
gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL),
gtk.RESPONSE_OK,
True, # select multiple true as we can select many files to send
gajim.config.get('last_send_dir'),
)
btn = dialog.add_button(_('_Send'), gtk.RESPONSE_OK)
btn.set_use_stock(True) # FIXME: add send icon to this button (JUMP_TO)
file_props = {}
while True:
response = dialog.run()
if response == gtk.RESPONSE_OK:
file_dir = None
files_path_list = dialog.get_filenames()
files_path_list = gtkgui_helpers.decode_filechooser_file_paths(
files_path_list)
for file_path in files_path_list:
if self.send_file(account, contact, file_path) and file_dir is None:
file_dir = os.path.dirname(file_path)
if file_dir:
gajim.config.set('last_send_dir', file_dir)
dialog.destroy()
break
else:
dialog.destroy()
break
btn = self.dialog.add_button(_('_Send'), gtk.RESPONSE_OK)
btn.set_use_stock(True) # FIXME: add send icon to this button (JUMP_TO)
btn.connect('clicked', on_ok)
def send_file(self, account, contact, file_path):
''' start the real transfer(upload) of the file '''