def _post_initialisations(self):
        """ Do some extra initializations.

        Display the version if a labelVersion is found.
        Set defaults (try to load them from a configuration file):
            - Window size and state (width, height and if maximized)
        Load any custom settings from a configuration file.
        """
        if 'trigger_before_exit' in self.passed_args:
            # must be a function on calling class
            self.trigger_before_exit = self.passed_args['trigger_before_exit']
            self.return_parameters = None

        # Bind message boxes.
        self.MessageBox = MessageBox(self.OptionsWindow, self.Application)
        self.msg = self.MessageBox.Message
        self.are_you_sure = self.MessageBox.are_you_sure

        # Reset MainWindow to a default or previous size and state.
        width = settings.get('width', 350)
        height = settings.get('height', 350)
        self.OptionsWindow.set_title(self.Application.MyArgs.localizedname + " - " + _('Options'))
        self.OptionsWindow.resize(width, height)
        self.OptionsWindow.set_icon(self.Application.icon)
        if settings.get_bool('maximized', False):
            self.OptionsWindow.maximize()

        # Set the label for labelVersion
        self.labelVersion.set_label(self.Application.MyArgs.version)
        self.labelVersion.set_tooltip_text(_("Version of this window:") + "\n" + VERSIONSTR)

        # Load any other settings here.
        self.current_dict_name = 'standard'
        self.thedicts['custom'] = self.thedicts['standard'].copy()
        tmpcustomdict = options.get('custom_dict', '').split(',')
        if len(tmpcustomdict) == 10 and tmpcustomdict[0].strip() == '':
            self.thedicts['custom'] = ['']
            for x in range (1, 10):
                self.thedicts['custom'].append(tmpcustomdict[x].strip())
        self.show_dicts()
        self.OptionsWindow.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#228b22"))#forest green

        simple = options.get('show_simple', False )
        self.checkbuttonShowPieces.set_active(not simple and options.get('show_pieces', False))
        self.checkbuttonShowTimer.set_active(not simple and options.get('show_timer', True))
        self.checkbuttonShowOnlyBoard.set_active(simple)
        scale = options.get('font_scale', 100)
        self.adjustment1.set_value(scale / 100)
        self.fontaspect = self.adjustment1.get_value()
        self.fontfamily = options.get('font', self.fontbutton1.get_font_name())
        self.fontbutton1.set_font_name(self.fontfamily)
        #print('self.fontbutton1.get_font_name()', self.fontbutton1.get_font_name())

        digits_dict = options.get('dict_to_use', 'standard')
        for b in self.gridDictionaries.get_children():
            if hasattr(b, 'tag') and b.tag == digits_dict:
                b.set_active(True)
                break

        self.picker = self.AppArgs.picker
Beispiel #2
0
    def _post_initialisations(self):
        """ Do some extra initializations.

        Display the version if a labelVersion is found.
        Set defaults (try to load them from a configuration file):
            - Window size and state (width, height and if maximized)
        Load saved custom settings.
        """
        # Init the settings module.
        self.dummy_for_settings = SectionConfig(self.app.id,
                                                self.__class__.__name__)
        global settings
        settings = self.dummy_for_settings

        self.dummy_for_options = OptionConfig(self.app.id)
        global options
        options = self.dummy_for_options

        # Bind message boxes.
        self.MessageBox = MessageBox(self)
        self.msg = self.MessageBox.Message
        self.are_you_sure = self.MessageBox.are_you_sure

        # Set previous size and state.
        width = settings.get('width', 350)
        height = settings.get('height', 350)
        self.set_title(self.app.localizedname)
        self.resize(width, height)
        if settings.get_bool('maximized', False):
            self.maximize()
        # Load any other settings here.

        self.synaptics_device = None
Beispiel #3
0
    def _post_initialisations(self):
        """ Do some extra initializations.

        Display the version if a labelVersion is found.
        Set defaults (try to load them from a configuration file):
            - Window size and state (width, height and if maximized)
        Load any custom settings from a configuration file.
        """
        if 'parent' in self.custom_args:#Is a child window, get the parent window
            self.myparent = self.custom_args['parent']

        if 'transient_for' in self.custom_args:
            self.set_transient_for(self.custom_args['transient_for'])
            # but modality can be false, and parent may not be present
            if 'is_modal' in self.custom_args:
                self.set_modal(self.custom_args['is_modal'])

        if 'trigger_before_exit' in self.custom_args:
            # must be a function on calling class
            self.trigger_before_exit = self.custom_args['trigger_before_exit']
            self.return_parameters = None

        # Bind message boxes.
        self.MessageBox = MessageBox(self.StartWindow, self.Application)
        self.msg = self.MessageBox.Message
        self.are_you_sure = self.MessageBox.are_you_sure

        # Reset MainWindow to a default or previous size and state.
        width = settings.get('width', 350)
        height = settings.get('height', 350)
        self.StartWindow.set_title(self.AppArgs.localizedname + " - " + _('Home'))
        self.StartWindow.resize(width, height)
        self.StartWindow.set_icon(self.Application.icon)
        if settings.get_bool('maximized', False):
            self.StartWindow.maximize()

        # Set the label for labelVersion
        self.labelVersion.set_label(self.AppArgs.version)
        self.labelVersion.set_tooltip_text(_("Version of this window:") + "\n" + VERSIONSTR)

        # Load any other settings here.
        self.reload_options()
        self.create_picker()
    def _post_initialisations(self):
        """ Do some extra initializations.

        Display the version if a labelVersion is found.
        Set defaults (try to load them from a configuration file):
            - Window size and state (width, height and if maximized)
        Load any custom settings from a configuration file.
        """
        if 'trigger_before_exit' in self.passed_args:
            # must be a function on calling class
            self.trigger_before_exit = self.passed_args['trigger_before_exit']
            self.return_parameters = None

        # Bind message boxes.
        self.MessageBox = MessageBox(self.PuzzleWindow, self.Application)
        self.msg = self.MessageBox.Message
        self.are_you_sure = self.MessageBox.are_you_sure

        # Reset MainWindow to a default or previous size and state.
        width = settings.get('width', 350)
        height = settings.get('height', 350)
        self.PuzzleWindow.set_title(self.AppArgs.localizedname)
        self.PuzzleWindow.resize(width, height)
        self.PuzzleWindow.set_icon(self.Application.icon)
        if settings.get_bool('maximized', False):
            self.PuzzleWindow.maximize()

        # Set the label for labelVersion
        self.labelVersion.set_label(self.AppArgs.version)
        self.labelVersion.set_tooltip_text(
            _("Version of this window:") + "\n" + VERSIONSTR)

        # Load any other settings here.
        self.exiting = False
        self.playing_history = False
        self.previous_sel = None

        self.AppArgs.picker.PickerWindow.set_transient_for(self.PuzzleWindow)
        self.AppArgs.picker.response_from_picker = self.response_from_picker
        self.listboxPieces.set_visible(self.AppArgs.show_pieces)
        self.boxTimer.set_visible(self.AppArgs.show_timer)

        self.eventboxPuzzle.drag_dest_set(0, [], 0)
Beispiel #5
0
class StartWindowBase(object):
    #FIXME: fix the docstring.
    """ Main window with all components. """

    def __init__(self, application, *args, **kwargs):
        # Set the app
        self.myparent = None
        self.custom_args = kwargs['custom_args']


        # bind settings,options to a class variable
        global settings
        settings = self.settings
        global options
        options = self.options

        # Before builder.
        self._run_before_builder()

        # Read GUI from file and retrieve objects from Gtk.Builder
        thebuilder = Gtk.Builder()
        thebuilder.set_translation_domain(self.Application.id)
        try:
            thebuilder.add_from_file(os.path.join(self.AppArgs.APP_DIR,
                'ui',
                'startwindow.glade')
                )
            thebuilder.connect_signals(self)
        except GObject.GError:
            print("Error reading GUI file")
            raise

        # Fire up the main window
        self.StartWindow = thebuilder.get_object("StartWindow")
        self.StartWindow.set_application(self.Application)
        self._get_from_builder(thebuilder)
        self._post_initialisations()

        self.StartWindow.show()
        self.create_picker()

