Esempio n. 1
0
    def render(self, grid: Gtk.Grid, grid_row: int) -> int:
        '''
        renders a question for adding to a questionnaire

        @param Grid grid: a grid object that this question will add to it
        @param int grid_row: The row that the question will add

        @rtype: int
        @return: the grid's row for adding the next object after adding the question
        '''
        row_counter = grid_row

        # Question box
        question_label_box = Gtk.Box(spacing=120)
        question_label = Gtk.Label()
        question_label.set_markup(FONT_STYLE.format(self._text))
        question_label_box.pack_start(question_label, False, False, 0)

        grid.attach(question_label_box, 0, row_counter, 1, 1)
        row_counter += 1

        # text box
        text_box = Gtk.Box(spacing=120)
        text_box.pack_start(self.answer_textbox, False, False, 0)
        grid.attach(text_box, 1, row_counter, 1, 1)
        row_counter += 1
        return row_counter
Esempio n. 2
0
    def __init__(self, variables=None, *args, **kwargs):
        Grid.__init__(self, *args, **kwargs)

        self.variables = variables
        self.subject.title = self.subject_title
        self.subject.description = self.subject_description
        self.property.title = self.property_title
        self.property.description = self.property_description
        self.object.title = self.object_title
        self.object.description = self.object_description

        self.members = (self.subject, self.property, self.object)

        for widget in self.members:
            widget.entity = {"Label":"", "Description":"", "URI":""}
            widget.popover = EntityPopover(widget.entity,
                                                  variables=self.variables)
            widget.popover.set_relative_to(widget)
            widget.popover.connect("default-variable-selected",
                                          self.default_variable_selected_cb)
            widget.popover.connect("entity-new",
                                          self.entity_new_clicked_cb)
            widget.popover.connect("new-window-clicked",
                                          self.new_window_clicked_cb)
            widget.popover.connect("object-selected",
                                          self.object_selected_cb)
            widget.popover.connect("variable-deleted",
                                          self.variable_deleted_cb)

        self.property.popover.search_entry.set_text("property:")

        self.show_all()
def make_row_entry(grid: Gtk.Grid, entry_label: str,
                   label_cell_factory=make_label,
                   value_cell_factory=make_textview) -> GObject:
  label = make_label(entry_label)
  cell = value_cell_factory()
  grid.add(label)
  grid.attach_next_to(cell, label, side=Gtk.PositionType.RIGHT,
                      width=1, height=1)
  return cell
Esempio n. 4
0
    def add_to_grid(self, grid: Gtk.Grid, index: int):
        """
        Shortcut to add both widgets to the given Gtk.Grid object.

        :param grid: Gtk.Grid object to add to.
        :param index: Integer index of the row to add to, with 0 at the top.
        :return:
        """
        grid.attach(self._label, 0, index, 1, 1)
        grid.attach(self._entry, 1, index, 1, 1)
Esempio n. 5
0
    def render(self, grid: Gtk.Grid, grid_row: int) -> int:
        '''
        renders a question for adding to a questionnaire

        Parameters
        ----------
        grid: Gtk.Grid
            a Gtk grid object that this question will be added to it
            
        grid_row: int
            The row number of grid that the question will be added to it
        
        Returns
        -------
        row_counter: int
            The grid's row for adding the next object after adding this question
        
        Examples
        --------
        Creating a text question and adding it to the questionnaire

        >>> question_1 = TextQuestion("q1",
        ...                           "1- What emotion did you feel the most?",
        ...                           default_answer="Happiness")
        >>> questionnaire = Questionnaire("after_stimuli",
        ...                               "study01_p10",
        ...                               "stimuli00",
        ...                               "After Stimulus Questionnaire")
        >>> questionnaire.add_question(question_1)

        See Also
        -----------
        :class:`octopus_sensing.questionnaire.questionnaire`
        
        '''
        row_counter = grid_row

        # Question box
        question_label_box = Gtk.Box(spacing=120)
        question_label = Gtk.Label()
        question_label.set_markup(FONT_STYLE.format(self._text))
        question_label_box.pack_start(question_label, False, False, 0)

        grid.attach(question_label_box, 0, row_counter, 1, 1)
        row_counter += 1

        # text box
        text_box = Gtk.Box(spacing=120)
        text_box.pack_start(self.answer_textbox, False, False, 0)
        grid.attach(text_box, 1, row_counter, 1, 1)
        row_counter += 1
        return row_counter
