def OnInit(self): self.pmgr = plugin.PluginManager() # Bare minimum profile bootstrap profiler.Profile_Set('ENCODING', locale.getpreferredencoding()) profiler.Profile_Set('ICONS', 'Tango') return 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) 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 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 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 CreateConfigDir(): """ Creates the user config directory its default sub directories and any of the default config files. @postcondition: all default configuration files/folders are created """ #---- Resolve Paths ----# config_dir = ed_glob.CONFIG['CONFIG_BASE'] if config_dir is None: config_dir = wx.StandardPaths_Get().GetUserDataDir() + os.sep profile_dir = os.path.join(config_dir, u"profiles") dest_file = os.path.join(profile_dir, u"default.ppb") ext_cfg = [u"cache", u"styles", u"plugins"] #---- Create Directories ----# if not os.path.exists(config_dir): os.mkdir(config_dir) if not os.path.exists(profile_dir): os.mkdir(profile_dir) for cfg in ext_cfg: if not HasConfigDir(cfg): MakeConfigDir(cfg) import profiler profiler.TheProfile.LoadDefaults() profiler.Profile_Set("MYPROFILE", dest_file) profiler.TheProfile.Write(dest_file) profiler.UpdateProfileLoader()
def CreateConfigDir(): """ Creates the user config directory its default sub directories and any of the default config files. @postcondition: all default configuration files/folders are created """ #---- Resolve Paths ----# config_dir = u"%s%s.%s" % (wx.GetHomeDir(), os.sep, ed_glob.PROG_NAME) profile_dir = u"%s%sprofiles" % (config_dir, os.sep) dest_file = u"%s%sdefault.ppb" % (profile_dir, os.sep) ext_cfg = ["cache", "styles", "plugins"] #---- Create Directories ----# if not os.path.exists(config_dir): os.mkdir(config_dir) if not os.path.exists(profile_dir): os.mkdir(profile_dir) for cfg in ext_cfg: if not HasConfigDir(cfg): MakeConfigDir(cfg) import profiler profiler.Profile().LoadDefaults() profiler.Profile_Set("MYPROFILE", dest_file) profiler.UpdateProfileLoader()
def OnInit(self): self.pmgr = plugin.PluginManager() # Bare minimum profile bootstrap profiler.Profile_Set('ICONS', 'Tango') return True
def OnShow(self, evt): """ Shows the Comment Browser @param event: wxEvent """ if evt.GetId() == ID_COMMENTBROWSE: mgr = self._mainwin.GetFrameManager() pane = mgr.GetPane(PANE_NAME) if pane.IsShown(): pane.Hide() profiler.Profile_Set(CB_KEY, False) else: pane.Show() profiler.Profile_Set(CB_KEY, True) mgr.Update() else: evt.Skip()
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 OnDeleteSession(self, evt): """Delete the current session""" if evt.EventObject is self._delb: ses = self.GetSelectedSession() if ses != EdSessionMgr().DefaultSession: EdSessionMgr().DeleteSession(ses) # Switch back to default session profiler.Profile_Set('LAST_SESSION', EdSessionMgr().DefaultSession) else: evt.Skip()
def setUp(self): profiler.Profile_Set('ENCODING', locale.getpreferredencoding()) self.app = common.EdApp(False) self.path = common.GetDataFilePath(u'test_read_utf8.txt') self.file = ed_txt.EdFile(self.path) self.mtime = ebmlib.GetFileModTime(self.path) self.rpath = common.GetDataFilePath(u'embedded_nulls.txt') self.rfile = ed_txt.EdFile(self.rpath) self.ipath = common.GetDataFilePath(u'image_test.png') self.img = ed_txt.EdFile(self.ipath) self.bpath = common.GetDataFilePath(u'test_read_utf8_bom.txt') self.utf8_bom_file = ed_txt.EdFile(self.bpath)
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 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
# 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 tval = sum(time.localtime(time.time())[:3]) if profiler.Profile_Get('CHECKUPDATE', default=True) and \ tval - profiler.Profile_Get('LASTCHECK', 'int', default=0) > 1: profiler.Profile_Set('LASTCHECK', tval) 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")
def OptionSave(self, key, value): profiler.Profile_Set('IPython.' + key, value)
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
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 #---- 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 Destroy(self):
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))