#********* Auto created "class defs" START ************************************************************
    def _run_before_builder(self):
        pass

    def _get_from_builder(self, builder):
        """ Create self names for easy access. """
        self.MainBox = builder.get_object('MainBox')
        self.boxForFooter = builder.get_object('boxForFooter')
        self.buttonAbout = builder.get_object('buttonAbout')
        self.buttonContinue = builder.get_object('buttonContinue')
        self.buttonExit = builder.get_object('buttonExit')
        self.buttonNewPuzzle = builder.get_object('buttonNewPuzzle')
        self.buttonOptions = builder.get_object('buttonOptions')
        self.dummylabel = builder.get_object('dummylabel')
        self.labelInfo = builder.get_object('labelInfo')
        self.labelVersion = builder.get_object('labelVersion')

        # Connect signals existing in the Glade file.
        builder.connect_signals(self)

        # Connect generated by OCPgenerator signals:
        # to builder's main window
        self.StartWindow.connect('delete-event', self.on_StartWindow_delete_event)
        self.StartWindow.connect('destroy', self.on_StartWindow_destroy)
        self.StartWindow.connect('size-allocate', self.on_StartWindow_size_allocate)
        self.StartWindow.connect('window-state-event', self.on_StartWindow_window_state_event)
        self.buttonAbout.connect('clicked', self.on_buttonAbout_clicked)
        self.buttonContinue.connect('clicked', self.on_buttonContinue_clicked)
        self.buttonExit.connect('clicked', self.on_buttonExit_clicked)
        self.buttonNewPuzzle.connect('clicked', self.on_buttonNewPuzzle_clicked)
        self.buttonOptions.connect('clicked', self.on_buttonOptions_clicked)

    def _post_initialisations(self):
        """ Do some extra initializations.

        Display the version if a labelVersion is found.
        Set defaults (try to load them from a configuration file):
            - Window size and state (width, height and if maximized)
        Load any custom settings from a configuration file.
        """
        if 'parent' in self.custom_args:#Is a child window, get the parent window
            self.myparent = self.custom_args['parent']

        if 'transient_for' in self.custom_args:
            self.set_transient_for(self.custom_args['transient_for'])
            # but modality can be false, and parent may not be present
            if 'is_modal' in self.custom_args:
                self.set_modal(self.custom_args['is_modal'])

        if 'trigger_before_exit' in self.custom_args:
            # must be a function on calling class
            self.trigger_before_exit = self.custom_args['trigger_before_exit']
            self.return_parameters = None

        # Bind message boxes.
        self.MessageBox = MessageBox(self.StartWindow, self.Application)
        self.msg = self.MessageBox.Message
        self.are_you_sure = self.MessageBox.are_you_sure

        # Reset MainWindow to a default or previous size and state.
        width = settings.get('width', 350)
        height = settings.get('height', 350)
        self.StartWindow.set_title(self.AppArgs.localizedname + " - " + _('Home'))
        self.StartWindow.resize(width, height)
        self.StartWindow.set_icon(self.Application.icon)
        if settings.get_bool('maximized', False):
            self.StartWindow.maximize()

        # Set the label for labelVersion
        self.labelVersion.set_label(self.AppArgs.version)
        self.labelVersion.set_tooltip_text(_("Version of this window:") + "\n" + VERSIONSTR)

        # Load any other settings here.
        self.reload_options()
        self.create_picker()

#********* Auto created handlers START *********************************
    def on_buttonContinue_clicked(self, widget, *args):
        """ Handler for buttonContinue.clicked. """
        self.open_PuzzleWindow(True)

    def on_buttonNewPuzzle_clicked(self, widget, *args):
        """ Handler for buttonNewPuzzle.clicked. """
        self.open_PuzzleWindow()

    def on_buttonOptions_clicked(self, widget, *args):
        """ Handler for buttonOptions.clicked. """
        self.open_OptionsWindow()

#********* Auto created handlers END ***********************************

#********* Standard handlers START *************************************
    def msg_not_yet(self):
        self.msg(_('Not yet implemented'))

    def on_buttonAbout_clicked(self, widget, *args):
        """ Handler for buttonAbout.clicked. """
        #TODO: Check if used.
        self.MessageBox.AboutBox()

    def on_buttonExit_clicked(self, widget, *args):
        """ Handler for buttonExit.clicked. """
        #TODO: Check if used.
        self.exit_requested()

    def on_StartWindow_delete_event(self, widget, event, *args):
        """ Handler for our main window: delete-event. """
        return (self.exit_requested())

    def on_StartWindow_destroy(self, widget, *args):
        """ Handler for our main window: destroy. """
        return (self.exit_requested('from_destroy'))

    def on_StartWindow_size_allocate(self, widget, allocation, *args):
        """ Handler for our main window: size-allocate. """
        self.save_my_size()

    def on_StartWindow_window_state_event(self, widget, event, *args):
        """ Handler for our main window: window-state-event. """
        settings.set('maximized',
            ((int(event.new_window_state) & Gdk.WindowState.ICONIFIED) != Gdk.WindowState.ICONIFIED) and
            ((int(event.new_window_state) & Gdk.WindowState.MAXIMIZED) == Gdk.WindowState.MAXIMIZED)
            )
        self.save_my_size()

#********* Standard handlers END ***************************************
#********* Standard exit defs START *********************************************************
    def exit_requested(self, *args, **kwargs):
        """ Final work before exit. """
        self.StartWindow.set_transient_for()
        self.StartWindow.set_modal(False)
        self.set_unhandled_settings()# also saves all settings
        if 'from_destroy' in args:
            return True
        else:
            # Check if we should provide info to caller
            if 'trigger_before_exit' in self.custom_args:
                self.trigger_before_exit(exiting = True,
                    return_parameters = self.return_parameters)
            self.StartWindow.destroy()

    def present(self):
        """ Show the window. """
        pass

    def save_my_size(self):
        """ Save the window size into settings, if not maximized. """
        if not settings.get_bool('maximized', False):
            width, height = self.StartWindow.get_size()
            settings.set('width', width)
            settings.set('height', height)

    def set_unhandled_settings(self):
        """ Set, before exit, any settings not applied during the session.

        Additionally, flush all settings to .conf file.
        """
        # Set any custom settings
        # which where not setted (ex. on some widget's state changed)

        # Save all settings
        settings.save()
Beispiel #6
0
class StartWindow(Gtk.ApplicationWindow):
    #FIXME: fix the docstring.
    """ Main window with all components. """
    def __init__(self, *args, **kwargs):
        # Set the app
        self.myparent = None
        if 'parent' in kwargs:  #use the same application
            self.myparent = kwargs['parent']
        if 'app' in kwargs:  #use the application
            self.app = kwargs['parent'].app
        elif 'application' in kwargs:
            self.app = kwargs['application']
        if self.myparent and 'modal' in kwargs:
            # "modal" means caller require transient
            self.set_transient_for(self.myparent)
            # but modality can be false, and parent may not be present
            if self.myparent:
                self.set_modal(kwargs['modal'])
        self.custom_args = {}
        if 'custom_args' in kwargs:
            self.custom_args = {k: v for k, v in kwargs['custom_args'].items()}
            # do not pass them to Gtk.ApplicationWindow init
            # otherwise will trigger an error
            del kwargs['custom_args']
            if 'trigger_before_exit' in self.custom_args:
                # must be a function on calling class
                self.trigger_before_exit = self.custom_args[
                    'trigger_before_exit']
                self.return_parameters = None

        # Before super initialization.

        # init super.
        # First init the window, otherwise MRO will mess it.
        Gtk.ApplicationWindow.__init__(self, *args, **kwargs)

        # Any nitializations required before loading the glade file.

        # Now load builder.
        self._get_from_builder()

        # Load any settings or run extra initializations.
        self._post_initialisations()

#********* Auto created "class defs" START ************************************************************

    def _get_from_builder(self):
        """ Load components from a glade file. """
        # Load the ui from a glade file.
        self.builder = Gtk.Builder()
        try:
            self.builder.add_from_file(
                os.path.join(self.app.BASE_DIR, 'ui', 'startwindow.glade'))
        except Exception as ex:
            print(str(ex))
            print('\n{}:\n{}\n{}'.format(
                _('Error loading from Glade file'),
                os.path.join(self.app.BASE_DIR, 'ui', 'startwindow.glade'),
                repr(ex)))
            sys.exit(ERROR_INVALID_GLADE_FILE)

        # Get gui objects.
        self.boxCommands = self.builder.get_object('boxCommands')
        self.boxCreateSynapticsShortcut = self.builder.get_object(
            'boxCreateSynapticsShortcut')
        self.boxForFooter = self.builder.get_object('boxForFooter')
        self.boxMain = self.builder.get_object('boxMain')
        self.boxRemoveDS_Store = self.builder.get_object('boxRemoveDS_Store')
        self.boxRemoveExecutable = self.builder.get_object(
            'boxRemoveExecutable')
        self.boxpkill = self.builder.get_object('boxpkill')
        self.buttonAbout = self.builder.get_object('buttonAbout')
        self.buttonExit = self.builder.get_object('buttonExit')
        self.buttonRemoveDS_Store = self.builder.get_object(
            'buttonRemoveDS_Store')
        self.buttonRemoveExecutable = self.builder.get_object(
            'buttonRemoveExecutable')
        self.buttonSynaptics = self.builder.get_object('buttonSynaptics')
        self.buttonpkill = self.builder.get_object('buttonpkill')
        self.dummylabel = self.builder.get_object('dummylabel')
        self.eventboxPathRemoveDS_Store = self.builder.get_object(
            'eventboxPathRemoveDS_Store')
        self.eventboxPathRemoveExecutable = self.builder.get_object(
            'eventboxPathRemoveExecutable')
        self.eventboxSynaptics = self.builder.get_object('eventboxSynaptics')
        self.eventboxpkill = self.builder.get_object('eventboxpkill')
        self.label1 = self.builder.get_object('label1')
        self.label2 = self.builder.get_object('label2')
        self.label3 = self.builder.get_object('label3')
        self.label4 = self.builder.get_object('label4')
        self.labelPathRemoveDS_Store = self.builder.get_object(
            'labelPathRemoveDS_Store')
        self.labelPathRemoveExecutable = self.builder.get_object(
            'labelPathRemoveExecutable')
        self.labelSynaptics = self.builder.get_object('labelSynaptics')
        self.labelVersion = self.builder.get_object('labelVersion')
        self.labelpkill = self.builder.get_object('labelpkill')
        self.labeltest = self.builder.get_object('labeltest')

        # Connect signals existing in the Glade file.
        self.builder.connect_signals(self)

        # Reparent our main container from glader file,
        # this way we have all Gtk.Window functionality using "self".
        thechild = self.builder.get_object('windowMain').get_child()
        thechild.get_parent().remove(thechild)
        self.add(thechild)

        # Connect generated signals:
        # top window signals and/or other generated signals.
        # top window signals were connected, by builder's "connect_signals" function,
        # to builder's main window
        self.buttonRemoveDS_Store.connect('clicked',
                                          self.on_buttonRemoveDS_Store_clicked)
        self.buttonRemoveExecutable.connect(
            'clicked', self.on_buttonRemoveExecutable_clicked)
        self.buttonSynaptics.connect('clicked',
                                     self.on_buttonSynaptics_clicked)
        self.buttonpkill.connect('clicked', self.on_buttonpkill_clicked)
        self.connect('delete-event', self.on_windowMain_delete_event)
        self.connect('destroy', self.on_windowMain_destroy)
        self.connect('size-allocate', self.on_windowMain_size_allocate)
        self.connect('window-state-event',
                     self.on_windowMain_window_state_event)

        # :builder top window properties.
        # Set the label for labelVersion
        self.labelVersion.set_label(VERSIONSTR)
        self.labelVersion.set_tooltip_text(
            _("""This is the version of this window.
Not the version of the application."""))
        self.can_focus = 'False'

        # Load window icon from app, if any.
        self.set_icon(self.app.icon)

    def _post_initialisations(self):
        """ Do some extra initializations.

        Display the version if a labelVersion is found.
        Set defaults (try to load them from a configuration file):
            - Window size and state (width, height and if maximized)
        Load saved custom settings.
        """
        # Init the settings module.
        self.dummy_for_settings = SectionConfig(self.app.id,
                                                self.__class__.__name__)
        global settings
        settings = self.dummy_for_settings

        self.dummy_for_options = OptionConfig(self.app.id)
        global options
        options = self.dummy_for_options

        # Bind message boxes.
        self.MessageBox = MessageBox(self)
        self.msg = self.MessageBox.Message
        self.are_you_sure = self.MessageBox.are_you_sure

        # Set previous size and state.
        width = settings.get('width', 350)
        height = settings.get('height', 350)
        self.set_title(self.app.localizedname)
        self.resize(width, height)
        if settings.get_bool('maximized', False):
            self.maximize()
        # Load any other settings here.

        self.synaptics_device = None

