import PyQt4.QtCore as QtCore
import PyQt4.QtGui as QtGui

from designer import settings_window_qt


class SettingsWindow(QtGui.QDialog, settings_window_qt.Ui_SettingsDialog):
    def __init__(self, parent=None):
        super(SettingsWindow, self).__init__(parent)

        # Setup the about dialog box
        self.setupUi(self)

        # Delete the object when dialog is closed
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        # Remove the help / whats this button from title bar
        self.setWindowFlags(
            self.windowFlags() ^ QtCore.Qt.WindowContextHelpButtonHint)

        # Open settings file with no registry fallback
        self.settings = QtCore.QSettings("settings.ini",
                                         QtCore.QSettings.IniFormat)
        self.settings.setFallbacksEnabled(False)

        # Get task window settings
        self.settings.beginGroup("TaskWindows")
        self.task_fullscreen = self.settings.value("fullscreen").toBool()
        self.task_width = self.settings.value("width").toString()
        self.task_height = self.settings.value("height").toString()
        self.settings.endGroup()

        # Set task window values
        self.settings_task_height_value.setText(self.task_height)
        self.settings_task_width_value.setText(self.task_width)

        # Set fullscreen check state
        self.settings_task_fullscreen_checkbox.setChecked(self.task_fullscreen)

        # Disable task window size entry if fullscreen is selected
        self.set_task_size_state(not self.task_fullscreen)

        # Bind button events
        self.settings_save_button.clicked.connect(self.save_settings)
        self.settings_cancel_button.clicked.connect(self.close)
        self.settings_task_fullscreen_checkbox.clicked.connect(
            self.task_fullscreen_checkbox)

    # Set state of the task window size entry fields
    def set_task_size_state(self, state):
        self.settings_task_height_value.setEnabled(state)
        self.settings_task_width_value.setEnabled(state)

    def task_fullscreen_checkbox(self):
        # Invert fullscreen selection state
        self.task_fullscreen = not self.task_fullscreen
        # Set entry boxes to opposite of new fullscreen state
        self.set_task_size_state(not self.task_fullscreen)

    def save_settings(self):
        self.settings.beginGroup("TaskWindows")
        self.settings.setValue('fullscreen', self.task_fullscreen)

        # Only save width and height if fullscreen is not selected
        if not self.task_fullscreen:
            self.settings.setValue('width',
                                   self.settings_task_width_value.text())
            self.settings.setValue('height',
                                   self.settings_task_height_value.text())

        self.settings.endGroup()

        self.close()

@@ -838,11 +838,237 @@
   # 
-Get
+Set initial settings window size from saved settings%0A        self.settings.beginGroup(%22SettingsWindow%22)%0A        self.resize(self.settings.value(%22size%22, self.size()).toSize())%0A        self.settings.endGroup()%0A%0A        # Get stored
  tas
@@ -1941,20 +1941,30 @@
 t(self.c
-lose
+ancel_settings
 )%0A      
@@ -2534,24 +2534,340 @@
 ullscreen)%0A%0A
+    def save_window_information(self):%0A        self.settings.beginGroup(%22SettingsWindow%22)%0A        self.settings.setValue('size', self.size())%0A        self.settings.endGroup()%0A%0A    def cancel_settings(self):%0A        # Save settings window size information%0A        self.save_window_information()%0A        self.close()%0A%0A
     def save
@@ -3368,32 +3368,119 @@
 ngs.endGroup()%0A%0A
+        # Save settings window size information%0A        self.save_window_information()%0A
         self.clo

Save and restore Settings window size