def is_data_float(self): """ test si la valeur du champ est bien un float ecrit les données dans P4Rm.fitting_parameters """ IsFloat = [] dataFloat = True for i in range(len(self.data_fields)): self.resultprojectfile[i] = self.data_fields[i].GetValue() for i in range(len(self.data_fields)): a = self.data_fields[i].GetValue() IsFloat.append(self.is_number(a)) if False in IsFloat: dataFloat = False StringPosition = [i for i, x in enumerate(IsFloat) if x is False] for ii in StringPosition: self.data_fields[ii].SetBackgroundColour('green') self.Refresh() msg = "Please, fill correctly the fields to continue" dlg = GMD.GenericMessageDialog(None, msg, "Attention", agwStyle=wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() for ii in StringPosition: self.data_fields[ii].SetBackgroundColour('white') self.Refresh() else: temp = [float(j) for j in self.resultprojectfile] P4Rm.fitting_parameters = temp return dataFloat
def on_search_empty_fields(self): """ Verification des champs, recherche des champs vide """ check_empty = True empty_fields = [] for ii in range(len(self.data_fields)): empt = self.data_fields[ii] if empt.GetValue() == "": empty_fields.append(ii) if empty_fields != []: check_empty = False for ii in empty_fields: self.data_fields[ii].SetBackgroundColour('red') self.Refresh() msg = "Please, fill the red empty fields to continue" dlg = GMD.GenericMessageDialog(None, msg, "Attention", agwStyle=wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() for ii in empty_fields: self.data_fields[ii].SetBackgroundColour('white') self.Refresh() return check_empty
def ScaleIntensities(self): title = 'Scale data?' message = 'Would you like to scale the intensities so that the various plots overlay?' dlg = GMD.GenericMessageDialog(None, message, title, agwStyle=wx.ICON_INFORMATION | wx.YES_NO) response = dlg.ShowModal() dlg.Destroy() if response == wx.ID_YES: self.logger.info('Scaling intensity data') time.sleep(5) if len(self.imagedict.keys()) > 0: highest_max = 0 for file in self.imagedict.keys(): self.imagedict[file]['max'] = max( self.imagedict[file]['I']) if self.imagedict[file]['max'] > highest_max: highest_max = self.imagedict[file]['max'] for file in self.imagedict.keys(): self.logger.info('scaling ' + str(file) + ' intensities by ' + str(highest_max / self.imagedict[file]['max'])) self.imagedict[file]['I'][:] = [ x * (highest_max / self.imagedict[file]['max']) for x in self.imagedict[file]['I'] ] else: self.logger.info('Will proceed with unscaled data')
def on_read_initial_file(self): a = P4Rm() b = ReadFile() if (os.path.exists(a.PathDict['DW_file']) and os.path.exists(a.PathDict['Strain_file']) and os.path.exists(a.PathDict['XRD_file'])) is True: try: """READING DW FILE""" b.read_dw_file(a.PathDict['DW_file']) """READING Strain FILE""" b.read_strain_file(a.PathDict['Strain_file']) """READING XRD FILE""" b.read_xrd_file(a.PathDict['XRD_file']) self.on_calc_from_xrd() P4Rm.ParamDictbackup['dwp'] = a.ParamDict['dwp'] P4Rm.ParamDictbackup['sp'] = a.ParamDict['sp'] P4Rm.ParamDict['sp_abrupt'] = a.ParamDict['sp'] P4Rm.ParamDict['dwp_abrupt'] = a.ParamDict['dwp'] P4Rm.ParamDict['sp_smooth'] = a.ParamDict['sp'] P4Rm.ParamDict['dwp_smooth'] = a.ParamDict['dwp'] except TypeError: logger.log(logging.WARNING, "!Please check your input file!") else: return True else: msg_ = "Please, check that the input files really exists" dlg = GMD.GenericMessageDialog(None, msg_, "Attention", agwStyle=wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() return False
def IsDataFloat(self): a = P4Rm() IsFloat = [] dataFloat = True for i in range(len(self.Textcontrol)): IsFloat.append(self.Is_number(self.Textcontrol[i].GetValue())) if False in IsFloat: dataFloat = False StringPosition = [i for i, x in enumerate(IsFloat) if x is False] for ii in StringPosition: self.Textcontrol[ii].SetBackgroundColour('green') self.Refresh() _msg = "Please, fill correctly the fields before to continue" dlg = GMD.GenericMessageDialog(None, _msg, "Attention", agwStyle=wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() for ii in StringPosition: self.Textcontrol[ii].SetBackgroundColour('white') self.Refresh() else: i = 0 for k in p4R.s_pv: val = self.Textcontrol[i].GetValue() P4Rm.AllDataDict[k] = float(val) self.Textcontrol[i].Clear() self.Textcontrol[i].AppendText(str(a.AllDataDict[k])) i += 1 return dataFloat
def on_save_data(self, event): _msg = "Save data as default ?\n" + \ "This change will be applied for all fit !!\n\n" dlg = GMD.GenericMessageDialog(None, _msg, "Attention", agwStyle=wx.OK | wx.CANCEL | wx.ICON_QUESTION) result = dlg.ShowModal() dlg.Destroy() if result == wx.ID_OK: pub.sendMessage(pubsub_Read_field_Bspline) pub.sendMessage(pubsub_Read_field_PseudoV) pub.sendMessage(pubsub_Read_field_Fit) success = self.IsDataFloat() if success: a = P4Rm() P4Rm.Paramwindowtest['FitParametersPanel'] = True if False not in a.Paramwindowtest: for k in p4R.Exp_read_only: P4Rm.DefaultDict[k] = a.AllDataDict[k] b = SaveFile4Diff() b.on_update_config_file_parameters( os.path.join(p4R.current_dir, p4R.filename + '.ini')) P4Rm.Paramwindowtest['FitParametersPanel'] = True pub.sendMessage(pubsub_Save_Param_and_quit, event=event) event.Skip()
def sendReport(self, parent, text): try: question = "Sorry, something went wrong and your mining session will stop.\n\nDo you want to send an error report? No personal data will be included." dlg = GMD.GenericMessageDialog(parent, question, "Send Error Report", wx.YES_NO | wx.ICON_STOP) result = dlg.ShowModal() == wx.ID_YES dlg.Destroy() if result: version = FrameMYR.VERSION + '.' + str(FrameMYR.REVISION) data = {'exception': text, 'version': version} #resp = requests.request('post', URL, data=data, timeout=TIMEOUT) fromaddr = '*****@*****.**' toaddrs = '*****@*****.**' message = 'Subject: Myriad Switcher ' + FrameMYR.VERSION + '.' + str( FrameMYR.REVISION) + ' Error\n\n%s' % (text) username = '******' password = '******' server = smtplib.SMTP('smtp.gmail.com:587') server.starttls() server.login(username, password) server.sendmail(fromaddr, toaddrs, message) server.quit() except: pass
def on_delete_data(self): a = P4Rm() _msg = "Do you really want to delete these datas?" dlg = GMD.GenericMessageDialog(None, _msg, "Confirm Suppression", agwStyle=wx.OK | wx.CANCEL | wx.ICON_QUESTION) result = dlg.ShowModal() dlg.Destroy() if result == wx.ID_OK: c = DataBaseUse() c.on_delete_data() self.on_fill_combobox() state1 = self.rb1.SetValue(True) state2 = self.rb2.SetValue(False) self.state = [state1, state2] for i in range(len(self.cb_list)): self.cb_list[i].SetValue(False) self.combo_list[i].Disable() empty = a.DBDict['session'].query(RadMaxData).first() if empty is None: s = a.DBDict['session'].query(RadMaxData).order_by( RadMaxData.id) c.on_read_database_and_fill_list(s) else: self.on_search_in_DB()
def display_warning(self, message, short_message, style=wx.OK | wx.ICON_WARNING): """Displays a warning message""" dlg = GMD.GenericMessageDialog(self.main_window, message, short_message, style) dlg.ShowModal() dlg.Destroy()
def onDonateMYR(self, event): myr_address = "MPLArvmR7dQrF7BCPDFsRCniFnCJhZkG9d" self.writeClipboard(myr_address) dlg = GMD.GenericMessageDialog( self, "MYR address " + myr_address + " copied to clipboard.\n\nThanks for your support.", "MYR Donation", wx.ICON_INFORMATION | wx.OK) dlg.ShowModal() dlg.Destroy()
def onDonateBTC(self, event): btc_address = "1PS2WmKorxCeFoNZbZ5XKgbiDjofxFgcPL" self.writeClipboard(btc_address) dlg = GMD.GenericMessageDialog( self, "BTC address " + btc_address + " copied to clipboard.\n\nThanks for your support.", "BTC Donation", wx.ICON_INFORMATION | wx.OK) dlg.ShowModal() dlg.Destroy()
def show_editor(self, objects): """create and show a new editor Args: objects: an Object, or a list of Objects. If it's an object, a Struct editor will be used If it's a list of object, even with only 1 object, a StructList editor will be used """ org = objects if type(objects) is not list: objects = [org] # order by id, by default if objects and objects[0].struct.has_attr('id'): objects.sort(key=lambda x: x.id) read_only = False while 1: # Is there any editor frames already editing (some of) objects editors = self._find_editors(objects, True) read_only = False # some of the objects are alread open if editors: # if only 1 objects is requested, just show that editor if len(objects) == 1: editors[0].Raise() return # prompt use to choose: close, read only or cancel import wx.lib.agw.genericmessagedialog as gmd msg = "%s objects(s) are already opened, you may close those editors, or open as read only mode." %\ len(editors), dlg = gmd.GenericMessageDialog( self, msg, "Oh~", wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION) dlg.SetYesNoCancelLabels('Close', '&Read Only', '&Cancel') ret = dlg.ShowModal() if ret == wx.ID_YES: for editor in editors: editor.close() continue elif ret == wx.ID_NO: read_only = True else: return break from structerui.editor.context import FrameEditorContext from structerui.editor.frame import EditorFrame ctx = FrameEditorContext(self.project, org, read_only) f = EditorFrame(self, ctx) self.add_editor(f) f.Show() f.Raise()
def onAbout(self, event): # Create a message dialog box dlg = GMD.GenericMessageDialog(self, " Myriad Switcher " + self.getVersion() + " by Dario Iriberri (dazz).", "About", agwStyle=wx.ICON_INFORMATION | wx.OK) dlg.ShowModal() dlg.Destroy()
def onFixerExplanationButton(self, event): from mainlogic import _ fixerExplanationMessage = _( "Checking this button allows (ONLY) the admin user to access the fixing scripts collection." ) title = _("Some explanation about fixer access.") dlg = GMD.GenericMessageDialog(self, fixerExplanationMessage, title, wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy()
def status(self, player, player1, player2): if player is player1: title = "Player 1's Turn" elif player is player2: title = "Player 2's Turn" message = "Money:" + str(player[0]) + "\nProperties:\n" + "\n".join( player[2:]) + "\n\nRoll\End Turn?" status = GMD.GenericMessageDialog(self, message, title, wx.DEFAULT) status.SetSize((200, 400)) status.SetPosition(position(350, -188)) status.ShowModal()
def main(): app = wx.PySimpleApp() try: version = "{}.{}".format(*list(sys.version_info[:2])) message = "Congratulations \nthis program uses\npython {}\nwxpython {}\nsqlalchemy {}".format(version , wx.__version__, sqlalchemy.__version__) except: message = "Sorry but you forgot to set the PYTHONPATH variable using source dothis" dlg = GMD.GenericMessageDialog(None, message , "A message for you", wx.OK | ( wx.ICON_INFORMATION + GMD.GMD_USE_GRADIENTBUTTONS ) ) dlg.ShowModal() dlg.Destroy() app.MainLoop()
def onPopUpDelete(self, event): question = "Are you sure you want to delete those files?" dlg = GMD.GenericMessageDialog(self, question, "Confirm deletion", wx.YES_NO | wx.NO_DEFAULT | wx.ICON_WARNING) result = dlg.ShowModal() == wx.ID_YES dlg.Destroy() if result: selected = self.listLogs.GetSelectedObjects() for file in selected: os.remove(self.logPath + '/' + file['log'] + '.html') self.loadList()
def checkMinersSelected(self): if not self.miners.checkMinersSelected(): dlg = GMD.GenericMessageDialog( self, "Pick at least one mining device in the lower panel to start your mining session.\n\n ", "Unable to start the mining session...", wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return False return True
def get_warning_choice(self, message, short_message, style=wx.YES_NO | wx.NO_DEFAULT | wx.ICON_WARNING): """Launches proceeding dialog and returns True if ok to proceed""" dlg = GMD.GenericMessageDialog(self.main_window, message, short_message, style) choice = dlg.ShowModal() dlg.Destroy() return choice == wx.ID_YES
def rolling(self, player): import random roll = random.randint(2, 12) player[1] += roll if player[1] > 39: player[1] -= 40 dlg = GMD.GenericMessageDialog(self, "You passed Go. Collect $200", "Passed Go", wx.OK) result = dlg.ShowModal() player[0] += 200 return player else: return player
def __init__(self, msg, title=None, showButtons=wx.OK, dialogType=wx.ICON_INFORMATION, allowCancel=True, display_index=0): ioHubDialog.__init__(self, display_index) if showButtons not in [ MessageDialog.YES_NO_BUTTONS, MessageDialog.OK_BUTTON ]: raise AttributeError( "MessageDialog showButtons arg must be either MessageDialog.YES_NO_BUTTONS or MessageDialog.OK_BUTTON" ) if showButtons == MessageDialog.YES_NO_BUTTONS: showButtons |= wx.YES_DEFAULT if allowCancel: showButtons |= wx.CANCEL if dialogType not in [ MessageDialog.INFORMATION_DIALOG, MessageDialog.WARNING_DIALOG, MessageDialog.IMPORTANT_DIALOG, MessageDialog.ERROR_DIALOG, MessageDialog.QUESTION_DIALOG ]: raise AttributeError( "MessageDialog dialogType arg must one of MessageDialog.INFORMATION_DIALOG, MessageDialog.WARNING_DIALOG, MessageDialog.IMPORTANT_DIALOG, MessageDialog.ERROR_DIALOG, MessageDialog.QUESTION_DIALOG." ) if title is None: if dialogType == MessageDialog.INFORMATION_DIALOG: title = "For Your Information" elif dialogType == MessageDialog.WARNING_DIALOG: title = "Warning" elif dialogType == MessageDialog.IMPORTANT_DIALOG: title = "Important Note" elif dialogType == MessageDialog.ERROR_DIALOG: title = "Error" elif dialogType == MessageDialog.QUESTION_DIALOG: title = "Input Required" d = wx.Display(0) x, y, w, h = d.GetGeometry() d = None self.dialog = GMD.GenericMessageDialog(None, msg, title, showButtons | dialogType) #, wrap=int(w/4)) #TODO Change to own image from . import images self.dialog.SetIcon(images.Mondrian.GetIcon()) self.set_frame_display()
def on_close_window(self, event, fram_obj): dlg = GMD.GenericMessageDialog( self, u'您已登录,确定退出?', u'提示', wx.YES_NO | GMD.GMD_USE_GRADIENTBUTTONS | wx.ICON_QUESTION) # dlg = wx.MessageDialog(self, u'您已登录,确定退出?', u'提示', wx.YES_NO | wx.ICON_QUESTION) result = dlg.ShowModal() == wx.ID_YES if result: self.Destroy() # fram_obj.login_btn.Enable(True) # fram_obj.login_btn.SetLabel(u'登录') # fram_obj.refresh_btn.Enable(True) # fram_obj.refresh_click(None) # fram_obj.Show(True) fram_obj.Destroy()
def test_lib_agw_genericmessagedialogMethods(self): dlg = GMD.GenericMessageDialog(self.frame, 'Hello World', 'A Nice Message Box', agwStyle=wx.ICON_INFORMATION|wx.OK) # Test custom and default button labels for kind in ['OK', 'Yes', 'No', 'Help', 'Cancel']: default = 'GetDefault%sLabel()'%kind custom = 'GetCustom%sLabel()'%kind self.assertEqual(eval('dlg.%s'%default), eval('dlg.%s'%custom)) self.assertTrue(not dlg.HasCustomBitmaps()) self.assertTrue(not dlg.GetExtendedMessage()) dlg.SetExtendedMessage('An extended message') self.assertEqual(dlg.GetFullMessage(), '%s\n\n%s'%(dlg.GetMessage(), dlg.GetExtendedMessage()))
def getMessageDialog(window, msg, caption, style, data): devwin = Config.getdevwin(window) topwin = wx.Window.FindWindowByName('MainFrame') win = devwin if Config.autopos else topwin dlg = GMD.GenericMessageDialog(win, msg, caption, style) okcancel_label = data.get('okcancel', '') adjustpos(win, dlg) if okcancel_label: dlg.SetOKCancelLabels(okcancel_label[0], okcancel_label[1]) if dlg.ShowModal() == wx.ID_OK: dlg.Destroy() return True else: dlg.Destroy() return False
def on_save_data(self, event): _msg = "Save data as default ?\n" + \ "This change will be applied for all fit !!\n\n" dlg = GMD.GenericMessageDialog(None, _msg, "Attention", agwStyle=wx.OK | wx.CANCEL | wx.ICON_QUESTION) result = dlg.ShowModal() dlg.Destroy() if result == wx.ID_OK: self.on_apply_color(event) b = SaveFile4Diff() name = p4R.filename + '.ini' b.on_update_config_file_parameters( os.path.join(p4R.current_dir, name)) event.Skip()
def __configError(self): dlg = GMD.GenericMessageDialog( self, 'The config file ' + self.activeFile + " is unreadable. Using defaults", 'Configuration Error', wx.OK | wx.ICON_ERROR #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION ) dlg.ShowModal() dlg.Destroy() config_json = self.getDefaultConfigJson() self.__loadNotebooksFromJson(config_json) self.saveConfig() return config_json
def on_load_project(self, paths): a = P4Rm() b = ReadFile() b.on_read_init_parameters(paths, p4R.ExperimentFile) datafromini = b.read_result_value() self.on_reset_deformation_multiplication() self.on_init_dictionnaries() P4Rm.ProjectFileData = datafromini[5:] i = 0 for k in p4R.Exp_file_all_section: if k in p4R.Exp_read_only: P4Rm.AllDataDict[k] = float(datafromini[i]) else: P4Rm.AllDataDict[k] = datafromini[i] i += 1 i = 0 for name in ['Compound_name', 'substrate_name', 'DW_file', 'Strain_file', 'XRD_file']: P4Rm.PathDict[name] = datafromini[i] i += 1 P4Rm.DefaultDict['project_folder'] = os.path.split(paths)[0] P4Rm.PathDict['path2ini'] = os.path.split(paths)[0] P4Rm.PathDict['path2inicomplete'] = paths P4Rm.PathDict['namefromini'] = os.path.splitext( os.path.basename(paths))[0] self.on_update_config_file('project_folder') if a.ProjectFileData == []: msg_ = ("Please, pay attention to your input files," + "there are some mistakes in the data") dlg = GMD.GenericMessageDialog(None, msg_, "Attention", agwStyle=wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() else: P4Rm.PathDict['project_name'] = os.path.splitext( os.path.basename(paths))[0] success = self.on_read_initial_file() if success: self.on_load_and_read_data()
def get_save_request_from_user(self): """Queries user if grid should be saved""" msg = _("There are unsaved changes.\nDo you want to save?") dlg = GMD.GenericMessageDialog( self.main_window, msg, _("Unsaved changes"), wx.YES_NO | wx.ICON_QUESTION | wx.CANCEL) save_choice = dlg.ShowModal() dlg.Destroy() if save_choice == wx.ID_YES: return True elif save_choice == wx.ID_NO: return False
def checkFileExists(self): active_log = self.logs_box.active_log.GetValue() logPath = self.logs_box.txtDir.GetValue() if active_log and not os.path.isdir(logPath): dlg = GMD.GenericMessageDialog( self, 'The logging directory ' + logPath + " does not exist", 'Configuration Error', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return False else: self.parent.parentNotebook.notebookControlChanged() return True
def onButtonRun(self, event): result = True if 'simple' == self.getMainMode() and not self.checkMinersSelected(): return if self.isThereAPreviousSession(): question = "This will delete your previously stored session data. Are you sure you want to continue?" dlg = GMD.GenericMessageDialog( self, question, "Warning", wx.YES_NO | wx.NO_DEFAULT | wx.ICON_WARNING) result = dlg.ShowModal() == wx.ID_YES dlg.Destroy() if result: if self.notebook.saveConfig(self.getExtraParams()): self.enabled_buttons(False) self.panelConsole.mine(self.notebook.activeFile)