#********* Auto created handlers START *********************************

    def on_buttonAbout_clicked(self, widget, *args):
        """ Handler for buttonAbout.clicked. """
        self.MessageBox.AboutBox()

    def on_buttonExit_clicked(self, widget, *args):
        """ Handler for buttonExit.clicked. """
        self.exit_requested()

    def on_buttonRemoveDS_Store_clicked(self, widget, *args):
        """ Handler for buttonRemoveDS_Store.clicked. """
        fullpath = self.labelPathRemoveDS_Store.get_tooltip_text()
        if fullpath and os.path.exists(fullpath):
            msg = _(
                'This will remove .DS_Store files, recursively, inside the directory:\n{}\n'
            )
            msg += _('Proceed?')
            ok = self.msg(msg.format(fullpath, ),
                          buttons='YESCANCEL',
                          boxtype='QUESTION')
            if ok:
                result = RemoveDS_Storefiles(fullpath)
                self.labelPathRemoveDS_Store.set_label('')
                self.labelPathRemoveDS_Store.set_tooltip_text('')
        else:
            self.msg('No valid path!' + '\n' + str(fullpath))

    def on_buttonRemoveExecutable_clicked(self, widget, *args):
        """ Handler for buttonRemoveExecutable.clicked. """
        fullpath = self.labelPathRemoveExecutable.get_tooltip_text()
        if fullpath and os.path.exists(fullpath):
            msg = _(
                'This will remove executable from files, recursively, inside the directory:\n{}\n'
            )
            msg += _('Proceed?')
            ok = self.msg(msg.format(fullpath, ),
                          buttons='YESNOCANCEL',
                          boxtype='WARNING')
            if ok:
                msg = _('This may make programs to stop responding!\n')
                msg += _('Are you sure?')
                ok = self.msg(msg.format(fullpath, ),
                              buttons='YESCANCEL',
                              boxtype='QUESTION')
                if ok:
                    result = RemoveExecutableFromFiles(fullpath)
                    self.labelPathRemoveExecutable.set_label('')
                    self.labelPathRemoveExecutable.set_tooltip_text('')
        else:
            self.msg('No valid path!' + '\n' + str(fullpath))

    def on_buttonSynaptics_clicked(self, widget, *args):
        """ Handler for buttonSynaptics.clicked. """
        if self.synaptics_device == None:
            self.msg(_("No device selected!"))
            return

        OR_WAIT = _(
            "You must manually alter it \nor wait for the version that will do this automatically."
        )
        key_combinations_bundled, custom_bindings_names, combination_exists = other_functions.get_shorcut_combinations(
        )
        if combination_exists:
            self.msg(_('The default combination already exists.\n') + OR_WAIT)
            return

        my_bin_path = os.path.expanduser("~/bin")
        disable_synaptics_path = os.path.join(my_bin_path,
                                              "my_disable_synaptics")
        if os.path.exists(disable_synaptics_path):
            self.msg(_('The default bash script already exists.\n') + OR_WAIT)
            return
        thescripttext = other_functions.create_synaptics_bash_file(
            self.synaptics_device)
        try:
            with open(disable_synaptics_path, 'x', encoding='utf-8') as f:
                f.write(thescripttext)
        except Exception as e:
            print("An exception occured.", e)
        make_executable(disable_synaptics_path)
        #other_functions.bind_shortcut_to_command(disable_synaptics_path, custom_bindings_names)
        other_functions.cinnamon_add_custom_setting(disable_synaptics_path)

        self.buttonSynaptics.set_sensitive(False)
        self.eventboxSynaptics.set_sensitive(False)
        msg = _(
            """A key binding to a newly created script has been created.""")

        self.msg(msg)

    def on_buttonpkill_clicked(self, widget, *args):
        """ Handler for buttonpkill.clicked. """
        process_name = self.labelpkill.get_label()
        output = other_functions.pkill_a_process(process_name)
        self.msg(output)

    def on_eventboxPathRemoveDS_Store_button_release_event(
            self, widget, event, *args):
        """ Handler for eventboxPathRemoveDS_Store.button-release-event. """
        dlg = ChooserDialog()
        thepath = dlg.select_folder(self)
        if thepath:
            head, tail = os.path.split(thepath)
            self.labelPathRemoveDS_Store.set_label(tail + '\n' + head)
            self.labelPathRemoveDS_Store.set_tooltip_text(thepath)

    def on_eventboxPathRemoveExecutable_button_press_event(
            self, widget, event, *args):
        """ Handler for eventboxPathRemoveExecutable.button-press-event. """
        dlg = ChooserDialog()
        thepath = dlg.select_folder(self)
        if thepath:
            head, tail = os.path.split(thepath)
            self.labelPathRemoveExecutable.set_label(tail + '\n' + head)
            self.labelPathRemoveExecutable.set_tooltip_text(thepath)

    def on_eventboxSynaptics_button_press_event(self, widget, event, *args):
        """ Handler for eventboxSynaptics.button-press-event. """
        some_custom_args = {}
        some_custom_args['modal'] = True
        #event to trigger on return
        some_custom_args[
            'trigger_before_exit'] = self.synaptice_device_selected
        #print(type(self.eventboxSynaptics.get_toplevel().super()))
        self.synaptics_select = SelectSynaptics(
            application=self.app,
            #parent = self.eventboxSynaptics.get_toplevel(),
            custom_args=some_custom_args,
            modal=True)
        self.hide()
        self.synaptics_select.present()

    def on_eventboxpkill_button_press_event(self, widget, event, *args):
        """ Handler for eventboxpkill.button-press-event. """
        pass

    def on_windowMain_delete_event(self, widget, event, *args):
        """ Handler for windowMain.delete-event. """
        return (self.exit_requested('from_delete_event'))

    def on_windowMain_destroy(self, widget, *args):
        """ Handler for windowMain.destroy. """
        return (self.exit_requested('from_destroy'))

    def on_windowMain_size_allocate(self, widget, allocation, *args):
        """ Handler for windowMain.size-allocate. """
        self.save_my_size()

    def on_windowMain_window_state_event(self, widget, event, *args):
        """ Handler for windowMain.window-state-event. """
        settings.set('maximized',
                     ((int(event.new_window_state) & Gdk.WindowState.ICONIFIED)
                      != Gdk.WindowState.ICONIFIED) and
                     ((int(event.new_window_state) & Gdk.WindowState.MAXIMIZED)
                      == Gdk.WindowState.MAXIMIZED))
        self.save_my_size()

#********* Auto created handlers  END **********************************

    def exit_requested(self, *args, **kwargs):
        """ Final work before exit. """
        self.set_transient_for()
        self.set_modal(False)
        self.set_unhandled_settings()  # also saves all settings
        if 'from_destroy' in args or 'from_delete_event' in args:
            return True
        else:
            # Check if we should provide info to caller
            if 'trigger_before_exit' in self.custom_args:
                self.trigger_before_exit(
                    exiting=True, return_parameters=self.return_parameters)
            self.destroy()

    def present(self):
        """ Show the window. """
        self.show_all()
        #"enable" next line to have some interactive view of potentiallities of GUI
        #self.set_interactive_debugging (True)
        super().present()

    def save_my_size(self):
        """ Save the window size into settings, if not maximized. """
        if not settings.get_bool('maximized', False):
            width, height = self.get_size()
            settings.set('width', width)
            settings.set('height', height)

    def set_unhandled_settings(self):
        """ Set, before exit, settings not applied during the session.

        Additionally, flush all settings to .conf file.
        """
        # Set any custom settings
        # which where not setted (ex. on some widget's state changed)

        # Save all settings
        settings.save()

