Esempio n. 1
0
  def display(self,path):
    import wx
    from rstbx.viewer.frame import XrayFrame

    app   = wx.App(0)
    frame = XrayFrame(None, -1, "X-ray image display", size=(1200,1080))
    frame.SetSize((1024,780))
    frame.load_image(path)
    frame.Show()
    app.MainLoop()
Esempio n. 2
0
def run(args):
  app = wx.App(0)
  wx.SystemOptions.SetOption("osx.openfiledialog.always-show-types", "1")
  frame = XrayFrame(None, -1, "X-ray image display", size=(800,720))
  if (len(args) == 1 and os.path.basename(args[0]) == "DISTL_pickle"):
    assert os.path.isfile(args[0])
    frame.load_distl_output(args[0])
  elif (len(args) > 0):
    for file_name in args:
      assert os.path.isfile(file_name)
      frame.add_file_name_or_data(file_name)
    frame.load_image(args[0])
  frame.Show()
  app.MainLoop()
Esempio n. 3
0
def run_one_index(path, *arguments, **kwargs):

    assert arguments[0].find("target=") == 0
    target = arguments[0].split("=")[1]

    from xfel.phil_preferences import load_cxi_phil
    if "--nodisplay" in arguments[1:]:
        display = False
        arguments = list(arguments)
        arguments.remove("--nodisplay")
    else:
        display = True

    args = [
        "indexing.data=%s" % path,
        "beam_search_scope=0.5",
        "lepage_max_delta = 3.0",
        "spots_pickle = None",
        "subgroups_pickle = None",
        "refinements_pickle = None",
        "rmsd_tolerance = 5.0",
        "mosflm_rmsd_tolerance = 5.0",
        "difflimit_sigma_cutoff=2.0",
        #"indexing.verbose_cv=True",
        "indexing.open_wx_viewer=%s" % display
    ] + list(arguments[1:])

    horizons_phil = load_cxi_phil(target, args)

    info = run_one_index_core(horizons_phil)
    info.Files = info.organizer.Files
    info.phil_params = info.horizons_phil

    # The spotfinder view within cxi.index is an anachronism; no useful purpose anymore
    # therefore remove this option within cxi.index:
    return
    work = wrapper_of_callback(info)

    if kwargs.get("display", False):
        import wx
        from rstbx.viewer import display
        from rstbx.viewer.frame import XrayFrame
        display.user_callback = work.user_callback

        app = wx.App(0)
        frame = XrayFrame(None, -1, "X-ray image display", size=(1200, 1080))
        frame.SetSize((1024, 780))
        frame.load_image(path)
        frame.Show()
        app.MainLoop()