Esempio n. 6
0
 def _append(self, grid: Gtk.Grid, x, y, index, image: Image.Image) -> Gtk.DrawingArea:
     self._surfaces.append(self._get_surface(image))
     box: Gtk.Box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 5)
     box.set_margin_bottom(10)
     label: Gtk.Label = Gtk.Label.new(f'{index}')
     draw_area: Gtk.DrawingArea = Gtk.DrawingArea.new()
     draw_area.set_halign(Gtk.Align.CENTER)
     draw_area.set_size_request(64, 64)
     box.pack_start(draw_area, False, True, 0)
     box.pack_start(label, False, True, 0)
     grid.attach(box, x, y, 1, 1)
     box.show_all()
     return draw_area
Esempio n. 7
0
    def _do_init(self, footer_area: Gtk.Grid) -> Gtk.Widget:
        self._widget = Gtk.Grid()

        frame = Gtk.Frame(margin=10, label_xalign=0.5)
        frame.show()
        self._widget.attach(frame, 0, 1, 1, 1)

        self._stack = Gtk.Stack()
        self._stack.show()
        frame.add(self._stack)

        _, self._individual_area = self.new_component(
            individual_cs.factory(model=self.presenter.individual_model))
        self._individual_area.show()
        self._stack.add_titled(self._individual_area,
                               name='Individual Fit',
                               title='Individual Fit')

        _, self._graphs_area = self.new_component(
            graphs_cs.factory(model=self.presenter.graphs_model))
        self._graphs_area.show()
        self._stack.add_titled(self._graphs_area,
                               name='Graphs',
                               title='Graphs')

        self._stack_switcher = Gtk.StackSwitcher(stack=self._stack)
        self._stack_switcher.show()
        frame.props.label_widget = self._stack_switcher

        self._stack.props.visible_child = self._individual_area

        _, footer_inner = self.new_component(
            results_footer_cs.factory(
                in_status=self.presenter.bn_footer_status,
                in_progress=self.presenter.bn_completion_progress,
                in_time_elapsed=self.presenter.bn_time_elapsed,
                in_time_remaining=self.presenter.bn_time_remaining,
                do_back=self.presenter.back,
                do_cancel=self.presenter.cancel,
                do_save=self.presenter.save,
            ))
        footer_inner.show()
        footer_area.add(footer_inner)

        self._confirm_cancel_dialog = None
        self._confirm_discard_dialog = None
        self._save_dialog_cid = None

        self.presenter.view_ready()

        return self._widget
Esempio n. 8
0
    def __add_widget_to_grid(self, grid: Gtk.Grid, nick: str,
                             widget: Gtk.Widget, reset_func: Callable,
                             y: int) -> None:
        text = _("%(preference_label)s:") % {"preference_label": nick}

        button = Gtk.Button.new_from_icon_name("edit-clear-all-symbolic",
                                               Gtk.IconSize.MENU)
        button.set_tooltip_text(_("Reset to default value"))
        button.set_relief(Gtk.ReliefStyle.NONE)
        button.connect("clicked", reset_func)

        label = Gtk.Label(label=text)
        label.props.yalign = 0.5
        grid.attach(label, 0, y, 1, 1)
        grid.attach(widget, 1, y, 1, 1)
        grid.attach(button, 2, y, 1, 1)
Esempio n. 9
0
    def add_to_grid(self, grid: Gtk.Grid):
        if self.tenant:
            raise Exception('Already added to a grid')
        tenant = self.tenant = GridRowTenant(grid)
        base = 0
        if tenant.base_row > 0:
            tenant.attach(Gtk.Separator(visible=True, hexpand=True),
                          width=FINISHED_JOB_COLUMNS)
            base += 1
        tenant.attach(self.title_box, top=base)
        tenant.attach(self.finish_box, top=base, left=1)
        tenant.attach(self.buttons, top=base, left=2)
        tenant.attach(self.extra, top=base + 1, width=FINISHED_JOB_COLUMNS)

        grid.get_toplevel().register_interest_in_sources(
            on_update_callback=self.on_source_update)
