def _do_init(self) -> Gtk.Grid:
        self._widget = Gtk.Grid(column_spacing=5)

        left_btn = Gtk.Button('<')
        self._widget.attach(left_btn, 0, 0, 1, 1)

        self._idx_inp = IntegerEntry(lower=1, width_chars=3)
        self._widget.attach(self._idx_inp, 1, 0, 1, 1)

        self._num_images_lbl = Gtk.Label()
        self._widget.attach(self._num_images_lbl, 2, 0, 1, 1)

        right_btn = Gtk.Button('>')
        self._widget.attach(right_btn, 3, 0, 1, 1)

        self.bn_show_index = GObjectPropertyBindable(
            g_obj=self._idx_inp,
            prop_name='value',
            # User input is 1-based indexing
            transform_to=lambda x: x+1 if x is not None else None,
            transform_from=lambda x: x-1 if x is not None else None,
        )
        self._idx_inp.connect('activate', lambda *_: self.presenter.view_show_idx_changed())
        self._idx_inp.connect('focus-out-event', lambda *_: self.presenter.view_show_idx_changed())

        left_btn.connect('clicked', lambda *_: self.presenter.prev_image())
        right_btn.connect('clicked', lambda *_: self.presenter.next_image())

        self._widget.show_all()

        self.presenter.view_ready()

        return self._widget
Ejemplo n.º 2
0
class ImageSequenceNavigatorView(View['ImageSequenceNavigatorPresenter',
                                      Gtk.Widget]):
    def _do_init(self) -> Gtk.Grid:
        self._widget = Gtk.Grid(column_spacing=5)

        left_btn = Gtk.Button('<')
        self._widget.attach(left_btn, 0, 0, 1, 1)

        self._idx_inp = IntegerEntry(lower=1, width_chars=3)
        self._widget.attach(self._idx_inp, 1, 0, 1, 1)

        self._num_images_lbl = Gtk.Label()
        self._widget.attach(self._num_images_lbl, 2, 0, 1, 1)

        right_btn = Gtk.Button('>')
        self._widget.attach(right_btn, 3, 0, 1, 1)

        self.bn_show_index = GObjectPropertyBindable(
            g_obj=self._idx_inp,
            prop_name='value',
            # User input is 1-based indexing
            transform_to=lambda x: x + 1 if x is not None else None,
            transform_from=lambda x: x - 1 if x is not None else None,
        )
        self._idx_inp.connect(
            'activate', lambda *_: self.presenter.view_show_idx_changed())
        self._idx_inp.connect(
            'focus-out-event',
            lambda *_: self.presenter.view_show_idx_changed())

        left_btn.connect('clicked', lambda *_: self.presenter.prev_image())
        right_btn.connect('clicked', lambda *_: self.presenter.next_image())

        self._widget.show_all()

        self.presenter.view_ready()

        return self._widget

    def set_num_images(self, num_images: int) -> None:
        self._num_images_lbl.props.label = ('of {}'.format(num_images))

        self._idx_inp.props.upper = num_images

    def hide(self) -> None:
        self._widget.foreach(Gtk.Widget.hide)

    def show(self) -> None:
        self._widget.show()

    def _do_destroy(self) -> None:
        self._widget.destroy()