Esempio n. 4
0
class ProcessingFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        wx.Frame.__init__(self, *args, **kwds)
        self.viewer = None
        self.toolbar = self.CreateToolBar(style=wx.TB_3DBUTTONS | wx.TB_TEXT)
        btn = self.toolbar.AddLabelTool(id=-1,
                                        label="Image viewer",
                                        bitmap=icons.hkl_file.GetBitmap(),
                                        shortHelp="Image viewer",
                                        kind=wx.ITEM_NORMAL)
        self.Bind(wx.EVT_MENU, self.OnLaunchViewer, btn)
        self.toolbar.Realize()
        self.statusbar = self.CreateStatusBar()
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.sizer)
        self.nb = fnb.FlatNotebook(self,
                                   agwStyle=fnb.FNB_DEFAULT_STYLE
                                   | fnb.FNB_NO_X_BUTTON)
        self.sizer.Add(self.nb, 1, wx.EXPAND)
        self.nb.SetMinSize((800, 40))
        self.start_panel = StartPanel(self.nb)
        self.nb.AddPage(self.start_panel, "Setup")
        self.output_panel = LogViewer(self.nb)
        self.nb.AddPage(self.output_panel, "Output")
        try:
            self.html_panel = wx.html2.WebView.New(self.nb)
        except NotImplementedError:
            self.html_panel = wx.html.HtmlWindow(self.nb)
        self.nb.AddPage(self.html_panel, "Report")
        #self.indexing_panel = indexing.IndexingPanel(self.nb)
        #self.nb.AddPage(self.indexing_panel, "Indexing")
        #self.integration_panel = integration.IntegrationPanel(self.nb)
        #self.nb.AddPage(self.integration_panel, "Integration")
        self.SetSize((800, 600))

        self.event_dispatcher = process_control.event_agent(window=self,
                                                            project_id=0,
                                                            job_id=0)

        self.was_aborted = False

    #def LoadResults (self, dir_name) :
    #self.result = results_base.result(dir_name)
    #self.indexing_panel.SetIndexingResults(self.result.get_indexing())
    #self.integration_panel.SetResults(self.result)
    #self.nb.SetSelection(1)

    def OnRunXia2(self, evt):

        #thread = WorkerThread(0, self)
        #thread.start()
        #return

        output_dir = self.start_panel.GetOutputDir()
        result = self.run_xia2(imagesets=self.start_panel.GetImagesets(),
                               output_dir=output_dir)

    def run_xia2(self, **kwds):
        output_dir = kwds['output_dir']
        imagesets = kwds['imagesets']
        args = []
        for imageset in imagesets:
            scan = imageset.get_scan()
            first, last = scan.get_image_range()
            args.append('image=%s:%i:%i' % (imageset.paths()[0], first, last))
        kwds = {}

        self.nb.AdvanceSelection(forward=True)
        thread = xia2Thread(self, output_dir, args)
        thread.start()
        return

    def launch_viewer_frame(self):
        if (self.viewer is None):
            self.viewer = XrayFrame(parent=self, title="Image viewer")
            self.viewer.Show()
            self.Bind(wx.EVT_CLOSE, self.OnCloseViewer, self.viewer)

    def get_viewer_frame(self):
        self.launch_viewer_frame()
        return self.viewer

    def set_viewer_frame(self, frame):
        assert (self.viewer is None)
        self.viewer = frame

    def OnCloseViewer(self, evt):
        self.viewer.Destroy()
        self.viewer = None

    def OnLaunchViewer(self, evt):
        self.launch_viewer_frame()

    def callback_start(self, data):
        self.event_dispatcher.callback_start(data)

    def callback_stdout(self, data):
        self.output_panel.AppendText(data)
        self.event_dispatcher.callback_stdout(data)

    def callback_other(self, data):
        print 'other'
        self.event_dispatcher.callback_other(data)

    def callback_abort(self):
        self.event_dispatcher.callback_abort()
        self.close()

    def callback_final(self, result):
        if self.was_aborted:  # XXX hack for jobs killed with 'qdel'
            self.callback_abort()
            return
        import glob
        html_files = glob.glob(
            os.path.join(result.output_dir, 'LogFiles/*_report.html'))
        print html_files
        if html_files:
            html_file = html_files[0]
            try:
                # wx.html.HtmlWindow
                self.html_panel.LoadFile(html_file)
            except AttributeError:
                # wx.html2.WebView
                self.html_panel.LoadURL(html_file)
            self.nb.AdvanceSelection()
        self.event_dispatcher.callback_final(result)
        self.close()

    def callback_error(self, error, traceback_info):
        self.event_dispatcher.callback_error(error, traceback_info)
        self.close()

    def callback_pause(self):
        self.event_dispatcher.callback_pause()

    def callback_resume(self):
        self.event_dispatcher.callback_resume()

    def close(self):
        pass

    def OnLogEvent(self, event):
        print event
Esempio n. 5
0
class _XrayFrameThread(threading.Thread):
    """The _XrayFrameThread class allows MainLoop() to be run as a
  thread, which is necessary because all calls to wxPython must be
  made from the same thread that originally imported wxPython.

  This is all based on "Running MainLoop in a separate thread",
  http://wiki.wxpython.org/MainLoopAsThread.
  """
    def __init__(self):
        """The thread is started automatically on initialisation.
    self.run() will initialise self.frame and release self._init_lock.
    """

        super(_XrayFrameThread, self).__init__()
        self.setDaemon(1)
        self._init_lock = threading.Lock()
        self._next_semaphore = threading.Semaphore()
        self._start_orig = self.start
        self._frame = None
        self.start = self._start_local

        self._init_lock.acquire()
        self.start()

    def _start_local(self):
        """The _start_local() function calls the run() function through
    self._start_orig, and exists only after self._init_lock has been
    released.  This eliminates a race condition which could cause
    updates to be sent to a non-existent frame.
    """

        self._start_orig()
        self._init_lock.acquire()

    def run(self):
        """The run() function defines the frame and starts the main loop.
    self._init_lock is released only when all initialisation is done.

    Whatever thread is the current one when wxWindows is initialised
    is what it will consider the "main thread." For wxPython 2.4 that
    happens when wxPython.wx is imported the first time.  For 2.5 it
    will be when the wx.App object is created.
    """

        import wx
        from wxtbx import bitmaps
        app = wx.App(0)
        self._bitmap_pause = bitmaps.fetch_icon_bitmap('actions', 'stop')
        self._bitmap_run = bitmaps.fetch_icon_bitmap('actions', 'runit')
        self._frame = XrayFrame(None,
                                -1,
                                "X-ray image display",
                                size=(800, 720))

        self._frame.Bind(wx.EVT_IDLE, self.OnIdle)

        self.setup_toolbar(self._frame.toolbar)
        self._frame.Show()

        self._init_lock.release()
        app.MainLoop()

        # Avoid deadlock where the send_data() function is waiting for the
        # semaphore after the frame has closed.
        self._next_semaphore.release()

    def send_data(self, img, title):
        """The send_data() function updates the wxPython application with
    @p img and @p title by sending it an ExternalUpdateEvent().  The
    function blocks until the event is processed."""

        from rstbx.viewer.frame import ExternalUpdateEvent

        event = ExternalUpdateEvent()
        event.img = img
        event.title = title
        if self.isAlive():
            try:
                # Saturating the event queue makes the whole caboodle
                # uselessly unresponsive.  Therefore, block until idle events
                # are processed.
                while self.isAlive() and not self._run_pause.IsToggled():
                    pass
                self._frame.AddPendingEvent(event)
                self._is_idle = False
                while self.isAlive() and not self._is_idle:
                    pass
            except Exception:
                pass

    def setup_toolbar(self, toolbar):
        import wx
        from wxtbx import icons

        toolbar.ClearTools()

        btn = toolbar.AddLabelTool(id=wx.ID_ANY,
                                   label="Settings",
                                   bitmap=icons.advancedsettings.GetBitmap(),
                                   shortHelp="Settings",
                                   kind=wx.ITEM_NORMAL)
        self._frame.Bind(wx.EVT_MENU, self._frame.OnShowSettings, btn)

        btn = toolbar.AddLabelTool(id=wx.ID_ANY,
                                   label="Zoom",
                                   bitmap=icons.search.GetBitmap(),
                                   shortHelp="Zoom",
                                   kind=wx.ITEM_NORMAL)
        self._frame.Bind(wx.EVT_MENU, self._frame.OnZoom, btn)

        # Reset the normal bitmap after the tool has been created, so that
        # it will update on the next event.  See also OnPauseRun()
        self._run_pause = toolbar.AddCheckLabelTool(id=wx.ID_ANY,
                                                    label="Run/Pause",
                                                    bitmap=self._bitmap_run,
                                                    shortHelp="Run/Pause")
        self._run_pause.SetNormalBitmap(self._bitmap_pause)
        self._frame.Bind(wx.EVT_MENU, self.OnPauseRun, self._run_pause)

    def OnIdle(self, event):
        self._is_idle = True
        event.RequestMore()

    def OnPauseRun(self, event):
        if self._run_pause.IsToggled():
            self._run_pause.SetNormalBitmap(self._bitmap_run)
        else:
            self._run_pause.SetNormalBitmap(self._bitmap_pause)

    def stop(self):
        from wx import CloseEvent
        self._frame.AddPendingEvent(CloseEvent())
