Skip to content

Commit

Permalink
gui: Make settings persistent across converter restarts
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Burman <[email protected]>
  • Loading branch information
yanburman committed May 7, 2017
1 parent 3d1df28 commit d5db984
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
86 changes: 86 additions & 0 deletions gui/Preferences.py
Original file line number Diff line number Diff line change
@@ -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()
26 changes: 26 additions & 0 deletions gui/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# begin wxGlade: extracode
from images import Images
from Preferences import Preferences
# end wxGlade

from threading import Thread
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -261,6 +271,22 @@ def OnClose(self, event): # wxGlade: MainFrame.<event_handler>
self.OnAbort(event)
self.Destroy()

def OnTIFFClicked(self, event): # wxGlade: MainFrame.<event_handler>
self.prefs.set_tiff(str(event.IsChecked()))
event.Skip()

def OnDNGClicked(self, event): # wxGlade: MainFrame.<event_handler>
self.prefs.set_dng(str(event.IsChecked()))
event.Skip()

def OnThumbnailClicked(self, event): # wxGlade: MainFrame.<event_handler>
self.prefs.set_thumbnail(str(event.IsChecked()))
event.Skip()

def OnRotationClicked(self, event): # wxGlade: MainFrame.<event_handler>
self.prefs.set_rotate(str(event.IsChecked()))
event.Skip()

# end of class MainFrame
class MyApp(wx.App):
def OnInit(self):
Expand Down
16 changes: 14 additions & 2 deletions gui/converter.wxg
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0"?>
<!-- generated by wxGlade 0.7.1 on Thu Apr 13 17:09:15 2017 -->
<!-- generated by wxGlade 0.7.1 on Sun May 7 13:37:02 2017 -->

<application class="" encoding="UTF-8" for_version="3.0" header_extension=".h" indent_amount="4" indent_symbol="space" is_template="0" language="python" name="" option="0" overwrite="0" path="converter.py" source_extension=".cpp" top_window="main_frame" use_gettext="1" use_new_namespace="1">
<object class="MainFrame" name="main_frame" base="EditFrame">
<extracode>from images import Images</extracode>
<extracode>from images import Images\nfrom Preferences import Preferences</extracode>
<style>wxDEFAULT_FRAME_STYLE</style>
<title>SJCAM RAW Converter</title>
<menubar>1</menubar>
Expand Down Expand Up @@ -107,6 +107,9 @@
<object class="wxCheckBox" name="tiff_checkbox" base="EditCheckBox">
<label>TIFF</label>
<tooltip>Convert to TIFF</tooltip>
<events>
<handler event="EVT_CHECKBOX">OnTIFFClicked</handler>
</events>
</object>
</object>
<object class="sizeritem">
Expand All @@ -116,6 +119,9 @@
<checked>1</checked>
<label>DNG</label>
<tooltip>Convert to DNG</tooltip>
<events>
<handler event="EVT_CHECKBOX">OnDNGClicked</handler>
</events>
</object>
</object>
<object class="sizeritem">
Expand All @@ -124,6 +130,9 @@
<object class="wxCheckBox" name="thumb_checkbox" base="EditCheckBox">
<label>Thumbnail</label>
<tooltip>Create thumbnail (needed by some editors e.g. darktable)</tooltip>
<events>
<handler event="EVT_CHECKBOX">OnThumbnailClicked</handler>
</events>
</object>
</object>
<object class="sizeritem">
Expand All @@ -132,6 +141,9 @@
<object class="wxCheckBox" name="rotate_checkbox" base="EditCheckBox">
<label>Rotation</label>
<tooltip>Check if images were taken with rotation enabled in camera</tooltip>
<events>
<handler event="EVT_CHECKBOX">OnRotationClicked</handler>
</events>
</object>
</object>
</object>
Expand Down

0 comments on commit d5db984

Please sign in to comment.