Ejemplo n.º 3
0
    def _do_init(self) -> Gtk.Widget:
        self._change_camera_dialog_cid = None  # type: Any

        self._widget = Gtk.Grid(row_spacing=10, column_spacing=10)

        # Populate self.widget

        camera_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
                                   spacing=5)
        self._widget.attach(camera_container, 0, 0, 2, 1)

        camera_lbl = Gtk.Label('Camera:', xalign=0)
        camera_container.add(camera_lbl)

        self._current_camera_lbl = Gtk.Label(xalign=0)
        camera_container.add(self._current_camera_lbl)

        self._change_camera_btn = Gtk.Button('Connect camera')
        self._change_camera_btn.get_style_context().add_class('small-pad')
        camera_container.add(self._change_camera_btn)

        num_frames_lbl = Gtk.Label('Number of images to capture:', xalign=0)
        self._widget.attach(num_frames_lbl, 0, 1, 1, 1)

        num_frames_inp_container = Gtk.Grid()
        self._widget.attach_next_to(num_frames_inp_container, num_frames_lbl,
                                    Gtk.PositionType.RIGHT, 1, 1)

        self._num_frames_inp = IntegerEntry(lower=1,
                                            upper=200,
                                            value=1,
                                            width_chars=6)
        self._num_frames_inp.get_style_context().add_class('small-pad')
        num_frames_inp_container.add(self._num_frames_inp)

        frame_interval_lbl = Gtk.Label('Frame interval (s):', xalign=0)
        self._widget.attach(frame_interval_lbl, 0, 2, 1, 1)

        frame_interval_inp_container = Gtk.Grid()
        self._widget.attach_next_to(frame_interval_inp_container,
                                    frame_interval_lbl, Gtk.PositionType.RIGHT,
                                    1, 1)

        self._frame_interval_inp = FloatEntry(lower=0,
                                              width_chars=6,
                                              sensitive=False,
                                              invisible_char='\0')
        self._frame_interval_inp.get_style_context().add_class('small-pad')
        frame_interval_inp_container.add(self._frame_interval_inp)

        self._current_camera_err_msg_lbl = Gtk.Label(xalign=0)
        self._current_camera_err_msg_lbl.get_style_context().add_class(
            'error-text')
        self._widget.attach_next_to(self._current_camera_err_msg_lbl,
                                    camera_container, Gtk.PositionType.RIGHT,
                                    1, 1)

        self._num_frames_err_msg_lbl = Gtk.Label(xalign=0)
        self._num_frames_err_msg_lbl.get_style_context().add_class(
            'error-text')
        self._widget.attach_next_to(self._num_frames_err_msg_lbl,
                                    num_frames_inp_container,
                                    Gtk.PositionType.RIGHT, 1, 1)

        self._frame_interval_err_msg_lbl = Gtk.Label(xalign=0)
        self._frame_interval_err_msg_lbl.get_style_context().add_class(
            'error-text')
        self._widget.attach_next_to(self._frame_interval_err_msg_lbl,
                                    frame_interval_inp_container,
                                    Gtk.PositionType.RIGHT, 1, 1)

        self._widget.show_all()

        # Wiring things up

        self._change_camera_btn.connect(
            'clicked',
            lambda *_: self.presenter.hdl_change_camera_btn_clicked())

        self.bn_frame_interval = GObjectPropertyBindable(
            self._frame_interval_inp, 'value')
        self.bn_num_frames = GObjectPropertyBindable(self._num_frames_inp,
                                                     'value')

        self.bn_frame_interval_sensitive = GObjectPropertyBindable(
            self._frame_interval_inp, 'sensitive')

        self._frame_interval_inp.bind_property(
            'sensitive', self._frame_interval_inp, 'visibility',
            GObject.BindingFlags.SYNC_CREATE)

        self.presenter.view_ready()

        return self._widget
Ejemplo n.º 4
0
    def _do_init(self, parent_window: Optional[Gtk.Window]) -> Gtk.Window:
        self._window = Gtk.Window(
            title='Select camera',
            transient_for=parent_window,
            resizable=False,
            modal=True,
            window_position=Gtk.WindowPosition.CENTER,
        )

        body = Gtk.Grid()
        self._window.add(body)

        content = Gtk.Grid(margin=10, column_spacing=10)
        body.attach(content, 0, 0, 1, 1)

        camera_index_lbl = Gtk.Label('Camera index:')
        content.attach(camera_index_lbl, 0, 0, 1, 1)

        camera_index_inp = IntegerEntry(lower=0,
                                        upper=99999,
                                        max_length=5,
                                        width_chars=6)
        camera_index_inp.get_style_context().add_class('small-pad')
        content.attach_next_to(camera_index_inp, camera_index_lbl,
                               Gtk.PositionType.RIGHT, 1, 1)

        # Setting max_width_chars to 0 seems to allow the label to occupy as much space as its parent, allowing
        # line wrapping to work.
        self._error_msg_lbl = Gtk.Label(margin_top=10, max_width_chars=0)
        self._error_msg_lbl.set_line_wrap(True)
        self._error_msg_lbl.get_style_context().add_class('error-text')
        content.attach(self._error_msg_lbl, 0, 1, 2, 1)

        footer = Gtk.Grid()
        footer.get_style_context().add_class('change-cam-dialog-view-footer')
        footer.get_style_context().add_class('linked')
        body.attach(footer, 0, 1, 1, 1)

        cancel_btn = Gtk.Button('Cancel', hexpand=True)
        cancel_btn.get_style_context().add_class('dialog-footer-button')
        footer.attach(cancel_btn, 0, 0, 1, 1)

        connect_btn = Gtk.Button('Connect', hexpand=True)
        connect_btn.get_style_context().add_class('dialog-footer-button')
        footer.attach(connect_btn, 1, 0, 1, 1)

        self._window.show_all()

        # Hide the error message label (since self.widget.show_all() would have made all descendant widgets
        # visible).
        self._error_msg_lbl.hide()

        # Wiring things up

        connect_btn.connect('clicked', lambda *_: self.presenter.connect())
        cancel_btn.connect('clicked', lambda *_: self.presenter.cancel())

        self._window.connect('delete-event', self._hdl_widget_delete_event)

        self.bn_camera_index = GObjectPropertyBindable(
            camera_index_inp, 'value')  # type: Bindable[int]
        self.bn_connect_btn_sensitive = GObjectPropertyBindable(
            connect_btn, 'sensitive')  # type: Bindable[bool]

        self.presenter.view_ready()

        return self._window
