def OnInit(self): sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ # replace text based exception handler by a graphical exception dialog sys.excepthook = self.graphical_exception_handler # use graphical implementation to show caught exceptions self._exception_orig = logging.exception logging.exception = self.exception # needed for wx >= 2.3.4 to disable wxPyAssertionError exceptions if not config.debugging: self.SetAssertMode(0) common.init_preferences() if config.preferences.log_debug_info: log.setDebugLevel() # enable Python faulthandler to dump a traceback on SIGSEGV, SIGFPE, SIGABRT, SIGBUS, and SIGILL signals. try: import faulthandler faulthandler.enable() logging.info(_('Python faulthandler found and activated')) except ImportError: logging.debug(_('Python faulthandler not found')) except RuntimeError as details: logging.info( _('Python faulthandler found, but enabling failed: %s'), details) except Exception as details: logging.info( _('Generic error during faulthandler initialisation: %s'), details) self.locale = wx.Locale(wx.LANGUAGE_DEFAULT) # avoid PyAssertionErrors compat.wx_ArtProviderPush(wxGladeArtProvider()) frame = wxGladeFrame() self.SetTopWindow(frame) self.SetExitOnFrameDelete(True) self.Bind(wx.EVT_IDLE, self.OnIdle) return True
def init_stage2(use_gui): """Initialise the remaining (non-path) parts of wxGlade (second stage) use_gui: Starting wxGlade GUI""" config.use_gui = use_gui if use_gui: # import proper wx-module using wxversion, which is only available in Classic if compat.IS_CLASSIC: if not hasattr(sys, "frozen") and 'wx' not in sys.modules: try: import wxversion wxversion.ensureMinimal('2.8') except ImportError: msg = _( 'Please install missing Python module "wxversion".') logging.error(msg) sys.exit(msg) try: import wx except ImportError: msg = _('Please install missing Python module "wxPython".') logging.error(msg) sys.exit(msg) # store current version and platform ('not_set' is default) config.platform = wx.Platform config.wx_version = wx.__version__ if sys.platform == "win32": # register ".wxg" extension try: import msw msw.register_extensions(["wxg"], "wxGlade") if not os.path.exists(config.rc_file): config.inform_screen_reader = msw.check_for_screen_reader() except ImportError: pass # codewrites, widgets and sizers are loaded in class main.wxGladeFrame else: # use_gui has to be set before importing config common.init_preferences() common.init_codegen()
def command_line_code_generation(filename, language, out_path=None): """Starts a code generator without starting the GUI. filename: Name of wxg file to generate code from language: Code generator language out_path: output file / output directory""" import application, tree # Instead of instantiating a main.wxGlade() object, that is # derived from wx.App, we must do the equivalent work. The # following lines are taken from main.wxGlade().OnInit() and # main.wxGladeFrame.__init__() common.init_preferences() common.root = app = application.Application() # The following lines contain code from tree.WidgetTree.__init__() if config.use_gui: common.app_tree = tree.WidgetTree(root_node, app) # Now we can load the file if filename is not None: b = _guiless_open_app(filename) if not b: sys.exit(1) try: if language not in common.code_writers: raise ValueError('Code writer for "%s" is not available.' % language) common.root.properties["language"].set(language) common.root.generate_code(out_path=out_path) except errors.WxgBaseException as inst: if config.debugging: raise logging.error(inst) sys.exit(inst) except Exception: if config.debugging: raise logging.error( _("An exception occurred while generating the code for the application.\n" "If you think this is a wxGlade bug, please report it.")) logging.exception(_('Internal Error')) sys.exit(1) sys.exit(0)
def setUpClass(cls): "Initialise parts of wxGlade before individual tests starts" # set icon path back to the default default #config.icons_path = 'icons' # initialise wxGlade preferences and set some useful values common.init_preferences() config.preferences.autosave = False config.preferences.write_timestamp = False config.preferences.show_progress = False #config.version = '"faked test version"' # make e.g. the preview raise Exceptions config.testing = True # Determinate case and output directory cls.caseDirectory = os.path.join( os.path.dirname(__file__), cls.caseDirectory ) cls.outDirectory = os.path.join( os.path.dirname(__file__), cls.outDirectory ) if not os.path.exists(cls.outDirectory): os.mkdir(cls.outDirectory) # disable bug dialogs sys._called_from_test = True
def setUpClass(cls): "Initialise parts of wxGlade before individual tests starts" # set icon path back to the default default config.icons_path = 'icons' # initialise wxGlade preferences and set some useful values common.init_preferences() config.preferences.autosave = False config.preferences.write_timestamp = False config.preferences.show_progress = False # Determinate case directory cls.caseDirectory = os.path.join( os.path.dirname(__file__), cls.caseDirectory, ) # disable bug dialogs sys._called_from_test = True # cache content to reduce IO fe = open(os.path.join(cls.caseDirectory, 'file_encodings.txt')) for line in fe.readlines(): line = line.strip() if not line or line.startswith('#'): continue cls._encoding_content.append(line) # platform specific list of existing / non-accessible directories cls.existing_directories = [ ".", '.%s' % os.path.sep, os.path.normpath('/tmp'), os.path.normpath('/'), os.path.normpath('/non-writable'), ] cls.non_accessible_directories = [os.path.normpath('/non-writable')] cls.non_accessible_files = \ os.path.normpath('/tmp/existing_but_no_access')
def init_stage2(use_gui): """\ Initialise the remaining (non-path) parts of wxGlade (second stage) @param use_gui: Starting wxGlade GUI @type use_gui: bool """ config.use_gui = use_gui if use_gui: # import proper wx-module using wxversion, which is only available in Classic if compat.IS_CLASSIC: if not hasattr(sys, "frozen") and 'wx' not in sys.modules: try: import wxversion wxversion.ensureMinimal('2.8') except ImportError: msg = _( 'Please install missing Python module "wxversion".') logging.error(msg) sys.exit(msg) try: import wx except ImportError: msg = _('Please install missing Python module "wxPython".') logging.error(msg) sys.exit(msg) # store current version and platform ('not_set' is default) config.platform = wx.Platform config.wx_version = wx.__version__ # codewrites, widgets and sizers are loaded in class main.wxGladeFrame else: # use_gui has to be set before importing config common.init_preferences() if config.preferences.log_debug_info: log.setDebugLevel() common.init_codegen()