From 2e22d04280e0dcf243a5305f9215aeccd582f377 Mon Sep 17 00:00:00 2001 From: "Robert B. Lowrie" Date: Sat, 2 Apr 2016 05:51:33 -0600 Subject: [PATCH] Fix logic on enabling Save button for Preferences. --- qt_config.py | 31 +++++++++++++++++-------------- utils.py | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/qt_config.py b/qt_config.py index a8452c2..70844bc 100644 --- a/qt_config.py +++ b/qt_config.py @@ -109,8 +109,8 @@ def __init__(self, config, units, parent=None): vbox.addLayout(self.create_buttons()) self.setLayout(vbox) - self.initialize() self.change_state = 0 + self.initialize() def create_units(self): '''Creates the layout for units preferences''' @@ -347,6 +347,8 @@ def initialize(self): ''' Initializes certain widgets to their current values in the config object. ''' + self.change_state_on_init = self.change_state + if self.config.metric: self.cb_units.setCurrentIndex(0) else: @@ -397,6 +399,9 @@ def _on_cancel(self): if self.config.debug: print('qt_config:_on_cancel') self.setResult(0) + # Set state back to the current configuration + self.new_config = self.config.__dict__.copy() + self.change_state = self.change_state_on_init self.close() @QtCore.pyqtSlot() @@ -432,7 +437,7 @@ def _on_save(self): else: self._on_cancel() elif self.change_state == 1: - # Units was not changed + # Units were not changed do_save_config = True if do_save_config: config_file.set_default_dimensions(self.new_config) @@ -442,8 +447,18 @@ def _on_save(self): if do_restart: os.execv(sys.argv[0], sys.argv) self.setResult(1) + self.change_state = 0 + self.btn_save.setEnabled(False) self.close() + def closeEvent(self, event): + ''' + This is called on save, cancel, and if user closes the window. + ''' + if self.config.debug: + print('qt_config:closeEvent') + self.btn_save.setEnabled(self.change_state > 0) + @QtCore.pyqtSlot(int) def _on_units(self, index): if self.config.debug: @@ -660,15 +675,3 @@ def _on_caul_trim(self): if val is not None: self.new_config['caul_trim'] = val self.update_state('caul_trim') - - def closeEvent(self, event): - ''' - For closeEvents (user closes window), ignore and call - _on_cancel() - ''' - if self.config.debug: - print('qt_config:closeEvent') - # Set state to the current configuration - self.new_config = self.config.__dict__.copy() - self.change_state = 0 - self.btn_save.setEnabled(False) diff --git a/utils.py b/utils.py index 64df729..1a00dbd 100644 --- a/utils.py +++ b/utils.py @@ -25,7 +25,7 @@ import math, fractions, os, glob, platform -VERSION = '0.8.9' +VERSION = '0.8.10' def my_round(f): '''