Esempio n. 10
0
    def __init__(self, claim, *args, new=False, **kwargs):
        Grid.__init__(self, *args, **kwargs)

        self.qualifier_new.modify_font(FontDescription('Cantarell 8'))
        self.reference_new.modify_font(FontDescription('Cantarell 8'))
        self.qualifier_pos = {}

        self.qualifier_row = 0
        self.reference_row = 0
        self.references_expanded = False

        if new:
            snak = None
        else:
            snak = claim['mainsnak']

        self.entity = Entity(snak=snak, new=new)
        self.entity.connect("entity-editing", self.entity_editing_cb)
        self.entity.connect("entity-leaving", self.entity_leaving_cb)
        self.entity.connect("object-selected", self.object_selected_cb, claim)
        self.entity.connect('new-window-clicked', self.new_window_clicked_cb)
        self.mainsnak.add(self.entity)

        self.hide_actions = True

        if 'qualifiers' in claim:
            self.props.row_spacing = 3
            self.qualifiers.set_visible(True)
            claims = claim['qualifiers']

            for i, P in enumerate(claims):
                download_light(P, self.load_qualifier, i, claims[P])

        self.actions_hide = False

        if 'references' in claim:
            self.references = claim['references']
            self.button_connection = self.button.connect(
                "button-press-event", self.references_expand_clicked_cb)
        else:
            self.icon.set_from_icon_name('list-add-symbolic', IconSize.BUTTON)
            #self.button_connection = self.button.connect("button-press-event", self.reference_new_clicked_cb)

        self.button_press_connection = self.connect("button-press-event",
                                                    self.clicked_cb)

        del claim
Esempio n. 11
0
    def _setSelectAll(self) -> None:
        """
        Sets up widgets to select all sentences.

        :return:
        """

        grid: Grid = Grid()
        grid.set_halign(Align.END)
        self._subtitles_grid.attach(grid, 0, 2, 1, 1)

        lbl: Label = Label(label='Select all')
        setMargin(lbl, 5)

        grid.attach(lbl, 0, 0, 1, 1)

        all_vid_toggle: CheckButton = CheckButton()
        all_vid_toggle.set_halign(Align.CENTER)
        all_vid_toggle.connect('toggled', self._onAllVideosToggled)

        setMargin(all_vid_toggle, 5)

        grid.attach(all_vid_toggle, 1, 0, 1, 1)

        lbl2: Label = Label(label='Videos')

        setMargin(lbl2, 5)

        grid.attach(lbl2, 1, 1, 1, 1)

        all_audio_toggle: CheckButton = CheckButton()
        all_audio_toggle.set_halign(Align.CENTER)
        all_audio_toggle.connect('toggled', self._onAllAudiosToggled,
                                 all_vid_toggle)

        setMargin(all_audio_toggle, 5)

        grid.attach(all_audio_toggle, 2, 0, 1, 1)

        lbl3: Label = Label(label='Audios')

        setMargin(lbl3, 5)

        grid.attach(lbl3, 2, 1, 1, 1)

        all_img_toggle: CheckButton = CheckButton()
        all_img_toggle.set_halign(Align.CENTER)
        all_img_toggle.connect('toggled', self._onAllImagesToggled)

        setMargin(all_img_toggle, 5)

        grid.attach(all_img_toggle, 3, 0, 1, 1)

        lbl4: Label = Label(label='Snapshot')

        setMargin(lbl4, 5)

        grid.attach(lbl4, 3, 1, 1, 1)
Esempio n. 12
0
    def _do_init(self, footer_area: Gtk.Grid) -> Gtk.Widget:
        self._widget = Gtk.Grid(margin=10, column_spacing=10, row_spacing=10)

        image_source_lbl = Gtk.Label('Image source:')
        self._widget.attach(image_source_lbl, 0, 0, 1, 1)

        self._image_source_combobox = Gtk.ComboBoxText(hexpand=True, halign=Gtk.Align.START)
        self._widget.attach(self._image_source_combobox, 1, 0, 1, 1)

        self._populate_combobox()

        self._widget.attach(
            Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL, hexpand=True),
            0, 1, 2, 1
        )

        _, configurator_area = self.new_component(
            configurator_cs.factory(
                in_acquirer=self.presenter.bn_acquirer
            )
        )
        self._widget.attach(configurator_area, 0, 2, 2, 1)

        self.bn_selected_acquirer_type = GObjectPropertyBindable(
            g_obj=self._image_source_combobox,
            prop_name='active-id',
            transform_to=lambda e: e.name if e is not None else None,
            transform_from=lambda name: AcquirerType[name] if name is not None else None,
        )  # type: Bindable[Optional[str]]

        _, footer_inside = self.new_component(
            linear_navigator_footer_cs.factory(
                do_next=self.presenter.next_page
            )
        )
        footer_inside.show()
        footer_area.add(footer_inside)

        self.presenter.view_ready()

        self._widget.foreach(Gtk.Widget.show)

        return self._widget
