mlhim-specs-dev team mailing list archive
-
mlhim-specs-dev team
-
Mailing list archive
-
Message #00787
[Branch ~cdd-dev/cdd/trunk] Rev 300: Separated ConfigDialog and MetadataPanel from main program
------------------------------------------------------------
revno: 300
committer: Eduardo Ribeiro <xcesar@xxxxxxxxx>
branch nick: devel
timestamp: Tue 2013-01-22 00:58:54 -0200
message:
Separated ConfigDialog and MetadataPanel from main program
added:
src/2.0/config.py
src/2.0/metadata.py
modified:
src/2.0/cdd.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/2.0/cdd.py'
--- src/2.0/cdd.py 2013-01-22 02:58:35 +0000
+++ src/2.0/cdd.py 2013-01-22 02:58:54 +0000
@@ -23,8 +23,6 @@
import sys
import os
-import ConfigParser
-
import gettext
import subprocess
@@ -593,234 +591,6 @@
# end of class CareEntry
-class ConfigDialog(cdd_gui.ConfigDialog):
- def __init__(self, *args, **kwds):
- cdd_gui.ConfigDialog.__init__(self, *args, **kwds)
- self.init_things()
-
- def init_things(self):
- self.info = None
- self.init_config()
- self.read_config()
-
- # Binds the function to EVT_TIMER
- self.Bind(wx.EVT_TIMER, self.timer_worker)
-
- # Timer that calls a function at a regular time.
- self.timer = wx.Timer(self)
- time = int(self.config.get('DEFAULT', 'autosave'))
- if time > 0:
- self.timer.Start(time*100)
-
- def update_values(self):
- time = int(self.config.get('DEFAULT', 'autosave'))
- if time > 0:
- self.timer.Start(time*1000*60)
-
- def timer_worker(self, event=None):
- #TODO: Put the CDD automatic save routine here
- pass
-
-
- 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' : '5',
- 'workspace' : home + '/' + 'MLHIM2',
- 'rm_version' : '2.4.0',
- })
-
- if not os.path.isdir(self.configdir):
- try:
- os.mkdir(self.configdir)
- except:
- popup_message(None, 'Config directory NOT created.', 'Error creating config dir', wx.ICON_EXCLAMATION)
-
-
- def read_config(self):
- self.config.read(self.configname)
- self.set_panel_configs()
-
- def save_config(self):
- #self.get_panel_configs()
- try:
- 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)
- except IOError:
- popup_message(None, 'Config could not be saved.', 'Error saving config', wx.ICON_EXCLAMATION)
-
- self.set_config_info()
-
- 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'))
- self.config.set('DEFAULT', 'rm_version', self.text_ctrl_rm_version.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'))
- self.text_ctrl_rm_version.SetValue(self.config.get('DEFAULT', 'rm_version'))
-
- def test_workspace_dir(self, panel):
- workspace = self.config.get('DEFAULT', 'workspace')
- if not os.path.exists(workspace):
- dlg = wx.TextEntryDialog(panel, 'Please choose the workpspace directory.',
- 'Workspace', defaultValue=workspace)
- result = dlg.ShowModal()
- if result == wx.ID_OK:
- workspace = dlg.GetValue()
- self.config.set('DEFAULT', 'workspace', workspace)
- self.set_panel_configs()
- self.save_config()
- if not os.path.isdir(workspace):
- try:
- os.mkdir(workspace)
- except OSError:
- popup_message(None, 'Workspace directory NOT created.', 'Error creating workspace dir', wx.ICON_EXCLAMATION)
- dlg.Destroy()
-
-
- def set_config_info(self):
- # Sets the necessary config information in the info object
- if self.info:
- rm_version = self.config.get('DEFAULT', 'rm_version')
- self.info.get_config_info(rm_version)
-
-
-# end of class ConfigDialog
-
-class MetadataPanel(cdd_gui.MetadataPanel):
- def __init__(self, *args, **kwds):
- cdd_gui.MetadataPanel.__init__(self, *args, **kwds)
- self.init_things()
-
- def init_things(self):
- self.info = None
- self.init_config()
- self.read_config()
- self.button_ok.Disable()
-
- 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 + '/' + 'metadata.cfg'
-
- self.config = ConfigParser.SafeConfigParser({
- 'title' : '',
- 'description' : '',
- 'creator' : '',
- 'creator_email' : '',
- 'contributor' : '',
- 'publisher' : '',
- 'subject' : '',
- 'source' : '',
- 'rights' : 'CC-BY http://creativecommons.org/licenses/by/3.0/',
- 'relation' : 'None',
- 'coverage' : 'Universal',
- 'language' : '76',
- 'choice_definition' : '0',
- })
-
- if not os.path.isdir(self.configdir):
- try:
- os.mkdir(self.configdir)
- except:
- popup_message(None, 'Config directory NOT created.', 'Error creating config dir', wx.ICON_EXCLAMATION)
-
-
- def read_config(self):
- self.config.read(self.configname)
- self.set_panel_configs()
-
- def save_config(self, event=None): # wxGlade: MetadataPanel.<event_handler>
- self.get_panel_configs()
- try:
- 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)
- except IOError:
- popup_message(None, 'Config could not be saved.', 'Error saving config', wx.ICON_EXCLAMATION)
-
- self.set_meta_info()
- self.button_ok.Disable()
-
- def set_meta_info(self):
- # Sets the necessary metadata information in the info object
- if self.info:
- title = self.text_ctrl_title.GetValue().encode('utf8')
- description = self.text_ctrl_description.GetValue().encode('utf8')
- creator = self.text_ctrl_creator.GetValue().encode('utf8')
- creator_email = self.text_ctrl_creator_email.GetValue().encode('utf8')
- contributor = self.text_ctrl_contributors.GetValue().encode('utf8')
-
- publisher = self.text_ctrl_publisher.GetValue().encode('utf8')
- subject = self.text_ctrl_subject.GetValue().encode('utf8')
- source = self.text_ctrl_source.GetValue().encode('utf8')
- rights = self.text_ctrl_rights.GetValue().encode('utf8')
- relation = self.text_ctrl_relation.GetValue().encode('utf8')
- coverage = self.text_ctrl_coverage.GetValue().encode('utf8')
-
- language = self.choice_lang.GetStringSelection()
-
- tempo = self.datepicker_ctrl_date.GetValue()
- date = '{Y}-{M:02}-{D:02}'.format(Y=tempo.GetYear(), M=tempo.GetMonth()+1, D=tempo.GetDay())
-
- self.info.get_metadata_info(title, description, date, creator, creator_email, contributor, language, publisher, subject, source, rights, relation, coverage)
-
-
- def get_panel_configs(self):
- self.config.set('DEFAULT', 'title', self.text_ctrl_title.GetValue().encode('utf8'))
- self.config.set('DEFAULT', 'description', self.text_ctrl_description.GetValue().encode('utf8'))
- self.config.set('DEFAULT', 'creator', self.text_ctrl_creator.GetValue().encode('utf8'))
- self.config.set('DEFAULT', 'creator_email', self.text_ctrl_creator_email.GetValue().encode('utf8'))
- self.config.set('DEFAULT', 'contributor', self.text_ctrl_contributors.GetValue().encode('utf8'))
-
- self.config.set('DEFAULT', 'publisher', self.text_ctrl_publisher.GetValue().encode('utf8'))
- self.config.set('DEFAULT', 'subject', self.text_ctrl_subject.GetValue().encode('utf8'))
- self.config.set('DEFAULT', 'source', self.text_ctrl_source.GetValue().encode('utf8'))
- self.config.set('DEFAULT', 'rights', self.text_ctrl_rights.GetValue().encode('utf8'))
- self.config.set('DEFAULT', 'relation', self.text_ctrl_relation.GetValue().encode('utf8'))
- self.config.set('DEFAULT', 'coverage', self.text_ctrl_coverage.GetValue().encode('utf8'))
-
- self.config.set('DEFAULT', 'language', str(self.choice_lang.GetSelection()))
-
- def set_panel_configs(self):
- self.text_ctrl_title.SetValue(self.config.get('DEFAULT', 'title'))
- self.text_ctrl_description.SetValue(self.config.get('DEFAULT', 'description'))
- self.text_ctrl_creator.SetValue(self.config.get('DEFAULT', 'creator'))
- self.text_ctrl_creator_email.SetValue(self.config.get('DEFAULT', 'creator_email'))
- self.text_ctrl_contributors.SetValue(self.config.get('DEFAULT', 'contributor'))
-
- self.text_ctrl_publisher.SetValue(self.config.get('DEFAULT', 'publisher'))
- self.text_ctrl_subject.SetValue(self.config.get('DEFAULT', 'subject'))
- self.text_ctrl_source.SetValue(self.config.get('DEFAULT', 'source'))
- self.text_ctrl_rights.SetValue(self.config.get('DEFAULT', 'rights'))
- self.text_ctrl_relation.SetValue(self.config.get('DEFAULT', 'relation'))
- self.text_ctrl_coverage.SetValue(self.config.get('DEFAULT', 'coverage'))
-
- self.choice_lang.SetSelection(int(self.config.get('DEFAULT', 'language')))
-
- def enable_ok(self, event): # wxGlade: MetadataPanel.<event_handler>
- self.button_ok.Enable()
-
-# end of class MetadataPanel
-
class MainFrame(cdd_gui.MainFrame):
def __init__(self, *args, **kwds):
cdd_gui.MainFrame.__init__(self, *args, **kwds)
@@ -1192,6 +962,12 @@
UnderConstruction = cdd_gui.UnderConstruction
+import metadata
+MetadataPanel = metadata.MetadataPanel
+
+import config
+ConfigDialog = config.ConfigDialog
+
# Object that retains all information necessary to create the cdd
import info
info = info.Info()
=== added file 'src/2.0/config.py'
--- src/2.0/config.py 1970-01-01 00:00:00 +0000
+++ src/2.0/config.py 2013-01-22 02:58:54 +0000
@@ -0,0 +1,112 @@
+import sys
+import os
+import ConfigParser
+
+import wx
+
+import cdd_gui
+
+class ConfigDialog(cdd_gui.ConfigDialog):
+ def __init__(self, *args, **kwds):
+ cdd_gui.ConfigDialog.__init__(self, *args, **kwds)
+ self.init_things()
+
+ def init_things(self):
+ self.info = None
+ self.init_config()
+ self.read_config()
+
+ # Binds the function to EVT_TIMER
+ self.Bind(wx.EVT_TIMER, self.timer_worker)
+
+ # Timer that calls a function at a regular time.
+ self.timer = wx.Timer(self)
+ time = int(self.config.get('DEFAULT', 'autosave'))
+ if time > 0:
+ self.timer.Start(time*100)
+
+ def update_values(self):
+ time = int(self.config.get('DEFAULT', 'autosave'))
+ if time > 0:
+ self.timer.Start(time*1000*60)
+
+ def timer_worker(self, event=None):
+ #TODO: Put the CDD automatic save routine here
+ pass
+
+
+ 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' : '5',
+ 'workspace' : home + '/' + 'MLHIM2',
+ 'rm_version' : '2.4.0',
+ })
+
+ if not os.path.isdir(self.configdir):
+ try:
+ os.mkdir(self.configdir)
+ except:
+ popup_message(None, 'Config directory NOT created.', 'Error creating config dir', wx.ICON_EXCLAMATION)
+
+
+ def read_config(self):
+ self.config.read(self.configname)
+ self.set_panel_configs()
+
+ def save_config(self):
+ #self.get_panel_configs()
+ try:
+ 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)
+ except IOError:
+ popup_message(None, 'Config could not be saved.', 'Error saving config', wx.ICON_EXCLAMATION)
+
+ self.set_config_info()
+
+ 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'))
+ self.config.set('DEFAULT', 'rm_version', self.text_ctrl_rm_version.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'))
+ self.text_ctrl_rm_version.SetValue(self.config.get('DEFAULT', 'rm_version'))
+
+ def test_workspace_dir(self, panel):
+ workspace = self.config.get('DEFAULT', 'workspace')
+ if not os.path.exists(workspace):
+ dlg = wx.TextEntryDialog(panel, 'Please choose the workpspace directory.',
+ 'Workspace', defaultValue=workspace)
+ result = dlg.ShowModal()
+ if result == wx.ID_OK:
+ workspace = dlg.GetValue()
+ self.config.set('DEFAULT', 'workspace', workspace)
+ self.set_panel_configs()
+ self.save_config()
+ if not os.path.isdir(workspace):
+ try:
+ os.mkdir(workspace)
+ except OSError:
+ popup_message(None, 'Workspace directory NOT created.', 'Error creating workspace dir', wx.ICON_EXCLAMATION)
+ dlg.Destroy()
+
+
+ def set_config_info(self):
+ # Sets the necessary config information in the info object
+ if self.info:
+ rm_version = self.config.get('DEFAULT', 'rm_version')
+ self.info.get_config_info(rm_version)
+
+# end of class ConfigDialog
=== added file 'src/2.0/metadata.py'
--- src/2.0/metadata.py 1970-01-01 00:00:00 +0000
+++ src/2.0/metadata.py 2013-01-22 02:58:54 +0000
@@ -0,0 +1,127 @@
+import sys
+import os
+import ConfigParser
+
+import cdd_gui
+
+class MetadataPanel(cdd_gui.MetadataPanel):
+ def __init__(self, *args, **kwds):
+ cdd_gui.MetadataPanel.__init__(self, *args, **kwds)
+ self.init_things()
+
+ def init_things(self):
+ self.info = None
+ self.init_config()
+ self.read_config()
+ self.button_ok.Disable()
+
+ 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 + '/' + 'metadata.cfg'
+
+ self.config = ConfigParser.SafeConfigParser({
+ 'title' : '',
+ 'description' : '',
+ 'creator' : '',
+ 'creator_email' : '',
+ 'contributor' : '',
+ 'publisher' : '',
+ 'subject' : '',
+ 'source' : '',
+ 'rights' : 'CC-BY http://creativecommons.org/licenses/by/3.0/',
+ 'relation' : 'None',
+ 'coverage' : 'Universal',
+ 'language' : '76',
+ 'choice_definition' : '0',
+ })
+
+ if not os.path.isdir(self.configdir):
+ try:
+ os.mkdir(self.configdir)
+ except:
+ popup_message(None, 'Config directory NOT created.', 'Error creating config dir', wx.ICON_EXCLAMATION)
+
+
+ def read_config(self):
+ self.config.read(self.configname)
+ self.set_panel_configs()
+
+ def save_config(self, event=None): # wxGlade: MetadataPanel.<event_handler>
+ self.get_panel_configs()
+ try:
+ 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)
+ except IOError:
+ popup_message(None, 'Config could not be saved.', 'Error saving config', wx.ICON_EXCLAMATION)
+
+ self.set_meta_info()
+ self.button_ok.Disable()
+
+ def set_meta_info(self):
+ # Sets the necessary metadata information in the info object
+ if self.info:
+ title = self.text_ctrl_title.GetValue().encode('utf8')
+ description = self.text_ctrl_description.GetValue().encode('utf8')
+ creator = self.text_ctrl_creator.GetValue().encode('utf8')
+ creator_email = self.text_ctrl_creator_email.GetValue().encode('utf8')
+ contributor = self.text_ctrl_contributors.GetValue().encode('utf8')
+
+ publisher = self.text_ctrl_publisher.GetValue().encode('utf8')
+ subject = self.text_ctrl_subject.GetValue().encode('utf8')
+ source = self.text_ctrl_source.GetValue().encode('utf8')
+ rights = self.text_ctrl_rights.GetValue().encode('utf8')
+ relation = self.text_ctrl_relation.GetValue().encode('utf8')
+ coverage = self.text_ctrl_coverage.GetValue().encode('utf8')
+
+ language = self.choice_lang.GetStringSelection()
+
+ tempo = self.datepicker_ctrl_date.GetValue()
+ date = '{Y}-{M:02}-{D:02}'.format(Y=tempo.GetYear(), M=tempo.GetMonth()+1, D=tempo.GetDay())
+
+ self.info.get_metadata_info(title, description, date, creator, creator_email, contributor, language, publisher, subject, source, rights, relation, coverage)
+
+
+ def get_panel_configs(self):
+ self.config.set('DEFAULT', 'title', self.text_ctrl_title.GetValue().encode('utf8'))
+ self.config.set('DEFAULT', 'description', self.text_ctrl_description.GetValue().encode('utf8'))
+ self.config.set('DEFAULT', 'creator', self.text_ctrl_creator.GetValue().encode('utf8'))
+ self.config.set('DEFAULT', 'creator_email', self.text_ctrl_creator_email.GetValue().encode('utf8'))
+ self.config.set('DEFAULT', 'contributor', self.text_ctrl_contributors.GetValue().encode('utf8'))
+
+ self.config.set('DEFAULT', 'publisher', self.text_ctrl_publisher.GetValue().encode('utf8'))
+ self.config.set('DEFAULT', 'subject', self.text_ctrl_subject.GetValue().encode('utf8'))
+ self.config.set('DEFAULT', 'source', self.text_ctrl_source.GetValue().encode('utf8'))
+ self.config.set('DEFAULT', 'rights', self.text_ctrl_rights.GetValue().encode('utf8'))
+ self.config.set('DEFAULT', 'relation', self.text_ctrl_relation.GetValue().encode('utf8'))
+ self.config.set('DEFAULT', 'coverage', self.text_ctrl_coverage.GetValue().encode('utf8'))
+
+ self.config.set('DEFAULT', 'language', str(self.choice_lang.GetSelection()))
+
+ def set_panel_configs(self):
+ self.text_ctrl_title.SetValue(self.config.get('DEFAULT', 'title'))
+ self.text_ctrl_description.SetValue(self.config.get('DEFAULT', 'description'))
+ self.text_ctrl_creator.SetValue(self.config.get('DEFAULT', 'creator'))
+ self.text_ctrl_creator_email.SetValue(self.config.get('DEFAULT', 'creator_email'))
+ self.text_ctrl_contributors.SetValue(self.config.get('DEFAULT', 'contributor'))
+
+ self.text_ctrl_publisher.SetValue(self.config.get('DEFAULT', 'publisher'))
+ self.text_ctrl_subject.SetValue(self.config.get('DEFAULT', 'subject'))
+ self.text_ctrl_source.SetValue(self.config.get('DEFAULT', 'source'))
+ self.text_ctrl_rights.SetValue(self.config.get('DEFAULT', 'rights'))
+ self.text_ctrl_relation.SetValue(self.config.get('DEFAULT', 'relation'))
+ self.text_ctrl_coverage.SetValue(self.config.get('DEFAULT', 'coverage'))
+
+ self.choice_lang.SetSelection(int(self.config.get('DEFAULT', 'language')))
+
+ def enable_ok(self, event): # wxGlade: MetadataPanel.<event_handler>
+ self.button_ok.Enable()
+
+# end of class MetadataPanel