def display_dialog(self, message, caption='Info', dialog_type='yesno', callbacks={}, scrollable=None): """Display a configurable dialog.""" style = None if dialog_type == 'yesno': style = wx.ICON_QUESTION|wx.YES_NO|wx.CANCEL elif dialog_type == 'okcancel': style = wx.ICON_QUESTION|wx.OK|wx.CANCEL else: style = wx.ICON_INFORMATION|wx.OK if scrollable is None: scrollable = message.count("\n") > 4 if scrollable: dialog = ScrolledMessageDialog( self.__frame, message, caption = caption, style = style) else: dialog = wx.MessageDialog( self.__frame, message, caption = caption, style = style) clicked = dialog.ShowModal() # find and execute the apropriate callback: # map wx.ID_??? against the dictionary passed as param to this function # if any key is not defined "do" will become an empty lambda expression do = { wx.ID_YES: callbacks.get('yes', lambda: None), wx.ID_NO: callbacks.get('no', lambda: None), wx.ID_CANCEL: callbacks.get('cancel', lambda: None), wx.ID_OK: callbacks.get('ok', lambda: None) }.get(clicked, lambda: None)() dialog.Destroy()
def OnErrScrolledDialog(self, event=None): if not isDarwin(): Warn(None, 'aborting: functionality only available on mac', 'Error') return ok = False import os.path fname = self.getLogFileName(pidoffset=-1) if os.path.isfile(fname): ok = True else: fname = self.getLogFileName(pidoffset=0) if os.path.isfile(fname): ok = True else: Warn( None, 'aborting: cannot find log file, tried %s and %s' % (self.getLogFileName(pidoffset=-1), self.getLogFileName(pidoffset=0))) if ok: with open(fname, "r") as f: txt = "\n".join(f.readlines()) dlg = ScrolledMessageDialog(self.visFr, txt, "VisGUI Error Output", size=(900, 400), style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE) dlg.ShowModal() dlg.Destroy()
def show_exception_as_dialog(type, value, tb, raisefurther=True): """Exception handler that show a dialog.""" import traceback import wx # if tb: # print((traceback.format_tb(tb))) if isinstance(value, ClearException): wx.MessageBox(value, value.heading, wx.OK | wx.ICON_ERROR) else: from wx.lib.dialogs import ScrolledMessageDialog lines = ['An error occurred in the program:\n'] lines += traceback.format_exception_only(type, value) lines += ['\nTraceback (most recent call last):\n'] if tb: lines += traceback.format_tb(tb) dlg = ScrolledMessageDialog(None, "".join(lines), 'Error', style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) dlg.ShowModal() if raisefurther: raise value
def OnHelpAbout(self, event): '''Stuff that gets displayed when you select Help -> About in the menu bar''' from wx.lib.dialogs import ScrolledMessageDialog about = ScrolledMessageDialog( self, "Write to file tool.\nA product of Wireless@VT.", "About...") about.ShowModal()
def reload_project_files(self, doReload=True, errors=None, show_dialog=True, save_reload=True): """reload_project_files(doReload=True, errors=None, show_dialog=True, reload_scene=True) doReload: force reload of all files errors: dict of errors. Will be filled with file errors. Errors can be provided in one of two forms... 1)module: sys.exc_info() or 2)*header: sys.exc_info() show_dialog: show a dialog displaying all file errors found save_reload: if True, save the working file before reloading project files, then reload the scene when done """ if save_reload: if not self.check_save(): return if errors is None: errors = {} self.reload_components(doReload=doReload, errors=errors) self.reload_object_list(doReload=doReload, errors=errors) self.reload_scene_list(doReload=doReload, errors=errors) if show_dialog and errors: keys = errors.keys() top_keys = [] # *'d keys with specific error headers mod_keys = [] # standard keys with error module for key in keys: if key[0] == '*': top_keys.append(key) else: mod_keys.append(key) keys.sort() top_keys.sort() msg = 'The following errors were found in the project files:\n\n' for header in top_keys: info = errors[header] header = header[1:] msg += header + ':\n\n' msg += ''.join(traceback.format_exception(*info)) msg += '_' * 90 + '\n\n' for mod in mod_keys: msg += 'Error in module ' + mod + ':\n\n' info = errors[mod] msg += ''.join(traceback.format_exception(*info)) msg += '_' * 90 + '\n\n' err = ScrolledMessageDialog(self.frame, msg, 'Project File Errors', size=(640, 320), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) err.ShowModal() err.Destroy() if save_reload: Opioid2D.ResourceManager.clear_cache() self.set_scene(self.scene.__class__.__name__, True)
def __OnViewSource(self, event): """ View document source @since 1.1 @author C.Dutoit """ source = self.html.GetParser().GetSource() dlg = ScrolledMessageDialog(self, source, _('HTML Source')) dlg.ShowModal() dlg.Destroy()
def give_scrolled_message(self, title, msg): dlg = ScrolledMessageDialog(self, msg, title, size=(1000, 600), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) points = dlg.text.GetFont().GetPointSize() # get the current size f = wx.Font(points, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL) dlg.text.SetFont(f) dlg.ShowModal() dlg.Destroy()
def OnLinkClicked(self, linkinfo): href = linkinfo.GetHref() if href == 'show_license': if config.license_file: from wx.lib.dialogs import ScrolledMessageDialog try: license_file = codecs.open( config.license_file, encoding='UTF-8') dlg = ScrolledMessageDialog( self, license_file.read(), _("wxGlade - License") ) license_file.close() dlg.ShowModal() dlg.Destroy() except IOError: wx.MessageBox( _('License file "LICENSE.txt" not found!\n' 'You can get a copy at \n' 'http://www.opensource.org/licenses/' 'mit-license.php'), _('Error'), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) else: wx.MessageBox( _('License file "LICENSE.txt" not found!\n' 'You can get a copy at \n' 'http://www.opensource.org/licenses/' 'mit-license.php'), _('Error'), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) elif href == 'show_credits': if config.credits_file: from wx.lib.dialogs import ScrolledMessageDialog try: credits_file = codecs.open( config.credits_file, encoding='UTF-8') dlg = ScrolledMessageDialog( self, credits_file.read(), _("wxGlade - Credits") ) credits_file.close() dlg.ShowModal() dlg.Destroy() except IOError: wx.MessageBox( _('Credits file "CREDITS.txt" not found!'), _('Error'), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) else: wx.MessageBox( _('Credits file "CREDITS.txt" not found!'), _('Error'), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) else: import webbrowser webbrowser.open(linkinfo.GetHref(), new=True)
def show_text_dialog(parent, text, caption): "Create and show a ScrolledMessageDialog" style = wx.CAPTION | wx.CLOSE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU dlg = ScrolledMessageDialog(parent, text, caption, style=style) font = wx.Font(12, wx.MODERN, wx.NORMAL, wx.NORMAL, False, 'Inconsolata') dlg.text.SetFont(font) n_lines = dlg.text.GetNumberOfLines() line_text = dlg.text.GetLineText(0) w, h = dlg.text.GetTextExtent(line_text) dlg.text.SetSize((w + 100, (h + 3) * n_lines + 50)) dlg.Fit() dlg.Show() return dlg
def _show_alert_dialog(self, text, details, severity='error'): if __debug__: log('showing message dialog') frame = self._current_frame() if severity == 'fatal': short = text style = wx.OK | wx.ICON_ERROR extra_text = 'fatal ' else: short = text + '\n\nWould you like to try to continue?\n(Click "no" to quit now.)' style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_EXCLAMATION extra_text = '' if details: style |= wx.HELP caption = "Check It! has encountered a {}problem".format(extra_text) dlg = wx.MessageDialog(frame, message=short, style=style, caption=caption) clicked = dlg.ShowModal() if clicked == wx.ID_HELP: body = ("Check It! has encountered a problem:\n" + "─" * 30 + "\n{}\n".format(details or text) + "─" * 30 + "\nIf the problem is due to a network timeout or " + "similar transient error, then please quit and try again " + "later. If you don't know why the error occurred or " + "if it is beyond your control, please also notify the " + "developers. You can reach the developers via email:\n\n" + " Email: [email protected]\n") info = ScrolledMessageDialog(frame, body, "Error") info.ShowModal() info.Destroy() frame.Destroy() self._queue.put(True) if 'fatal' in severity: if __debug__: log('sending stop message to UI') wx.CallAfter(pub.sendMessage, 'stop') elif clicked in [wx.ID_NO, wx.ID_OK]: dlg.Destroy() frame.Destroy() self._queue.put(True) if __debug__: log('sending stop message to UI') wx.CallAfter(pub.sendMessage, 'stop') else: dlg.Destroy() self._queue.put(True)
def OnLogScrolledDialog(self, event=None, type='worker', mode='stderr'): if type == 'worker': filename = self.getLogFileNameWorker(0, mode) elif type == 'server': filename = self.getLogFileNameServer(mode) else: raise RuntimeError('invalid type %s' % type) with open(filename, "r") as f: txt = "\n".join(f.readlines()) dlg = ScrolledMessageDialog(self, txt, "%s %s" % (type, mode), size=(900, 400), style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE) dlg.ShowModal() dlg.Destroy()
def OnWorkerFileDialog(self, event=None): import tempfile tmpdir = tempfile.gettempdir() filename = wx.FileSelector( 'load worker stdout or stderr...', wildcard= "Stdout files (PYMEworker*.stdout)|*.stdout|Stderr files (PYMEworker*.stderr)|*.stderr", flags=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST, default_path=tmpdir) logging.info('loading %s' % filename) with open(filename, "r") as f: txt = "\n".join(f.readlines()) dlg = ScrolledMessageDialog(self, txt, os.path.basename(filename), size=(900, 400), style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE) dlg.ShowModal() dlg.Destroy()
def show_exception_dialog(parent=None, prefix='', exc_info=None, modal=False): """ExceptionDialog(parent=None, prefix='', exc_info=None) show exception info in a dialog parent: parent frame prefix: show in title of window before exception type exc_info: if provided, this is the data from sys.exc_info(). If not, use the current sys.exc_info() modal: if True, show dialog as a modal dialog """ if exc_info is None: info = sys.exc_info() else: info = exc_info if parent is None: parent = wx.GetApp().get_project_frame() filepath = traceback.extract_tb(info[2])[-1:][0][0] try: title = prefix + info[0].__name__ + ' in ' + os.path.split(filepath)[1] except: title = prefix + info[0].__name__ msg = traceback.format_exception(info[0], info[1], info[2]) msg = ''.join(msg) err = ScrolledMessageDialog(parent, msg, title, size=(640, 320), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) # scroll to bottom err.Children[0].ShowPosition(len(msg)) if modal: err.ShowModal() else: err.Show() wx.Bell() return
def OnLinkClicked(self, event): href = event.GetLinkInfo().GetHref() if href == 'show_license': if config.license_file: from wx.lib.dialogs import ScrolledMessageDialog try: license_file = codecs.open(config.license_file, encoding='UTF-8') dlg = ScrolledMessageDialog(self, license_file.read(), "wxGlade - License") license_file.close() dlg.ShowModal() dlg.Destroy() except EnvironmentError as inst: bugdialog.ShowEnvironmentError( _('''Can't read the file "LICENSE.txt".\n\nYou can get a license copy at\n''' '''http://www.opensource.org/licenses/mit-license.php''' ), inst) else: wx.MessageBox( _('File "LICENSE.txt" not found!\nYou can get a license copy at\n' 'http://www.opensource.org/licenses/mit-license.php'), _('Error'), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) elif href == 'show_credits': if config.credits_file: from wx.lib.dialogs import ScrolledMessageDialog try: credits_file = codecs.open(config.credits_file, encoding='UTF-8') dlg = ScrolledMessageDialog(self, credits_file.read(), _("wxGlade - Credits")) credits_file.close() dlg.ShowModal() dlg.Destroy() except EnvironmentError as inst: bugdialog.ShowEnvironmentError( _('''Can't read the file "CREDITS.txt"'''), inst) else: wx.MessageBox(_('File "CREDITS.txt" not found!'), _('Error'), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) else: import webbrowser webbrowser.open(href, new=True)
def OnLinkClicked(self, linkinfo): href = linkinfo.GetHref() if href == 'show_license': from wx.lib.dialogs import ScrolledMessageDialog try: license = open( os.path.join(common.wxglade_path, 'license.txt')) dlg = ScrolledMessageDialog(self, license.read(), _("wxGlade - License")) license.close() dlg.ShowModal() dlg.Destroy() except IOError: wx.MessageBox( _("Can't find the license!\n" "You can get a copy at \n" "http://www.opensource.org/licenses/" "mit-license.php"), _("Error"), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) elif href == 'show_credits': from wx.lib.dialogs import ScrolledMessageDialog try: credits = open( os.path.join(common.wxglade_path, 'credits.txt')) dlg = ScrolledMessageDialog(self, credits.read(), _("wxGlade - Credits")) credits.close() dlg.ShowModal() dlg.Destroy() except IOError: wx.MessageBox(_("Can't find the credits file!\n"), _("Oops!"), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) else: import webbrowser webbrowser.open(linkinfo.GetHref(), new=True)
def OnPageChanging(self, evt): if evt.GetDirection() == True: if (self.example.GetLabel() == 'Invalid table prefix.' and self.listTables.GetSelection() == wx.NOT_FOUND): evt.Veto() elif self.listTables.GetSelection() != wx.NOT_FOUND: self.Parent.outPerImage, self.Parent.outPerObject = self.listTables.GetStringSelection( ).split(',') self.Parent.masterExists = True if len(self.Parent.perImageTables) > 0: colnames = set(db.GetColumnNames( self.Parent.outPerImage)) - set(['TableNumber']) for t in self.Parent.perImageTables: colnames2 = set(db.GetColumnNames(t)) if colnames != colnames2: errdlg = ScrolledMessageDialog( self, 'The column names in tables "%s" and "%s" do not match.\n\n' 'Mismatched columns were:\n%s' % (self.Parent.outPerObject, t, ', '.join( colnames.symmetric_difference(colnames2))), 'Table column names do not match.', style=wx.OK | wx.ICON_EXCLAMATION | wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) errdlg.ShowModal() evt.Veto() if len(self.Parent.perObjectTables) > 0: colnames = set(db.GetColumnNames( self.Parent.outPerObject)) - set(['TableNumber']) for t in self.Parent.perObjectTables: colnames2 = set(db.GetColumnNames(t)) if colnames != colnames2: errdlg = ScrolledMessageDialog( self, 'The column names in tables "%s" and "%s" do not match.\n\n' 'Mismatched columns were:\n%s' % (self.Parent.outPerObject, t, ', '.join( colnames.symmetric_difference(colnames2))), 'Table column names do not match.', style=wx.OK | wx.ICON_EXCLAMATION | wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) errdlg.ShowModal() evt.Veto()
def OnPageChanging(self, evt): if evt.GetDirection() == True: if self.listTables.GetSelections() == (): evt.Veto() self.directions.SetForegroundColour('#FF0000') if len(self.Parent.perImageTables) > 1: colnames = set(db.GetColumnNames( self.Parent.perImageTables[0])) for t in self.Parent.perImageTables: colnames2 = set(db.GetColumnNames(t)) if colnames != colnames2: errdlg = ScrolledMessageDialog( self, 'The column names in tables "%s" and "%s" do not match.\n\n' 'Mismatched columns were:\n%s' % (self.Parent.perImageTables[0], t, ', '.join( colnames.symmetric_difference(colnames2))), 'Table column names do not match.', style=wx.OK | wx.ICON_EXCLAMATION | wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) errdlg.ShowModal() evt.Veto() if len(self.Parent.perObjectTables) > 1: colnames = set( db.GetColumnNames(self.Parent.perObjectTables[0])) for t in self.Parent.perObjectTables: colnames2 = set(db.GetColumnNames(t)) if colnames != colnames2: errdlg = ScrolledMessageDialog( self, 'The column names in tables "%s" and "%s" do not match.\n\n' 'Mismatched columns were:\n%s' % (self.Parent.perObjectTables[0], t, ', '.join( colnames.symmetric_difference(colnames2))), 'Table column names do not match.', style=wx.OK | wx.ICON_EXCLAMATION | wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) errdlg.ShowModal() evt.Veto()
def OnCombineError(self, message): from wx.lib.dialogs import ScrolledMessageDialog ScrolledMessageDialog(self.view, message.data, u"Notice").ShowModal()
def showMessage(self, cmd, msg): dlg = ScrolledMessageDialog(self.list, msg, cmd) try: dlg.ShowModal() finally: dlg.Destroy()
def OnHelpAbout(self, event): from wx.lib.dialogs import ScrolledMessageDialog about = ScrolledMessageDialog(self, __doc__, "About...") about.ShowModal()
def exception_hook(self, etype, value, trace): dlg = ScrolledMessageDialog( self, ''.join(traceback.format_exception(etype, value, trace)), "Error") dlg.ShowModal() dlg.Destroy()
def _OnHelpAbout(self, event): ''' Stuff that gets displayed when you select Help -> About in the menu bar''' from wx.lib.dialogs import ScrolledMessageDialog about = ScrolledMessageDialog(self, "Arbitrary Waveform Generator.\nA product of Wireless@VT.\n\nFor OSSIE 0.6.2.", "About...") about.ShowModal()
def OnHelpAbout(self, event): from wx.lib.dialogs import ScrolledMessageDialog print "import is ok " about = ScrolledMessageDialog(self,self.__doc__, "About...") print " about creation is ok " about.ShowModal()
def OnOk(self, event): print "OK" d = ScrolledMessageDialog(GraphUtil.root, "Hello world", "Test") d.ShowModal() pass