← Back to team overview

mlhim-specs-dev team mailing list archive

[Branch ~cdd-dev/cdd/trunk] Rev 155: Added a persistent configuration in "$HOME/.cdg-1.0/cdg.cfg"

 

------------------------------------------------------------
revno: 155
fixes bug: https://launchpad.net/bugs/1021992
committer: Eduardo César <xcesar@xxxxxxxxx>
branch nick: cdd
timestamp: Fri 2012-07-06 22:51:13 -0300
message:
  Added a persistent configuration in "$HOME/.cdg-1.0/cdg.cfg" 
modified:
  Generator/cdg/MainFrame.py
  Generator/cdg/cdg_custom.py
  Generator/cdg/cdg_extra.py
  Generator/cdg_wxglade.wxg


--
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 'Generator/cdg/MainFrame.py'
--- Generator/cdg/MainFrame.py	2012-07-05 02:22:25 +0000
+++ Generator/cdg/MainFrame.py	2012-07-07 01:51:13 +0000
@@ -36,16 +36,17 @@
         self.label_source = wx.StaticText(self.panel_principal, -1, "Source:  ")
         self.text_ctrl_source = wx.TextCtrl(self.panel_principal, -1, "")
         self.label_rights = wx.StaticText(self.panel_principal, -1, "Rights:  ")
-        self.text_ctrl_rights = wx.TextCtrl(self.panel_principal, -1, "CC-BY http://creativecommons.org/licenses/by/3.0/";)
+        self.text_ctrl_rights = wx.TextCtrl(self.panel_principal, -1, "")
         self.label_relation = wx.StaticText(self.panel_principal, -1, "Relation:  ")
-        self.text_ctrl_relation = wx.TextCtrl(self.panel_principal, -1, "None")
+        self.text_ctrl_relation = wx.TextCtrl(self.panel_principal, -1, "")
         self.label_coverage = wx.StaticText(self.panel_principal, -1, "Coverage:  ")
-        self.text_ctrl_coverage = wx.TextCtrl(self.panel_principal, -1, "Universal")
+        self.text_ctrl_coverage = wx.TextCtrl(self.panel_principal, -1, "")
         self.label_contributors = wx.StaticText(self.panel_principal, -1, "Contributors:  ")
         self.text_ctrl_contributors = wx.TextCtrl(self.panel_principal, -1, "")
         self.label_ccd_definition = wx.StaticText(self.panel_principal, -1, "CCD definition class:  ")
         self.combo_box_ccd = wx.ComboBox(self.panel_principal, -1, choices=["CareEntryType", "AdminEntryType", "DemographicEntryType", "ClusterType", "ElementType", "SlotType"], style=wx.CB_DROPDOWN | wx.CB_SIMPLE | wx.CB_DROPDOWN | wx.CB_READONLY)
         self.button_about = wx.Button(self.panel_principal, -1, "&About")
+        self.button_save_config = wx.Button(self.panel_principal, -1, "Save config")
         self.button_help = wx.Button(self.panel_principal, wx.ID_HELP, "")
         self.button_generate = wx.Button(self.panel_principal, -1, "&Generate")
         self.button_1 = wx.Button(self.panel_principal, wx.ID_EXIT, "")
@@ -53,20 +54,33 @@
         self.__set_properties()
         self.__do_layout()
 
+        self.Bind(wx.EVT_TEXT, self.enable_save, self.text_ctrl_title)
+        self.Bind(wx.EVT_TEXT, self.enable_save, self.text_ctrl_description)
+        self.Bind(wx.EVT_CHOICE, self.enable_save, self.choice_lang)
+        self.Bind(wx.EVT_TEXT, self.enable_save, self.text_ctrl_creator)
+        self.Bind(wx.EVT_TEXT, self.enable_save, self.text_ctrl_publisher)
+        self.Bind(wx.EVT_TEXT, self.enable_save, self.text_ctrl_subject)
+        self.Bind(wx.EVT_TEXT, self.enable_save, self.text_ctrl_source)
+        self.Bind(wx.EVT_TEXT, self.enable_save, self.text_ctrl_rights)
+        self.Bind(wx.EVT_TEXT, self.enable_save, self.text_ctrl_relation)
+        self.Bind(wx.EVT_TEXT, self.enable_save, self.text_ctrl_coverage)
+        self.Bind(wx.EVT_TEXT, self.enable_save, self.text_ctrl_contributors)
         self.Bind(wx.EVT_BUTTON, self.about, self.button_about)