Ejemplo n.º 5
0
class USBCameraView(View['USBCameraPresenter', Gtk.Widget]):
    STYLE = '''
    .change-cam-dialog-view-footer {
         background-color: gainsboro;
    }

    .small-pad {
         min-height: 0px;
         min-width: 0px;
         padding: 6px 4px 6px 4px;
    }

    .dialog-footer-button {
         min-height: 0px;
         min-width: 0px;
         padding: 8px 6px 8px 6px;
    }

    .error {
        color: red;
        border: 1px solid red;
    }

    .error-text {
        color: red;
    }
    '''

    _STYLE_PROV = Gtk.CssProvider()
    _STYLE_PROV.load_from_data(bytes(STYLE, 'utf-8'))
    Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),
                                             _STYLE_PROV,
                                             Gtk.STYLE_PROVIDER_PRIORITY_USER)

    def _do_init(self) -> Gtk.Widget:
        self._change_camera_dialog_cid = None  # type: Any

        self._widget = Gtk.Grid(row_spacing=10, column_spacing=10)

        # Populate self.widget

        camera_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
                                   spacing=5)
        self._widget.attach(camera_container, 0, 0, 2, 1)

        camera_lbl = Gtk.Label('Camera:', xalign=0)
        camera_container.add(camera_lbl)

        self._current_camera_lbl = Gtk.Label(xalign=0)
        camera_container.add(self._current_camera_lbl)

        self._change_camera_btn = Gtk.Button('Connect camera')
        self._change_camera_btn.get_style_context().add_class('small-pad')
        camera_container.add(self._change_camera_btn)

        num_frames_lbl = Gtk.Label('Number of images to capture:', xalign=0)
        self._widget.attach(num_frames_lbl, 0, 1, 1, 1)

        num_frames_inp_container = Gtk.Grid()
        self._widget.attach_next_to(num_frames_inp_container, num_frames_lbl,
                                    Gtk.PositionType.RIGHT, 1, 1)

        self._num_frames_inp = IntegerEntry(lower=1,
                                            upper=200,
                                            value=1,
                                            width_chars=6)
        self._num_frames_inp.get_style_context().add_class('small-pad')
        num_frames_inp_container.add(self._num_frames_inp)

        frame_interval_lbl = Gtk.Label('Frame interval (s):', xalign=0)
        self._widget.attach(frame_interval_lbl, 0, 2, 1, 1)

        frame_interval_inp_container = Gtk.Grid()
        self._widget.attach_next_to(frame_interval_inp_container,
                                    frame_interval_lbl, Gtk.PositionType.RIGHT,
                                    1, 1)

        self._frame_interval_inp = FloatEntry(lower=0,
                                              width_chars=6,
                                              sensitive=False,
                                              invisible_char='\0')
        self._frame_interval_inp.get_style_context().add_class('small-pad')
        frame_interval_inp_container.add(self._frame_interval_inp)

        self._current_camera_err_msg_lbl = Gtk.Label(xalign=0)
        self._current_camera_err_msg_lbl.get_style_context().add_class(
            'error-text')
        self._widget.attach_next_to(self._current_camera_err_msg_lbl,
                                    camera_container, Gtk.PositionType.RIGHT,
                                    1, 1)

        self._num_frames_err_msg_lbl = Gtk.Label(xalign=0)
        self._num_frames_err_msg_lbl.get_style_context().add_class(
            'error-text')
        self._widget.attach_next_to(self._num_frames_err_msg_lbl,
                                    num_frames_inp_container,
                                    Gtk.PositionType.RIGHT, 1, 1)

        self._frame_interval_err_msg_lbl = Gtk.Label(xalign=0)
        self._frame_interval_err_msg_lbl.get_style_context().add_class(
            'error-text')
        self._widget.attach_next_to(self._frame_interval_err_msg_lbl,
                                    frame_interval_inp_container,
                                    Gtk.PositionType.RIGHT, 1, 1)

        self._widget.show_all()

        # Wiring things up

        self._change_camera_btn.connect(
            'clicked',
            lambda *_: self.presenter.hdl_change_camera_btn_clicked())

        self.bn_frame_interval = GObjectPropertyBindable(
            self._frame_interval_inp, 'value')
        self.bn_num_frames = GObjectPropertyBindable(self._num_frames_inp,
                                                     'value')

        self.bn_frame_interval_sensitive = GObjectPropertyBindable(
            self._frame_interval_inp, 'sensitive')

        self._frame_interval_inp.bind_property(
            'sensitive', self._frame_interval_inp, 'visibility',
            GObject.BindingFlags.SYNC_CREATE)

        self.presenter.view_ready()

        return self._widget

    def set_camera_index(self, camera_index: Optional[int]) -> None:
        if camera_index is None:
            self._current_camera_lbl.props.label = ''
            self._current_camera_lbl.props.visible = False
            self._change_camera_btn.props.label = 'Connect camera'
        else:
            self._current_camera_lbl.props.label = '(Connected to index {})'.format(
                camera_index)
            self._current_camera_lbl.props.visible = True
            self._change_camera_btn.props.label = 'Change camera'

    def show_change_camera_dialog(self) -> None:
        if self._change_camera_dialog_cid is not None:
            return

        self._change_camera_dialog_cid, _ = self.new_component(
            _change_camera_dialog_cs.factory(
                on_response=self.presenter.hdl_change_camera_dialog_response,
                parent_window=self._get_window(),
            ))

    def hide_change_camera_dialog(self) -> None:
        if self._change_camera_dialog_cid is None:
            return

        self.remove_component(self._change_camera_dialog_cid)
        self._change_camera_dialog_cid = None

    def _get_window(self) -> Optional[Gtk.Window]:
        toplevel = self._widget.get_toplevel()
        if isinstance(toplevel, Gtk.Window):
            return toplevel
        else:
            return None

    def _do_destroy(self) -> None:
        self._widget.destroy()
