/SoundChooserDialog are now non blocker. Fixes #777

This commit is contained in:
Yann Leboulanger 2006-04-10 17:21:28 +00:00
parent 2b845f6fd5
commit a1b8dfbcd7
2 changed files with 60 additions and 56 deletions

View file

@ -920,20 +920,32 @@ class PreferencesWindow:
(model, iter) = self.sound_tree.get_selection().get_selected() (model, iter) = self.sound_tree.get_selection().get_selected()
if not iter: if not iter:
return return
path_to_snd_file = model[iter][2].decode('utf-8') def on_ok(widget, path_to_snd_file):
path_to_snd_file = os.path.join(os.getcwd(), path_to_snd_file) self.dialog.destroy()
dlg_instance = dialogs.SoundChooserDialog(path_to_snd_file) model, iter = self.sound_tree.get_selection().get_selected()
path_to_snd_file = dlg_instance.path_to_snd_file if not path_to_snd_file:
dlg_instance.dialog.destroy() model[iter][2] = ''
self.xml.get_widget('sounds_entry').set_text('')
if path_to_snd_file: model[iter][0] = False
return
directory = os.path.dirname(path_to_snd_file) directory = os.path.dirname(path_to_snd_file)
gajim.config.set('last_sounds_dir', directory) gajim.config.set('last_sounds_dir', directory)
self.xml.get_widget('sounds_entry').set_text(path_to_snd_file) self.xml.get_widget('sounds_entry').set_text(path_to_snd_file)
model[iter][2] = path_to_snd_file # set new path to sounds_model model[iter][2] = path_to_snd_file # set new path to sounds_model
model[iter][0] = True # set the sound to enabled model[iter][0] = True # set the sound to enabled
def on_cancel(widget):
self.dialog.destroy()
model, iter = self.sound_tree.get_selection().get_selected()
model[iter][2] = ''
model[iter][0] = False
path_to_snd_file = model[iter][2].decode('utf-8')
path_to_snd_file = os.path.join(os.getcwd(), path_to_snd_file)
self.dialog = dialogs.SoundChooserDialog(path_to_snd_file, on_ok,
on_cancel)
def on_sounds_entry_changed(self, widget): def on_sounds_entry_changed(self, widget):
path_to_snd_file = widget.get_text() path_to_snd_file = widget.get_text()
model, iter = self.sound_tree.get_selection().get_selected() model, iter = self.sound_tree.get_selection().get_selected()

View file