+        self.Bind(wx.EVT_BUTTON, self.save_config, self.button_save_config)
         self.Bind(wx.EVT_BUTTON, self.help, self.button_help)
         self.Bind(wx.EVT_BUTTON, self.generate, self.button_generate)
         self.Bind(wx.EVT_BUTTON, self.quit_program, self.button_1)
         # end wxGlade
 
-        cdg_extra.set_icon(self)
+        self.init_things()
+
 
     def __set_properties(self):
         # begin wxGlade: MainFrame.__set_properties
         self.SetTitle("Constraint Definition Generator")
         self.SetSize((800, 470))
         self.label_date.SetToolTipString("Defalts to current day.")
-        self.datepicker_ctrl_date.SetMinSize((105, 28))
+        self.datepicker_ctrl_date.SetMinSize((111, 28))
         self.choice_lang.SetItems(cdg_extra.get_lang_list())
         self.choice_lang.SetSelection(cdg_extra.get_lang_list().index('en-US') | 0)
         self.label_creator.SetToolTipString("Format emails as: Timothy W. Cook <timothywayne.cook@xxxxxxxxx>")
@@ -76,6 +90,7 @@
         self.label_contributors.SetToolTipString("Separate multiple contributors with a semi-colon and format them as:Eduardo Cesar <xcesar@xxxxxxxxx>; Luciana Cavalini <lutricav@xxxxxxxxx>")
         self.text_ctrl_contributors.SetToolTipString("Separate multiple contributors with a semi-colon and format them as:Eduardo Cesar <xcesar@xxxxxxxxx>; Luciana Cavalini <lutricav@xxxxxxxxx>")
         self.combo_box_ccd.SetSelection(0)
+        self.button_save_config.Enable(False)
         # end wxGlade
 
     def __do_layout(self):
@@ -133,6 +148,8 @@
         sizer_2.Add(self.combo_box_ccd, 0, wx.ALIGN_CENTER_VERTICAL, 0)
         sizer_3.Add(sizer_2, 1, wx.EXPAND, 0)
         sizer_2_copy.Add(self.button_about, 0, wx.ALIGN_BOTTOM, 0)
+        sizer_2_copy.Add((20, 20), 0, 0, 0)
+        sizer_2_copy.Add(self.button_save_config, 0, wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM, 0)
         sizer_2_copy.Add((20, 20), 1, wx.EXPAND, 1)
         sizer_2_copy.Add((20, 20), 0, 0, 0)
         sizer_2_copy.Add(self.button_help, 0, wx.ALIGN_BOTTOM, 0)
@@ -183,6 +200,13 @@
         # Show dialog
         cdg_extra.wrote_diag(self, ccd_id)
 
+    def init_things(self):
+
+        cdg_extra.set_icon(self)
+        self.c = cdg_custom.Config(self)
+        self.c.read_config()
+        self.c.set_panel_configs()
+        self.button_save_config.Disable()
 
     def about(self, event):  # wxGlade: MainFrame.<event_handler>
         cdg_extra.about_box(self)
@@ -197,4 +221,12 @@
     def quit_program(self, event):  # wxGlade: MainFrame.<event_handler>
         cdg_extra.quit_program(self)
 
+    def enable_save(self, event):  # wxGlade: MainFrame.<event_handler>
+        self.button_save_config.Enable()
+
+    def save_config(self, event):  # wxGlade: MainFrame.<event_handler>
+        self.c.get_panel_configs()
+        self.c.save_config()
+        self.button_save_config.Disable()
+
 # end of class MainFrame

=== modified file 'Generator/cdg/cdg_custom.py'
--- Generator/cdg/cdg_custom.py	2012-07-03 15:16:14 +0000
+++ Generator/cdg/cdg_custom.py	2012-07-07 01:51:13 +0000
@@ -1,5 +1,7 @@
 import os
+import sys
 import uuid
