def trainKNN(self, classData, dialog, metric):
ks = np.arange(1,10)
trainAUC = np.zeros(ks.shape)
validAUC = np.zeros(ks.shape)
partitionGenerator = ml.part.classRandomSubSample(classData,
self.trainFrac, self.nFold)
for fold, trainData, validData in partitionGenerator:
dialog.Update(fold, 'Validation Fold: %d' % fold)
for i, k in enumerate(ks):
classifier = ml.KNN(trainData, k=k, distMetric=metric)
trainAUC[i] += classifier.auc(trainData)
validAUC[i] += classifier.auc(validData)
dialog.Update(self.nFold, 'Training Final Classifier')
trainAUC /= self.nFold
validAUC /= self.nFold
print 'train AUC: ', trainAUC
print 'valid AUC: ', validAUC
bestK = ks[np.argmax(validAUC)]
print 'best K: ', bestK
self.classifier = ml.KNN(classData, k=bestK, distMetric=metric)
finalAUC = self.classifier.auc(classData)
dialog.Destroy()
wx.MessageBox(message=('Best K: %d\n' % bestK) + \
('Mean Validation AUC: %f\n' % np.max(validAUC)) +
('Final Training AUC: %f' % finalAUC),
caption='Training Completed!', style=wx.OK | wx.ICON_INFORMATION)
python类ICON_INFORMATION的实例源码
def afterTest(self, earlyStop):
if not earlyStop:
self.saveCap()
ca = np.mean(np.diag(self.confusion))/self.nTestTrial
wx.MessageBox(('Test CA: %f\n' % ca) +
'Confusion Matrix:\n' + str(self.confusion/self.nTestTrial),
'Testing Complete', wx.OK | wx.ICON_INFORMATION)
def OnDropFiles(self, x, y, filenames):
wx.MessageBox(
u"Items Added:\n{}".format("\n".join(filenames)), #message
u'Evidence Dropped', #title
wx.OK | wx.ICON_INFORMATION
)
for filename in filenames:
self.window.EnumerateSource(
filename
)
pass
def ok_click(self, e):
# check for changes to cron
if self.cron_lamp_on.GetLabel() == "not found" or self.cron_lamp_off.GetLabel() == "not found":
mbox = wx.MessageDialog(None, "Add new job to cron?", "Are you sure?", wx.YES_NO|wx.ICON_QUESTION)
sure = mbox.ShowModal()
if sure == wx.ID_YES:
if self.cron_lamp_on.GetLabel() == "not found":
cron_task = "/home/pi/Pigrow/scripts/switches/" + "lamp_on.py"
MainApp.cron_info_pannel.add_to_onetime_list("new", "True", self.new_on_string_text.GetLabel(), cron_task)
if self.cron_lamp_off.GetLabel() == "not found":
cron_task = "/home/pi/Pigrow/scripts/switches/" + "lamp_off.py"
MainApp.cron_info_pannel.add_to_onetime_list("new", "True", self.new_off_string_text.GetLabel(), cron_task)
MainApp.cron_info_pannel.update_cron_click("e")
elif not self.new_on_string_text.GetLabel() == self.cron_lamp_on.GetLabel() or not self.new_off_string_text.GetLabel() == self.cron_lamp_off.GetLabel():
print(":" + self.new_on_string_text.GetLabel() + ":")
print(":" + self.cron_lamp_on.GetLabel() + ":")
mbox = wx.MessageDialog(None, "Update cron timing?", "Are you sure?", wx.YES_NO|wx.ICON_QUESTION)
sure = mbox.ShowModal()
result_on = 'done' # these are for cases when only one is changed
result_off = 'done' # if it attempts to update cron and fails it'll change to an error message
if sure == wx.ID_YES:
if not self.new_on_string_text.GetLabel() == self.cron_lamp_on.GetLabel():
result_on = self.change_cron_trigger("lamp_on.py", self.new_on_string_text.GetLabel())
if not self.new_off_string_text.GetLabel() == self.cron_lamp_off.GetLabel():
result_off = self.change_cron_trigger("lamp_off.py", self.new_off_string_text.GetLabel())
if result_on != "done" or result_off != "done":
wx.MessageBox('Cron update error, edit lamp switches in the cron pannel', 'Info', wx.OK | wx.ICON_INFORMATION)
else:
MainApp.cron_info_pannel.update_cron_click("e")
# check for changes to settings file
time_lamp_on = str(self.on_hour_spin.GetValue()) + ":" + str(self.on_min_spin.GetValue())
time_lamp_off = str(self.off_hour_spin.GetValue()) + ":" + str(self.off_min_spin.GetValue())
if not MainApp.config_ctrl_pannel.config_dict["time_lamp_on"] == time_lamp_on or not MainApp.config_ctrl_pannel.config_dict["time_lamp_off"] == time_lamp_off:
MainApp.config_ctrl_pannel.config_dict["time_lamp_on"] = time_lamp_on
MainApp.config_ctrl_pannel.config_dict["time_lamp_off"] = time_lamp_off
MainApp.config_ctrl_pannel.update_setting_click("e")
MainApp.config_ctrl_pannel.update_config_click("e")
self.Destroy()
def set_new_gpio_link(self, e):
#get data from combo boxes.
unused_gpio = self.list_unused_gpio(self.list_used_gpio())
config_ctrl_pnl.device_new = self.devices_combo.GetValue()
config_ctrl_pnl.gpio_new = self.gpio_tc.GetValue()
config_ctrl_pnl.wiring_new = self.wiring_combo.GetValue()
#check to see if info is valid and closes if it is
should_close = True
# check if device is set
if config_ctrl_pnl.device_new == "":
wx.MessageBox('Select a device to link from the list', 'Error', wx.OK | wx.ICON_INFORMATION)
should_close = False
#check if gpio number is valid
if not config_ctrl_pnl.gpio_new == config_ctrl_pnl.gpio_toedit or config_ctrl_pnl.gpio_toedit == "":
if not config_ctrl_pnl.gpio_new in unused_gpio and should_close == True:
wx.MessageBox('Select a valid and unused gpio pin', 'Error', wx.OK | wx.ICON_INFORMATION)
config_ctrl_pnl.gpio_new = self.gpio_tc.SetValue("")
should_close = False
# check if wiring direction is set to a valid setting
if not config_ctrl_pnl.wiring_new == "low" and should_close == True:
if not config_ctrl_pnl.wiring_new == "high":
wx.MessageBox("No wiring direction set, \nIf you don't know guess and change it if the device turns on when it should be off", 'Error', wx.OK | wx.ICON_INFORMATION)
should_close = False
# if box should be closed then close it
if should_close == True:
#checks to see if changes have been made and updates ui if so
if not config_ctrl_pnl.device_new == config_ctrl_pnl.device_toedit:
config_ctrl_pnl.currently_new = 'unlinked'
else:
if not config_ctrl_pnl.gpio_new == config_ctrl_pnl.gpio_toedit:
config_ctrl_pnl.currently_new = 'unlinked'
else:
if not config_ctrl_pnl.wiring_new == config_ctrl_pnl.wiring_toedit:
config_ctrl_pnl.currently_new = 'unlinked'
else:
config_ctrl_pnl.currently_new = config_ctrl_pnl.currently_toedit
self.Destroy()
def show_help(self, e):
script_path = self.cron_path_combo.GetValue()
script_name = self.cron_script_cb.GetValue()
helpfile = self.get_help_text(str(script_path + script_name))
msg_text = script_name + ' \n \n'
msg_text += str(helpfile)
wx.MessageBox(msg_text, 'Info', wx.OK | wx.ICON_INFORMATION)
def OnAbout(self, event):
wx.MessageBox(u"????????\n??????????hack?????????",u"??", wx.OK | wx.ICON_INFORMATION, self)
def on_request_transform_button_click(self, event):
url = self.url_text.GetValue()
method = self.method_choice.GetStringSelection()
params_value = self.post_params_text.GetValue()
headers_value = self.headers_text.GetValue()
slice_startswith = self.slice_text.GetValue()
template_path = self.get_template_path()
request_forms = {k: v[0] for k, v in urlparse.parse_qs(params_value).items()}
headers = headers_value.split('\n')
handler = Request2Doc(url, method, request_forms)
if slice_startswith:
handler.set_slice_startswith(slice_startswith)
if headers:
handler.set_headers(headers)
try:
if not handler.validate():
return wx.MessageDialog(None, handler.error_message(), u"Info", wx.OK | wx.ICON_INFORMATION).ShowModal()
handler.request()
if not handler.get_response_data():
return wx.MessageDialog(None, u'Response body is not legal format', u"Information", wx.OK | wx.ICON_INFORMATION).ShowModal()
res = handler.render_string(template_path)
self.GetParent().set_response_content(json.dumps(handler.get_response_data(), indent=2))
self.GetParent().set_document_content(res)
except Exception, e:
return wx.MessageDialog(None, traceback.format_exc(), u"Exception", wx.OK | wx.ICON_ERROR).ShowModal()
TortoiseSVNPlugin.py 文件源码
项目:robotframework-ride-tortoisesvn
作者: ukostas
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def create_callable(self, name, action):
def callable(event):
# check if this is for whole project or file/directory
if 'item' in name.lower(): # for one single item - file/directory
if not self.datafile:
return
full_cmd = action.format(path=self.datafile.source)
else: # for whole project - root file/directory
full_cmd = action.format(path=self.model.suite.source)
# RideLogMessage(name + " clicked: " + fullCmd).publish()
if full_cmd.lower().startswith('http'):
wx.LaunchDefaultBrowser(full_cmd)
else:
try:
subprocess.Popen(full_cmd)
except OSError as error:
s = "This is the error we got trying to execute {executor_name} executable file:\n" \
"\"{error}\"\n\n" \
"Probably this file in not in your PATH. Try to reinstall {executor_name}.\n" \
"Do you want to open download page?".format(error=error.strerror, executor_name=self.MENU_NAME)
dlg = wx.MessageDialog(parent=self.frame, caption="Hmm, something went wrong...", message=s,
style=wx.YES_NO | wx.CENTER | wx.ICON_INFORMATION)
if dlg.ShowModal() == wx.ID_YES:
wx.LaunchDefaultBrowser(self.SVN_INSTALLATION_URL)
dlg.Destroy()
return callable
def update_check_done(self, result):
# Update check function ended
r = result.get()
self.checking_updates = False
if isinstance(r, basestring):
# Error returned
self.updates_available = False
if self.upd_error_count < 2 and not self.show_no_updates:
# only display update errors on automatic check after the third error in a row
self.upd_error_count += 1
else:
error_str = _(u"Could not load updates:") + "\n" + r
self.ShowBalloon(title=_(u'Update Error'), text=error_str, msec=20*1000, flags=wx.ICON_ERROR)
# reset update error counter
self.upd_error_count = 0
elif r:
self.upd_error_count = 0
action_dict = {'update': _(u'UPD:') + '\t',
'install': _(u'NEW:') + '\t',
'remove': _(u'REM:') + '\t',
'downgrade': _(u'DOW:') + '\t'}
# Updates Found
self.updates_available = True
text = ''
for action, name, version in r:
text += action_dict[action] + name + ', v. ' + version + '\n'
self.ShowBalloon(title=_(u"Update(s) available:"), text=text, msec=20*1000, flags=wx.ICON_INFORMATION)
else:
# No Updates Found
self.upd_error_count = 0
self.updates_available = False
if self.show_no_updates:
self.ShowBalloon(title=_(u"No Updates"), text=" ", msec=20 * 1000, flags=wx.ICON_INFORMATION)
self.show_no_updates = False
def update_check_done(self, result):
# Update check function ended
r = result.get()
self.checking_updates = False
if isinstance(r, basestring):
# Error returned
self.updates_available = False
if self.upd_error_count < 2 and not self.show_no_updates:
# only display update errors on automatic check after the third error in a row
self.upd_error_count += 1
else:
error_str = _(u"Could not load updates:") + "\n" + r
self.ShowBalloon(title=_(u'Update Error'), text=error_str, msec=20*1000, flags=wx.ICON_ERROR)
# reset update error counter
self.upd_error_count = 0
elif r:
self.upd_error_count = 0
action_dict = {'update': _(u'UPD:') + '\t',
'install': _(u'NEW:') + '\t',
'remove': _(u'REM:') + '\t',
'downgrade': _(u'DOW:') + '\t'}
# Updates Found
self.updates_available = True
text = ''
for action, name, version in r:
text += action_dict[action] + name + ', v. ' + version + '\n'
self.ShowBalloon(title=_(u"Update(s) available:"), text=text, msec=20*1000, flags=wx.ICON_INFORMATION)
else:
# No Updates Found
self.upd_error_count = 0
self.updates_available = False
if self.show_no_updates:
self.ShowBalloon(title=_(u"No Updates"), text=" ", msec=5*1000, flags=wx.ICON_INFORMATION)
self.show_no_updates = False
def save(self):
stream = StreamWrite.from_file(self._filename, Endianness.BIG)
levels_not_saved = 0
for level_index, level in enumerate(self._levels):
if level.modified:
if not level.can_save():
levels_not_saved += 1
continue
# Write entities first.
level.write_entities(stream)
# Save level data.
if level_index == 0:
level.save(stream)
else:
filename = 'L{}-{}'.format(self._world_index + 1, level_index + 1)
game_dir = os.path.dirname(self._filename)
filename = os.path.join(game_dir, filename)
level_stream = StreamWrite.from_file(filename, Endianness.BIG)
if self._world_index == 2 and level_index == 1:
offset = 19620
else:
offset = 0
level.save(level_stream, offset)
level_stream.write_to_file(filename)
# Save level header.
stream.seek(self._level_offsets[level_index])
level.save_header(stream)
level.modified = False
stream.write_to_file(self._filename)
if levels_not_saved:
wx.MessageBox('{} level(s) could not be saved.'.format(levels_not_saved), 'Levels not saved', wx.ICON_INFORMATION | wx.OK)
def Add_Clicked(self,event):
if (self.Validate_Roll_No(self.text_ctrl_1.Value)) and (self.Validate_Adm_No(self.text_ctrl_2.Value)) and (self.Validate_Name(self.text_ctrl_3.Value)):
try:
student_id,t1_id,t2_id,t3_id=self.DB.Add_Student(self.text_ctrl_1.Value,self.text_ctrl_2.Value,self.text_ctrl_3.Value,self.Parent.YEAR,self.Parent.CLASS,self.Parent.DIV)
#term,div_id,subject_index,student_id="All"
student_id="All"
if self.Parent.TERM_INDEX==0:
term="1"
t_id=t1_id
elif self.Parent.TERM_INDEX==1:
term="2"
t_id=t2_id
elif self.Parent.TERM_INDEX==2:
term="3"
t_id=t3_id
if self.Parent.SUBJECT=="Select":
ROW=[False,student_id,self.text_ctrl_2.Value,self.text_ctrl_3.Value,t_id,self.text_ctrl_1.Value,0,0,0,0]
div_id=self.DB.Get_Div_Id(self.Parent.YEAR,self.Parent.CLASS,self.Parent.DIV)
self.DB.Score_and_Roll(term,div_id,self.Parent.SUBJECT_INDEX,student_id)
dlg = wx.MessageDialog(self, 'Added Successfully', '',wx.OK | wx.ICON_INFORMATION)
self.success=True
self.STUDENT_INFO=[self.text_ctrl_1.Value,self.text_ctrl_2.Value,self.text_ctrl_3.Value]
dlg.ShowModal()
dlg.Destroy()
except:
dlg = wx.MessageDialog(self, 'Sorry, Could not Add', '',wx.OK | wx.ICON_ERROR)
self.STUDENT_INFO=[]
dlg.ShowModal()
dlg.Destroy()
self.Close()
def OnMenu_PerformanceReport(self,event):
import subprocess
if STD=='9' or STD=='10':
#self.Sheet.Refresh()
R=Report()
R.SetTable_Style()
R.PopulateTables(self.YEAR,self.CLASS,self.DIV,self.TERM_INDEX)
R.Save()
else:
try:
R=Report_8()
R.SetTable_Style()
R.PopulateTables(self.YEAR,self.CLASS,self.DIV,self.TERM_INDEX)
R.Save()
except:
dlg = wx.MessageDialog(None, 'Error in File', '',wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
def on_email(self,event):
msg="This feature is not yet activated"
dlg = wx.MessageDialog(self, msg, '',wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
self.label_email.SetForegroundColour(self.label_fg_color)
def OnSave(self, event): # wxGlade: working_days.<event_handler>
t1=str(self.text_ctrl_1.Value)
t2=str(self.text_ctrl_2.Value)
t3=str(self.text_ctrl_3.Value)
err=False
if not self.text_ctrl_1.Value.isdigit() and not self.text_ctrl_1.Value=='':err=True;self.text_ctrl_1.Value=''
if not self.text_ctrl_2.Value.isdigit() and not self.text_ctrl_2.Value=='':err=True;self.text_ctrl_2.Value=''
if not self.text_ctrl_3.Value.isdigit() and not self.text_ctrl_3.Value=='':err=True;self.text_ctrl_3.Value=''
if err:
dlg = wx.MessageDialog(self, 'Working days should be a digit', '',wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
return 0
try:
self.DB.Set_Working_Days(self.YEAR,'1',self.text_ctrl_1.Value)
self.DB.Set_Working_Days(self.YEAR,'2',self.text_ctrl_2.Value)
self.DB.Set_Working_Days(self.YEAR,'3',self.text_ctrl_3.Value)
dlg = wx.MessageDialog(self, 'Successfully Saved', '',wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
except:
dlg = wx.MessageDialog(self, 'Some error occured', '',wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
event.Skip()
# end of class working_days
def on_save(self, event): # wxGlade: secret_win.<event_handler>
self.DB.Set_School_Name(self.text_ctrl_1.Value)
self.DB.Set_School_Code(self.text_ctrl_2.Value)
dlg = wx.MessageDialog(self, 'Done', '',wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
self.Close()
event.Skip()
def OnOk(self, event): # wxGlade: Institution.<event_handler>
'''if self.text_ctrl_1.Value=='admin' and self.text_ctrl_2.Value=='admin':
self.DB.Set_School_Name(self.text_ctrl_3.Value)
elif self.text_ctrl_1.Value=='theadmin' and self.text_ctrl_2.Value=='theadmin':
self.DB.Set_School_Code(self.text_ctrl_3.Value)
else:
'''
try:
self.DB.Set_School_Name(self.text_ctrl_5.Value)
self.DB.Set_School_Code(self.text_ctrl_6.Value)
self.DB.Set_School_Email(self.text_ctrl_1.Value)
self.DB.Set_School_Contact(self.text_ctrl_2.Value)
self.DB.Set_School_DEO(self.text_ctrl_3.Value)
dlg = wx.MessageDialog(self, 'Successfully Saved', '',wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
except:
dlg = wx.MessageDialog(self, 'Could not save some values', '',wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
self.Close(True)
event.Skip()