Пример #1
0
    def __init__(self,
                 parent,
                 phil,
                 backend_name='BACKEND',
                 target=None,
                 content_style='normal',
                 label_style='bold',
                 opt_size=(500, 500),
                 phil_size=(500, 500),
                 *args,
                 **kwargs):
        BaseDialog.__init__(self,
                            parent,
                            content_style=content_style,
                            label_style=label_style,
                            *args,
                            **kwargs)

        self.parent = parent
        self.target_phil = target
        self.backend = backend_name
        self.params = phil.extract()
        self.opt_size = opt_size
        self.phil_size = phil_size
        self.sash_position = None

        self.splitter = wx.SplitterWindow(self,
                                          style=wx.SP_LIVE_UPDATE
                                          | wx.SP_3DSASH | wx.SP_NOBORDER)

        # Create options panel (all objects should be called as self.options.object)
        self.options = ScrolledPanel(self.splitter, size=self.opt_size)
        self.options_sizer = wx.BoxSizer(wx.VERTICAL)
        self.options.SetSizer(self.options_sizer)

        # Create PHIL panel
        phil_label = "{} Target Settings".format(backend_name)
        self.phil_panel = wx.Panel(self.splitter, size=self.opt_size)
        phil_box = wx.StaticBox(self.phil_panel, label=phil_label)
        self.phil_sizer = wx.StaticBoxSizer(phil_box, wx.VERTICAL)
        self.phil_panel.SetSizer(self.phil_sizer)

        # Dialog control
        self.dlg_ctr = ct.DialogButtonsCtrl(self, preset='PROC_DIALOG')

        # Splitter button
        self.btn_hide_script = GenToggleButton(self, label='Show Script >>>')
        self.show_hide_script()
        self.btn_hide_script.SetValue(False)

        self.main_sizer.Add(self.btn_hide_script,
                            flag=wx.ALIGN_RIGHT | wx.ALL,
                            border=10)
        self.main_sizer.Add(self.splitter,
                            1,
                            flag=wx.EXPAND | wx.ALL,
                            border=10)
        self.main_sizer.Add(self.dlg_ctr,
                            flag=wx.EXPAND | wx.ALIGN_RIGHT | wx.RIGHT,
                            border=10)
Пример #2
0
    def __init__(self,
                 parent,
                 id=-1,
                 label='',
                 window_cb=None,
                 available_cb=None,
                 **kwargs):
        """Creates a springtab button
        
        This button on the springtab is linked to a callback function that
        creates a window on demand when the button is clicked.
        
        @param parent: parent window: a L{SpringTab} instance
        
        @param id: optional id of the new button
        
        @param label: label of the springtab button
        
        @param window_cb: callback to create the contents of the popup.  This
        functor will be passed two arguments: the first is the popup window
        determined from L{SpringTab.get_new_popup} to be used as the parent
        window for the popup contents.  The second argument is the kwargs dict.
        
        @param available_cb: callback to see if the button should be displayed
        in the L{SpringTab}.  This callback takes a single argument; the
        kwargs dict and should return a boolean indicating whether or not the
        button will be visible.
        
        @param kwargs: dict containing any keyword arguments necessary to
        create the popup contents or check for button availability.
        """
        self.border = 2
        self.hover = False

        GenToggleButton.__init__(self, parent, id, label)
        self.Bind(wx.EVT_ENTER_WINDOW, self.on_enter)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.on_leave)

        self.window_cb = window_cb
        self.available_cb = available_cb
        if self.available_cb:
            self.Show(self.available_cb(**kwargs))
        self.kwargs = kwargs
        self.popup = None
        self.notification_count = 0
        self.skip_next_lose_focus = False