#********* Auto created "class defs" END **************************************************************

    def synaptice_device_selected(self, *args, **kwargs):
        #print(args)
        #print(kwargs)
        return_parameters = kwargs['return_parameters']
        if return_parameters['has selection']:
            self.labelSynaptics.set_markup(
                _("Selected device") + ":\n<b>" +
                return_parameters['selected'] + "</b>")
            self.synaptics_device = return_parameters['selected']
        else:
            self.labelSynaptics.set_markup("<b>" + _("No device selected!!!") +
                                           "</b>")
            self.synaptics_device = None
        self.show()
class PuzzleWindowBase(object):
    #FIXME: fix the docstring.
    """ Main window with all components. """

    #def __init__(self, application, *args, **kwargs):
    def __init__(self, *args, **kwargs):
        # Set the app
        self.myparent = None
        self.passed_args = kwargs['args_to_pass']
        self.AppArgs = self.Application.MyArgs
        self.puzzle = None
        self.old_allocation = Gdk.Rectangle()
        self.old_allocation.width = 0
        self.old_allocation.height = 0

        # bind settings,options to a class variable
        global settings
        settings = self.settings
        global options
        options = self.options

        # Before builder.
        self._run_before_builder()

        # Read GUI from file and retrieve objects from Gtk.Builder
        thebuilder = Gtk.Builder()
        thebuilder.set_translation_domain(self.Application.id)
        try:
            thebuilder.add_from_file(
                os.path.join(self.AppArgs.APP_DIR, 'ui', 'puzzlewindow.glade'))
            thebuilder.connect_signals(self)
        except GObject.GError:
            print("Error reading GUI file")
            raise

        # Fire up the main window
        self.PuzzleWindow = thebuilder.get_object("PuzzleWindow")
        self.PuzzleWindow.set_application(self.Application)
        self._get_from_builder(thebuilder)
        self._post_initialisations()

        self.PuzzleWindow.show()

#********* Auto created "class defs" START ************************************************************

    def _run_before_builder(self):
        self.is_picker_visible = False
        self.working_restangle = Gdk.Rectangle()

    def _get_from_builder(self, builder):
        """ Create self names for easy access. """
        self.MainBox = builder.get_object('MainBox')
        self.boxDown = builder.get_object('boxDown')
        self.boxMenu = builder.get_object('boxMenu')
        self.boxTimer = builder.get_object('boxTimer')
        self.boxUndoRedo = builder.get_object('boxUndoRedo')
        self.boxUp = builder.get_object('boxUp')
        self.buttonHome = builder.get_object('buttonHome')
        self.buttonRedo = builder.get_object('buttonRedo')
        self.buttonUndo = builder.get_object('buttonUndo')
        self.drawingareaPuzzle = builder.get_object('drawingareaPuzzle')
        self.eventboxPuzzle = builder.get_object('eventboxPuzzle')
        self.imageClock = builder.get_object('imageClock')
        self.imageRedo = builder.get_object('imageRedo')
        self.imageUndo = builder.get_object('imageUndo')
        self.labelClock = builder.get_object('labelClock')
        self.labelVersion = builder.get_object('labelVersion')
        self.listboxPieces = builder.get_object('listboxPieces')

        # Connect signals existing in the Glade file.
        builder.connect_signals(self)

        # Connect generated by OCPgenerator signals:
        # to builder's main window
        self.PuzzleWindow.connect('delete-event',
                                  self.on_PuzzleWindow_delete_event)
        self.PuzzleWindow.connect('destroy', self.on_PuzzleWindow_destroy)
        self.PuzzleWindow.connect('size-allocate',
                                  self.on_PuzzleWindow_size_allocate)
        self.PuzzleWindow.connect('window-state-event',
                                  self.on_PuzzleWindow_window_state_event)
        self.PuzzleWindow.connect('window-state-event',
                                  self.on_PuzzleWindow_window_state_event)
        self.buttonHome.connect('clicked', self.on_buttonHome_clicked)

    def _post_initialisations(self):
        """ Do some extra initializations.

        Display the version if a labelVersion is found.
        Set defaults (try to load them from a configuration file):
            - Window size and state (width, height and if maximized)
        Load any custom settings from a configuration file.
        """
        if 'trigger_before_exit' in self.passed_args:
            # must be a function on calling class
            self.trigger_before_exit = self.passed_args['trigger_before_exit']
            self.return_parameters = None

        # Bind message boxes.
        self.MessageBox = MessageBox(self.PuzzleWindow, self.Application)
        self.msg = self.MessageBox.Message
        self.are_you_sure = self.MessageBox.are_you_sure

        # Reset MainWindow to a default or previous size and state.
        width = settings.get('width', 350)
        height = settings.get('height', 350)
        self.PuzzleWindow.set_title(self.AppArgs.localizedname)
        self.PuzzleWindow.resize(width, height)
        self.PuzzleWindow.set_icon(self.Application.icon)
        if settings.get_bool('maximized', False):
            self.PuzzleWindow.maximize()

        # Set the label for labelVersion
        self.labelVersion.set_label(self.AppArgs.version)
        self.labelVersion.set_tooltip_text(
            _("Version of this window:") + "\n" + VERSIONSTR)

        # Load any other settings here.
        self.exiting = False
        self.playing_history = False
        self.previous_sel = None

        self.AppArgs.picker.PickerWindow.set_transient_for(self.PuzzleWindow)
        self.AppArgs.picker.response_from_picker = self.response_from_picker
        self.listboxPieces.set_visible(self.AppArgs.show_pieces)
        self.boxTimer.set_visible(self.AppArgs.show_timer)

        self.eventboxPuzzle.drag_dest_set(0, [], 0)

#********* Auto created handlers START *********************************

    def on_buttonHome_clicked(self, widget, *args):
        """ Handler for buttonHome.clicked. """
        self.picker_resize()
        self.exit_requested()

    def on_buttonRedo_clicked(self, widget, *args):
        """ Handler for buttonRedo.clicked. """
        self.puzzle_set_number(self, undoredo=MOVE_REDO)

    def on_buttonUndo_clicked(self, widget, *args):
        """ Handler for buttonUndo.clicked. """
        self.puzzle_set_number(self, undoredo=MOVE_UNDO)

    def on_drawingareaPuzzle_draw(self, widget, cr, *args):
        """ Handler for drawingareaPuzzle.draw. """
        if self.puzzle:
            an_9 = self.puzzle.draw(cr, widget.get_allocated_width(),
                                    widget.get_allocated_height())
            if not self.init_picker_done:
                self.init_picker_done = True
                self.picker_resize(an_9)

    def on_eventboxPuzzle_button_release_event(self, widget, event, *args):
        """ Handler for eventboxPuzzle.button-release-event. """
        col, row = col_row_of_x_y_in_restangle(event.x, event.y,
                                               self.working_restangle)
        #print(col, row , 'col, row ')
        if col >= 0 and row >= 0 and col < 9 and row < 9:
            selected = int(col) * 9 + int(row)
            self.puzzle_move_cursor(selected)
            if self.is_picker_visible:
                self.picker_hide()
            else:
                if not self.puzzle.puzzlenums[selected]['const']:
                    if event.button == 1:
                        self.picker_show(event, col, row)
                        #full_size = self.eventboxPuzzle.get_allocation()
                        self.AppArgs.picker.PickerWindow.show_all()
                        self.AppArgs.picker.PickerWindow.grab_focus()
                        #return True

    def on_eventboxPuzzle_drag_data_received(self, widget, context, x, y,
                                             selection_data, info, time_,
                                             *args):
        """ Handler for eventboxPuzzle.drag-data-received. """
        if self.number_picked:
            thenum = int(self.number_picked)
            self.number_picked = None
            col, row = col_row_of_x_y_in_restangle(x, y,
                                                   self.working_restangle)
            if col >= 0 and row >= 0 and col < 9 and row < 9:
                cell_selected = int(col) * 9 + int(row)
                self.puzzle_move_cursor(cell_selected)
                if not self.puzzle.puzzlenums[
                        self.puzzle.current_cell]['const']:
                    self.puzzle_set_number(thenum)
        #context.drag_finish(True, False, time_)

    def on_eventboxPuzzle_drag_drop(self, widget, context, x, y, time_, *args):
        """ Handler for eventboxPuzzle.drag-drop. """
        widget.drag_get_data(context, context.list_targets()[-1], time_)

    def on_eventboxPuzzle_drag_motion(self, widget, context, x, y, time_,
                                      *args):
        """ Handler for eventboxPuzzle.drag-motion. """
        #TODO: check if in a valid square?
        Gdk.drag_status(context, Gdk.DragAction.COPY, time_)
        return True

    def on_eventboxPuzzle_size_allocate(self, widget, allocation, *args):
        """ Handler for eventboxPuzzle.size-allocate. """
        if (self.old_allocation.width != allocation.width) or (
                self.old_allocation.height != allocation.height):
            #print('on_PuzzleWindow_size_allocate 1', self.old_allocation.width, allocation.width,
            #self.old_allocation.height, allocation.height)
            self.old_allocation = allocation
            sizes = self.eventboxPuzzle.get_allocation()
            min_size = min(sizes.width, sizes.height)
            self.working_restangle.x = int((sizes.width - min_size) / 2)
            self.working_restangle.y = int((sizes.height - min_size) / 2)
            self.working_restangle.width = int(min_size)
            self.working_restangle.height = int(min_size)
            self.picker_resize()
            #print('on_PuzzleWindow_size_allocate 2', self.working_restangle.x, "#", sizes.width, "#", sizes.height , min_size)

#********* Auto created handlers END ***********************************

