Skip to content

Commit

Permalink
Fix logic on enabling Save button for Preferences.
Browse files Browse the repository at this point in the history
  • Loading branch information
lowrie committed Apr 2, 2016
1 parent 472a626 commit 2e22d04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 17 additions & 14 deletions qt_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'''
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import math, fractions, os, glob, platform

VERSION = '0.8.9'
VERSION = '0.8.10'

def my_round(f):
'''
Expand Down

0 comments on commit 2e22d04

Please sign in to comment.