本文整理汇总了Python中CDMLib.dlgErrorMsg方法的典型用法代码示例。如果您正苦于以下问题:Python CDMLib.dlgErrorMsg方法的具体用法?Python CDMLib.dlgErrorMsg怎么用?Python CDMLib.dlgErrorMsg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDMLib
的用法示例。
在下文中一共展示了CDMLib.dlgErrorMsg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DeleteProjectRecord
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def DeleteProjectRecord(self):
""" Delete the Project record pointed on in the list"""
index = self.lc_project.GetFirstSelected()
if index in [ -1, 0 ]: # -1 : nothing selected, 0 : or selected 'New Project'
return
msg = 'Selected project will be deleted permanently.\n'
msg += 'Are you sure you want to delete the selected project?'
ans = cdml.dlgSimpleMsg('WARNING', msg, wx.YES_NO, wx.ICON_WARNING, Parent = self)
if ans == wx.ID_NO: return
ProjectIndex = self.lc_project.GetItemData(index)
pid = self.IndexToPID[ProjectIndex]
if pid not in DB.Projects.keys(): return
try:
DB.Projects.Delete(pid) # delete database object
self.ShowProjectList()
# set the focus on the next record after the deleted one
self.lc_project.Select(index)
except:
cdml.dlgErrorMsg(Parent = self)
示例2: ImportCSV
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def ImportCSV(self):
""" Import Population Data from a CSV file"""
wildcard = "CSV File (*.csv)|*.csv| All files (*.*)|*.*"
dialog = wx.FileDialog(None, "Choose a file", os.getcwd(), "", wildcard, wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
try:
(DataColumns, Data) = DB.ImportDataFromCSV(dialog.GetPath())
Objectives = [] # currently no objectives imported
# Make sure that DataColumns is composed of strings
# alone and not numbers or other data types
# this is a minimal precaution - no other validity checks
# are made other than what made in ImportDataFromCSV
AllStrings = all(map(lambda (ColumnName,Distribution): DB.IsStr(ColumnName), DataColumns))
if not AllStrings:
raise ValueError, 'Error Loading CSV file - headers are not all strings'
except:
cdml.dlgErrorMsg(Parent = self)
else:
# set the HasDistribution flag to False since loading
# a distribution is not currently supported.
self.HasDistribution = False
self.lc_dist.Enable(not self.HasDistribution)
self.tc_dist_text.Enable(not self.HasDistribution)
# also load this data to the object
self.ShowTabData()
self.DataColumns = DataColumns
self.Data = Data
self.Objectives = Objectives
self.ShowData(DataColumns, Data, Objectives)
self.Raise()
dialog.Destroy() # Destroy file selection dialog
示例3: LoadReportOptions
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def LoadReportOptions(self):
""" Load report options from file"""
path = self.GetReportOptionsFileName(wx.FD_OPEN)
if path != None:
try:
BackupFormatOptions = copy.deepcopy(self.FormatOptions)
FormatOptions = DB.LoadOptionList(path)
KeyFilterOptionValue = DB.HandleOption('KeyFilter', self.FormatOptions, Value = None, UseNewValue = False, DeleteThisOption = False)
if KeyFilterOptionValue != None:
DB.HandleOption('KeyFilter', FormatOptions, Value = KeyFilterOptionValue, UseNewValue = True, DeleteThisOption = False)
# now load the data to the controls to reflect the newly loaded data
# note that not validity checks are made, so if the file loaded
# properly and had bad data this may be reflected as bad text in
# the control or even raise an error that can be caught. Since this
# is not disruptive to data stored in the system no additional
# checks are made beyond what the system will allow in the controls
self.PopulateOptionsOnScreen(FormatOptions)
# now after data was updated update self with the new options
self.FormatOptions = FormatOptions
# Everything went fine - no need for backup anymore
BackupFormatOptions = None
except:
cdml.dlgErrorMsg(Parent = self)
if BackupFormatOptions != None:
try:
# in case of a bad file or an error, restore blank values
self.PopulateOptionsOnScreen(BackupFormatOptions)
except:
answer = cdml.dlgErrorMsg(msg_prefix='ASSERTION ERROR: Unable to recover from Error. Here are additional details: ',yesno=True, Parent = self)
if answer == wx.ID_YES :
return
else:
cdml.CloseForm(self, False)
return
示例4: DelSimResult
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def DelSimResult(self, event):
id = event.GetId()
try:
if id == wx.ID_DELETE:
id = self.cc_id_sim.GetValue() # Retrieve simulation ID from combo box
if id == "":
cdml.dlgSimpleMsg("ERROR", "No Result ID was selected", Parent=self)
return
if self.cc_id_sim.GetCount() == 1:
msg = "This is the last simulation result. "
msg += "After deleting this result, the form will be closed automatically."
msg += "\nDo you want to continue?"
ans = cdml.dlgSimpleMsg("WARNING", msg, wx.YES_NO, wx.ICON_WARNING, Parent=self)
if ans == wx.ID_NO:
return
id_sim = int(id)
target_id = [
result.ID
for result in DB.SimulationResults.values()
if result.ID == id_sim and result.ProjectID == self.idPrj
]
if target_id == []:
return
DB.SimulationResults.Delete(target_id[0], ProjectBypassID=self.idPrj)
self.cc_id_sim.Delete(self.cc_id_sim.GetSelection())
self.grid.ClearGrid()
if self.cc_id_sim.GetCount() == 0:
self.cc_id_sim.Clear()
self.cc_id_sim.SetValue("")
else:
self.cc_id_sim.SetSelection(0)
self.ShowSimResult()
else:
for result in DB.SimulationResults.values():
if result.ProjectID != self.idPrj:
continue
DB.SimulationResults.Delete(result.ID, ProjectBypassID=self.idPrj)
self.cc_id_sim.Clear()
self.cc_id_sim.SetValue("")
self.grid.ClearGrid() # Clear current values in grid control
except:
cdml.dlgErrorMsg()
示例5: ChangeSimulaionRules
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def ChangeSimulaionRules(self, event):
""" Add/Remove simulation rules when user click up/down button"""
id_btn = event.GetId()
lc = getattr( self, 'tab' + str(self.curPage) + '_list' )
index = lc.GetFirstSelected()
try :
list_rules = getattr(self, 'SimRule')[self.curPage]
if id_btn == wx.ID_ADD: # UP ARROW - Add/Insert a rule
if index == -1 : index = lc.GetItemCount()
rule = []
no_blank = 0
for i in range(3):
cc = getattr(self, 'combo_box_'+str(i+1))
rule.append( str(cc.GetValueString()) )
if rule[i] == '' : no_blank += 1
if no_blank == 3 : return # no rules are set in the combo boxes
notes = str(self.tc_notes_rule.GetValue())
new_rule = DB.SimulationRule(rule[0], self.curPage, rule[1], rule[2], notes)
list_rules.insert(index, new_rule)
lc.AddItem((rule[0], rule[1], rule[2], notes, -1), index)
# Do not clear panel so that it can be used as a clipboard
# for copy operations.
#self.ClearPanel(self.panel_combo)
else: # DOWN ARROW - Remove a rule
if index == -1 : return
# the new implementation is:
# get the information from the list_rules buffer rather than
# from the listbox in the screen.
cur_rule = [str(list_rules[index].AffectedParam), str(list_rules[index].OccurrenceProbability), str(list_rules[index].AppliedFormula), str(list_rules[index].Notes) ]
for i in range(3):
cc = getattr(self, 'combo_box_' + str(i+1))
cc.GetTextCtrl().SetValue(cur_rule[i])
self.tc_notes_rule.SetValue(cur_rule[-1])
list_rules.pop(index)
lc.DeleteItem(index)
if len(list_rules) > index:
lc.Select(index, True)
except:
cdml.dlgErrorMsg(Parent = self)
示例6: OpenDB
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def OpenDB(self, menuId):
if DB.AccessDirtyStatus():
ans = cdml.dlgSimpleMsg('WARNING', "The data is not saved in a file. Do you want to save it?", wx.YES_NO|wx.CANCEL, wx.ICON_WARNING, Parent = self)
if ans == wx.ID_YES :
if not self.SaveDB(wx.ID_SAVE): return
if ans == wx.ID_CANCEL:
return
if menuId == wx.ID_NEW: # if New menu selected,
path = os.getcwd() + os.sep + 'new_file.zip' # set dummy path
else:
path = self.GetNameDB(wx.OPEN) # else get database name
if path == None : return
if not os.path.isfile(path):
cdml.dlgSimpleMsg('ERROR', 'The file does not exist, please make sure the path is valid', Parent = self)
return
wx.BeginBusyCursor()
reload(DB)
try:
if os.path.isfile(path):
# test the version of the file:
(FileVersion, IsCompatible, IsUpgradable, DidLoad, HasResults) = DB.ReconstructDataFileAndCheckCompatibility(InputFileName = path, JustCheckCompatibility = True, RegenerationScriptName = None, ConvertResults = False, KnownNumberOfErrors = 0, CatchError = True)
if IsCompatible:
# If versions are compatible, just load the file
DB.LoadAllData(path) # If Open menu, load data
elif IsUpgradable:
if HasResults:
wx.EndBusyCursor()
AnswerForConvertResults = cdml.dlgSimpleMsg('Data Conversion', 'This file was generated with an older version of data definitions.: ' + str(FileVersion) + '. It was converted to the new version ' + str (DB.Version) + ' . Converting simulation results may take a long time and such results may not be reproducible with the current version. Even if simulation results are not loaded, the parameters, states, models, Population sets and projects will be loaded.\nDo you wish to convert simulation results from this file? ', wx.YES_NO, wx.ICON_QUESTION, Parent = self)
AnswerForConvertResultsBoolean = AnswerForConvertResults == wx.ID_YES
wx.BeginBusyCursor()
else:
AnswerForConvertResultsBoolean = False
print '*** Converting file to the new version. Please wait - this may take a while ***'
# if a version upgrade is needed, convert the data
(FileVersion, IsCompatible, IsUpgradable, DidLoad, HasResults) = DB.ReconstructDataFileAndCheckCompatibility(InputFileName = path, JustCheckCompatibility = False, RegenerationScriptName = None, ConvertResults = AnswerForConvertResultsBoolean, KnownNumberOfErrors = 0, CatchError = True)
self.ShowProjectList(None)
self.SetTitle("MIST - " + path)
self._db_opened = True
self._path = path
except:
cdml.dlgErrorMsg(Parent = self)
wx.EndBusyCursor()
示例7: OnClose
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def OnClose(self, event):
""" Event handler activated when this dialog is closed"""
if event.GetId() == wx.ID_OK:
type_wizard = cdml.iif( 'Cost' in self.cb_type.GetValue(), 0, 1)
ival = self.ed_ival.GetValue()
coef, val = [], []
item_num = self.lc_vector.GetItemCount()
for i in range(item_num):
coef.append(str(self.lc_vector.GetItem(i,0).GetText()))
val.append(str(self.lc_vector.GetItem(i,1).GetText()))
wizard_output = [ type_wizard, ival, coef, val ]
try :
CostWizardOutput = DB.ConstructCostWizardString(wizard_output)
cdml.SetRefreshInfo(self, '', CostWizardOutput)
except:
CostWizardOutput = None
ans = cdml.dlgErrorMsg(0, True, Parent = self)
if ans == wx.ID_YES : return
cdml.CloseForm(self, True, '', CostWizardOutput)
else:
cdml.CloseForm(self, False)
示例8: CopyProject
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def CopyProject(self):
""" Copies project and refreshes the form accordingly with the copied Data """
# It is assumed that the data is saved
# Eclose the copying in a try statement just in case of an error
copy_ok = False
try:
new_record = DB.Projects.Copy(self.idPrj)
copy_ok = True
except:
cdml.dlgErrorMsg(Parent = self)
if copy_ok:
self.idPrj = new_record.ID
self.Initialize()
return copy_ok
示例9: CopyProjectRecord
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def CopyProjectRecord(self):
""" Delete the Project record pointed on in the list"""
index = self.lc_project.GetFirstSelected()
if index in [ -1, 0 ]: # -1 : nothing selected, 0 : or selected 'New Project'
return
ProjectIndex = self.lc_project.GetItemData(index)
pid = self.IndexToPID[ProjectIndex]
if pid not in DB.Projects.keys(): return
try:
DB.Projects.Copy(pid)
self.ShowProjectList()
except:
cdml.dlgErrorMsg(Parent = self)
示例10: SaveDB
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def SaveDB(self, menuId=wx.ID_SAVE):
""" Save current database. If current database is new one, remove asterisk(*) from title"""
if not self._db_opened : return
if menuId == wx.ID_SAVEAS or (self._path == (os.getcwd() + os.sep + 'new_file.zip')):
path = self.GetNameDB(wx.SAVE)
if path == None: return False
self._path = path # replace previous path with current path
try:
DB.SaveAllData(FileName = self._path, Overwrite = True, CompressFile = True, CreateBackupBeforeSave = True)
except:
(ExceptType, ExceptValue, ExceptTraceback) = sys.exc_info()
cdml.dlgErrorMsg(Parent = self)
self.SetTitle('MIST - ' + self._path)
return True
示例11: SaveReportOptions
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def SaveReportOptions(self):
""" Save report options to file"""
FormatOptions = self.ExtractReportOptions()
if FormatOptions != None:
# filter out the KeyFilter options since it is internal to the system
# and should not be loaded or saved
FormatOptionModified = DB.HandleOption('KeyFilter', FormatOptions, Value = None, UseNewValue = False, DeleteThisOption = True)
if FormatOptionModified == None:
# if KeyFilter did not exist, then use the original OptionList
FormatOptionModified = FormatOptions
# get path name
path = self.GetReportOptionsFileName(wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
if path != None:
try:
DB.SaveOptionList(path,FormatOptionModified)
except:
cdml.dlgErrorMsg(Parent = self)
return
示例12: OnMenuSelected
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def OnMenuSelected(self, event):
""" Do something when action buttons are clicked.
Action buttons are Save, Run Simulation, View Result and Close"""
menuId = event.GetId()
evtType = event.GetEventType()
if evtType==wx.wxEVT_COMMAND_MENU_SELECTED:
if menuId not in [cdml.ID_MENU_REPORT_ALL]:
# Use the default handler first and if no more processing needed return
if cdml.OnMenuSelected(self, event):
return
try:
# In any case, if a button - Save, Run, View Result - is clicked, data will be save
save_ok = self.CheckData()
if evtType == wx.wxEVT_CLOSE_WINDOW: # Close Window Event
#cdml.CloseForm(self, True, self.Collection, self.idPrj)
cdml.CloseForm(self, True)
return
elif menuId == cdml.ID_MENU_COPY_RECORD:
copy_ok = self.CopyProject()
if not copy_ok: return
cdml.dlgSimpleMsg('INFO', 'The project has been successfully copied - you are now working on the new copy', wx.OK, wx.ICON_INFORMATION, Parent = self)
elif menuId == wx.ID_SAVE :
if not save_ok: return
cdml.dlgSimpleMsg('INFO', 'The project data has been saved successfully', wx.OK, wx.ICON_INFORMATION, Parent = self)
elif menuId == wx.ID_APPLY: # Run Simulation
self.RunSimulation()
elif menuId == wx.ID_VIEW_DETAILS: # View Results / Extract PopulationSets
self.ShowSimResult()
elif menuId == wx.ID_CLEAR:
result_ids = [ result.ID for result in DB.SimulationResults.values()
if result.ProjectID == self.idPrj ]
if result_ids == [] :
cdml.dlgSimpleMsg('ERROR', "There are no simulation results for this project", Parent = self)
else:
ans = cdml.dlgSimpleMsg('WARNING', 'Simulation results will be deleted permanently.\nDo you want to continue with deletion?', wx.YES_NO, wx.ICON_WARNING, Parent = self)
if ans == wx.ID_NO: return
for id in result_ids:
DB.SimulationResults.Delete(id, ProjectBypassID = self.idPrj)
cdml.dlgSimpleMsg('INFO', 'All simulation results were deleted', wx.OK, wx.ICON_INFORMATION, Parent = self)
except:
(ExceptType, ExceptValue, ExceptTraceback) = sys.exc_info()
need_ans = cdml.iif(evtType == wx.wxEVT_CLOSE_WINDOW, True, False)
if cdml.dlgErrorMsg(yesno=need_ans, Parent = self) == wx.ID_NO:
cdml.CloseForm(self, False)
示例13: AddObjective
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def AddObjective(self):
"Adds an objective to the objectives list box"
obj_filter_expr_txt = str(self.tc_obj_filter_expr.GetValue())
obj_stat_expr_txt = str(self.tc_obj_stat_expr.GetValue())
obj_stat_func = str(self.cc_obj_stat_func.GetTextCtrl().GetValue())
obj_target_txt = str(self.tc_obj_target.GetValue())
obj_weight_txt = str(self.tc_obj_weight.GetValue())
# Validate that this is a valid entry
try:
ErrorControl = "Filter Expression"
obj_filter_expr = DB.Expr(obj_filter_expr_txt)
ErrorControl = "Statistics Expression"
obj_stat_expr = DB.Expr(obj_stat_expr_txt)
ErrorControl = "Statistics Function"
if obj_stat_func.strip() == '':
raise ValueError, 'Empty statistics function cannot be used'
ErrorControl = "Target Value"
obj_target = float(obj_target_txt)
if not DB.IsFinite(obj_target):
raise ValueError, 'Target Value must be finite'
ErrorControl = "Weight"
obj_weight = float(obj_weight_txt)
if not DB.IsFinite(obj_weight):
raise ValueError, 'Weight Value must be finite'
except:
cdml.dlgErrorMsg(msg_prefix = 'Error detected while processing ' + ErrorControl + ': ', Parent = self)
return
# If this point was reached, then the objective is ok
# Add new the new objective to the list in the appropriate place
idx = self.lc_objectives.GetFirstSelected()
if idx == -1 : idx = self.lc_objectives.GetItemCount()
ItemToAdd = (obj_filter_expr, obj_stat_expr, obj_stat_func, obj_target, obj_weight, None, None)
# add to display
self.lc_objectives.AddItem(ItemToAdd, idx, False)
# update the objectives - this duality is needed for windows systems
# that store only 512 characters in a listbox
self.Objectives.insert(idx, ItemToAdd)
示例14: ExportCSV
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def ExportCSV(self, DataColumns, Data ):
""" Export Population Data from a CSV file"""
wildcard = "CSV File (*.csv)|*.csv| All files (*.*)|*.*"
dialog = wx.FileDialog(None, "Choose a file name to save the data", os.getcwd(), "", wildcard, wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
if dialog.ShowModal() == wx.ID_OK:
try:
# convert the columns from tuples to strings
ColumnHeadersToUse = map(lambda (ColumnName , Distribution) : ColumnName, DataColumns)
DB.ExportDataToCSV(dialog.GetPath(), Data, ColumnHeadersToUse)
except:
cdml.dlgErrorMsg(Parent = self)
else:
# successfully saved the exported data
cdml.dlgSimpleMsg('INFO', 'The data has been successfully saved to file', wx.OK, wx.ICON_INFORMATION, Parent = self)
self.Raise()
dialog.Destroy() # Destroy file selection dialog
示例15: OnButtonClick
# 需要导入模块: import CDMLib [as 别名]
# 或者: from CDMLib import dlgErrorMsg [as 别名]
def OnButtonClick(self, event):
""" Event handler for buttons """
btn_id = event.GetId()
try:
if btn_id == cdml.IDF_BUTTON2: # Import
self.ImportCSV()
if btn_id == cdml.IDF_BUTTON3: # Export
try:
self.SaveData()
self.ShowData(self.DataColumns, self.Data, self.Objectives)
except :
cdml.dlgErrorMsg(Parent = self)
else:
if self.Data == []:
cdml.dlgSimpleMsg('INFO', 'No data has been defined so exporting makes no sense', wx.OK, wx.ICON_INFORMATION, Parent = self)
else:
self.ExportCSV(self.DataColumns, self.Data)
elif btn_id == cdml.IDF_BUTTON4 : # Undo
self.Undo()
elif btn_id == cdml.IDF_BUTTON5 or \
event.GetEventType() == wx.wxEVT_CLOSE_WINDOW : # Ok or Close
try:
self.SaveData()
except :
cdml.dlgErrorMsg(Parent = self)
else :
cdml.CloseForm(self, False)
elif btn_id == wx.ID_ADD: # Up Arrow : Add new State/Distribution
self.AddColumn()
elif btn_id == wx.ID_DELETE: # Down Arrow : Delete State/Distribution
self.DeleteColumn()
elif btn_id == cdml.IDF_BUTTON7: # Down Arrow in objective pane
self.DeleteObjective()
elif btn_id == cdml.IDF_BUTTON8: # Up Arrow in objective pane
self.AddObjective()
except:
cdml.dlgErrorMsg(Parent = self)