#********* Standard handlers START *************************************

    def msg_not_yet(self):
        self.msg(_('Not yet implemented'))

    def on_buttonAbout_clicked(self, widget, *args):
        """ Handler for buttonAbout.clicked. """
        #TODO: Check if used.
        self.MessageBox.AboutBox()
#"configure-event"

    def on_PuzzleWindow_configure_event(self, widget, event, *args):
        """ Handler for our main window: configure-event. """

    def on_PuzzleWindow_delete_event(self, widget, event, *args):
        """ Handler for our main window: delete-event. """
        return (self.exit_requested())

    def on_PuzzleWindow_destroy(self, widget, *args):
        """ Handler for our main window: destroy. """
        return (self.exit_requested('from_destroy'))

    def on_PuzzleWindow_size_allocate(self, widget, allocation, *args):
        """ Handler for our main window: size-allocate. """
        if not settings.get_bool('maximized', False):
            width, height = self.PuzzleWindow.get_size()
            settings.set('width', width)
            settings.set('height', height)

    def on_PuzzleWindow_window_state_event(self, widget, event, *args):
        """ Handler for our main window: window-state-event. """
        settings.set('maximized',
                     ((int(event.new_window_state) & Gdk.WindowState.ICONIFIED)
                      != Gdk.WindowState.ICONIFIED) and
                     ((int(event.new_window_state) & Gdk.WindowState.MAXIMIZED)
                      == Gdk.WindowState.MAXIMIZED))

#********* Standard handlers END ***************************************
#********* Standard exit defs START *********************************************************

    def exit_requested(self, *args, **kwargs):
        """ Final work before exit. """
        self.exiting = True
        self.PuzzleWindow.set_transient_for()
        self.PuzzleWindow.set_modal(False)
        if 'from_destroy' in args:
            self.picker_hide()
            self.set_unhandled_settings()  # also saves all settings
            return True
        else:
            # Check if we should provide info to caller
            if 'trigger_before_exit' in self.passed_args:
                self.trigger_before_exit(
                    exiting=True, return_parameters=self.return_parameters)
            self.PuzzleWindow.destroy()

    def present(self):
        """ Show the window. """
        if self.passed_args['continue']:
            self.puzzle_continue()
            return
        self.puzzle_start()

    def set_unhandled_settings(self):
        """ Set, before exit, any settings not applied during the session.

        Additionally, flush all settings to .conf file.
        """
        # Set any custom settings or options
        # which where not setted (ex. on some widget's state changed)
        options.set('last_solved', self.puzzle.solved)
        options.set(
            'last_time',
            str(self.timepassed.days) + ',' + str(self.timepassed.seconds))
        options.set('last_history', ','.join(self.puzzle.history))
        options.set('last_undos', self.puzzle.undos)

        # Save all settings
        settings.save()
Beispiel #8
0
    def __init__(self, app):
        # Set the app
        self.app = app

        # Basic initializations.
        self.we_can_exit_now = False
        self.return_parameter = (False, "00:00")
        self.picker = None
        self.picker_size = 10.
        self.previous_sel = None
        self.timer_started = None
        self.history_counter = 0
        self.playing_history = False

        #self.strings_to_use = [' ','α','β','γ','δ','ε','ς','ζ','η','θ']
        #self.strings_to_use = [' ','1','2','3','4','5','6','7','8','9']

        # Init the settings module.
        self.dummy_for_settings = SectionConfig(self.app.name,
                                                self.__class__.__name__)
        global settings
        settings = self.dummy_for_settings

        self.dummy_for_options = OptionConfig(self.app.name)
        global options
        options = self.dummy_for_options

        Gtk.Window.__init__(self)
        self.set_title(self.app.localizedname)

        # Initializations required before loading glade file.

        # Bind the locale.
        locale.bindtextdomain(self.app.domain,
                              os.path.join(self.app.BASE_DIR, 'locale'))
        locale.textdomain(self.app.domain)

        # Load app and window icon.
        self.set_icon(self.app.icon)

        # Bind message boxes.
        self.MessageBox = MessageBox(self)
        self.msg = self.MessageBox.Message

        # Glade stuff
        # Load Glade file to self
        self.builder = Gtk.Builder()
        try:
            self.builder.add_from_file(
                os.path.join(self.app.BASE_DIR, 'ui', 'puzzlewindow.glade'))
        except Exception as ex:
            print(str(ex))
            print('\n{}:\n{}\n{}'.format(
                _('Error loading from Glade file'),
                os.path.join(self.app.BASE_DIR, 'ui', 'puzzlewindow.glade'),
                repr(ex)))
            sys.exit(ERROR_INVALID_GLADE_FILE)

        # Get gui objects
        self.MainBox = self.builder.get_object('MainBox')
        self.boxTimer = self.builder.get_object('boxTimer')
        self.boxMenu = self.builder.get_object('boxMenu')
        self.buttonHome = self.builder.get_object('buttonHome')
        self.drawingareaPuzzle = self.builder.get_object('drawingareaPuzzle')
        self.eventboxPuzzle = self.builder.get_object('eventboxPuzzle')
        self.imageClock = self.builder.get_object('imageClock')
        self.labelClock = self.builder.get_object('labelClock')
        self.labelVersion = self.builder.get_object('labelVersion')
        self.listboxPieces = self.builder.get_object('listboxPieces')

        # Connect signals existing in the Glade file
        self.builder.connect_signals(self)

        # Reparent our main container from glader file,
        # this way we have all Gtk.Window functionality using "self"
        thechild = self.builder.get_object('PuzzleWindow').get_child()
        thechild.get_parent().remove(thechild)
        self.add(thechild)

        # Connect generated signals.
        self.buttonHome.connect('clicked', self.on_buttonHome_clicked)
        self.connect('delete-event', self.on_PuzzleWindow_delete_event)
        self.connect('destroy', self.on_PuzzleWindow_destroy)
        self.connect('key-release-event',
                     self.on_PuzzleWindow_key_release_event)
        self.connect('size-allocate', self.on_PuzzleWindow_size_allocate)
        self.connect('window-state-event',
                     self.on_PuzzleWindow_window_state_event)

        # Get any properties of top window.
        # Set the label for labelVersion
        self.labelVersion.set_label(VERSIONSTR)
        self.can_focus = 'False'

        # Load any settings or run extra initializations
        self.post_initialisations()
Beispiel #9
0
    def __init__(self, app):
        # Set the app
        self.app = app
        self.app.thehistory = None

        # Basic initializations.
        self.we_can_exit_now = False
        self.return_parameter = None

        self.thedicts = THEDICTS

        # Init the settings module.
        self.dummy_for_settings = SectionConfig(self.app.name,
                                                self.__class__.__name__)
        global settings
        settings = self.dummy_for_settings

        self.dummy_for_options = OptionConfig(self.app.name)
        global options
        options = self.dummy_for_options

        Gtk.Window.__init__(self)

        # Initializations required before loading glade file.

        # Bind the locale.
        locale.bindtextdomain(self.app.domain,
                              os.path.join(self.app.BASE_DIR, 'locale'))
        locale.textdomain(self.app.domain)

        # Load app and window icon.
        self.set_icon(self.app.icon)

        # Bind message boxes.
        self.MessageBox = MessageBox(self)
        self.msg = self.MessageBox.Message

        # Glade stuff.
        # Load Glade file to self.
        self.builder = Gtk.Builder()
        try:
            self.builder.add_from_file(
                os.path.join(self.app.BASE_DIR, 'ui', 'sudokugtk.glade'))
        except Exception as ex:
            print(str(ex))
            print('\n{}:\n{}\n{}'.format(
                _('Error loading from Glade file'),
                os.path.join(self.app.BASE_DIR, 'ui', 'sudokugtk.glade'),
                repr(ex)))
            sys.exit(ERROR_INVALID_GLADE_FILE)

        # Get gui objects.
        self.MainBox = self.builder.get_object('MainBox')
        self.boxForFooter = self.builder.get_object('boxForFooter')
        self.buttonAbout = self.builder.get_object('buttonAbout')
        self.buttonContinue = self.builder.get_object('buttonContinue')
        self.buttonExit = self.builder.get_object('buttonExit')
        self.buttonNewPuzzle = self.builder.get_object('buttonNewPuzzle')
        self.buttonOptions = self.builder.get_object('buttonOptions')
        self.dummylabel = self.builder.get_object('dummylabel')
        self.labelInfo = self.builder.get_object('labelInfo')
        self.labelVersion = self.builder.get_object('labelVersion')

        # Connect signals existing in the Glade file
        self.builder.connect_signals(self)

        # Reparent our main container from glader file,
        # this way we have all Gtk.Window functionality using "self".
        thechild = self.builder.get_object('windowMain').get_child()
        thechild.get_parent().remove(thechild)
        self.add(thechild)

        # Connect generated signals.
        self.buttonAbout.connect('clicked', self.on_buttonAbout_clicked)
        self.buttonContinue.connect('clicked', self.on_buttonContinue_clicked)
        self.buttonExit.connect('clicked', self.on_buttonExit_clicked)
        self.buttonNewPuzzle.connect('clicked',
                                     self.on_buttonNewPuzzle_clicked)
        self.buttonOptions.connect('clicked', self.on_buttonOptions_clicked)
        self.connect('delete-event', self.on_windowMain_delete_event)
        self.connect('destroy', self.on_windowMain_destroy)
        self.connect('size-allocate', self.on_windowMain_size_allocate)
        self.connect('window-state-event',
                     self.on_windowMain_window_state_event)

        # Get any properties of top window.
        # Set the label for labelVersion
        self.labelVersion.set_label(VERSIONSTR)
        self.can_focus = 'False'

        # Load any settings or run extra initializations.
        self.post_initialisations()