Ejemplo n.º 6
0
    def _do_init(self, figure_name: str) -> Gtk.Widget:
        self._widget = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)

        self._should_save_figure_inp = Gtk.CheckButton(
            label='Save {}'.format(figure_name))
        self._widget.add(self._should_save_figure_inp)

        self._more_options = Gtk.Grid(margin_left=30,
                                      row_spacing=5,
                                      column_spacing=10)
        self._widget.add(self._more_options)

        dpi_lbl = Gtk.Label('Figure DPI:', xalign=0)
        self._more_options.attach(dpi_lbl, 0, 0, 1, 1)

        dpi_inp_ctn = Gtk.Grid()
        self._more_options.attach_next_to(dpi_inp_ctn, dpi_lbl,
                                          Gtk.PositionType.RIGHT, 1, 1)
        dpi_inp = IntegerEntry(value=300, lower=72, upper=10000, width_chars=5)
        dpi_inp.get_style_context().add_class('small-pad')
        dpi_inp_ctn.add(dpi_inp)

        dpi_err_lbl = Gtk.Label(xalign=0, width_request=190)
        dpi_err_lbl.get_style_context().add_class('error-text')
        self._more_options.attach_next_to(dpi_err_lbl, dpi_inp_ctn,
                                          Gtk.PositionType.RIGHT, 1, 1)

        size_lbl = Gtk.Label('Figure size (cm):', xalign=0)
        self._more_options.attach(size_lbl, 0, 1, 1, 1)

        size_inp_ctn = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
                               spacing=5)
        self._more_options.attach_next_to(size_inp_ctn, size_lbl,
                                          Gtk.PositionType.RIGHT, 1, 1)

        size_w_lbl = Gtk.Label('W:')
        size_inp_ctn.add(size_w_lbl)
        size_w_inp = FloatEntry(value=10, lower=0, upper=10000, width_chars=6)
        size_w_inp.get_style_context().add_class('small-pad')

        size_inp_ctn.add(size_w_inp)
        size_h_lbl = Gtk.Label('H:')
        size_inp_ctn.add(size_h_lbl)

        size_h_inp = FloatEntry(value=10, lower=0, upper=10000, width_chars=6)
        size_h_inp.get_style_context().add_class('small-pad')
        size_inp_ctn.add(size_h_inp)

        size_err_lbl = Gtk.Label(xalign=0, width_request=190)
        size_err_lbl.get_style_context().add_class('error-text')
        self._more_options.attach_next_to(size_err_lbl, size_inp_ctn,
                                          Gtk.PositionType.RIGHT, 1, 1)

        self._should_save_figure_inp.bind_property(
            'active',  # source_property
            self._more_options,  # target
            'sensitive',  # target_property
            GObject.BindingFlags.SYNC_CREATE,  # flags
        )

        self.bn_should_save = GObjectPropertyBindable(
            g_obj=self._should_save_figure_inp,
            prop_name='active',
        )

        self.bn_dpi = GObjectPropertyBindable(
            g_obj=dpi_inp,
            prop_name='value',
        )

        self.bn_size_w = GObjectPropertyBindable(
            g_obj=size_w_inp,
            prop_name='value',
        )

        self.bn_size_h = GObjectPropertyBindable(
            g_obj=size_h_inp,
            prop_name='value',
        )

        self.presenter.view_ready()

        self._widget.show_all()

        return self._widget