← Back to team overview

mlhim-specs-dev team mailing list archive

[Branch ~cdd-dev/cdd/trunk] Rev 198: Saving config file for the config dialog.

 

------------------------------------------------------------
revno: 198
committer: Eduardo C. P. Ribeiro <eduardo.cesar@xxxxxxx>
branch nick: cdd
timestamp: Fri 2012-07-27 19:12:44 -0300
message:
  Saving config file for the config dialog.
modified:
  src/cdd.py
  src/cdg_cdd.wxg
  src/cdg_main.py


--
lp:cdd
https://code.launchpad.net/~cdd-dev/cdd/trunk

Your team MLHIM Specifications Developers is subscribed to branch lp:cdd.
To unsubscribe from this branch go to https://code.launchpad.net/~cdd-dev/cdd/trunk/+edit-subscription
=== modified file 'src/cdd.py'
--- src/cdd.py	2012-07-27 21:25:53 +0000
+++ src/cdd.py	2012-07-27 22:12:44 +0000
@@ -393,7 +393,9 @@
 
 
     def show_config(self, event):
-        self.config_dialog.ShowModal()
+        result = self.config_dialog.ShowModal()
+        if result == wx.ID_OK:
+            self.config_dialog.save_config()
 
 # end of class MainFrame
 

=== modified file 'src/cdg_cdd.wxg'
--- src/cdg_cdd.wxg	2012-07-27 21:25:53 +0000
+++ src/cdg_cdd.wxg	2012-07-27 22:12:44 +0000
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<!-- generated by wxGlade 0.6.4 on Fri Jul 27 17:19:28 2012 -->
+<!-- generated by wxGlade 0.6.4 on Fri Jul 27 18:37:17 2012 -->
 
 <application path="cdg_main.py" name="" class="" option="0" language="python" top_window="frame_principal" encoding="UTF-8" use_gettext="0" overwrite="0" use_new_namespace="1" for_version="2.8" is_template="0" indent_amount="4" indent_symbol="space" source_extension=".cpp" header_extension=".h">
     <object class="MainDialog" name="dialog_principal" base="EditDialog">
@@ -468,7 +468,7 @@
                             <object class="sizeritem">
                                 <border>0</border>
                                 <option>0</option>
-                                <object class="wxTextCtrl" name="text_ctrl_1" base="EditTextCtrl">
+                                <object class="wxTextCtrl" name="text_ctrl_autosave" base="EditTextCtrl">
                                     <size>110, 27</size>
                                 </object>
                             </object>

=== modified file 'src/cdg_main.py'
--- src/cdg_main.py	2012-07-27 21:25:53 +0000
+++ src/cdg_main.py	2012-07-27 22:12:44 +0000
@@ -29,7 +29,7 @@
         wx.Dialog.__init__(self, *args, **kwds)
         self.text_ctrl_workspace = wx.TextCtrl(self, -1, "")
         self.sizer_9_staticbox = wx.StaticBox(self, -1, "Workspace path:")
-        self.text_ctrl_1 = wx.TextCtrl(self, -1, "")
+        self.text_ctrl_autosave = wx.TextCtrl(self, -1, "")
         self.sizer_12_staticbox = wx.StaticBox(self, -1, "Autosave timer: ")
         self.button_2 = wx.Button(self, wx.ID_CANCEL, "")
         self.button_1 = wx.Button(self, wx.ID_OK, "")
@@ -43,7 +43,7 @@
         # begin wxGlade: ConfigDialog.__set_properties
         self.SetTitle("Configuration")
         self.SetSize((596, 158))
-        self.text_ctrl_1.SetMinSize((110, 27))
+        self.text_ctrl_autosave.SetMinSize((110, 27))
         # end wxGlade
 
     def __do_layout(self):
@@ -59,7 +59,7 @@
         sizer_9.Add(self.text_ctrl_workspace, 1, 0, 0)
         sizer_2.Add(sizer_9, 1, wx.EXPAND, 7)
         sizer_main.Add(sizer_2, 1, wx.EXPAND, 0)
-        sizer_12.Add(self.text_ctrl_1, 0, 0, 0)
+        sizer_12.Add(self.text_ctrl_autosave, 0, 0, 0)
         sizer_11.Add(sizer_12, 0, wx.EXPAND, 0)
         sizer_11.Add((20, 20), 1, wx.EXPAND, 0)
         sizer_main.Add(sizer_11, 1, wx.EXPAND, 0)
@@ -73,8 +73,54 @@
         # end wxGlade
 
     def init_things(self):
-        home = wx.GetUserHome()
-        self.text_ctrl_workspace.SetValue(home + '/MLHIM2')
+        self.init_config()
+        self.read_config()
+
+    def init_config(self):
+        if sys.platform.startswith('linux'):
+            home = os.environ['HOME']
+        elif sys.platform.startswith('win'):
+            home = os.environ['HOMEDRIVE'] + '/' +os.environ['HOMEPATH']
+
+        else:
+            home = './'
+        self.configdir = home + '/.mlhim'
+        self.configname = self.configdir + '/' + 'cdg.cfg'
+
+        self.config = ConfigParser.SafeConfigParser({
+                'autosave' : '300',
+                'workspace' : home + '/' + 'MLHIM2'
+                })
+
+    def read_config(self):
+        try:
+            if not self.config.read(self.configname):
+                self.make_config_dir()
+        except:
+            self.save_config()
+        self.set_panel_configs()
+
+
+    def make_config_dir(self):
+        if not os.path.exists(self.configdir):
+            os.mkdir(self.configdir)
+        # with open(self.configname, 'wb') as configfile:
+        #     self.config.write(configfile)
+
+    def save_config(self):
+        self.get_panel_configs()
+        with open(self.configname, 'wb') as configfile:
+            configfile.write('# Concept Definition Designer Configuration\n# Do not edit the text to the left of the equal symbol (=)\n\n')
+            self.config.write(configfile)
+
+
+    def get_panel_configs(self):
+        self.config.set('DEFAULT', 'autosave', self.text_ctrl_autosave.GetValue().encode('utf8'))
+        self.config.set('DEFAULT', 'workspace', self.text_ctrl_workspace.GetValue().encode('utf8'))
+ 
+    def set_panel_configs(self):
+        self.text_ctrl_autosave.SetValue(self.config.get('DEFAULT', 'autosave'))
+        self.text_ctrl_workspace.SetValue(self.config.get('DEFAULT', 'workspace'))
 
 # end of class ConfigDialog
 
@@ -394,7 +440,7 @@
 
     def save_config(self):
         with open(self.configname, 'wb') as configfile:
-            configfile.write('# Concept Definition Generator Configuration\n# Do not edit the text to the left of the equal symbol (=)\n\n')
+            configfile.write('# CDD Metadata Configuration\n# Do not edit the text to the left of the equal symbol (=)\n\n')
             self.config.write(configfile)