Beispiel #10
0
class windowMain(Gtk.Window):
    """ Main window with all components. """
    def __init__(self, app):
        # Set the app
        self.app = app
        self.app.thehistory = None

        # Basic initializations.
        self.we_can_exit_now = False
        self.return_parameter = None

        self.thedicts = THEDICTS

        # Init the settings module.
        self.dummy_for_settings = SectionConfig(self.app.name,
                                                self.__class__.__name__)
        global settings
        settings = self.dummy_for_settings

        self.dummy_for_options = OptionConfig(self.app.name)
        global options
        options = self.dummy_for_options

        Gtk.Window.__init__(self)

        # Initializations required before loading glade file.

        # Bind the locale.
        locale.bindtextdomain(self.app.domain,
                              os.path.join(self.app.BASE_DIR, 'locale'))
        locale.textdomain(self.app.domain)

        # Load app and window icon.
        self.set_icon(self.app.icon)

        # Bind message boxes.
        self.MessageBox = MessageBox(self)
        self.msg = self.MessageBox.Message

        # Glade stuff.
        # Load Glade file to self.
        self.builder = Gtk.Builder()
        try:
            self.builder.add_from_file(
                os.path.join(self.app.BASE_DIR, 'ui', 'sudokugtk.glade'))
        except Exception as ex:
            print(str(ex))
            print('\n{}:\n{}\n{}'.format(
                _('Error loading from Glade file'),
                os.path.join(self.app.BASE_DIR, 'ui', 'sudokugtk.glade'),
                repr(ex)))
            sys.exit(ERROR_INVALID_GLADE_FILE)

        # Get gui objects.
        self.MainBox = self.builder.get_object('MainBox')
        self.boxForFooter = self.builder.get_object('boxForFooter')
        self.buttonAbout = self.builder.get_object('buttonAbout')
        self.buttonContinue = self.builder.get_object('buttonContinue')
        self.buttonExit = self.builder.get_object('buttonExit')
        self.buttonNewPuzzle = self.builder.get_object('buttonNewPuzzle')
        self.buttonOptions = self.builder.get_object('buttonOptions')
        self.dummylabel = self.builder.get_object('dummylabel')
        self.labelInfo = self.builder.get_object('labelInfo')
        self.labelVersion = self.builder.get_object('labelVersion')

        # Connect signals existing in the Glade file
        self.builder.connect_signals(self)

        # Reparent our main container from glader file,
        # this way we have all Gtk.Window functionality using "self".
        thechild = self.builder.get_object('windowMain').get_child()
        thechild.get_parent().remove(thechild)
        self.add(thechild)

        # Connect generated signals.
        self.buttonAbout.connect('clicked', self.on_buttonAbout_clicked)
        self.buttonContinue.connect('clicked', self.on_buttonContinue_clicked)
        self.buttonExit.connect('clicked', self.on_buttonExit_clicked)
        self.buttonNewPuzzle.connect('clicked',
                                     self.on_buttonNewPuzzle_clicked)
        self.buttonOptions.connect('clicked', self.on_buttonOptions_clicked)
        self.connect('delete-event', self.on_windowMain_delete_event)
        self.connect('destroy', self.on_windowMain_destroy)
        self.connect('size-allocate', self.on_windowMain_size_allocate)
        self.connect('window-state-event',
                     self.on_windowMain_window_state_event)

        # Get any properties of top window.
        # Set the label for labelVersion
        self.labelVersion.set_label(VERSIONSTR)
        self.can_focus = 'False'

        # Load any settings or run extra initializations.
        self.post_initialisations()

#********* Auto created "class defs" START ************************************************************
#********* Auto created handlers START *********************************

    def on_buttonAbout_clicked(self, widget, *args):
        """ Handler for buttonAbout.clicked. """
        self.MessageBox.AboutBox()

    def on_buttonContinue_clicked(self, widget, *args):
        """ Handler for buttonContinue.clicked. """
        self.msg(_('Experimental'))
        thestr = options.get('last_history', '')
        try:
            thehistory = ast.literal_eval(thestr)
        except:
            thehistory = None
        if thehistory:
            self.app.thehistory = thehistory
            tmp = [thehistory[0][x]['num'] for x in thehistory[0]]
            self.app.puzzle_str = ''.join(
                [str(x) if x != 0 else '.' for x in tmp])
            p = PuzzleWindow(self.app)
            response = p.run()
            self.show()
        else:
            self.msg(_('Not a valid history in conf'))

    def on_buttonExit_clicked(self, widget, *args):
        """ Handler for buttonExit.clicked. """
        self.exit_requested()

    def on_buttonNewPuzzle_clicked(self, widget, *args):
        """ Handler for buttonNewPuzzle.clicked. """
        self.app.thehistory = None
        self.app.puzzle_str = self.get_a_puzzle()
        self.hide()
        p = PuzzleWindow(self.app)
        response = p.run()
        self.show()

    def on_buttonOptions_clicked(self, widget, *args):
        """ Handler for buttonOptions.clicked. """
        p = windowOptions(app=self.app)
        p.set_transient_for(self)
        p.set_modal(True)
        response = p.run()
        #print('options response', response)
        self.reload_options()

    def on_windowMain_delete_event(self, widget, event, *args):
        """ Handler for window1.delete-event. """
        self.set_unhandled_settings()
        return False

    def on_windowMain_destroy(self, widget, *args):
        """ Handler for window1.destroy. """
        self.exit_requested()
        return False

    def on_windowMain_size_allocate(self, widget, allocation, *args):
        """ Handler for window1.size-allocate. """
        self.save_my_size()

    def on_windowMain_window_state_event(self, widget, event, *args):
        """ Handler for window1.window-state-event. """
        settings.set('maximized',
                     ((int(event.new_window_state) & Gdk.WindowState.ICONIFIED)
                      != Gdk.WindowState.ICONIFIED) and
                     ((int(event.new_window_state) & Gdk.WindowState.MAXIMIZED)
                      == Gdk.WindowState.MAXIMIZED))
        self.save_my_size()

#********* Auto created handlers  END **********************************

    def post_initialisations(self):
        """ Do some extra initializations.

        Display the version if a labelVersion is found.
        Set defaults (try to load them from a configuration file):
            - Window size and state (width, height and if maximized)
        Load saved custom settings.
        """
        # Set previous size and state.
        width = settings.get('width', 350)
        height = settings.get('height', 350)
        self.set_title(self.app.localizedname)
        self.resize(width, height)
        if settings.get_bool('maximized', False):
            self.maximize()
        # Load any other settings here.
        self.reload_options()

    def set_unhandled_settings(self):
        """ Set, before exit, settings not applied during the session.

        Mass set some non critical settings for widgets
        (which where not setted when some widget's state changed).
        """
        #custom settings

    def save_my_size(self):
        """ Save the window size into settings if not maximized. """
        if not settings.get_bool('maximized', False):
            width, height = self.get_size()
            settings.set('width', width)
            settings.set('height', height)

    def exit_requested(self, *args):
        """Set the param in order to exit from "run" method. """
        self.set_transient_for()
        self.set_modal(False)
        self.set_unhandled_settings()
        self.we_can_exit_now = True
        self.destroy()  #Will not call Handler for delete-event

    def run(self):
        """Start the main loop.

        WARNING:
            The "destroy" event of the main window
            MUST set the "we_can_exit_now" to True,
            else program will never exit.
        Save settings on exit.
        Return "return_parameter" on exit.

        """
        #now we can show the main window.
        self.show_all()
        #"enable" next line to have some interactive view of potentiallities of GUI
        #self.set_interactive_debugging (True)
        #loop eternaly
        while True:
            #if we want to exit...
            if self.we_can_exit_now:
                #break the loop
                break
            #else... give others a change...
            while Gtk.events_pending():
                Gtk.main_iteration()
        #we can now return to "caller"
        #print(settings)
        settings.save()
        #self.return_parameter = 0 #set return_parameter if needed, last change... to change... it!!!
        #return_parameter should be checked and defined usually before this
        return self.return_parameter

#********* Auto created "class defs" END **************************************************************
#TODO: get directly from qqwing library.

    def get_a_puzzle(self):
        b = subprocess.run(
            ['qqwing', "--generate", "--difficulty", "easy", "--compact"],
            stdout=subprocess.PIPE).stdout.decode('utf-8')
        return b.replace('\n', '')

    def reload_options(self):
        self.thedicts['custom'] = self.thedicts['standard'].copy()
        tmpcustomdict = options.get('custom_dict', '').split(',')
        if len(tmpcustomdict) == 10 and tmpcustomdict[0].strip() == '':
            self.thedicts['custom'] = ['']
            for x in range(1, 10):
                self.thedicts['custom'].append(tmpcustomdict[x].strip())
        dict_to_use = options.get('dict_to_use', 'standard')
        if dict_to_use in self.thedicts:
            self.app.strings_to_use = self.thedicts[dict_to_use]
        self.app.font_scale = options.get('font_scale', 110)
        self.app.show_simple = options.get('show_simple', False)
        self.app.show_timer = options.get('show_timer', True)
        self.app.show_pieces = options.get('show_pieces', True)
        if self.app.show_simple:
            self.app.show_timer = False
            self.app.show_pieces = False
        if self.app.font_scale < 105 or self.app.font_scale > 250:
            self.app.font_scale = 110
        self.show_info()

    def show_info(self):
        text = 'font_scale:' + str(self.app.font_scale) + '\n'
        text += 'show_simple:' + str(self.app.show_simple) + '\n'
        text += 'show_timer:' + str(self.app.show_timer) + '\n'
        text += 'show_pieces:' + str(self.app.show_pieces) + '\n'
        text += 'strings_to_use:' + str(self.app.strings_to_use)
        self.labelInfo.set_label(text)