+import ConfigParser
 from xml.sax.saxutils import escape
 
 def generate_files(path, title, description, date, creator, contributor, language, publisher, subject, source, rights, relation, coverage, choice_definition):
@@ -126,3 +128,99 @@
 
     f.close()
     return ccd_id
+
+# TODO: Make a class to put the config part
+class Config(object):
+    def __init__(self, panel):
+        if sys.platform.startswith('linux'):
+            home = os.environ['HOME']
+        elif sys.platform.startswith('win'):
+            home = os.environ['HOMEPATH']
+        else:
+            home = './'
+            
+        self.configdir = home + '/.cdg-1.0'
+        self.configname = self.configdir + '/cdg.cfg'
+
+        self.panel = panel
+        
+
+        self.title = None
+        self.description = None
+        self.creator = None
+        self.contributor = None
+        
+        self.publisher = None
+        self.subject = None
+        self.source = None
+        self.rights = None
+        self.relation = None
+        self.coverage = None
+
+        self.config = ConfigParser.SafeConfigParser({
+                'title' : '',
+                'description' : '',
+                'creator' : '',
+                'contributor' : '',
+                'publisher' : '',
+                'subject' : '',
+                'source' : '',
+                'rights' : 'CC-BY http://creativecommons.org/licenses/by/3.0/',
+                'relation' : 'None',
+                'coverage' : 'Universal',
+                'language' : '76',
+                'choice_definition' : '0',
+                })
+
+    def read_config(self):
+        try:
+            if not self.config.read(self.configname):
+                self.make_config()
+        except:
+            self.save_config()
+
+
+    def make_config(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):
+        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')
+            self.config.write(configfile)
+
+        
+    def get_panel_configs(self):
+        self.config.set('DEFAULT', 'title', self.panel.text_ctrl_title.GetValue().encode('utf8'))
+        self.config.set('DEFAULT', 'description', self.panel.text_ctrl_description.GetValue().encode('utf8'))
+        self.config.set('DEFAULT', 'creator', self.panel.text_ctrl_creator.GetValue().encode('utf8'))
+        self.config.set('DEFAULT', 'contributor', self.panel.text_ctrl_contributors.GetValue().encode('utf8'))
+
+        self.config.set('DEFAULT', 'publisher', self.panel.text_ctrl_publisher.GetValue().encode('utf8'))
+        self.config.set('DEFAULT', 'subject', self.panel.text_ctrl_subject.GetValue().encode('utf8'))
+        self.config.set('DEFAULT', 'source', self.panel.text_ctrl_source.GetValue().encode('utf8'))
+        self.config.set('DEFAULT', 'rights', self.panel.text_ctrl_rights.GetValue().encode('utf8'))
+        self.config.set('DEFAULT', 'relation', self.panel.text_ctrl_relation.GetValue().encode('utf8'))
+        self.config.set('DEFAULT', 'coverage', self.panel.text_ctrl_coverage.GetValue().encode('utf8'))
+
+        self.config.set('DEFAULT', 'language', str(self.panel.choice_lang.GetSelection()))
+        self.config.set('DEFAULT', 'choice_definition', str(self.panel.combo_box_ccd.GetSelection()))
+
+    def set_panel_configs(self):
+        self.panel.text_ctrl_title.SetValue(self.config.get('DEFAULT', 'title'))
+        self.panel.text_ctrl_description.SetValue(self.config.get('DEFAULT', 'description'))
+        self.panel.text_ctrl_creator.SetValue(self.config.get('DEFAULT', 'creator'))
+        self.panel.text_ctrl_contributors.SetValue(self.config.get('DEFAULT', 'contributor'))
+
+        self.panel.text_ctrl_publisher.SetValue(self.config.get('DEFAULT', 'publisher'))
+        self.panel.text_ctrl_subject.SetValue(self.config.get('DEFAULT', 'subject'))
+        self.panel.text_ctrl_source.SetValue(self.config.get('DEFAULT', 'source'))
+        self.panel.text_ctrl_rights.SetValue(self.config.get('DEFAULT', 'rights'))
+        self.panel.text_ctrl_relation.SetValue(self.config.get('DEFAULT', 'relation'))
+        self.panel.text_ctrl_coverage.SetValue(self.config.get('DEFAULT', 'coverage'))
+
+        self.panel.choice_lang.SetSelection(int(self.config.get('DEFAULT', 'language')))
+        self.panel.combo_box_ccd.SetSelection(int(self.config.get('DEFAULT','choice_definition')))
+