@ -1529,48 +1529,43 @@ class ProgressDialog:
return True # WM's X button or Escape key should not destroy the window return True # WM's X button or Escape key should not destroy the window
class SoundChooserDialog: class SoundChooserDialog(FileChooserDialog):
def __init__(self, path_to_snd_file = ''): def __init__(self, path_to_snd_file = '', on_response_ok = None,
on_response_cancel = None):
'''optionally accepts path_to_snd_file so it has that as selected''' '''optionally accepts path_to_snd_file so it has that as selected'''
self.dialog = gtk.FileChooserDialog(_('Choose Sound'), None, def on_ok(widget, callback):
gtk.FILE_CHOOSER_ACTION_OPEN, '''check if file exists and call callback'''
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, path_to_snd_file = self.get_filename()
gtk.STOCK_OPEN, gtk.RESPONSE_OK)) try:
self.dialog.set_default_response(gtk.RESPONSE_OK) path_to_snd_file = path_to_snd_file.decode(
last_sounds_dir = gajim.config.get('last_sounds_dir') sys.getfilesystemencoding())
if last_sounds_dir and os.path.isdir('last_sounds_dir'): except:
self.dialog.set_current_folder(last_sounds_dir) pass
else: if os.path.exists(path_to_snd_file):
self.dialog.set_current_folder(gajim.HOME_DIR) callback(widget, path_to_snd_file)
FileChooserDialog.__init__(self,
title_text = _('Choose Sound'),
action = gtk.FILE_CHOOSER_ACTION_OPEN,
buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK),
default_response = gtk.RESPONSE_OK,
current_folder = gajim.config.get('last_sounds_dir'),
on_response_ok = (on_ok, on_response_ok),
on_response_cancel = on_response_cancel)
filter = gtk.FileFilter() filter = gtk.FileFilter()
filter.set_name(_('All files')) filter.set_name(_('All files'))
filter.add_pattern('*') filter.add_pattern('*')
self.dialog.add_filter(filter) self.add_filter(filter)
filter = gtk.FileFilter() filter = gtk.FileFilter()
filter.set_name(_('Wav Sounds')) filter.set_name(_('Wav Sounds'))
filter.add_pattern('*.wav') filter.add_pattern('*.wav')
self.dialog.add_filter(filter) self.add_filter(filter)
self.dialog.set_filter(filter) self.set_filter(filter)
self.path_to_snd_file = path_to_snd_file self.set_filename(path_to_snd_file)
self.dialog.set_filename(self.path_to_snd_file)
self.path_to_snd_file = ''
while True:
response = self.dialog.run()
if response != gtk.RESPONSE_OK:
break
self.path_to_snd_file = self.dialog.get_filename()
try:
self.path_to_snd_file = path_to_snd_file.decode(
sys.getfilesystemencoding())
except:
pass
if os.path.exists(self.path_to_snd_file):
break
class AddSpecialNotificationDialog: class AddSpecialNotificationDialog:
def __init__(self, jid): def __init__(self, jid):
@ -1586,20 +1581,18 @@ class AddSpecialNotificationDialog:
self.notification_popup_yes_no_combobox.set_active(0) self.notification_popup_yes_no_combobox.set_active(0)
self.listen_sound_combobox = self.xml.get_widget('listen_sound_combobox') self.listen_sound_combobox = self.xml.get_widget('listen_sound_combobox')
self.listen_sound_combobox.set_active(0) self.listen_sound_combobox.set_active(0)
self.jid = jid self.jid = jid
self.xml.get_widget('when_foo_becomes_label').set_text( self.xml.get_widget('when_foo_becomes_label').set_text(
_('When %s becomes:') % self.jid) _('When %s becomes:') % self.jid)
self.window.set_title(_('Adding Special Notification for %s') % jid) self.window.set_title(_('Adding Special Notification for %s') % jid)
self.window.show_all() self.window.show_all()
self.xml.signal_autoconnect(self) self.xml.signal_autoconnect(self)
def on_cancel_button_clicked(self, widget): def on_cancel_button_clicked(self, widget):
self.window.destroy() self.window.destroy()
def on_add_special_notification_window_delete_event(self, widget, event): def on_add_special_notification_window_delete_event(self, widget, event):
self.window.destroy() self.window.destroy()
@ -1607,22 +1600,21 @@ class AddSpecialNotificationDialog:
model = widget.get_model() model = widget.get_model()
active = widget.get_active() active = widget.get_active()
if active == 1: # user selected 'choose sound' if active == 1: # user selected 'choose sound'
dlg_instance = SoundChooserDialog() def on_ok(widget, path_to_snd_file):
path_to_snd_file = dlg_instance.path_to_snd_file
dlg_instance.dialog.destroy()
if path_to_snd_file:
print path_to_snd_file print path_to_snd_file
else: # user selected nothing (X button or Cancel)
def on_cancel(widget):
widget.set_active(0) # go back to No Sound widget.set_active(0) # go back to No Sound
#model[iter][0] =
self.dialog = SoundChooserDialog(on_response_ok = on_ok,
on_response_cancel = on_cancel)
def on_ok_button_clicked(self, widget): def on_ok_button_clicked(self, widget):
conditions = ('online', 'chat', 'online_and_chat', conditions = ('online', 'chat', 'online_and_chat',
'away', 'xa', 'away_and_xa', 'dnd', 'xa_and_dnd', 'offline') 'away', 'xa', 'away_and_xa', 'dnd', 'xa_and_dnd', 'offline')
active = self.condition_combobox.get_active() active = self.condition_combobox.get_active()
print conditions[active] print conditions[active]
active_iter = self.listen_sound_combobox.get_active_iter() active_iter = self.listen_sound_combobox.get_active_iter()
listen_sound_model = self.listen_sound_combobox.get_model() listen_sound_model = self.listen_sound_combobox.get_model()
print listen_sound_model[active_iter][0] print listen_sound_model[active_iter][0]