class OptionsWindowBase(object):
    #FIXME: fix the docstring.
    """ Main window with all components. """

    def __init__(self, application, *args, **kwargs):
        # Set the app
        self.myparent = None
        self.passed_args = kwargs['args_to_pass']

        # bind settings,options to a class variable
        global settings
        settings = self.settings
        global options
        options = self.options

        # Before builder.
        self._run_before_builder()

        # Read GUI from file and retrieve objects from Gtk.Builder
        thebuilder = Gtk.Builder()
        thebuilder.set_translation_domain(self.Application.id)
        try:
            thebuilder.add_from_file(os.path.join(self.Application.MyArgs.APP_DIR,
                'ui',
                'optionswindow.glade')
                )
            thebuilder.connect_signals(self)
        except GObject.GError:
            print("Error reading GUI file")
            raise

        # Fire up the main window
        self.OptionsWindow = thebuilder.get_object("OptionsWindow")
        self.OptionsWindow.set_application(self.Application)
        self._get_from_builder(thebuilder)
        self._post_initialisations()

        self.OptionsWindow.show()

#********* Auto created "class defs" START ************************************************************
    def _run_before_builder(self):
        self.fontaspect = 0.85
        self.example_int = 9
        self.example_char = '9'
        self.fontfamily = 'Sans'
        self.canceled = True
        self.squares = {}

        self.thedicts = THEDICTS

        self.color = (0,0,0)

    def _get_from_builder(self, builder):
        """ Create self names for easy access. """
        self.MainBox = builder.get_object('MainBox')
        self.adjustment1 = builder.get_object('adjustment1')
        self.box3 = builder.get_object('box3')
        self.boxForDisplay = builder.get_object('boxForDisplay')
        self.boxForFooter = builder.get_object('boxForFooter')
        self.buttonBackColorSelect = builder.get_object('buttonBackColorSelect')
        self.buttonCancel = builder.get_object('buttonCancel')
        self.buttonForeColorSelect = builder.get_object('buttonForeColorSelect')
        self.buttonSave = builder.get_object('buttonSave')
        self.checkbuttonShowOnlyBoard = builder.get_object('checkbuttonShowOnlyBoard')
        self.checkbuttonShowPieces = builder.get_object('checkbuttonShowPieces')
        self.checkbuttonShowTimer = builder.get_object('checkbuttonShowTimer')
        self.drawingareaExample = builder.get_object('drawingareaExample')
        self.eventbox1 = builder.get_object('eventbox1')
        self.eventbox2 = builder.get_object('eventbox2')
        self.eventbox3 = builder.get_object('eventbox3')
        self.eventbox4 = builder.get_object('eventbox4')
        self.eventbox5 = builder.get_object('eventbox5')
        self.eventbox6 = builder.get_object('eventbox6')
        self.eventbox7 = builder.get_object('eventbox7')
        self.eventbox8 = builder.get_object('eventbox8')
        self.eventbox9 = builder.get_object('eventbox9')
        self.eventboxForDrawingSample = builder.get_object('eventboxForDrawingSample')
        self.fontbutton1 = builder.get_object('fontbutton1')
        self.gridDictionaries = builder.get_object('gridDictionaries')
        self.image1 = builder.get_object('image1')
        self.label1 = builder.get_object('label1')
        self.label10 = builder.get_object('label10')
        self.label11 = builder.get_object('label11')
        self.label2 = builder.get_object('label2')
        self.label3 = builder.get_object('label3')
        self.label4 = builder.get_object('label4')
        self.label5 = builder.get_object('label5')
        self.label6 = builder.get_object('label6')
        self.label7 = builder.get_object('label7')
        self.label8 = builder.get_object('label8')
        self.label9 = builder.get_object('label9')
        self.labelVersion = builder.get_object('labelVersion')
        self.radiobuttonDict1 = builder.get_object('radiobuttonDict1')
        self.scale1 = builder.get_object('scale1')
        self.viewportSample = builder.get_object('viewportSample')

        # Connect signals existing in the Glade file.
        builder.connect_signals(self)

        # Connect generated by OCPgenerator signals:
        # to builder's main window
        self.OptionsWindow.connect('delete-event', self.on_OptionsWindow_delete_event)
        self.OptionsWindow.connect('destroy', self.on_OptionsWindow_destroy)
        self.OptionsWindow.connect('size-allocate', self.on_OptionsWindow_size_allocate)
        self.OptionsWindow.connect('window-state-event', self.on_OptionsWindow_window_state_event)
        self.buttonBackColorSelect.connect('clicked', self.on_buttonBackColorSelect_clicked)
        self.buttonCancel.connect('clicked', self.on_buttonCancel_clicked)
        self.buttonForeColorSelect.connect('clicked', self.on_buttonForeColorSelect_clicked)
        self.buttonSave.connect('clicked', self.on_buttonSave_clicked)
        self.checkbuttonShowPieces.connect('clicked', self.on_checkbuttonShowPieces_toggled)
        self.checkbuttonShowTimer.connect('clicked', self.on_checkbuttonShowTimer_toggled)

    def _post_initialisations(self):
        """ Do some extra initializations.

        Display the version if a labelVersion is found.
        Set defaults (try to load them from a configuration file):
            - Window size and state (width, height and if maximized)
        Load any custom settings from a configuration file.
        """
        if 'trigger_before_exit' in self.passed_args:
            # must be a function on calling class
            self.trigger_before_exit = self.passed_args['trigger_before_exit']
            self.return_parameters = None

        # Bind message boxes.
        self.MessageBox = MessageBox(self.OptionsWindow, self.Application)
        self.msg = self.MessageBox.Message
        self.are_you_sure = self.MessageBox.are_you_sure

        # Reset MainWindow to a default or previous size and state.
        width = settings.get('width', 350)
        height = settings.get('height', 350)
        self.OptionsWindow.set_title(self.Application.MyArgs.localizedname + " - " + _('Options'))
        self.OptionsWindow.resize(width, height)
        self.OptionsWindow.set_icon(self.Application.icon)
        if settings.get_bool('maximized', False):
            self.OptionsWindow.maximize()

        # Set the label for labelVersion
        self.labelVersion.set_label(self.Application.MyArgs.version)
        self.labelVersion.set_tooltip_text(_("Version of this window:") + "\n" + VERSIONSTR)

        # Load any other settings here.
        self.current_dict_name = 'standard'
        self.thedicts['custom'] = self.thedicts['standard'].copy()
        tmpcustomdict = options.get('custom_dict', '').split(',')
        if len(tmpcustomdict) == 10 and tmpcustomdict[0].strip() == '':
            self.thedicts['custom'] = ['']
            for x in range (1, 10):
                self.thedicts['custom'].append(tmpcustomdict[x].strip())
        self.show_dicts()
        self.OptionsWindow.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#228b22"))#forest green

        simple = options.get('show_simple', False )
        self.checkbuttonShowPieces.set_active(not simple and options.get('show_pieces', False))
        self.checkbuttonShowTimer.set_active(not simple and options.get('show_timer', True))
        self.checkbuttonShowOnlyBoard.set_active(simple)
        scale = options.get('font_scale', 100)
        self.adjustment1.set_value(scale / 100)
        self.fontaspect = self.adjustment1.get_value()
        self.fontfamily = options.get('font', self.fontbutton1.get_font_name())
        self.fontbutton1.set_font_name(self.fontfamily)
        #print('self.fontbutton1.get_font_name()', self.fontbutton1.get_font_name())

        digits_dict = options.get('dict_to_use', 'standard')
        for b in self.gridDictionaries.get_children():
            if hasattr(b, 'tag') and b.tag == digits_dict:
                b.set_active(True)
                break

        self.picker = self.AppArgs.picker
        #self.image1.set_from_pixbuf(pixbuf)

