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 testSendCommands(self): command = ed_ipc.IPCCommand() rval = ed_ipc.SendCommands(command, self.key) self.assertTrue(rval)