Esempio n. 6
0
class ProcessingFrame (wx.Frame) :
  def __init__ (self, *args, **kwds) :
    wx.Frame.__init__(self, *args, **kwds)
    self.viewer = None
    self.toolbar = self.CreateToolBar(style=wx.TB_3DBUTTONS|wx.TB_TEXT)
    btn = self.toolbar.AddLabelTool(id=-1,
      label="Image viewer",
      bitmap=icons.hkl_file.GetBitmap(),
      shortHelp="Image viewer",
      kind=wx.ITEM_NORMAL)
    self.Bind(wx.EVT_MENU, self.OnLaunchViewer, btn)
    self.toolbar.Realize()
    self.statusbar = self.CreateStatusBar()
    self.sizer = wx.BoxSizer(wx.VERTICAL)
    self.SetSizer(self.sizer)
    self.nb = wx.lib.agw.flatnotebook.FlatNotebook(self)
    self.sizer.Add(self.nb, 1, wx.EXPAND)
    self.nb.SetMinSize((800,40))
    self.start_panel = StartPanel(self.nb)
    self.nb.AddPage(self.start_panel, "Setup")
    self.indexing_panel = indexing.IndexingPanel(self.nb)
    self.nb.AddPage(self.indexing_panel, "Indexing")
    self.integration_panel = integration.IntegrationPanel(self.nb)
    self.nb.AddPage(self.integration_panel, "Integration")
    self.SetSize((800,600))

  def LoadResults (self, dir_name) :
    self.result = results_base.result(dir_name)
    self.indexing_panel.SetIndexingResults(self.result.get_indexing())
    self.integration_panel.SetResults(self.result)
    self.nb.SetSelection(1)

  def OnRunIndexing (self, evt) :
    dataset, frames = self.start_panel.GetDataset()
    output_dir = self.start_panel.GetOutputDir()
    result = self.run_indexing(
      dataset=dataset,
      frames=frames,
      output_dir=output_dir)
    self.LoadResults(output_dir)

  def run_indexing (self, **kwds) :
    from rstbx.viewer import drivers
    run = drivers.run_indexing(**kwds)
    indexing_result = process_control.run_function_as_process_in_dialog(
      parent=self,
      thread_function=run,
      title="Running LABELIT",
      message="Indexing images and performing simple test integration")
    return indexing_result

  def launch_viewer_frame (self) :
    if (self.viewer is None) :
      self.viewer = XrayFrame(
        parent=self,
        title="Image viewer")
      self.viewer.Show()
      self.Bind(wx.EVT_CLOSE, self.OnCloseViewer, self.viewer)

  def get_viewer_frame (self) :
    self.launch_viewer_frame()
    return self.viewer

  def set_viewer_frame (self, frame) :
    assert (self.viewer is None)
    self.viewer = frame

  def OnCloseViewer (self, evt) :
    self.viewer.Destroy()
    self.viewer = None

  def OnLaunchViewer (self, evt) :
    self.launch_viewer_frame()