Author: bugman Date: Thu Jul 28 22:26:26 2011 New Revision: 13973 URL: http://svn.gna.org/viewcvs/relax?rev=13973&view=rev Log: Converted the question() dialog launching function into a class derived from wx.Dialog. This implements a custom yes/no dialog that is consistent between different operating systems. Modified: branches/gui_testing/gui/analyses/__init__.py branches/gui_testing/gui/analyses/auto_model_free.py branches/gui_testing/gui/controller.py branches/gui_testing/gui/message.py branches/gui_testing/gui/pipe_editor.py branches/gui_testing/gui/relax_gui.py branches/gui_testing/gui/settings.py branches/gui_testing/gui/spin_viewer/tree.py Modified: branches/gui_testing/gui/analyses/__init__.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/analyses/__init__.py?rev=13973&r1=13972&r2=13973&view=diff ============================================================================== --- branches/gui_testing/gui/analyses/__init__.py (original) +++ branches/gui_testing/gui/analyses/__init__.py Thu Jul 28 22:26:26 2011 @@ -40,7 +40,7 @@ from gui.analyses.auto_r2 import Auto_r2 from gui.analyses.results import Results_viewer from gui.analyses.wizard import Analysis_wizard -from gui.message import error_message, question +from gui.message import error_message, Question # The package contents. @@ -253,7 +253,7 @@ # Ask if this should be done. msg = "Are you sure you would like to close the current %s analysis tab?" % ds.relax_gui.analyses[index].analysis_type - if not question(msg, default=False): + if Question(msg, default=False).ShowModal() == wx.ID_NO: return # Delete. @@ -269,7 +269,7 @@ # Ask if this should be done. msg = "Are you sure you would like to close all analyses? All data will be erased and the relax data store reset." - if not question(msg, default=False): + if Question(msg, default=False).ShowModal() == wx.ID_NO: return # Delete. Modified: branches/gui_testing/gui/analyses/auto_model_free.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/analyses/auto_model_free.py?rev=13973&r1=13972&r2=13973&view=diff ============================================================================== --- branches/gui_testing/gui/analyses/auto_model_free.py (original) +++ branches/gui_testing/gui/analyses/auto_model_free.py Thu Jul 28 22:26:26 2011 @@ -49,7 +49,7 @@ from gui.controller import Redirect_text from gui.filedialog import opendir from gui.fonts import font -from gui.message import error_message, question, Missing_data +from gui.message import error_message, Question, Missing_data from gui.misc import add_border, gui_to_int, gui_to_str, list_to_gui, protected_exec, str_to_gui from gui import paths @@ -855,7 +855,7 @@ # First state that this should not be done. msg = "The model-free models used in dauvergne_protocol auto-analysis should almost never be changed! The consequences will be unpredictable. Please proceed only if you are sure of what you are doing. Would you like to modify the model-free model list?" - if not question(msg, caption="Warning - do not change!", default=False): + if Question(msg, title="Warning - do not change!", default=False).ShowModal() == wx.ID_YES: return # Set the model selector window selections. Modified: branches/gui_testing/gui/controller.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/controller.py?rev=13973&r1=13972&r2=13973&view=diff ============================================================================== --- branches/gui_testing/gui/controller.py (original) +++ branches/gui_testing/gui/controller.py Thu Jul 28 22:26:26 2011 @@ -35,7 +35,7 @@ # relax GUI module imports. from gui.icons import relax_icons from gui.paths import IMAGE_PATH -from message import question +from message import Question class Controller(wx.Frame): @@ -180,10 +180,10 @@ """ # Ask if the user is sure they would like to exit. - doexit = question('Are you sure you would like to kill your current relax session? All unsaved data will be lost.', default=True) + doexit = Question('Are you sure you would like to kill your current relax session? All unsaved data will be lost.', default=True).ShowModal() # Kill session. - if doexit: + if doexit == wx.ID_YES: sys.exit(0) Modified: branches/gui_testing/gui/message.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/message.py?rev=13973&r1=13972&r2=13973&view=diff ============================================================================== --- branches/gui_testing/gui/message.py (original) +++ branches/gui_testing/gui/message.py Thu Jul 28 22:26:26 2011 @@ -25,6 +25,7 @@ from os import sep import sys import wx +import wx.lib.buttons import wx.lib.scrolledpanel # relax module imports. @@ -32,7 +33,7 @@ # relax GUI module imports. from gui.icons import relax_icons -from gui.paths import IMAGE_PATH, icon_48x48 +from gui.paths import IMAGE_PATH, icon_22x22, icon_48x48 import gui @@ -72,46 +73,6 @@ return check -def question(msg, caption='', default=False): - """A generic question box. - - @param msg: The text message to display. - @type msg: str - @keyword caption: The window title. - @type caption: str - @keyword default: If True, the default button will be 'yes', otherwise it will be 'no'. - @type default: bool - @return: The answer. - @rtype: bool - """ - - # If default. - if default: - style = wx.YES_DEFAULT - else: - style = wx.NO_DEFAULT - - # The dialog window. - dialog = wx.MessageDialog(None, message=msg, caption=caption, style=wx.YES_NO|style) - - # Set up the window icon. - dialog.SetIcons(relax_icons) - - # The answer. - answer = False - - # No GUI, so always answer True. - if not status.show_gui: - answer = True - - # Otherwise get the answer from the user. - elif dialog.ShowModal() == wx.ID_YES: - answer = True - - # Return the answer. - return answer - - def relax_run_ok(msg1): """Message box stating that the relax run completed ok.""" @@ -184,3 +145,132 @@ # Otherwise throw the error out to stderr. else: sys.stderr.write("Missing data: %s\n" % msg) + + + +class Question(wx.Dialog): + """Question box GUI element for obtaining a yes/no response from the user.""" + + # Some class variables. + border = 10 + spacer_button = 10 + spacer_main = 20 + height_button = 30 + width_button = 50 + + def __init__(self, msg, title='', size=(350, 125), default=False): + """A generic question box. + + @param msg: The text message to display. + @type msg: str + @keyword title: The window title. + @type title: str + @keyword default: If True, the default button will be 'yes', otherwise it will be 'no'. + @type default: bool + @return: The answer. + @rtype: bool + """ + + # The default. + if default: + self.answer = wx.ID_YES + else: + self.answer = wx.ID_NO + + # Initialise the base class. + wx.Dialog.__init__(self, None, title=title, size=size, style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) + + # Set up the window icon. + self.SetIcons(relax_icons) + + # A sizer for the dialog. + main_sizer = wx.BoxSizer(wx.HORIZONTAL) + self.SetSizer(main_sizer) + + # Build the central sizer, with borders. + sizer = gui.misc.add_border(main_sizer, border=self.border, packing=wx.HORIZONTAL) + + # Add the graphic. + bitmap = wx.StaticBitmap(self, -1, wx.Bitmap(icon_48x48.dialog_warning, wx.BITMAP_TYPE_ANY)) + sizer.Add(bitmap) + + # Spacing. + sizer.AddSpacer(self.spacer_main) + + # A vertical sizer for the right hand contents. + sub_sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(sub_sizer, 1, wx.ALL|wx.EXPAND, 0) + + # Convert to a text element. + text = wx.StaticText(self, -1, msg, style=wx.TE_MULTILINE) + sub_sizer.Add(text, 1, wx.ALL|wx.EXPAND, 0) + + # A sizer for the buttons. + button_sizer = wx.BoxSizer(wx.HORIZONTAL) + sub_sizer.Add(button_sizer, 0, wx.ALL|wx.EXPAND, 0) + + # The yes button. + button_yes = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Yes") + button_yes.SetBitmapLabel(wx.Bitmap(icon_22x22.dialog_ok, wx.BITMAP_TYPE_ANY)) + button_yes.SetMinSize((self.width_button, self.height_button)) + button_sizer.Add(button_yes, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) + self.Bind(wx.EVT_BUTTON, self.yes, button_yes) + + # Button spacing. + button_sizer.AddSpacer(self.spacer_button) + + # The no button. + button_no = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " No") + button_no.SetBitmapLabel(wx.Bitmap(icon_22x22.dialog_cancel, wx.BITMAP_TYPE_ANY)) + button_no.SetMinSize((self.width_button, self.height_button)) + button_sizer.Add(button_no, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) + self.Bind(wx.EVT_BUTTON, self.no, button_no) + + # Set the focus to the default button. + if self.answer == wx.ID_YES: + button_yes.SetFocus() + else: + button_no.SetFocus() + + + def ShowModal(self): + """Replacement ShowModal method. + + @return: The answer to the question, either wx.ID_YES or wx.ID_NO. + @rtype: int + """ + + # Call the dialog's ShowModal method. + if status.show_gui: + super(Question, self).ShowModal() + + # Return the answer. + return self.answer + + + def no(self, event): + """No selection. + + @param event: The wx event. + @type event: wx event + """ + + # Set the answer. + self.answer = wx.ID_NO + + # Close the dialog. + self.Close() + + + def yes(self, event): + """Yes selection. + + @param event: The wx event. + @type event: wx event + """ + + # Set the answer. + self.answer = wx.ID_YES + + # Close the dialog. + self.Close() Modified: branches/gui_testing/gui/pipe_editor.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/pipe_editor.py?rev=13973&r1=13972&r2=13973&view=diff ============================================================================== --- branches/gui_testing/gui/pipe_editor.py (original) +++ branches/gui_testing/gui/pipe_editor.py Thu Jul 28 22:26:26 2011 @@ -35,7 +35,7 @@ from gui.components.menu import build_menu_item from gui.fonts import font from gui.icons import relax_icons -from gui.message import question +from gui.message import Question from gui.misc import add_border, gui_to_str, str_to_gui from gui.paths import icon_16x16, icon_22x22, WIZARD_IMAGE_PATH @@ -289,7 +289,7 @@ # Ask if this should be done. msg = "Are you sure you would like to delete the '%s' data pipe? This operation cannot be undone." % self.selected_pipe - if not question(msg, default=False): + if Question(msg, default=False).ShowModal() == wx.ID_NO: return # Delete the data pipe. Modified: branches/gui_testing/gui/relax_gui.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/relax_gui.py?rev=13973&r1=13972&r2=13973&view=diff ============================================================================== --- branches/gui_testing/gui/relax_gui.py (original) +++ branches/gui_testing/gui/relax_gui.py Thu Jul 28 22:26:26 2011 @@ -57,7 +57,7 @@ from gui.fonts import font from gui.icons import Relax_task_bar_icon, relax_icons from gui.menu import Menu -from gui.message import dir_message, error_message, question +from gui.message import dir_message, error_message, Question from gui import paths from gui.pipe_editor import Pipe_editor from gui.references import References @@ -248,10 +248,10 @@ """ # Ask if the user is sure they would like to exit. - doexit = question('Are you sure you would like to quit relax? All unsaved data will be lost.', caption='Exit relax', default=True) + doexit = Question('Are you sure you would like to quit relax? All unsaved data will be lost.', title='Exit relax', default=True).ShowModal() # Exit. - if doexit: + if doexit == wx.ID_YES: # Restore the IO streams. io_streams_restore(verbosity=0) @@ -354,7 +354,7 @@ def reset_setting(self, event): #reset all settings - if question('Do you realy want to change relax settings?'): + if Question('Do you realy want to change relax settings?').ShowModal() == wx.ID_YES: ds.relax_gui.free_file_format.reset() @@ -433,7 +433,7 @@ msg = "Loading a saved relax state file will cause all unsaved data to be lost. Are you sure you would to open a save file?" # The dialog. - if not question(msg, default=True): + if Question(msg, default=True).ShowModal() == wx.ID_NO: return # Open the dialog. Modified: branches/gui_testing/gui/settings.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/settings.py?rev=13973&r1=13972&r2=13973&view=diff ============================================================================== --- branches/gui_testing/gui/settings.py (original) +++ branches/gui_testing/gui/settings.py Thu Jul 28 22:26:26 2011 @@ -132,7 +132,7 @@ # The cancel button. button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Cancel") - button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.cancel, wx.BITMAP_TYPE_ANY)) + button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.dialog_cancel, wx.BITMAP_TYPE_ANY)) button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) self.Bind(wx.EVT_BUTTON, self.cancel, button) Modified: branches/gui_testing/gui/spin_viewer/tree.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/spin_viewer/tree.py?rev=13973&r1=13972&r2=13973&view=diff ============================================================================== --- branches/gui_testing/gui/spin_viewer/tree.py (original) +++ branches/gui_testing/gui/spin_viewer/tree.py Thu Jul 28 22:26:26 2011 @@ -36,7 +36,7 @@ # relax GUI module imports. from gui import paths from gui.components.menu import build_menu_item -from gui.message import question +from gui.message import Question from gui.misc import gui_to_str @@ -200,7 +200,7 @@ # Ask if this should be done. msg = "Are you sure you would like to delete this molecule? This operation cannot be undone." - if not question(msg, default=False): + if Question(msg, default=False).ShowModal() == wx.ID_NO: return # Delete the molecule. @@ -219,7 +219,7 @@ # Ask if this should be done. msg = "Are you sure you would like to delete this residue? This operation cannot be undone." - if not question(msg, default=False): + if Question(msg, default=False).ShowModal() == wx.ID_NO: return # Delete the residue. @@ -238,7 +238,7 @@ # Ask if this should be done. msg = "Are you sure you would like to delete this spin? This operation cannot be undone." - if not question(msg, default=False): + if Question(msg, default=False).ShowModal() == wx.ID_NO: return # Delete the spin. @@ -257,7 +257,7 @@ # Ask if this should be done. msg = "Are you sure you would like to deselect all spins of this molecule?" - if not question(msg, default=False): + if Question(msg, default=False).ShowModal() == wx.ID_NO: return # Deselect the molecule. @@ -276,7 +276,7 @@ # Ask if this should be done. msg = "Are you sure you would like to deselect all spins of this residue?" - if not question(msg, default=False): + if Question(msg, default=False).ShowModal() == wx.ID_NO: return # Deselect the residue. @@ -505,7 +505,7 @@ # Ask if this should be done. msg = "Are you sure you would like to select all spins of this molecule?" - if not question(msg, default=False): + if Question(msg, default=False).ShowModal() == wx.ID_NO: return # Select the molecule. @@ -524,7 +524,7 @@ # Ask if this should be done. msg = "Are you sure you would like to select all spins of this residue?" - if not question(msg, default=False): + if Question(msg, default=False).ShowModal() == wx.ID_NO: return # Select the residue.