Esempio n. 13
0
    def __init__(self, *args, **kwargs):
        Window.__init__(self, *args, **kwargs)

        icon = lambda x: IconTheme.get_default().load_icon((name), x, 0)
        icons = [icon(size) for size in [32, 48, 64, 96]]
        self.set_icon_list(icons)

        self.credentials.set_header_func(self.update_header)
        self.languages.set_header_func(self.update_header)

        for key in self.config.data['credentials']:
            row = ListBoxRow()
            grid = Grid()
            grid.props.column_homogeneous = True
            label = Label()
            label.set_text(key)
            label.props.halign = Align(1)
            context = label.get_style_context()
            resource = "/ml/prevete/Daty/gtk/value.css"
            set_style(context, resource, "dim-label", True)
            entry = Entry()
            entry.set_text(self.config.data['credentials'][key])
            context = entry.get_style_context()
            set_style(context, resource, "flat", True)
            grid.attach(label, 0, 0, 1, 1)
            grid.attach(entry, 1, 0, 2, 1)
            row.add(grid)
            self.credentials.add(row)
        self.credentials.show_all()

        query = """SELECT ?item ?itemLabel ?c
{
  ?item wdt:P424 ?c .
  MINUS{?item wdt:P31/wdt:P279* wd:Q14827288} #exclude Wikimedia projects
  MINUS{?item wdt:P31/wdt:P279* wd:Q17442446} #exclude Wikimedia internal stuff
  SERVICE wikibase:label { bd:serviceParam wikibase:language "your_first_language". }
}
        """

        query = sub("your_first_language", self.config.data['languages'][0],
                    query)
        self.retrieve(query, self.languages_callback)
Esempio n. 14
0
    def __init__(self, grid: Gtk.Grid, label_text: str, x: int, y: int):
        super().__init__()

        self._empty = True

        self.state = Observable(ErrorType.ok)
        label = create_status_label(label_text, self.state)
        label.set_xalign(1)
        grid.attach(label, x, y, 1, 1)

        self.desired = NumberEntry()
        self.desired.set_width_chars(4)
        self.desired.set_max_length(4)

        def on_enter(entry: Gtk.Entry):
            val = int(entry.get_text())
            entry.set_text(str(val))
            self.emit('completed', val)

        self.desired.connect('activate', on_enter)
        grid.attach(self.desired, x + 1, y, 1, 1)

        self.actual = Gtk.Entry()
        self.actual.set_sensitive(False)
        self.actual.set_width_chars(4)
        grid.attach(self.actual, x + 2, y, 1, 1)
Esempio n. 15
0
    def __init__(self, config, *args, **kwargs):
        Assistant.__init__(self)

        icon = lambda x: IconTheme.get_default().load_icon((name), x, 0)
        icons = [icon(size) for size in [32, 48, 64, 96]];
        self.set_icon_list(icons);

        self.config = config
        self.credentials.set_header_func(self.update_header)

        elements = [("user", self.username_label, self.username),
                    ("bot_user", self.bot_username_label, self.bot_username),
                    ("bot_password", self.bot_password_label, self.bot_password)]

        for key, label, entry in elements:
            row = ListBoxRow()
            grid = Grid()
            grid.props.column_homogeneous = True
            label.props.halign = Align(1)
            grid.attach(label, 0, 0, 1, 1)
            grid.attach(entry, 1, 0, 2, 1)
            row.add(grid)
            self.credentials.add(row)
        self.credentials.show_all()

        lc, encoding = getdefaultlocale()
        if (lc):
            language = lc.split("_")[0]
        else:
            language = environ.get("LANGUAGE", None)
            if language:
                language = language.split(":")[0]
        self.config.data['languages'] = [language]

        self.connect('destroy', main_quit)
        self.show_all()