Пример #3
0
 def __init__(self, parent, id=-1, label='', window_cb=None, available_cb=None, **kwargs):
     """Creates a springtab button
     
     This button on the springtab is linked to a callback function that
     creates a window on demand when the button is clicked.
     
     @param parent: parent window: a L{SpringTab} instance
     
     @param id: optional id of the new button
     
     @param label: label of the springtab button
     
     @param window_cb: callback to create the contents of the popup.  This
     functor will be passed two arguments: the first is the popup window
     determined from L{SpringTab.getNewPopup} to be used as the parent
     window for the popup contents.  The second argument is the kwargs dict.
     
     @param available_cb: callback to see if the button should be displayed
     in the L{SpringTab}.  This callback takes a single argument; the
     kwargs dict and should return a boolean indicating whether or not the
     button will be visible.
     
     @param kwargs: dict containing any keyword arguments necessary to
     create the popup contents or check for button availability.
     """
     self.border = 2
     self.hover = False
     
     GenToggleButton.__init__(self, parent, id, label)
     self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
     self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
     
     self.window_cb = window_cb
     self.available_cb = available_cb
     if self.available_cb:
         self.Show(self.available_cb(**kwargs))
     self.kwargs = kwargs
     self.popup = None
     self.notification_count = 0
Пример #4
0
class BaseBackendDialog(IOTABaseDialog):
    def __init__(
        self,
        parent,
        phil,
        backend_name="BACKEND",
        target=None,
        content_style="normal",
        label_style="bold",
        opt_size=(500, 500),
        phil_size=(500, 500),
        *args,
        **kwargs
    ):
        IOTABaseDialog.__init__(
            self,
            parent,
            content_style=content_style,
            label_style=label_style,
            *args,
            **kwargs
        )

        self.parent = parent
        self.target_phil = target
        self.backend = backend_name
        self.params = phil.extract()
        self.opt_size = opt_size
        self.phil_size = phil_size
        self.sash_position = None

        self.splitter = wx.SplitterWindow(
            self, style=wx.SP_LIVE_UPDATE | wx.SP_3DSASH | wx.SP_NOBORDER
        )

        # Create options panel (all objects should be called as self.options.object)
        self.options = ScrolledPanel(self.splitter, size=self.opt_size)
        self.options_sizer = wx.BoxSizer(wx.VERTICAL)
        self.options.SetSizer(self.options_sizer)

        # Create PHIL panel
        phil_label = "{} Target Settings".format(backend_name)
        self.phil_panel = wx.Panel(self.splitter, size=self.opt_size)
        phil_box = wx.StaticBox(self.phil_panel, label=phil_label)
        self.phil_sizer = wx.StaticBoxSizer(phil_box, wx.VERTICAL)
        self.phil_panel.SetSizer(self.phil_sizer)

        # Dialog control
        self.dlg_ctr = ct.DialogButtonsCtrl(self, preset="PROC_DIALOG")

        # Splitter button
        self.btn_hide_script = GenToggleButton(self, label="Show Script >>>")
        self.show_hide_script()
        self.btn_hide_script.SetValue(False)

        self.main_sizer.Add(
            self.btn_hide_script, flag=wx.ALIGN_RIGHT | wx.ALL, border=10
        )
        self.main_sizer.Add(self.splitter, 1, flag=wx.EXPAND | wx.ALL, border=10)
        self.main_sizer.Add(
            self.dlg_ctr, flag=wx.EXPAND | wx.ALIGN_RIGHT | wx.RIGHT, border=10
        )

    def show_hide_script(self, initialized=False):
        if self.btn_hide_script.GetValue():
            if initialized:
                h = self.GetSize()[1]
                w = self.GetSize()[0] + self.phil_size[0]
                self.SetSize((w, h))
            self.splitter.SplitVertically(self.options, self.phil_panel)
            self.splitter.SetSashPosition(self.sash_position)
            self.phil_panel.SetSize(self.phil_size)
            self.options.SetSize(self.opt_size)
            self.btn_hide_script.SetLabel("<<< Hide Script")
        else:
            h = self.GetSize()[1]
            w = self.GetSize()[0] - self.phil_size[0]
            self.SetSize((w, h))
            self.splitter.Unsplit()
            self.phil_panel.SetSize(self.phil_size)
            self.options.SetSize(self.opt_size)
            self.btn_hide_script.SetLabel("Show Script >>>")
        self.splitter.UpdateSize()

    def get_target_file(self):
        dlg = wx.FileDialog(
            self,
            message="Select CCTBX.XFEL target file",
            defaultDir=os.curdir,
            defaultFile="*.phil",
            wildcard="*",
            style=wx.FD_OPEN | wx.FD_CHANGE_DIR,
        )
        if dlg.ShowModal() == wx.ID_OK:
            filepath = dlg.GetPaths()[0]

            with open(filepath, "r") as phil_file:
                phil_content = phil_file.read()
            return phil_content
        else:
            return None

    def write_default_phil(self):
        if str.lower(self.backend) in ("cctbx.xfel", "dials"):
            method = "cctbx.xfel"
        elif str.lower(self.backend) in ("cctbx", "ha14", "labelit"):
            method = "ha14"
        else:
            method = "current"
        from iota.init.iota_input import write_defaults

        default_phil, _ = write_defaults(
            method=method, write_target_file=False, write_param_file=False
        )
        self.target_phil = default_phil.as_str()
