コード例 #1
0
ファイル: gtkpcilist.py プロジェクト: d4nj1/TLPUI
def edit_list(self, configname: str, usblistlabel: Gtk.Label, window: Gtk.Window):
    tlpobject = settings.tlpconfig[configname]
    pcilistpattern = re.compile(r'^([a-f\d]{2}:[a-f\d]{2}\.[a-f\d])(.+?)$')
    currentitems = tlpobject.get_value().split(' ')

    tlpusblist = check_output(["lspci"]).decode(sys.stdout.encoding)

    pciitems = OrderedDict()
    for line in tlpusblist.splitlines():
        matcher = pcilistpattern.match(line)
        pciid = matcher.group(1)
        description = matcher.group(2).lstrip()

        pciitems[pciid] = [description, (pciid in currentitems)]

    grid = Gtk.Grid()
    grid.set_row_homogeneous(True)
    grid.set_column_spacing(12)

    grid.attach(Gtk.Label(''), 0, 0, 1, 1)
    grid.attach(Gtk.Label(label='ID', halign=Gtk.Align.START), 1, 0, 1, 1)
    grid.attach(Gtk.Label(label='Description', halign=Gtk.Align.START), 2, 0, 1, 1)
    grid.attach(Gtk.Label(''), 3, 0, 1, 1)

    rowindex = 2
    allitems = list()
    selecteditems = list()
    for key, value in pciitems.items():
        allitems.append(key)
        toggle = Gtk.ToggleButton(key)
        toggle.connect('toggled', on_button_toggled, key, selecteditems)

        if value[1]:
            toggle.set_active(True)

        label = Gtk.Label(value[0])
        label.set_halign(Gtk.Align.START)

        grid.attach(toggle, 1, rowindex, 1, 1)
        grid.attach(label, 2, rowindex, 1, 1)

        rowindex += 1

    dialog = Gtk.Dialog('PCI(e) devices', window, 0, (
        Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
        Gtk.STOCK_OK, Gtk.ResponseType.OK
    ))

    contentarea = dialog.get_content_area()
    contentarea.set_spacing(6)
    contentarea.add(grid)
    dialog.show_all()

    response = dialog.run()
    if response == Gtk.ResponseType.OK:
        configvalue = ' '.join(str(item) for item in selecteditems)
        tlpobject.set_value(configvalue)
        usblistlabel.set_text(configvalue.replace(" ", "\n"))

    dialog.destroy()
コード例 #2
0
 def set_label_string(label: Gtk.Label, text: str) -> None:
     """
     Sets the displayed text of a label widget
     :param label: the label to be modified
     :param text: the text to be displayed
     :return: void
     """
     label.set_text(text)
コード例 #3
0
 def languages_callback(self, results):
     languages = self.config.data['languages']
     self.language_results = results['results']['bindings']
     for lang in languages:
         for r in self.language_results:
             if r['c']['value'] == lang:
                 row = ListBoxRow()
                 label = Label()
                 label.set_text(r['itemLabel']['value'])
                 label.props.halign = Align(1)
                 row.add(label)
                 self.languages.add(row)
     self.languages.show_all()
コード例 #4
0
    def __init__(self, languages, *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.languages.set_header_func(self.update_header)
        for language in languages:
            row = ListBoxRow()
            label = Label()
            label.set_text(language['itemLabel']['value'])
            label.code = language['c']['value']
            row.child = label
            row.add(label)
            self.languages.add(row)
        self.languages.show_all()
コード例 #5
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)
コード例 #6
0
def edit_list(self, configname: str, usblistlabel: Gtk.Label,
              window: Gtk.Window):
    tlpobject = settings.tlpconfig[configname]
    pcilistpattern = re.compile(r'^([a-f\d]{2}:[a-f\d]{2}\.[a-f\d])(.+?)$')
    currentitems = tlpobject.get_value().split(' ')

    tlpusblist = check_output(["lspci"]).decode(sys.stdout.encoding)

    pciitems = OrderedDict()
    for line in tlpusblist.splitlines():
        matcher = pcilistpattern.match(line)
        pciid = matcher.group(1)
        description = matcher.group(2).lstrip()

        pciitems[pciid] = [description, (pciid in currentitems)]

    grid = Gtk.Grid()
    grid.set_row_homogeneous(True)
    grid.set_column_spacing(12)

    grid.attach(Gtk.Label(''), 0, 0, 1, 1)
    grid.attach(Gtk.Label(label='ID', halign=Gtk.Align.START), 1, 0, 1, 1)
    grid.attach(Gtk.Label(label='Description', halign=Gtk.Align.START), 2, 0,
                1, 1)
    grid.attach(Gtk.Label(''), 3, 0, 1, 1)

    rowindex = 2
    allitems = list()
    selecteditems = list()
    for key, value in pciitems.items():
        allitems.append(key)
        toggle = Gtk.ToggleButton(key)
        toggle.connect('toggled', on_button_toggled, key, selecteditems)

        if value[1]:
            toggle.set_active(True)

        label = Gtk.Label(value[0])
        label.set_halign(Gtk.Align.START)

        grid.attach(toggle, 1, rowindex, 1, 1)
        grid.attach(label, 2, rowindex, 1, 1)

        rowindex += 1

    dialog = Gtk.Dialog('PCI(e) devices', window, 0,
                        (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                         Gtk.STOCK_OK, Gtk.ResponseType.OK))

    contentarea = dialog.get_content_area()
    contentarea.set_spacing(6)
    contentarea.add(grid)
    dialog.show_all()

    response = dialog.run()
    if response == Gtk.ResponseType.OK:
        configvalue = ' '.join(str(item) for item in selecteditems)
        tlpobject.set_value(configvalue)
        usblistlabel.set_text(configvalue.replace(" ", "\n"))

    dialog.destroy()
