class MainFrame(wx.Frame): def __init__(self, parent, id, title): self._settings = Settings() if self._settings.val('phenix'): import sys p = self._settings.val('phenix') base = p + '/Contents/' + os.path.basename(p).lower() if os.path.exists(base): sys.path.append(base + '/elbow') sys.path.append(base) libtbx.env.add_repository(base) libtbx.env.process_module(None, 'elbow', False) CootClient.set_start_coot(self.start_coot) SettingsDialog.set_settings(self._settings) HelpDialog.set_settings(self._settings) wx.Frame.__init__(self, parent, id, title, size=(850,540)) self.Bind(wx.EVT_CLOSE, self._on_close) self.toolbar = wx.ToolBar(self, style=wx.TB_3DBUTTONS|wx.TB_TEXT) quit = self.toolbar.AddLabelTool(wx.ID_ANY, 'Quit', wxtbx.bitmaps.fetch_icon_bitmap('actions', 'exit')) settings = self.toolbar.AddLabelTool(wx.ID_ANY, 'Settings', wxtbx.bitmaps.fetch_icon_bitmap('actions', 'configure')) about = self.toolbar.AddLabelTool(wx.ID_ANY, 'About', wxtbx.bitmaps.fetch_icon_bitmap('actions', 'info')) help = self.toolbar.AddLabelTool(wx.ID_ANY, 'Help', wxtbx.bitmaps.fetch_icon_bitmap('actions', 'agt_support')) self.toolbar.AddSeparator() coot = self.toolbar.AddLabelTool(wx.ID_ANY, 'Coot', wx.Bitmap(self._settings.proot + 'Resources/gui_resources/coot.png')) ligand = self.toolbar.AddLabelTool(wx.ID_ANY, 'Ligands', wx.Bitmap(self._settings.proot + 'Resources/gui_resources/ligand_32.png')) self.SetToolBar(self.toolbar) self.toolbar.Realize() self.Bind(wx.EVT_TOOL, self._on_close, quit) self.Bind(wx.EVT_TOOL, self.start_coot, coot) self.Bind(wx.EVT_TOOL, self._show_settings, settings) self.Bind(wx.EVT_TOOL, self._show_about, about) self.Bind(wx.EVT_TOOL, self._show_help, help) self.Bind(wx.EVT_TOOL, self._view_ligand, ligand) self._coot_timer = None self._coot_process = None self._coot_client = CootClient() nb = wx.aui.AuiNotebook(self, -1, style=wx.NB_TOP) self.sheet1 = Manager(nb) Tab.set_settings(self._settings) CootClient.set_p8(self._settings.proot) Tab.set_coot_client(self._coot_client) Tab.set_start_coot(self.start_coot) Tab.set_update_sb(self.set_status) self.sheet2 = ProcessManager(nb) self.sheet3 = Compare(nb) Jobs.set_new_refinement(self.sheet2.new_refinement) Jobs.set_load_refinement(self.sheet2.load_refinement) Jobs.set_auto_refinement(self.sheet2.auto_refinement) nb.AddPage(self.sheet1, 'Manage') nb.AddPage(self.sheet2, 'Process') nb.AddPage(self.sheet3, 'Compare') self.sb = self.CreateStatusBar() self.sb.SetFieldsCount(2) self.sb.SetStatusWidths([-4, -1]) self.sheet2.SetFocus() self.sheet1.load_project() self.sheet1.refresh_tabs() #self.sheet1.sheet2._test() def _view_ligand(self, event): dlg = wx.FileDialog(self, 'Select a PDB file to load', defaultDir=os.getcwd(), wildcard='PDB File|*.pdb') if dlg.ShowModal() == wx.ID_OK: lig = Ligand(str(dlg.GetPath()), os.path.basename(str(dlg.GetPath()))) lig.Show(True) dlg.Destroy() def _show_settings(self, event): dlg = SettingsDialog(self) dlg.Show(True) def _show_about(self, event): dlg = AboutDialog(self) dlg.Show(True) def _show_help(self, event): dlg = HelpDialog(self) dlg.Show(True) def set_status(self, text, fld =0): self.sb.SetStatusText(text, fld) def set_project(self, project): self._project = project def start_coot(self, event): coot_exe = self._settings.val('coot') + '/Contents/MacOS/coot' if os.path.exists(coot_exe): if self._coot_process is not None: print self._coot_process.poll() if self._coot_process == None: self._coot_timer = wx.Timer(self, 201) wx.EVT_TIMER(self, 201, self.check_coot) self._coot_timer.Start(250, False) try: # need to reset env to get coot to load self._coot_process = subprocess.Popen([coot_exe, '--script='+self._settings.proot+'Coot.py'], shell=False, env={'DISPLAY': os.environ['DISPLAY'], 'HOME': os.environ['HOME']}) except: wx.MessageBox('Couldnt Start Coot', 'Proton8 couldnt find coot', style=wx.OK | wx.CENTRE) else: wx.MessageBox('Couldnt Start Coot', 'You need to set the path to coot in the settings panel before launching', style=wx.OK | wx.CENTRE) def check_coot(self, event): if self._coot_process is not None: if self._coot_process.poll() is not None: self._coot_process = None self._coot_timer = None else: self._coot_timer = None def _on_close(self, event): if self._coot_process is not None: if self._coot_process.poll() is None: self._coot_process.terminate() self.Destroy()