Esempio n. 16
0
    def __init__(self, app: Application):
        super().__init__(title='Asts', application=app)

        self._app: Application = app

        self.set_default_size(1000, 700)
        self.set_keep_above(True)
        self.set_resizable(False)

        self._box: Box = Box()
        self._box.set_orientation(Orientation.VERTICAL)

        setBgColor(widget=self, alpha=0.93)

        setMargin(self._box, 10)

        self._fst_grid: Grid = Grid()

        # labels
        self._setLabels()

        # file choosers button
        # _fc_s[0] = anki2.collection file
        # _fc_s[1] = video file
        # _fc_s[2] = subtitle file
        # _fc_s[3] = optional subtitle file
        self._fc_s: List[FileChooser] = self._setFileChoosers()

        # text entry
        self._entry: Entry
        self._setTextEntry()

        self._fillCachedFile()

        # filters
        self._setFilters()

        # buttons
        self._next_btn: Button
        self._setButtonsSignals()

        # box.pack_(child, expand, fill, padding)
        self._box.pack_start(self._fst_grid, False, True, 0)

        self.add(self._box)
Esempio n. 17
0
    def render(self, grid: Gtk.Grid, grid_row: int) -> int:
        '''
        renders a question for adding to a questionnaire

        @param Grid grid: a grid object that this question will add to it
        @param int grid_row: The row that the question will add

        @rtype: int
        @return: the grid's row for adding the next object after adding the question
        '''
        row_counter = grid_row

        # Question box
        question_label_box = Gtk.Box(spacing=120)
        question_label = Gtk.Label()
        question_label.set_markup(FONT_STYLE.format(self._text))
        question_label_box.pack_start(question_label, False, False, 0)

        grid.attach(question_label_box, 0, row_counter, 1, 1)
        row_counter += 1

        # Image box
        image_box = None
        if self._image_path is not None:
            image_box = Gtk.Box(spacing=120)
            image = Gtk.Image.new_from_file(self._image_path)
            image_box.pack_start(image, False, False, 0)
            grid.attach(image_box, 0, row_counter, 1, 1)
            row_counter += 1

        # Options box
        options_box = Gtk.Box(spacing=120)
        option_buttons: List[Gtk.RadioButton] = []
        for i, option in enumerate(self._options):
            if i == 0:
                option_button = \
                    Gtk.RadioButton.new_with_label_from_widget(None, str(option.id))
            else:
                option_button = \
                    Gtk.RadioButton.new_with_label_from_widget(option_buttons[0],
                                                               str(option.id))
            option_button.connect("toggled", self.__on_option_button_toggled,
                                  option.value)
            option_button.get_child().set_markup(
                FONT_STYLE.format(option.label))
            option_buttons.append(option_button)
            options_box.pack_start(option_button, False, False, 0)
            if option.value == self.answer:
                option_button.set_active(True)
        grid.attach(options_box, 0, row_counter, 1, 1)
        row_counter += 1
        return row_counter
 def _update_param_grid_rows(self, grid: Gtk.Grid,
                             params: Dict[str, pyspiel.GameParameter]):
   actual_grid_rows = num_grid_rows(grid)
   expected_num_rows = len(params)
   if expected_num_rows == actual_grid_rows:
     pass
   elif expected_num_rows < actual_grid_rows:
     # Remove
     for i in range(expected_num_rows, actual_grid_rows):
       label = grid.get_child_at(left=0, top=i)
       tv = grid.get_child_at(left=1, top=i)
       grid.remove(label)
       grid.remove(tv)
   else:
     # Add
     num_row_additions = expected_num_rows - actual_grid_rows
     for _ in range(num_row_additions):
       tv = make_row_entry(grid, "", lambda: Gtk.TextView(monospace=True))
       tv.connect("key-press-event", self._on_param_change)
Esempio n. 19
0
def add_usb_item(self, entry: Gtk.Entry, grid: Gtk.Grid, allitems: list, selecteditems: list):
    """Add usb config item."""
    key = entry.get_text()
    if key in allitems:
        return
    allitems.append(key)

    toggle = Gtk.ToggleButton(key)
    toggle.connect('toggled', on_button_toggled, key, selecteditems)
    toggle.set_active(True)

    label = Gtk.Label('')
    label.set_halign(Gtk.Align.START)

    global indexstore
    grid.attach(toggle, 1, indexstore, 1, 1)
    grid.attach(label, 2, indexstore, 1, 1)

    indexstore += 1
    grid.show_all()