Пример #5
0
class BaseBackendDialog(BaseDialog):
    def __init__(self,
                 parent,
                 phil,
                 backend_name='BACKEND',
                 content_style='normal',
                 label_style='bold',
                 opt_size=(500, 500),
                 phil_size=(500, 500),
                 *args,
                 **kwargs):
        BaseDialog.__init__(self,
                            parent,
                            content_style=content_style,
                            label_style=label_style,
                            *args,
                            **kwargs)

        self.parent = parent
        self.backend = backend_name
        self.opt_size = opt_size
        self.phil_size = phil_size
        self.sash_position = None

        self.splitter = wx.SplitterWindow(self,
                                          style=wx.SP_LIVE_UPDATE
                                          | wx.SP_3DSASH | wx.SP_NOBORDER)

        # Create options panel (all objects should be called as self.options.object)
        self.options = ScrolledPanel(self.splitter, size=self.opt_size)
        self.options_sizer = wx.BoxSizer(wx.VERTICAL)
        self.options.SetSizer(self.options_sizer)

        # Create PHIL panel
        phil_label = "{} Target Settings".format(backend_name)
        self.phil_panel = wx.Panel(self.splitter, size=self.opt_size)
        phil_box = wx.StaticBox(self.phil_panel, label=phil_label)
        self.phil_sizer = wx.StaticBoxSizer(phil_box, wx.VERTICAL)
        self.phil_panel.SetSizer(self.phil_sizer)

        # Dialog control
        self.dlg_ctr = ct.DialogButtonsCtrl(self, preset='PROC_DIALOG')

        # Splitter button
        self.btn_hide_script = GenToggleButton(self, label='Show Script >>>')
        self.show_hide_script()
        self.btn_hide_script.SetValue(False)

        self.main_sizer.Add(self.btn_hide_script,
                            flag=wx.ALIGN_RIGHT | wx.ALL,
                            border=10)
        self.main_sizer.Add(self.splitter,
                            1,
                            flag=wx.EXPAND | wx.ALL,
                            border=10)
        self.main_sizer.Add(self.dlg_ctr,
                            flag=wx.EXPAND | wx.ALIGN_RIGHT | wx.RIGHT,
                            border=10)

    def show_hide_script(self, initialized=False):
        if self.btn_hide_script.GetValue():
            if initialized:
                h = self.GetSize()[1]
                w = self.GetSize()[0] + self.phil_size[0]
                self.SetSize((w, h))
            self.splitter.SplitVertically(self.options, self.phil_panel)
            self.splitter.SetSashPosition(self.sash_position)
            self.phil_panel.SetSize(self.phil_size)
            self.options.SetSize(self.opt_size)
            self.btn_hide_script.SetLabel('<<< Hide Script')
        else:
            h = self.GetSize()[1]
            w = self.GetSize()[0] - self.phil_size[0]
            self.SetSize((w, h))
            self.splitter.Unsplit()
            self.phil_panel.SetSize(self.phil_size)
            self.options.SetSize(self.opt_size)
            self.btn_hide_script.SetLabel('Show Script >>>')
        self.splitter.SizeWindows()

    def get_target_file(self):
        dlg = wx.FileDialog(self,
                            message="Select PRIME settings file",
                            defaultDir=os.curdir,
                            defaultFile="*.phil",
                            wildcard="*",
                            style=wx.OPEN | wx.CHANGE_DIR)
        if dlg.ShowModal() == wx.ID_OK:
            filepath = dlg.GetPaths()[0]

            with open(filepath, 'r') as phil_file:
                phil_content = phil_file.read()
            return phil_content
        else:
            return None
Пример #6
0
 def ButtonCB(parent, **kwargs):
     button = GenToggleButton(parent, -1, "Whatevar!!!")