From d5db984fdf310332a74218ab73f80e56f3c79778 Mon Sep 17 00:00:00 2001 From: Yan Burman Date: Sun, 7 May 2017 14:02:38 +0300 Subject: [PATCH] gui: Make settings persistent across converter restarts Signed-off-by: Yan Burman --- ChangeLog | 1 + gui/Preferences.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++ gui/converter.py | 26 ++++++++++++++ gui/converter.wxg | 16 +++++++-- 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 gui/Preferences.py diff --git a/ChangeLog b/ChangeLog index 2d87c48..5d1ad16 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ v1.2.0 +* Make GUI settings persistent between converter restarts * Added support for stills taken in rotated orientation (in GUI as well) * Add full support for crop FOV in M20 and SJ5000x * Add support for non-zero stride diff --git a/gui/Preferences.py b/gui/Preferences.py new file mode 100644 index 0000000..a86a8c7 --- /dev/null +++ b/gui/Preferences.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +import ConfigParser +import sys +import os + + +class Preferences(ConfigParser.SafeConfigParser): + def __init__(self): + ConfigParser.SafeConfigParser.__init__(self) + + # make config case sensitive + self.optionxform = str + + self.settings_section = 'Settings' + self.general_section = 'General' + defaults = dict() + defaults[self.settings_section] = {'DNG': True, 'TIFF': False, 'Thumbnail': False, 'Rotate': False} + defaults[self.general_section] = {'Language': 'en'} + + self.prefs_path = os.path.join(os.path.dirname(sys.argv[0]), 'preferences.ini') + self.read(self.prefs_path) + + need_to_write = False + + for section in defaults: + if not self.has_section(section): + self.add_section(section) + need_to_write = True + values = defaults[section] + for key, val in values.items(): + if not self.has_option(section, key): + self.set(section, key, str(val)) + need_to_write = True + + if need_to_write: + self.write() + + def write(self): + with open(self.prefs_path, 'wb') as configfile: + ConfigParser.SafeConfigParser.write(self, configfile) + + def get_dng(self): + return self.getboolean(self.settings_section, 'DNG') + + def get_tiff(self): + return self.getboolean(self.settings_section, 'TIFF') + + def get_thumbnail(self): + return self.getboolean(self.settings_section, 'Thumbnail') + + def get_rotate(self): + return self.getboolean(self.settings_section, 'Rotate') + + def get_lang(self): + return self.get(self.general_section, 'Language') + + def set_dng(self, val): + self.set(self.settings_section, 'DNG', val) + self.write() + + def set_tiff(self, val): + self.set(self.settings_section, 'TIFF', val) + self.write() + + def set_thumbnail(self, val): + self.set(self.settings_section, 'Thumbnail', val) + self.write() + + def set_rotate(self, val): + self.set(self.settings_section, 'Rotate', val) + self.write() + + def set_lang(self, val): + self.set(self.general_section, 'Language') + self.write() + + +if __name__ == "__main__": + prefs = Preferences() + print prefs.get_dng() + print prefs.get_tiff() + print prefs.get_thumbnail() + print prefs.get_rotate() + print prefs.get_lang() diff --git a/gui/converter.py b/gui/converter.py index f76f6c8..54f3e79 100755 --- a/gui/converter.py +++ b/gui/converter.py @@ -12,6 +12,7 @@ # begin wxGlade: extracode from images import Images +from Preferences import Preferences # end wxGlade from threading import Thread @@ -139,6 +140,10 @@ def __init__(self, *args, **kwds): self.Bind(wx.EVT_MENU, self.OnMenuAbout, self.About) self.Bind(wx.EVT_BUTTON, self.OnSrcFolder, self.src_dir_button) self.Bind(wx.EVT_BUTTON, self.OnDstFolder, self.dst_folder_button) + self.Bind(wx.EVT_CHECKBOX, self.OnTIFFClicked, self.tiff_checkbox) + self.Bind(wx.EVT_CHECKBOX, self.OnDNGClicked, self.dng_checkbox) + self.Bind(wx.EVT_CHECKBOX, self.OnThumbnailClicked, self.thumb_checkbox) + self.Bind(wx.EVT_CHECKBOX, self.OnRotationClicked, self.rotate_checkbox) self.Bind(wx.EVT_BUTTON, self.OnConvert, self.convert_button) self.Bind(wx.EVT_BUTTON, self.OnAbort, self.abort_button) # end wxGlade @@ -147,6 +152,11 @@ def __init__(self, *args, **kwds): self.proc = None self.Bind(wx.EVT_CLOSE, self.OnClose) self.SetMinSize(self.GetSize()) + self.prefs = Preferences() + self.dng_checkbox.SetValue(self.prefs.get_dng()) + self.tiff_checkbox.SetValue(self.prefs.get_tiff()) + self.thumb_checkbox.SetValue(self.prefs.get_thumbnail()) + self.rotate_checkbox.SetValue(self.prefs.get_rotate()) def __set_properties(self): # begin wxGlade: MainFrame.__set_properties @@ -261,6 +271,22 @@ def OnClose(self, event): # wxGlade: MainFrame. self.OnAbort(event) self.Destroy() + def OnTIFFClicked(self, event): # wxGlade: MainFrame. + self.prefs.set_tiff(str(event.IsChecked())) + event.Skip() + + def OnDNGClicked(self, event): # wxGlade: MainFrame. + self.prefs.set_dng(str(event.IsChecked())) + event.Skip() + + def OnThumbnailClicked(self, event): # wxGlade: MainFrame. + self.prefs.set_thumbnail(str(event.IsChecked())) + event.Skip() + + def OnRotationClicked(self, event): # wxGlade: MainFrame. + self.prefs.set_rotate(str(event.IsChecked())) + event.Skip() + # end of class MainFrame class MyApp(wx.App): def OnInit(self): diff --git a/gui/converter.wxg b/gui/converter.wxg index dda515a..16ac753 100644 --- a/gui/converter.wxg +++ b/gui/converter.wxg @@ -1,9 +1,9 @@ - + - from images import Images + from images import Images\nfrom Preferences import Preferences SJCAM RAW Converter 1 @@ -107,6 +107,9 @@ Convert to TIFF + + OnTIFFClicked + @@ -116,6 +119,9 @@ 1 Convert to DNG + + OnDNGClicked + @@ -124,6 +130,9 @@ Create thumbnail (needed by some editors e.g. darktable) + + OnThumbnailClicked + @@ -132,6 +141,9 @@ Check if images were taken with rotation enabled in camera + + OnRotationClicked +