Esempio n. 20
0
 def grid_remove_all (grid: Gtk.Grid) -> None:
     for child in grid.get_children ():
         grid.remove (child)
Esempio n. 21
0
 def grid_remove_all(grid: Gtk.Grid) -> None:
     for child in grid.get_children():
         grid.remove(child)
Esempio n. 22
0
    def render(self, grid: Gtk.Grid, grid_row: int):
        '''
        renders a question for adding to a questionnaire

        Parameters
        ----------
        grid: Gtk.Grid
            a Gtk grid object that this question will be added to it
            
        grid_row: int
            The row number of grid that the question will be added to it
        
        Returns
        -------
        row_counter: int
            The grid's row for adding the next object after adding this question
        
        Examples
        --------
        Creating an opinion question and adding it to the questionnaire

        >>> emotions = {"Happiness": 4, "Sadness": 6, "Neutral": 5, "Fear": 3, "Anger": 1}
        >>> question_1 = OpinionQuestion("q1",
        ...                              "1- What emotion did you feel the most?",
        ...                              options=emotions,
        ...                              default_answer=5)
        >>> questionnaire = Questionnaire("after_stimuli",
        ...                               "study01_p10",
        ...                               "stimuli00",
        ...                               "After Stimulus Questionnaire")
        >>> questionnaire.add_questions([question_1])

        See Also
        -----------
        :class:`octopus_sensing.questionnaire.questionnaire`

        '''

        row_counter = grid_row

        # Question box
        question_label_box = Gtk.Box(spacing=120)
        question_label = Gtk.Label()
        question_label.set_markup(FONT_STYLE.format(self._text))
        question_label_box.pack_start(question_label, False, False, 0)

        grid.attach(question_label_box, 0, row_counter, 1, 1)
        row_counter += 1

        # Image box
        image_box = None
        if self._image_path is not None:
            image_box = Gtk.Box(spacing=120)
            image = Gtk.Image.new_from_file(self._image_path)
            image_box.pack_start(image, False, False, 0)
            grid.attach(image_box, 0, row_counter, 1, 1)
            row_counter += 1

        # Options box
        options_box = Gtk.Box(spacing=120)
        option_buttons: List[Gtk.RadioButton] = []
        for i, option in enumerate(self._options):
            if i == 0:
                option_button = \
                    Gtk.RadioButton.new_with_label_from_widget(None, str(option.id))
            else:
                option_button = \
                    Gtk.RadioButton.new_with_label_from_widget(option_buttons[0],
                                                               str(option.id))
            option_button.connect("toggled", self.__on_option_button_toggled,
                                  option.value)
            option_button.get_child().set_markup(
                FONT_STYLE.format(option.label))
            option_buttons.append(option_button)
            options_box.pack_start(option_button, False, False, 0)
            if option.value == self.answer:
                option_button.set_active(True)
        grid.attach(options_box, 0, row_counter, 1, 1)
        row_counter += 1
        return row_counter
Esempio n. 23
0
def rows(grid: Gtk.Grid) -> int:
    return max(map(lambda child: grid.child_get_property(child, 'top-attach'),
                   grid.get_children()),
               default=-1) + 1