コード例 #7
0
def edit_list(self, configname: str, usblistlabel: Gtk.Label,
              window: Gtk.Window):
    tlpobject = settings.tlpconfig[configname]
    usblistpattern = re.compile(r'^.+?([a-f\d]{4}:[a-f\d]{4})(.+?)$')
    currentitems = OrderedDict()
    if tlpobject.get_value() != '':
        for item in tlpobject.get_value().split(' '):
            currentitems[item] = ["", True]

    tlpusblist = check_output(["tlp-usblist"]).decode(sys.stdout.encoding)

    usbitems = OrderedDict()
    for line in tlpusblist.splitlines():
        matcher = usblistpattern.match(line)
        usbid = matcher.group(1)
        description = matcher.group(2)
        active = False

        # only add usb id once
        if usbid in usbitems:
            continue

        # check if item is selected
        if usbid in currentitems:
            active = True
            del currentitems[usbid]
        usbitems[usbid] = [description, active]

    usbitems.update(currentitems)

    grid = Gtk.Grid()
    grid.set_row_homogeneous(True)
    grid.set_column_spacing(12)

    grid.attach(Gtk.Label(''), 0, 0, 1, 1)
    grid.attach(Gtk.Label(label='ID', halign=Gtk.Align.START), 1, 0, 1, 1)
    grid.attach(Gtk.Label(label='Description', halign=Gtk.Align.START), 2, 0,
                1, 1)
    grid.attach(Gtk.Label(''), 3, 0, 1, 1)

    rowindex = 2
    allitems = list()
    selecteditems = list()
    for key, value in usbitems.items():
        allitems.append(key)
        toggle = Gtk.ToggleButton(key)
        toggle.connect('toggled', on_button_toggled, key, selecteditems)

        if value[1]:
            toggle.set_active(True)

        label = Gtk.Label(value[0])
        label.set_halign(Gtk.Align.START)

        grid.attach(toggle, 1, rowindex, 1, 1)
        grid.attach(label, 2, rowindex, 1, 1)

        rowindex += 1

    addbutton = Gtk.Button(label=' Add',
                           image=get_theme_image('list-add-symbolic',
                                                 Gtk.IconSize.BUTTON))
    addbutton.set_sensitive(False)
    addbutton.set_always_show_image(True)

    addentry = Gtk.Entry()
    addentry.set_width_chars(9)
    addentry.set_max_length(9)
    addentry.connect('changed', usb_entry_check, addbutton)

    addbutton.connect('clicked', add_usb_item, addentry, grid, allitems,
                      selecteditems)

    addlabel = Gtk.Label(label='Add custom unattached USB IDs:',
                         halign=Gtk.Align.START)

    addbox = Gtk.Box()
    addbox.pack_start(addentry, False, False, 0)
    addbox.pack_start(addbutton, False, False, 12)
    addbox.pack_start(Gtk.Label(''), True, True, 0)

    grid.attach(addlabel, 1, rowindex, 2, 1)
    grid.attach(addbox, 1, rowindex + 1, 2, 1)

    global indexstore
    indexstore = rowindex + 2

    dialog = Gtk.Dialog('Usb devices', window, 0,
                        (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                         Gtk.STOCK_OK, Gtk.ResponseType.OK))

    contentarea = dialog.get_content_area()
    contentarea.set_spacing(6)
    contentarea.add(grid)
    dialog.show_all()

    response = dialog.run()
    if response == Gtk.ResponseType.OK:
        configvalue = ' '.join(str(item) for item in selecteditems)
        tlpobject.set_value(configvalue)
        usblistlabel.set_text(configvalue.replace(" ", "\n"))

    dialog.destroy()
コード例 #8
0
 def generate_sentence(self, generated_text_widget: Gtk.Label):
     text = self.__marcow_chain.generate()
     generated_text_widget.set_text(text)