def __init__(self, *args, **kargs): """Initialize that main app and its attributes @postcondition: application is created and ready to be run in mainloop """ wx.App.__init__(self, *args, **kargs) events.AppEventHandlerMixin.__init__(self) self.SetAppName(ed_glob.PROG_NAME) # Attributes self.profile_updated = InitConfig() self._log = dev_tool.DEBUGP self._lock = False self._windows = dict() if ed_glob.SINGLE: # Setup the instance checker instance_name = u"%s-%s" % (self.GetAppName(), wx.GetUserId()) self._instance = wx.SingleInstanceChecker(instance_name) if self._instance.IsAnotherRunning(): try: opts, args = getopt.getopt(sys.argv[1:], "dhv", ['debug', 'help', 'version']) except getopt.GetoptError, msg: self._log("[app][err] %s" % str(msg)) args = list() if not len(args): args.append(APP_CMD_OPEN_WINDOW) rval = ed_ipc.SendCommands(args, profiler.Profile_Get('SESSION_KEY')) # If sending the command failed then let the editor startup # a new instance if not rval: self._isfirst = True else: self._log("[app][info] Starting Ipc server...") # Set the session key and save it to the users profile so # that other instances can access the server key = unicode(base64.b64encode(os.urandom(8), 'zZ')) key = wx.GetUserName() + key profiler.Profile_Set('SESSION_KEY', key) profiler.Profile_Set('ISBINARY', hasattr(sys, 'frozen')) path = profiler.Profile_Get('MYPROFILE') profiler.Profile().Write(path) try: self._server = ed_ipc.EdIpcServer( self, profiler.Profile_Get('SESSION_KEY')) self._server.start() except Exception, msg: self._log("[app][err] Failed to start ipc server") self._log("[app][err] %s" % str(msg)) self._server = None self._isfirst = True
def OnInit(self): """Initialize the Editor @note: this gets called before __init__ @postcondition: custom artprovider and plugins are loaded """ self.SetAppName(ed_glob.PROG_NAME) self._log = dev_tool.DEBUGP self._log("[app][info] Editra is Initializing") self._isfirst = False # Is the first instance self._instance = None if ed_glob.SINGLE: # Setup the instance checker instance_name = u"%s-%s" % (self.GetAppName(), wx.GetUserId()) self._instance = wx.SingleInstanceChecker(instance_name) if self._instance.IsAnotherRunning(): try: opts, args = getopt.getopt(sys.argv[1:], "dhv", ['debug', 'help', 'version']) except getopt.GetoptError, msg: self._log("[app][err] %s" % str(msg)) args = list() if not len(args): args.append(APP_CMD_OPEN_WINDOW) rval = ed_ipc.SendCommands(args, profiler.Profile_Get('SESSION_KEY')) # If sending the command failed then let the editor startup # a new instance if not rval: self._isfirst = True else: self._log("[app][info] Starting Ipc server...") # Set the session key and save it to the users profile so # that other instances can access the server key = unicode(base64.b64encode(os.urandom(8), 'zZ')) key = wx.GetUserName() + key profiler.Profile_Set('SESSION_KEY', key) profiler.Profile_Set('ISBINARY', hasattr(sys, 'frozen')) path = profiler.Profile_Get('MYPROFILE') profiler.Profile().Write(path) try: self._server = ed_ipc.EdIpcServer( self, profiler.Profile_Get('SESSION_KEY')) self._server.start() except Exception, msg: self._log("[app][err] Failed to start ipc server") self._log("[app][err] %s" % str(msg)) self._server = None self._isfirst = True
def __init__(self, *args, **kargs): """Initialize that main app and its attributes @postcondition: application is created and ready to be run in mainloop """ wx.App.__init__(self, *args, **kargs) events.AppEventHandlerMixin.__init__(self) # Attributes self._log = dev_tool.DEBUGP self._lock = False self._windows = dict() # Setup Locale locale.setlocale(locale.LC_ALL, '') self.locale = wx.Locale(ed_i18n.GetLangId( profiler.Profile_Get('LANG'))) if self.locale.GetCanonicalName() in ed_i18n.GetAvailLocales(): self.locale.AddCatalogLookupPathPrefix(ed_glob.CONFIG['LANG_DIR']) self.locale.AddCatalog(ed_glob.PROG_NAME) else: del self.locale self.locale = None # Setup Plugins after locale as they may have resource that need to # be loaded. self._pluginmgr = plugin.PluginManager() self._log("[app][info] Registering Editra's ArtProvider") wx.ArtProvider.PushProvider(ed_art.EditraArt())
def __init__(self, style=0): """Initializes the Menubar @keyword style: style to set for menu bar """ super(EdMenuBar, self).__init__(style) # Setup if EdMenuBar.keybinder.GetCurrentProfile() is None: kprof = profiler.Profile_Get('KEY_PROFILE', default='default') EdMenuBar.keybinder.LoadKeyProfile(kprof) # Attributes self._menus = dict() self.GenFileMenu() self.GenEditMenu() self.GenViewMenu() self.GenFormatMenu() self.GenSettingsMenu() self.GenToolsMenu() self.GenHelpMenu() # Message handlers ed_msg.Subscribe(self.OnRebind, ed_msg.EDMSG_MENU_REBIND) ed_msg.Subscribe(self.OnLoadProfile, ed_msg.EDMSG_MENU_LOADPROFILE) ed_msg.Subscribe(self.OnCreateLexerMenu, ed_msg.EDMSG_CREATE_LEXER_MENU)
def setup_profile(): version = profiler.Profile_Get("RENPY_VERSION", default=0) if version < 2: profiler.Profile_Set("CHECKUPDATE", False) profiler.Profile_Set("AALIASING", True) if version < 3: profiler.Profile_Set("SYNTHEME", "RenPy") if version < 4: profiler.Profile_Set("LEXERMENU", ["Ren'Py"]) profiler.Profile_Set("DEFAULT_LEX", "Ren'Py") if version < 5: profiler.Profile_Set("APPSPLASH", False) if version < 6: profiler.Profile_Set("SHOW_EDGE", False) if version < 7: profiler.Profile_Set("ENCODING", "utf-8") # Set the RENPY_VERSION setting to store the version of # the Ren'Py profile in use. profiler.Profile_Set("RENPY_VERSION", 7)
def CreateItem(self, parent): """Returns an IPythonShell Panel""" self._log = wx.GetApp().GetLog() self._log("[xPyShell][info] Creating IPythonShell instance for Shelf") #main_win = wx.GetApp().GetMainWindow() #parent.AddPage(self.history_panel,'IPythonHistory',False) splitter = wx.SplitterWindow(parent, -1, style=wx.SP_LIVE_UPDATE) self.history_panel = IPythonHistoryPanel(splitter) self.history_panel.setOptionTrackerHook(self.OptionSave) self.ipython_panel = IPShellWidget(splitter, background_color="BLACK") #user_ns=locals(),user_global_ns=globals(),) self.ipython_panel.setOptionTrackerHook(self.OptionSave) self.ipython_panel.setHistoryTrackerHook(self.history_panel.write) options_ipython = self.ipython_panel.getOptions() for key in options_ipython.keys(): saved_value = profiler.Profile_Get('IPython.' + key) if saved_value is not None: options_ipython[key]['value'] = saved_value options_history = self.history_panel.getOptions() for key in options_history.keys(): saved_value = profiler.Profile_Get('IPython.' + key) if saved_value is not None: options_history[key]['value'] = saved_value self.ipython_panel.reloadOptions(options_ipython) self.history_panel.reloadOptions(options_history) splitter.SetMinimumPaneSize(20) splitter.SplitVertically(self.ipython_panel, self.history_panel, -100) #splitter.SplitVertically(frame, self.history_panel, -100) ### for better split window sizing behavior self._splitter = splitter shell_window = splitter.GetWindow1() shell_window.SetMinSize((500, 0)) history_window = splitter.GetWindow2() history_window.SetMinSize((100, 0)) splitter.SetSashGravity(0.7) return splitter
def UpdateSelectedSession(self): """Select the currently configured session""" ses = profiler.Profile_Get('LAST_SESSION') if ses: if ses == EdSessionMgr().DefaultSession: self._sch.SetSelection(0) elif ses in self._sch.Items: self._sch.SetStringSelection(ses)
def Exit(self, force=False): """Exit the program @postcondition: If no toplevel windows are present program will exit. @postcondition: Program may remain open if an open window is locking. """ self._pluginmgr.WritePluginConfig() profiler.Profile().Write(profiler.Profile_Get('MYPROFILE')) if not self._lock or force: wx.App.Exit(self)
def TranslateEOLMode(): """Translate old eol mode persistance to new one @prerequisite: Profile has been initialized / loaded """ eol_m = profiler.Profile_Get('EOL') if len(eol_m) > 4: emap = {'m': 'CR', 'w': 'CRLF', 'u': 'LF'} cmode = eol_m[0].lower() profiler.Profile_Set('EOL', emap.get(cmode, 'LF'))
def PopulateLexerMenu(langmenu): """Create a menu with all the lexer options @return: wx.Menu """ mconfig = profiler.Profile_Get('LEXERMENU', default=list()) mconfig.sort() for label in mconfig: lid = synglob.GetIdFromDescription(label) langmenu.Append(lid, label, _("Switch Lexer to %s") % label, wx.ITEM_CHECK)
def OnInit(self): """Initialize the Editor @note: this gets called before __init__ @postcondition: custom artprovider and plugins are loaded """ self._log = dev_tool.DEBUGP self._log("[app][info] Editra is Initializing") self._isfirst = False # Is the first instance self._instance = None # Setup Locale locale.setlocale(locale.LC_ALL, '') self.locale = wx.Locale(ed_i18n.GetLangId( profiler.Profile_Get('LANG'))) if self.locale.GetCanonicalName() in ed_i18n.GetAvailLocales(): self.locale.AddCatalogLookupPathPrefix(ed_glob.CONFIG['LANG_DIR']) self.locale.AddCatalog(ed_glob.PROG_NAME) else: del self.locale self.locale = None # Check and set encoding if necessary if not profiler.Profile_Get('ENCODING'): profiler.Profile_Set('ENCODING', locale.getpreferredencoding()) # Setup the Error Reporter if profiler.Profile_Get('REPORTER', 'bool', True): sys.excepthook = dev_tool.ExceptionHook #---- Bind Events ----# self.Bind(wx.EVT_ACTIVATE_APP, self.OnActivate) self.Bind(wx.EVT_MENU, self.OnNewWindow, id=ed_glob.ID_NEW_WINDOW) self.Bind(wx.EVT_MENU, self.OnCloseWindow) self.Bind(ed_event.EVT_NOTIFY, self.OnNotify) self.Bind(ed_ipc.EVT_COMMAND_RECV, self.OnCommandRecieved) return True
def RepairConfigState(path): """Repair the state of profile path, updating and creating it it does not exist. @param path: path of profile """ if os.path.isabs(path) and os.path.exists(path): return path else: # Need to fix some stuff up CreateConfigDir() import profiler return profiler.Profile_Get("MYPROFILE")
def Exit(self, force=False): """Exit the program @postcondition: If no toplevel windows are present program will exit. @postcondition: Program may remain open if an open window is locking. """ self._pluginmgr.WritePluginConfig() profiler.Profile().Write(profiler.Profile_Get('MYPROFILE')) if not self._lock or force: if hasattr(self, 'server'): self.server.ShutDown() try: # Cleanup the instance checker del self._instance except AttributeError: pass # Exit the app wx.App.ExitMainLoop(self)
def OnInit(self): """Initialize the Editor @note: this gets called before __init__ @postcondition: custom artprovider and plugins are loaded """ self.SetAppName(ed_glob.PROG_NAME) self._log = dev_tool.DEBUGP self._log("[app][info] Editra is Initializing") if profiler.Profile_Get('REPORTER', 'bool', True): sys.excepthook = dev_tool.ExceptionHook #---- Bind Events ----# self.Bind(wx.EVT_ACTIVATE_APP, self.OnActivate) self.Bind(wx.EVT_MENU, self.OnNewWindow, id=ed_glob.ID_NEW_WINDOW) self.Bind(wx.EVT_MENU, self.OnCloseWindow) self.Bind(ed_event.EVT_NOTIFY, self.OnNotify) return True
def OpenNewWindow(self, fname=u'', caller=None): """Open a new window @keyword fname: Open a file in the new window """ frame = ed_main.MainWindow(None, wx.ID_ANY, profiler.Profile_Get('WSIZE'), ed_glob.PROG_NAME) if caller: pos = caller.GetPosition() frame.SetPosition((pos.x + 22, pos.y + 22)) self.RegisterWindow(repr(frame), frame, True) self.SetTopWindow(frame) if isinstance(fname, basestring) and fname != u'': frame.DoOpen(ed_glob.ID_COMMAND_LINE_OPEN, fname) frame.Show(True) # Ensure frame gets an Activate event when shown # this doesn't happen automatically on windows if wx.Platform == '__WXMSW__': wx.PostEvent(frame, wx.ActivateEvent(wx.wxEVT_ACTIVATE, True))
def CreateLexerMenu(self): """Create the Lexer menu""" settingsmenu = self._menus['settings'] item = settingsmenu.FindItemById(ed_glob.ID_LEXER) if item: settingsmenu.Remove(ed_glob.ID_LEXER) mconfig = profiler.Profile_Get('LEXERMENU', default=list()) mconfig.sort() # Create the menu langmenu = wx.Menu() langmenu.Append(ed_glob.ID_LEXER_CUSTOM, _("Customize..."), _("Customize the items shown in this menu.")) langmenu.AppendSeparator() for label in mconfig: lid = synglob.GetIdFromDescription(label) langmenu.Append(lid, label, _("Switch Lexer to %s") % label, wx.ITEM_CHECK) settingsmenu.AppendMenu(ed_glob.ID_LEXER, _("Lexers"), langmenu, _("Manually Set a Lexer/Syntax"))
# Create Application dev_tool.DEBUGP("[main][info] Initializing Application...") editra_app = Editra(False) if profile_updated: # Make sure window iniliazes to default position profiler.Profile_Del('WPOS') wx.MessageBox(_("Your profile has been updated to the latest " "version") + u"\n" + \ _("Please check the preferences dialog to reset " "your preferences"), _("Profile Updated")) # Splash a warning if version is not a final version if profiler.Profile_Get('APPSPLASH') and int(ed_glob.VERSION[0]) < 1: import edimage splash_img = edimage.splashwarn.GetBitmap() splash = wx.SplashScreen(splash_img, wx.SPLASH_CENTRE_ON_PARENT | \ wx.SPLASH_NO_TIMEOUT, 0, None, wx.ID_ANY) splash.Show() if profiler.Profile_Get('SET_WSIZE'): wsize = profiler.Profile_Get('WSIZE') else: wsize = (700, 450) frame = ed_main.MainWindow(None, wx.ID_ANY, wsize, ed_glob.PROG_NAME) frame.Maximize(profiler.Profile_Get('MAXIMIZED')) editra_app.RegisterWindow(repr(frame), frame, True) editra_app.SetTopWindow(frame) frame.Show(True)
def Main(): """Configures and Runs an instance of Editra @summary: Parses command line options, loads the user profile, creates an instance of Editra and starts the main loop. """ opts, args = ProcessCommandLine() # We are ready to run so fire up the config and launch the app profile_updated = InitConfig() # Put extern subpackage on path so that bundled external dependancies # can be found if needed. if not hasattr(sys, 'frozen'): epath = os.path.join(os.path.dirname(__file__), 'extern') if os.path.exists(epath): sys.path.append(epath) # Create Application dev_tool.DEBUGP("[main][app] Initializing application...") editra_app = Editra(False) # Print ipc server authentication info if '--auth' in opts: opts.remove('--auth') print "port=%d,key=%s" % (ed_ipc.EDPORT, profiler.Profile_Get('SESSION_KEY')) # Check if this is the only instance, if its not exit since # any of the opening commands have already been passed to the # master instance if not editra_app.IsOnlyInstance(): dev_tool.DEBUGP("[main][info] Second instance exiting...") editra_app.Destroy() os._exit(0) if profile_updated: # Make sure window iniliazes to default position profiler.Profile_Del('WPOS') wx.MessageBox(_("Your profile has been updated to the latest " "version") + u"\n" + \ _("Please check the preferences dialog to check " "your preferences"), _("Profile Updated")) # Splash a warning if version is not a final version if profiler.Profile_Get('APPSPLASH'): import edimage splash_img = edimage.splashwarn.GetBitmap() splash = wx.SplashScreen(splash_img, wx.SPLASH_CENTRE_ON_PARENT | \ wx.SPLASH_NO_TIMEOUT, 0, None, wx.ID_ANY) splash.Show() if profiler.Profile_Get('SET_WSIZE'): wsize = profiler.Profile_Get('WSIZE') else: wsize = (700, 450) frame = ed_main.MainWindow(None, wx.ID_ANY, wsize, ed_glob.PROG_NAME) frame.Maximize(profiler.Profile_Get('MAXIMIZED')) editra_app.RegisterWindow(repr(frame), frame, True) editra_app.SetTopWindow(frame) frame.Show(True) # Load Session Data # But not if there are command line args for files to open if profiler.Profile_Get('SAVE_SESSION', 'bool', False) and not len(args): frame.GetNotebook().LoadSessionFiles() # Unlike wxMac/wxGTK Windows doesn't post an activate event when a window # is first shown, so do it manually to make sure all event handlers get # pushed. if wx.Platform == '__WXMSW__': wx.PostEvent(frame, wx.ActivateEvent(wx.wxEVT_ACTIVATE, True)) if 'splash' in locals(): splash.Destroy() # Do update check, only check if its been more than a day since the last # check if profiler.Profile_Get('CHECKUPDATE', default=True): uthread = updater.UpdateThread(editra_app, ID_UPDATE_CHECK) uthread.start() for arg in args: try: arg = os.path.abspath(arg) fname = ed_txt.DecodeString(arg, sys.getfilesystemencoding()) frame.DoOpen(ed_glob.ID_COMMAND_LINE_OPEN, fname) except IndexError: dev_tool.DEBUGP("[main][err] IndexError on commandline args") # 3. Start Applications Main Loop dev_tool.DEBUGP("[main][info] Starting MainLoop...") editra_app.MainLoop() dev_tool.DEBUGP("[main][info] MainLoop finished exiting application") os._exit(0)
def InitConfig(): """Initializes the configuration data @postcondition: all configuration data is set """ ed_glob.CONFIG['PROFILE_DIR'] = util.ResolvConfigDir("profiles") profile_updated = False if util.HasConfigDir(): if profiler.ProfileIsCurrent(): profiler.Profile().Load(profiler.GetProfileStr()) else: dev_tool.DEBUGP( "[InitConfig][info] Updating Profile to current version") # Load and update profile pstr = profiler.GetProfileStr() profiler.Profile().Load(pstr) profiler.Profile().Update() #---- Temporary Profile Adaptions ----# # GUI_DEBUG mode removed in 0.2.5 mode = profiler.Profile_Get('MODE') if mode == 'GUI_DEBUG': profiler.Profile_Set('MODE', 'DEBUG') profiler.Profile_Del('LASTCHECK') #---- End Temporary Profile Adaptions ----# # Write out updated profile profiler.Profile().Write(pstr) # When upgrading from an older version make sure all # config directories are available. for cfg in ["cache", "styles", "plugins", "profiles"]: if not util.HasConfigDir(cfg): util.MakeConfigDir(cfg) profile_updated = True else: # Fresh install util.CreateConfigDir() # Set default eol for windows if wx.Platform == '__WXMSW__': profiler.Profile_Set('EOL', 'Windows (\\r\\n)') # Set debug mode if 'DEBUG' in profiler.Profile_Get('MODE'): ed_glob.DEBUG = True # Resolve resource locations ed_glob.CONFIG['CONFIG_DIR'] = util.ResolvConfigDir("") ed_glob.CONFIG['SYSPIX_DIR'] = util.ResolvConfigDir("pixmaps", True) ed_glob.CONFIG['PLUGIN_DIR'] = util.ResolvConfigDir("plugins") ed_glob.CONFIG['THEME_DIR'] = util.ResolvConfigDir( os.path.join("pixmaps", "theme")) ed_glob.CONFIG['LANG_DIR'] = util.ResolvConfigDir("locale", True) ed_glob.CONFIG['STYLES_DIR'] = util.ResolvConfigDir("styles") ed_glob.CONFIG['SYS_PLUGIN_DIR'] = util.ResolvConfigDir("plugins", True) ed_glob.CONFIG['SYS_STYLES_DIR'] = util.ResolvConfigDir("styles", True) ed_glob.CONFIG['TEST_DIR'] = util.ResolvConfigDir( os.path.join("tests", "syntax"), True) if not util.HasConfigDir("cache"): util.MakeConfigDir("cache") ed_glob.CONFIG['CACHE_DIR'] = util.ResolvConfigDir("cache") return profile_updated
key = wx.GetUserName() + key profiler.Profile_Set('SESSION_KEY', key) profiler.Profile_Set('ISBINARY', hasattr(sys, 'frozen')) path = profiler.Profile_Get('MYPROFILE') profiler.Profile().Write(path) self._server = ed_ipc.EdIpcServer( self, profiler.Profile_Get('SESSION_KEY')) self._server.start() self._isfirst = True else: self._isfirst = True # Setup Locale locale.setlocale(locale.LC_ALL, '') self.locale = wx.Locale(ed_i18n.GetLangId( profiler.Profile_Get('LANG'))) if self.locale.GetCanonicalName() in ed_i18n.GetAvailLocales(): self.locale.AddCatalogLookupPathPrefix(ed_glob.CONFIG['LANG_DIR']) self.locale.AddCatalog(ed_glob.PROG_NAME) else: del self.locale self.locale = None # Setup the Error Reporter if profiler.Profile_Get('REPORTER', 'bool', True): sys.excepthook = dev_tool.ExceptionHook #---- Bind Events ----# self.Bind(wx.EVT_ACTIVATE_APP, self.OnActivate) self.Bind(wx.EVT_MENU, self.OnNewWindow, id=ed_glob.ID_NEW_WINDOW) self.Bind(wx.EVT_MENU, self.OnCloseWindow)
def AutoIndenter(stc, current_pos, indent_char): """ Determines the indentation rule. 0) If the line is empty except for whitespace, indent to the current column. 1) If all strings and parenthesis are closed, then indent based on how this line has been styled. 2) If we're in a string, indent to one more than the position at which the string started. 3) If we've opened more parenthesis then we closed on the current line, indent by 1. 4) If we've closed more parenthesis than we opened on the current line, dedent by 1. 5) Otherwise, keep the current indentation. """ line = stc.LineFromPosition(current_pos) while line >= 0: line_state = stc.GetLineState(line) if line_state: break line -= 1 start = stc.PositionFromLine(line) text = stc.GetTextRangeUTF8(start, current_pos) pos = -1 len_text = len(text) # States for the indenting state machine. ISTATE_INDENT = 0 # Line indentation. ISTATE_CODE = 1 # Normal code. ISTATE_COMMENT = 2 # Comment. ISTATE_COMMENT_LINE = 3 # Full-line comment. ISTATE_STRING = 4 # In a string. ISTATE_EOL = 5 # At the end of the line. state = ISTATE_EOL # The indentation of the last non-blank, non-comment line. prior_indent = 0 # The number of parens that are open in the statement. open_parens = 0 # The net change in parens on the current line. net_parens = 0 # Where the current line started. line_start = 0 # The quote characters used to close the current string. quote_chars = None # The indentation to use if we're in a quote. quote_indent = 0 while pos + 1 < len_text: pos += 1 c = text[pos] if state == ISTATE_EOL: line_start = pos net_parens = 0 state = ISTATE_INDENT if state == ISTATE_INDENT: if c == " ": continue elif c == "\n": state = ISTATE_EOL continue elif c == "#": state = ISTATE_COMMENT_LINE continue state = ISTATE_CODE prior_indent = pos - line_start # Intentionally fall through. if state == ISTATE_COMMENT or state == ISTATE_COMMENT_LINE: if c == "\n": state = ISTATE_EOL continue continue elif state == ISTATE_CODE: if c == "\n": state = ISTATE_EOL continue if c in "\"'`": start = text[pos:pos + 3] if start == "'''" or start == '"""': quote_chars = start quote_indent = pos - line_start pos += 2 state = ISTATE_STRING continue quote_chars = c quote_indent = 1 + pos - line_start state = ISTATE_STRING continue if c in "([{": net_parens += 1 open_parens += 1 continue if c in ")]}": net_parens -= 1 open_parens -= 1 continue if c == "#": state = ISTATE_COMMENT continue continue elif state == ISTATE_STRING: if c == "\n": line_start = pos + 1 continue if c == "\\": pos += 1 continue if c == quote_chars: state = ISTATE_CODE continue if text[pos:pos + 3] == quote_chars: pos += 2 state = ISTATE_CODE continue continue # Compute the indent of the line itself. INDENTWIDTH = profiler.Profile_Get("INDENTWIDTH") line_indent = line_state & INDENT_MASK if state == ISTATE_STRING: indent = quote_indent elif state == ISTATE_COMMENT_LINE: l = stc.GetCurrentLine() indent = stc.GetLineIndentation(l) elif open_parens <= 0: if state == ISTATE_INDENT or state == ISTATE_EOL: l = stc.GetCurrentLine() if stc.GetLineIndentPosition(l) == stc.GetLineEndPosition(l): indent = stc.GetColumn(current_pos) else: indent = line_indent elif line_state & INDENTS: indent = line_indent + INDENTWIDTH else: indent = line_indent elif net_parens > 0: indent = prior_indent + INDENTWIDTH elif net_parens < 0: indent = max(line_indent + INDENTWIDTH, prior_indent - INDENTWIDTH) else: indent = prior_indent # Implement the indent. eolch = stc.GetEOLChar() stc.AddText(eolch) l = stc.GetCurrentLine() stc.SetLineIndentation(l, indent) stc.GotoPos(stc.GetLineIndentPosition(l))
"\nFrom: %s\n\nTo: %s") % (old_cdir, config_base) wx.MessageBox(msg, "Upgrade Failed", style=wx.ICON_WARNING | wx.OK) # Set default eol for windows if wx.Platform == '__WXMSW__': profiler.Profile_Set('EOL', 'CRLF') profiler.Profile_Set('ICONSZ', (16, 16)) #---- Profile Loaded / Installed ----# # Extra Adaption checks TranslateEOLMode() # End Extra Adaptions # Set debug mode if 'DEBUG' in profiler.Profile_Get('MODE'): ed_glob.DEBUG = True # Resolve resource locations ed_glob.CONFIG['CONFIG_DIR'] = util.ResolvConfigDir("") ed_glob.CONFIG['SYSPIX_DIR'] = util.ResolvConfigDir("pixmaps", True) ed_glob.CONFIG['PLUGIN_DIR'] = util.ResolvConfigDir("plugins") ed_glob.CONFIG['THEME_DIR'] = util.ResolvConfigDir( os.path.join("pixmaps", "theme")) ed_glob.CONFIG['LANG_DIR'] = util.ResolvConfigDir("locale", True) ed_glob.CONFIG['STYLES_DIR'] = util.ResolvConfigDir("styles") ed_glob.CONFIG['SYS_PLUGIN_DIR'] = util.ResolvConfigDir("plugins", True) ed_glob.CONFIG['SYS_STYLES_DIR'] = util.ResolvConfigDir("styles", True) ed_glob.CONFIG['TEST_DIR'] = util.ResolvConfigDir( os.path.join("tests", "syntax"), True)
def InitConfig(): """Initializes the configuration data @postcondition: all configuration data is set """ # Look for a profile directory on the system level. If this directory exists # Use it instead of the user one. This will allow for running Editra from # a portable drive or for system administrators to enforce settings on a # system installed version. config_base = util.ResolvConfigDir(u'.Editra', True) if os.path.exists(config_base): ed_glob.CONFIG['CONFIG_BASE'] = config_base ed_glob.CONFIG['PROFILE_DIR'] = os.path.join(config_base, u"profiles") ed_glob.CONFIG['PROFILE_DIR'] += os.sep else: config_base = wx.StandardPaths.Get().GetUserDataDir() ed_glob.CONFIG['PROFILE_DIR'] = util.ResolvConfigDir("profiles") # Check for if config directory exists and if profile is from the current # running version of Editra. profile_updated = False if util.HasConfigDir() and os.path.exists(ed_glob.CONFIG['PROFILE_DIR']): if profiler.ProfileIsCurrent(): profiler.Profile().Load(profiler.GetProfileStr()) else: dev_tool.DEBUGP( "[InitConfig][info] Updating Profile to current version") # Load and update profile pstr = profiler.GetProfileStr() profiler.Profile().Load(pstr) profiler.Profile().Update() #---- Temporary Profile Adaptions ----# # GUI_DEBUG mode removed in 0.2.5 mode = profiler.Profile_Get('MODE') if mode == 'GUI_DEBUG': profiler.Profile_Set('MODE', 'DEBUG') # This key has been removed so clean it from old profiles profiler.Profile_Del('LASTCHECK') # Print modes don't use strings anymore if isinstance(profiler.Profile_Get('PRINT_MODE'), basestring): profiler.Profile_Set('PRINT_MODE', ed_glob.PRINT_BLACK_WHITE) # Simplifications to eol mode persistance (0.4.0) TranslateEOLMode() #---- End Temporary Profile Adaptions ----# # Write out updated profile profiler.Profile().Write(pstr) # When upgrading from an older version make sure all # config directories are available. for cfg in ["cache", "styles", "plugins", "profiles"]: if not util.HasConfigDir(cfg): util.MakeConfigDir(cfg) profile_updated = True else: # Fresh install util.CreateConfigDir() # Check and upgrade installs from old location success = True try: success = UpgradeOldInstall() except Exception, msg: dev_tool.DEBUGP("[InitConfig][err] %s" % msg) success = False if not success: old_cdir = u"%s%s.%s%s" % (wx.GetHomeDir(), os.sep, ed_glob.PROG_NAME, os.sep) msg = ( "Failed to upgrade your old installation\n" "To retain your old settings you may need to copy some files:\n" "\nFrom: %s\n\nTo: %s") % (old_cdir, config_base) wx.MessageBox(msg, "Upgrade Failed", style=wx.ICON_WARNING | wx.OK) # Set default eol for windows if wx.Platform == '__WXMSW__': profiler.Profile_Set('EOL', 'CRLF') profiler.Profile_Set('ICONSZ', (16, 16))
# Create Application dev_tool.DEBUGP("[main][info] Initializing Application...") editra_app = Editra(False) if profile_updated: # Make sure window iniliazes to default position profiler.Profile_Del('WPOS') wx.MessageBox(_("Your profile has been updated to the latest " "version") + u"\n" + \ _("Please check the preferences dialog to reset " "your preferences"), _("Profile Updated")) # Splash a warning if version is not a final version if profiler.Profile_Get('APPSPLASH') and int(ed_glob.VERSION[0]) < 1: import edimage splash_img = edimage.splashwarn.GetBitmap() splash = wx.SplashScreen(splash_img, wx.SPLASH_CENTRE_ON_PARENT | \ wx.SPLASH_NO_TIMEOUT, 0, None, wx.ID_ANY) splash.Show() frame = ed_main.MainWindow(None, wx.ID_ANY, profiler.Profile_Get('WSIZE'), ed_glob.PROG_NAME) editra_app.RegisterWindow(repr(frame), frame, True) editra_app.SetTopWindow(frame) frame.Show(True) # Load Session Data # But not if there are command line args for files to open if profiler.Profile_Get('SAVE_SESSION', 'bool', False) and not len(args):
try: self._server = ed_ipc.EdIpcServer( self, profiler.Profile_Get('SESSION_KEY')) self._server.start() except Exception, msg: self._log("[app][err] Failed to start ipc server") self._log("[app][err] %s" % str(msg)) self._server = None self._isfirst = True else: self._isfirst = True # Setup Locale locale.setlocale(locale.LC_ALL, '') self.locale = wx.Locale(ed_i18n.GetLangId( profiler.Profile_Get('LANG'))) if self.locale.GetCanonicalName() in ed_i18n.GetAvailLocales(): self.locale.AddCatalogLookupPathPrefix(ed_glob.CONFIG['LANG_DIR']) self.locale.AddCatalog(ed_glob.PROG_NAME) else: del self.locale self.locale = None # Check and set encoding if necessary if not profiler.Profile_Get('ENCODING'): profiler.Profile_Set('ENCODING', locale.getpreferredencoding()) # Setup the Error Reporter if profiler.Profile_Get('REPORTER', 'bool', True): sys.excepthook = dev_tool.ExceptionHook
def InitConfig(): """Initializes the configuration data @postcondition: all configuration data is set """ # Look for a profile directory on the system level. If this directory exists # Use it instead of the user one. This will allow for running Editra from # a portable drive or for system administrators to enforce settings on a # system installed version. config_base = util.ResolvConfigDir(u'.Editra', True) if os.path.exists(config_base): ed_glob.CONFIG['CONFIG_BASE'] = config_base ed_glob.CONFIG['PROFILE_DIR'] = os.path.join(config_base, u"profiles") ed_glob.CONFIG['PROFILE_DIR'] += os.sep else: ed_glob.CONFIG['PROFILE_DIR'] = util.ResolvConfigDir("profiles") # Check for if config directory exists and if profile is from the current # running version of Editra. profile_updated = False if util.HasConfigDir() and os.path.exists(ed_glob.CONFIG['PROFILE_DIR']): if profiler.ProfileIsCurrent(): profiler.Profile().Load(profiler.GetProfileStr()) else: dev_tool.DEBUGP( "[InitConfig][info] Updating Profile to current version") # Load and update profile pstr = profiler.GetProfileStr() profiler.Profile().Load(pstr) profiler.Profile().Update() #---- Temporary Profile Adaptions ----# # GUI_DEBUG mode removed in 0.2.5 mode = profiler.Profile_Get('MODE') if mode == 'GUI_DEBUG': profiler.Profile_Set('MODE', 'DEBUG') # This key has been removed so clean it from old profiles profiler.Profile_Del('LASTCHECK') # Print modes don't use strings anymore if isinstance(profiler.Profile_Get('PRINT_MODE'), basestring): profiler.Profile_Set('PRINT_MODE', ed_glob.PRINT_BLACK_WHITE) #---- End Temporary Profile Adaptions ----# # Write out updated profile profiler.Profile().Write(pstr) # When upgrading from an older version make sure all # config directories are available. for cfg in ["cache", "styles", "plugins", "profiles"]: if not util.HasConfigDir(cfg): util.MakeConfigDir(cfg) profile_updated = True else: # Fresh install util.CreateConfigDir() # Set default eol for windows if wx.Platform == '__WXMSW__': profiler.Profile_Set('EOL', 'Windows (\\r\\n)') # Set debug mode if 'DEBUG' in profiler.Profile_Get('MODE'): ed_glob.DEBUG = True # Resolve resource locations ed_glob.CONFIG['CONFIG_DIR'] = util.ResolvConfigDir("") ed_glob.CONFIG['SYSPIX_DIR'] = util.ResolvConfigDir("pixmaps", True) ed_glob.CONFIG['PLUGIN_DIR'] = util.ResolvConfigDir("plugins") ed_glob.CONFIG['THEME_DIR'] = util.ResolvConfigDir( os.path.join("pixmaps", "theme")) ed_glob.CONFIG['LANG_DIR'] = util.ResolvConfigDir("locale", True) ed_glob.CONFIG['STYLES_DIR'] = util.ResolvConfigDir("styles") ed_glob.CONFIG['SYS_PLUGIN_DIR'] = util.ResolvConfigDir("plugins", True) ed_glob.CONFIG['SYS_STYLES_DIR'] = util.ResolvConfigDir("styles", True) ed_glob.CONFIG['TEST_DIR'] = util.ResolvConfigDir( os.path.join("tests", "syntax"), True) if not util.HasConfigDir("cache"): util.MakeConfigDir("cache") ed_glob.CONFIG['CACHE_DIR'] = util.ResolvConfigDir("cache") return profile_updated