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

@ -638,11 +638,10 @@ class HigDialog(gtk.MessageDialog):
self.destroy() self.destroy()
return response return response
class FileChooserDialog(gtk.FileChooserDialog): class FileChooserDialog(gtk.FileChooserDialog):
'''Non-blocking FileChooser Dialog around gtk.FileChooserDialog''' '''Non-blocking FileChooser Dialog around gtk.FileChooserDialog'''
def __init__(self, title_text, action, buttons, default_response, 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): on_response_cancel = None):
gtk.FileChooserDialog.__init__(self, title = title_text, gtk.FileChooserDialog.__init__(self, title = title_text,
@ -655,8 +654,27 @@ class FileChooserDialog(gtk.FileChooserDialog):
else: else:
self.set_current_folder(helpers.get_documents_path()) 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() self.show_all()
def just_destroy(self, widget):
self.destroy()
class ConfirmationDialog(HigDialog): class ConfirmationDialog(HigDialog):
'''HIG compliant confirmation dialog.''' '''HIG compliant confirmation dialog.'''

View File

@ -244,22 +244,9 @@ _('Connection with peer cannot be established.'))
self.tree.get_selection().unselect_all() self.tree.get_selection().unselect_all()
def show_file_send_request(self, account, contact): def show_file_send_request(self, account, contact):
dialog = dialogs.FileChooserDialog(_('Choose File to Send...'), def on_ok(widget):
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 file_dir = None
files_path_list = dialog.get_filenames() files_path_list = self.dialog.get_filenames()
files_path_list = gtkgui_helpers.decode_filechooser_file_paths( files_path_list = gtkgui_helpers.decode_filechooser_file_paths(
files_path_list) files_path_list)
for file_path in files_path_list: for file_path in files_path_list:
@ -267,11 +254,18 @@ _('Connection with peer cannot be established.'))
file_dir = os.path.dirname(file_path) file_dir = os.path.dirname(file_path)
if file_dir: if file_dir:
gajim.config.set('last_send_dir', file_dir) gajim.config.set('last_send_dir', file_dir)
dialog.destroy() self.dialog.destroy()
break
else: self.dialog = dialogs.FileChooserDialog(_('Choose File to Send...'),
dialog.destroy() gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL),
break gtk.RESPONSE_OK,
True, # select multiple true as we can select many files to send
gajim.config.get('last_send_dir'),
)
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): def send_file(self, account, contact, file_path):
''' start the real transfer(upload) of the file ''' ''' start the real transfer(upload) of the file '''