=== modified file 'Generator/cdg/cdg_extra.py'
--- Generator/cdg/cdg_extra.py	2012-07-05 02:22:25 +0000
+++ Generator/cdg/cdg_extra.py	2012-07-07 01:51:13 +0000
@@ -100,6 +100,20 @@
     if result == wx.ID_OK:
         self.Destroy()
 
+def quit_program(self):
+    msg = "Are you sure you want to exit?"
+    icon = wx.ICON_QUESTION
+    if self.button_save_config.Enabled:
+        msg = "Configuration not saved!\nAre you sure you want to exit?"
+        icon = wx.ICON_EXCLAMATION
+
+    dlg = wx.MessageDialog(self, msg,
+                           "Quit", wx.OK|wx.CANCEL|icon)
+    result = dlg.ShowModal()
+    dlg.Destroy()
+    if result == wx.ID_OK:
+        self.Destroy()
+
 
 
 LICENSE = """

=== modified file 'Generator/cdg_wxglade.wxg'
--- Generator/cdg_wxglade.wxg	2012-07-05 02:22:25 +0000
+++ Generator/cdg_wxglade.wxg	2012-07-07 01:51:13 +0000
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<!-- generated by wxGlade 0.6.4 on Wed Jul  4 23:14:52 2012 -->
+<!-- generated by wxGlade 0.6.4 on Fri Jul  6 22:46:26 2012 -->
 
 <application path="cdg" name="" class="" option="1" 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="MainFrame" name="frame_principal" base="EditFrame">
@@ -60,6 +60,9 @@
                                             <border>1</border>
                                             <option>1</option>
                                             <object class="wxTextCtrl" name="text_ctrl_title" base="EditTextCtrl">
+                                                <events>
+                                                    <handler event="EVT_TEXT">enable_save</handler>
+                                                </events>
                                             </object>
                                         </object>
                                         <object class="sizeritem">
@@ -85,7 +88,7 @@
                                             <border>0</border>
                                             <option>0</option>
                                             <object class="wxDatePickerCtrl" name="datepicker_ctrl_date" base="EditDatePickerCtrl">
-                                                <size>105, 28</size>
+                                                <size>111, 28</size>
                                             </object>
                                         </object>
                                     </object>
@@ -111,6 +114,9 @@
                                             <option>1</option>
                                             <object class="wxTextCtrl" name="text_ctrl_description" base="EditTextCtrl">
                                                 <style>wxTE_MULTILINE</style>
+                                                <events>
+                                                    <handler event="EVT_TEXT">enable_save</handler>
+                                                </events>
                                             </object>
                                         </object>
                                         <object class="sizeritem">
@@ -138,6 +144,9 @@
                                                 <selection>0</selection>
                                                 <choices>
                                                 </choices>
+                                                <events>
+                                                    <handler event="EVT_CHOICE">enable_save</handler>
+                                                </events>
                                                 <extraproperties>
                                                     <property name="items">cdg_extra.get_lang_list()</property>
                                                     <property name="selection">cdg_extra.get_lang_list().index('en-US') | 0</property>
@@ -168,6 +177,9 @@
                                             <option>1</option>
                                             <object class="wxTextCtrl" name="text_ctrl_creator" base="EditTextCtrl">
                                                 <tooltip>Format emails as: Timothy W. Cook &lt;timothywayne.cook@xxxxxxxxx&gt;</tooltip>
+                                                <events>
+                                                    <handler event="EVT_TEXT">enable_save</handler>
+                                                </events>
                                             </object>
                                         </object>
                                         <object class="sizeritem">
@@ -193,6 +205,9 @@
                                             <option>1</option>
                                             <object class="wxTextCtrl" name="text_ctrl_publisher" base="EditTextCtrl">
                                                 <tooltip>Format emails as: Timothy W. Cook &lt;timothywayne.cook@xxxxxxxxx&gt;</tooltip>
+                                                <events>
+                                                    <handler event="EVT_TEXT">enable_save</handler>
+                                                </events>
                                             </object>
                                         </object>
                                         <object class="sizeritem">
@@ -218,6 +233,9 @@
                                             <option>1</option>
                                             <object class="wxTextCtrl" name="text_ctrl_subject" base="EditTextCtrl">
                                                 <tooltip>Format emails as: Timothy W. Cook &lt;timothywayne.cook@xxxxxxxxx&gt;</tooltip>
+                                                <events>
+                                                    <handler event="EVT_TEXT">enable_save</handler>
+                                                </events>
                                             </object>
                                         </object>
                                     </object>
@@ -242,6 +260,9 @@
                                             <border>1</border>
                                             <option>1</option>
                                             <object class="wxTextCtrl" name="text_ctrl_source" base="EditTextCtrl">
+                                                <events>
+                                                    <handler event="EVT_TEXT">enable_save</handler>
+                                                </events>
                                             </object>
                                         </object>
                                         <object class="sizeritem">
@@ -266,7 +287,9 @@
                                             <border>1</border>
                                             <option>1</option>
                                             <object class="wxTextCtrl" name="text_ctrl_rights" base="EditTextCtrl">
-                                                <value>CC-BY http://creativecommons.org/licenses/by/3.0/</value>
+                                                <events>
+                                                    <handler event="EVT_TEXT">enable_save</handler>
+                                                </events>
                                             </object>
                                         </object>
                                     </object>
@@ -291,7 +314,9 @@
                                             <border>1</border>
                                             <option>1</option>
                                             <object class="wxTextCtrl" name="text_ctrl_relation" base="EditTextCtrl">
-                                                <value>None</value>
+                                                <events>
+                                                    <handler event="EVT_TEXT">enable_save</handler>
+                                                </events>
                                             </object>
                                         </object>
                                         <object class="sizeritem">
@@ -316,7 +341,9 @@
                                             <border>1</border>
                                             <option>1</option>
                                             <object class="wxTextCtrl" name="text_ctrl_coverage" base="EditTextCtrl">
-                                                <value>Universal</value>
+                                                <events>
+                                                    <handler event="EVT_TEXT">enable_save</handler>
+                                                </events>
                                             </object>
                                         </object>
                                     </object>
@@ -343,6 +370,9 @@
                                             <option>1</option>
                                             <object class="wxTextCtrl" name="text_ctrl_contributors" base="EditTextCtrl">
                                                 <tooltip>Separate multiple contributors with a semi-colon and format them as:Eduardo Cesar &lt;xcesar@xxxxxxxxx&gt;; Luciana Cavalini &lt;lutricav@xxxxxxxxx&gt;</tooltip>
+                                                <events>
+                                                    <handler event="EVT_TEXT">enable_save</handler>
+                                                </events>
                                             </object>
                                         </object>
                                     </object>
@@ -399,6 +429,26 @@
                                             </object>
                                         </object>
                                         <object class="sizeritem">
+                                            <border>0</border>
+                                            <option>0</option>
+                                            <object class="spacer" name="spacer" base="EditSpacer">
+                                                <height>20</height>
+                                                <width>20</width>
+                                            </object>
+                                        </object>
+                                        <object class="sizeritem">
+                                            <flag>wxALIGN_RIGHT|wxALIGN_BOTTOM</flag>
+                                            <border>0</border>
+                                            <option>0</option>
+                                            <object class="wxButton" name="button_save_config" base="EditButton">
+                                                <label>Save config</label>
+                                                <disabled>1</disabled>
+                                                <events>
+                                                    <handler event="EVT_BUTTON">save_config</handler>
+                                                </events>
+                                            </object>
+                                        </object>
+                                        <object class="sizeritem">
                                             <flag>wxEXPAND</flag>
                                             <border>1</border>
                                             <option>1</option>
@@ -460,6 +510,7 @@
                                             <option>0</option>
                                             <object class="wxButton" name="button_1" base="EditButton">
                                                 <stockitem>EXIT</stockitem>
+                                                <label>&amp;Quit</label>
                                                 <events>
                                                     <handler event="EVT_BUTTON">quit_program</handler>
                                                 </events>