Esempio n. 24
0
    def _do_init(self, footer_area: Gtk.Grid) -> Gtk.Widget:
        self._widget = Gtk.Grid(margin=20, row_spacing=10, column_spacing=10)

        # Label widgets
        inner_density_lbl = Gtk.Label('Inner density (kg/m³):', xalign=0)
        self._widget.attach(inner_density_lbl, 0, 0, 1, 1)

        outer_density_lbl = Gtk.Label('Outer density (kg/m³):', xalign=0)
        self._widget.attach(outer_density_lbl, 0, 1, 1, 1)

        needle_width_lbl = Gtk.Label('Needle diameter (mm):', xalign=0)
        self._widget.attach(needle_width_lbl, 0, 2, 1, 1)

        gravity_lbl = Gtk.Label('Gravity (m/s²):', xalign=0)
        self._widget.attach(gravity_lbl, 0, 3, 1, 1)

        # Input widgets
        self._inner_density_inp = FloatEntry(lower=0, width_chars=10)
        self._widget.attach_next_to(self._inner_density_inp, inner_density_lbl,
                                    Gtk.PositionType.RIGHT, 1, 1)

        self._outer_density_inp = FloatEntry(lower=0, width_chars=10)
        self._widget.attach_next_to(self._outer_density_inp, outer_density_lbl,
                                    Gtk.PositionType.RIGHT, 1, 1)

        self._needle_width_inp = FloatEntry(lower=0, width_chars=10)
        self._widget.attach_next_to(self._needle_width_inp, needle_width_lbl,
                                    Gtk.PositionType.RIGHT, 1, 1)

        self._gravity_inp = FloatEntry(lower=0, width_chars=10)
        self._widget.attach_next_to(self._gravity_inp, gravity_lbl,
                                    Gtk.PositionType.RIGHT, 1, 1)

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

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

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

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

        self._widget.show_all()

        self.bn_inner_density = GObjectPropertyBindable(
            g_obj=self._inner_density_inp,
            prop_name='value',
        )

        self.bn_outer_density = GObjectPropertyBindable(
            g_obj=self._outer_density_inp,
            prop_name='value',
        )

        self.bn_needle_width = GObjectPropertyBindable(
            g_obj=self._needle_width_inp,
            prop_name='value',
            # Needle width shown to user is in millimetres.
            transform_from=lambda x: x / 1000 if x is not None else None,
            transform_to=lambda x: x * 1000 if x is not None else None,
        )

        self.bn_gravity = GObjectPropertyBindable(
            g_obj=self._gravity_inp,
            prop_name='value',
        )

        _, footer_inside = self.new_component(
            linear_navigator_footer_cs.factory(
                do_back=self.presenter.prev_page,
                do_next=self.presenter.next_page,
            ))
        footer_inside.show()
        footer_area.add(footer_inside)

        self.presenter.view_ready()

        return self._widget
def num_grid_rows(grid: Gtk.Grid) -> int:
  grid_children = grid.get_children()
  assert len(grid_children) % 2 == 0
  return int(len(grid_children) / 2)
Esempio n. 26
0
    def __init__(self, parent: Window, app: Application,
                 col_filename: Filename, vid_filename: Filename,
                 sub_filename: Filename, opt_sub_filename: OptFilename,
                 deck_name: str):

        super().__init__(title='Asts - Anki Card Generator',
                         application=app,
                         transient_for=parent)

        self.set_default_size(width=1000, height=700)
        self.set_keep_above(True)
        self.set_modal(True)
        self.set_resizable(False)

        setBgColor(widget=self, alpha=0.93)

        self._main_box: Box = Box()
        self._main_box.set_orientation(Orientation.VERTICAL)
        setMargin(self._main_box, 10)

        self.add(self._main_box)

        self._subtitles_grid: Grid = Grid()
        setMargin(self._subtitles_grid, 5)

        # box.pack_(expand, fill, padding)
        self._main_box.pack_start(self._subtitles_grid, False, True, 0)

        self._collection_filename: Filename = col_filename
        self._video_filename: Filename = vid_filename
        self._subtitles_filename: Filename = sub_filename
        self._opt_subtitles_filename: OptFilename = opt_sub_filename
        self._deck_name: str = deck_name

        self._any_media_toggled: bool = False
        self._dict_any_media: Dict[str, bool]

        self._dict_any_change_front: Dict[str, bytes]
        self._dict_any_change_back: Dict[str, bytes]

        self._textview_front: TextView
        self._textview_back: TextView

        self._textbuffer_front: TextBuffer
        self._textbuffer_back: TextBuffer

        self._subtitles_liststore: ListStore
        self._subtitles_liststore_back: ListStore

        self._subtitles_treeview: TreeView

        self._selected_row: TreeSelection

        self._progress_bar: ProgressBar

        self._cancel_btn: Button
        self._generate_btn: Button

        self._cur_progress: int
        self._max_tasks: int

        self._cancel_task: bool

        self._list_of_sentences: ListSentences
        self._list_info_medias: List[List[Info]]

        self._color_tag_names: List[str]
        # TheadingHandler will utilize these
        # updating the status for each task tasks
        # also the sensitive and progress of the progress bar
        # depends on these.
        self._futures_list: List[Future]