#********* Auto created handlers START *********************************
    def on_NUM_button_press_event(self, widget, event, *args):
        """ Handler for eventbox1.button-press-event. """
        self.example_int = int(widget.get_child().get_label())
        self.drawingareaExample.queue_draw()

    def on_adjustment1_changed(self, widget, *args):
        """ Handler for adjustment1.changed. """
        pass

    def on_buttonBackColorSelect_clicked(self, widget, *args):
        """ Handler for buttonBackColorSelect.clicked. """
        self.msg_not_yet()

    def on_buttonCancel_clicked(self, widget, *args):
        """ Handler for buttonCancel.clicked. """
        self.exit_requested()

    def on_buttonForeColorSelect_clicked(self, widget, *args):
        """ Handler for buttonForeColorSelect.clicked. """
        self.select_fore_color()

    def on_buttonSave_clicked(self, widget, *args):
        """ Handler for buttonSave.clicked. """
        self.canceled = False
        self.exit_requested()

    def on_checkbuttonShowOnlyBoard_toggled(self, widget, *args):
        """ Handler for checkbuttonShowOnlyBoard.toggled. """
        boolval = self.checkbuttonShowOnlyBoard.get_active()
        self.checkbuttonShowPieces.set_sensitive(not boolval)
        self.checkbuttonShowTimer.set_sensitive(not boolval)

    def on_checkbuttonShowPieces_toggled(self, widget, *args):
        """ Handler for checkbuttonShowPieces.clicked. """
        pass

    def on_checkbuttonShowTimer_toggled(self, widget, *args):
        """ Handler for checkbuttonShowTimer.clicked. """
        pass

    def on_drawingareaExample_draw(self, widget, cr, *args):
        """ Handler for drawingareaExample.draw. """
        sizes = self.eventboxForDrawingSample.get_allocation()
        min_size = min(sizes.width, sizes.height)
        self.working_restangle = Gdk.Rectangle()
        self.working_restangle.x = int((sizes.width - min_size) / 2)
        self.working_restangle.y = int((sizes.height - min_size) / 2)
        self.working_restangle.width = int(min_size)
        self.working_restangle.height = int(min_size)
        self.draw_example(cr)
        #print('on_drawingareaExample_draw', self.fontfamily)

    def on_eventboxForDrawingSample_button_press_event(self, widget, event, *args):
        """ Handler for eventboxForDrawingSample.button-press-event. """
        pass

    def on_fontbutton1_font_set(self, widget, *args):
        """ Handler for fontbutton1.font-set. """
        self.fontfamily = self.fontbutton1.get_font_name()
        self.drawingareaExample.queue_draw()

    def on_radiobuttonDict1_toggled(self, widget, *args):
        """ Handler for radiobuttonDict1.toggled. """
        if widget.get_active():
            self.current_dict_name = widget.tag
            self.drawingareaExample.queue_draw()

    def on_scale1_change_value(self, widget, scroll, new_value, *args):
        """ Handler for scale1.change-value. """
        if new_value <= self.adjustment1.get_upper():
            self.fontaspect = new_value
            self.drawingareaExample.queue_draw()

#********* Auto created handlers END ***********************************

#********* Standard handlers START *************************************
    def msg_not_yet(self):
        self.msg(_('Not yet implemented'))

    def on_buttonAbout_clicked(self, widget, *args):
        """ Handler for buttonAbout.clicked. """
        #TODO: Check if used.
        self.MessageBox.AboutBox()

    def on_buttonExit_clicked(self, widget, *args):
        """ Handler for buttonExit.clicked. """
        #TODO: Check if used.
        self.exit_requested()

    def on_OptionsWindow_delete_event(self, widget, event, *args):
        """ Handler for our main window: delete-event. """
        return (self.exit_requested())

    def on_OptionsWindow_destroy(self, widget, *args):
        """ Handler for our main window: destroy. """
        return (self.exit_requested('from_destroy'))

    def on_OptionsWindow_size_allocate(self, widget, allocation, *args):
        """ Handler for our main window: size-allocate. """
        self.save_my_size()

    def on_OptionsWindow_window_state_event(self, widget, event, *args):
        """ Handler for our main window: window-state-event. """
        settings.set('maximized',
            ((int(event.new_window_state) & Gdk.WindowState.ICONIFIED) != Gdk.WindowState.ICONIFIED) and
            ((int(event.new_window_state) & Gdk.WindowState.MAXIMIZED) == Gdk.WindowState.MAXIMIZED)
            )
        self.save_my_size()

#********* Standard handlers END ***************************************
#********* Standard exit defs START *********************************************************
    def exit_requested(self, *args, **kwargs):
        """ Final work before exit. """
        self.OptionsWindow.set_transient_for()
        self.OptionsWindow.set_modal(False)
        self.set_unhandled_settings()# also saves all settings
        if 'from_destroy' in args:
            return True
        else:
            # Check if we should provide info to caller
            if 'trigger_before_exit' in self.passed_args:
                self.trigger_before_exit(exiting = True,
                    return_parameters = self.return_parameters)
            self.OptionsWindow.destroy()

    def present(self):
        """ Show the window. """
        pass

    def save_my_size(self):
        """ Save the window size into settings, if not maximized. """
        if not settings.get_bool('maximized', False):
            width, height = self.OptionsWindow.get_size()
            settings.set('width', width)
            settings.set('height', height)

    def set_unhandled_settings(self):
        """ Set, before exit, any settings not applied during the session.

        Additionally, flush all settings to .conf file.
        """
        # Set any custom settings
        # which where not setted (ex. on some widget's state changed)
        if not self.canceled:
            options.set('dict_to_use', self.current_dict_name)
            options.set('custom_dict', ','.join(self.thedicts['custom']))
            scale = self.adjustment1.get_value()
            options.set('font_scale', int(scale * 100))
            options.set('font', self.fontbutton1.get_font_name())
            boolval = self.checkbuttonShowOnlyBoard.get_active()
            options.set('show_simple', boolval )
            options.set('show_pieces', (not boolval) and self.checkbuttonShowPieces.get_active())
            options.set('show_timer', (not boolval) and self.checkbuttonShowTimer.get_active())

            options.set('fore_color',','.join(['{:0.4f}'.format(x) for x in self.color]))
        # Save all settings
        settings.save()
Beispiel #12
0
    def __init__(self, app):
        # Set the app
        self.app = app

        # Basic initializations.
        self.we_can_exit_now = False
        self.return_parameter = None

        self.fontaspect = 1.85
        self.example_int = 9
        self.example_char = '9'
        self.fontfamily = 'Sans'

        self.thedicts = THEDICTS

        self.current_dict_name = 'standard'

        # Init the settings module.
        self.dummy_for_settings = SectionConfig(self.app.name,
                                                self.__class__.__name__)
        global settings
        settings = self.dummy_for_settings

        self.dummy_for_options = OptionConfig(self.app.name)
        global options
        options = self.dummy_for_options

        Gtk.Window.__init__(self)

        # Initializations required before loading glade file.

        # Bind the locale.
        locale.bindtextdomain(self.app.domain,
                              os.path.join(self.app.BASE_DIR, 'locale'))
        locale.textdomain(self.app.domain)

        # Load app and window icon.
        self.set_icon(self.app.icon)

        # Bind message boxes.
        self.MessageBox = MessageBox(self)
        self.msg = self.MessageBox.Message

        # Glade stuff.
        # Load Glade file to self.
        self.builder = Gtk.Builder()
        try:
            self.builder.add_from_file(
                os.path.join(self.app.BASE_DIR, 'ui', 'options.glade'))
        except Exception as ex:
            print(str(ex))
            print('\n{}:\n{}\n{}'.format(
                _('Error loading from Glade file'),
                os.path.join(self.app.BASE_DIR, 'ui', 'options.glade'),
                repr(ex)))
            sys.exit(ERROR_INVALID_GLADE_FILE)

        # Get gui objects.
        self.MainBox = self.builder.get_object('MainBox')
        self.adjustment1 = self.builder.get_object('adjustment1')
        self.box1 = self.builder.get_object('box1')
        self.box2 = self.builder.get_object('box2')
        self.box3 = self.builder.get_object('box3')
        self.buttonCancel = self.builder.get_object('buttonCancel')
        self.buttonSave = self.builder.get_object('buttonSave')
        self.checkbuttonShowOnlyBoard = self.builder.get_object(
            'checkbuttonShowOnlyBoard')
        self.checkbuttonShowPieces = self.builder.get_object(
            'checkbuttonShowPieces')
        self.checkbuttonShowTimer = self.builder.get_object(
            'checkbuttonShowTimer')
        self.drawingareaExample = self.builder.get_object('drawingareaExample')
        self.eventbox1 = self.builder.get_object('eventbox1')
        self.eventbox2 = self.builder.get_object('eventbox2')
        self.eventbox3 = self.builder.get_object('eventbox3')
        self.eventbox4 = self.builder.get_object('eventbox4')
        self.eventbox5 = self.builder.get_object('eventbox5')
        self.eventbox6 = self.builder.get_object('eventbox6')
        self.eventbox7 = self.builder.get_object('eventbox7')
        self.eventbox8 = self.builder.get_object('eventbox8')
        self.eventbox9 = self.builder.get_object('eventbox9')
        self.fontbutton1 = self.builder.get_object('fontbutton1')
        self.gridDictionaries = self.builder.get_object('gridDictionaries')
        self.label1 = self.builder.get_object('label1')
        self.label10 = self.builder.get_object('label10')
        self.label2 = self.builder.get_object('label2')
        self.label3 = self.builder.get_object('label3')
        self.label4 = self.builder.get_object('label4')
        self.label5 = self.builder.get_object('label5')
        self.label6 = self.builder.get_object('label6')
        self.label7 = self.builder.get_object('label7')
        self.label8 = self.builder.get_object('label8')
        self.label9 = self.builder.get_object('label9')
        self.labeltest = self.builder.get_object('labeltest')
        self.radiobuttonDict1 = self.builder.get_object('radiobuttonDict1')
        self.scale1 = self.builder.get_object('scale1')
        self.scrolledwindow1 = self.builder.get_object('scrolledwindow1')
        self.viewport1 = self.builder.get_object('viewport1')

        # Connect signals existing in the Glade file
        self.builder.connect_signals(self)

        # Reparent our main container from glader file,
        # this way we have all Gtk.Window functionality using "self".
        thechild = self.builder.get_object('windowOptions').get_child()
        thechild.get_parent().remove(thechild)
        self.add(thechild)

        # Connect generated signals.
        self.buttonCancel.connect('clicked', self.on_buttonCancel_clicked)
        self.buttonSave.connect('clicked', self.on_buttonSave_clicked)
        self.connect('delete-event', self.on_windowOptions_delete_event)
        self.connect('destroy', self.on_windowOptions_destroy)
        self.connect('size-allocate', self.on_windowOptions_size_allocate)
        self.connect('window-state-event',
                     self.on_windowOptions_window_state_event)

        # Get any properties of top window.
        self.can_focus = 'False'

        # Load any settings or run extra initializations.
        self.post_initialisations()