Пример #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
Пример #2
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)
Пример #3
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
Пример #4
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
Пример #5
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)
Пример #6
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)
Пример #7
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()
Пример #8
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)
Пример #9
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()
Пример #10
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
Пример #11
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