예제 #1
0
    def __init__(self, W, H, scriptdir):
        if (platform.system() == "Darwin"):
            self.stdwinx = 0; self.stdwiny = 24
        else:
            self.stdwinx = 0; self.stdwiny = 0
        self.stdwinw = 370; self.stdwinh = H-40
        self.screenH = H; self.screenW = W
        winx = self.stdwinx; winy = self.stdwiny
        winw = self.stdwinw; winh = self.stdwinh
        self.scriptdir = scriptdir
        homedir = os.path.expanduser("~")
        # Try to get the save values from the cfg file
        try:
            if (platform.system() == "Windows"):
                f = open(homedir + "\\InteractiveROSETTA\\protwindow.cfg", "r")
            else:
                f = open(homedir + "/.InteractiveROSETTA/protwindow.cfg", "r")
            for aline in f:
                if (aline.find("[OFFSET X]") >= 0):
                    winx = winx + int(aline.split()[len(aline.split())-1])
                elif (aline.find("[OFFSET Y]") >= 0):
                    winy = winy + int(aline.split()[len(aline.split())-1])
                elif (aline.find("[OFFSET WIDTH]") >= 0):
                    winw = winw + int(aline.split()[len(aline.split())-1])
                elif (aline.find("[OFFSET HEIGHT]") >= 0):
                    winh = winh + int(aline.split()[len(aline.split())-1])
            f.close()
        except:
            pass
        if (winx > self.screenW - 100):
            winx = self.stdwinx
        if (winy > self.screenH - 100):
            winy = self.stdwiny
        # Catch bad cached sizes
        if (winw < 200):
            winw = self.stdwinw
        if (winh < 200):
            winh = self.stdwinh
        # Maybe the screen resolution has changed and the saved dimensions put the windows in
        # weird places, so default them to better positions and the user can change them later
        #if (winw < 350):
        #    winw = 370
        #elif (winw > W):
        #    winw = 370
        #if (winx < 0):
        #    winx = 0
        #elif (winx > W-winw):
        #    winx = W-winw
        #if (winh > H - 40):
        #    winh = H - 40
        #if (winy < 0):
        #    winy = 0
        #elif (winy > H-winh):
        #    winh = H-40
        wx.Frame.__init__(self, None, -1, "InteractiveROSETTA - Protocols", size=(winw, winh))
        self.SetPosition((winx, winy))
        self.SetBackgroundColour("#333333")
        self.SetSizeHints(330, 560, 370, H)
        self.SetIcon(icon.GetIcon())
        self.Show()

        self.Protocols = ProtocolsPanel(self, winw, winh)
        self.Selection = SelectPanel(self, winw, winh)
        self.Protocols.setSelectWin(self.Selection)
        self.Selection.setProtPanel(self.Protocols)

        self.saveTimer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.saveWindowData, self.saveTimer)
        self.Bind(wx.EVT_SIZE, self.windowGeometryChange)
        self.Bind(wx.EVT_MOTION, self.windowGeometryChange)
        self.Bind(wx.EVT_ACTIVATE, self.focusEvent)

        # Start the Rosetta daemon that will run in the background looking for job input files generated
        # by the main GUI
        # It could be the case that the user was in the middle of a protocol, then quits suddenly so the
        # daemon doesn't terminate itself because it's in the middle of a protocol
        # The the user restarts the GUI before the daemon has a chance to finish the protocol
        # This checks to see if the daemon is already active and doesn't spawn a new one if one is already
        # running
        stillrunning = False
        count = 0
        for proc in psutil.process_iter():
            try:
                if (platform.system() == "Windows"):
                    if (len(proc.cmdline()) >= 3 and proc.cmdline()[0].find("python") >= 0 and proc.cmdline()[2].find("from multiprocessing.forking") >= 0):
                        stillrunning = True
                        break
                else:
                    # On Unix systems you just have to make sure two instances of python are running
                    # because there isn't any forking information in the daemon's instance of python
                    if (len(proc.cmdline()) >= 2 and proc.cmdline()[0].find("python") >= 0 and proc.cmdline()[1].find("InteractiveROSETTA.py") >= 0):
                        count = count + 1
            except:
                # In Windows it will crash if you try to read process information for the Administrator
                # Doesn't matter though since InteractiveROSETTA is run by a non-Administrator
                # But we need to catch these errors since we don't know which processes are admin ones
                pass
        if (platform.system() != "Windows" and count == 2):
            stillrunning = True
        if (not(stillrunning)):
            print "Starting Rosetta protocol daemon..."
            #if (platform.system() == "Linux"):
                #self.daemon_process = subprocess.Popen(args=["cd " + self.scriptdir + "/scripts" + "; python", "daemon.py"], shell=False)
            #else:
            self.daemon_process = multiprocessing.Process(target=daemonLoop)
            self.daemon_process.start()