Verified Commit 8b6dfc9e authored by tallero's avatar tallero

snappity

parent bc820972
# -*- coding: utf-8 -*-
# LanguageAdd
#
# ----------------------------------------------------------------------
# Copyright © 2018 Pellegrino Prevete
#
# All rights reserved
# ----------------------------------------------------------------------
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
from gi import require_version
require_version('Gtk', '3.0')
from gi.repository.Gtk import CssProvider, Label, ListBoxRow, Separator, StyleContext, STYLE_PROVIDER_PRIORITY_APPLICATION, Window, IconTheme, Template
from .util import set_style
#from .wikidata import Wikidata
name = 'ml.prevete.Daty'
@Template.from_resource("/ml/prevete/Daty/gtk/languageadd.ui")
class LanguageAdd(Window):
__gtype_name__ = "LanguageAdd"
cancel = Template.Child("cancel")
select = Template.Child("select")
languages = Template.Child("languages")
search_entry = Template.Child("search_entry")
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()
@Template.Callback()
def cancel_clicked_cb(self, widget):
self.hide()
self.destroy()
@Template.Callback()
def select_clicked_cb(self, widget):
pass
@Template.Callback()
def search_entry_search_changed_cb(self, entry):
for row in self.languages.get_children():
if entry.get_text().lower() in row.child.get_text().lower():
row.set_visible(True)
row.set_no_show_all(False)
else:
row.set_visible(False)
row.set_no_show_all(True)
self.languages.show_all()
def update_header(self, row, before, *args):
"""See GTK+ Documentation"""
if before:
row.set_header(Separator())
# -*- coding: utf-8 -*-
# Preferences
#
# ----------------------------------------------------------------------
# Copyright © 2018 Pellegrino Prevete
#
# All rights reserved
# ----------------------------------------------------------------------
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
from gi import require_version
require_version('Gtk', '3.0')
from gi.repository.GLib import idle_add
from gi.repository.Gtk import Align, CssProvider, Dialog, Entry, Grid, Label, ListBoxRow, Separator, StyleContext, STYLE_PROVIDER_PRIORITY_APPLICATION, IconTheme, Template, Window
from pprint import pprint
from pywikibot.data.sparql import SparqlQuery
from re import sub
from threading import Thread
from .config import Config
from .languageadd import LanguageAdd
from .util import set_style
#from .wikidata import Wikidata
name = 'ml.prevete.Daty'
@Template.from_resource("/ml/prevete/Daty/gtk/preferences.ui")
class Preferences(Window):
__gtype_name__ = "Preferences"
config = Config()
credentials = Template.Child("credentials")
languages = Template.Child("languages")
#values = Template.Child("values")
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)
@Template.Callback()
def language_new_clicked_cb(self, widget):
language_add = LanguageAdd(self.language_results)
print(language_add)
language_add.show_all()
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()
def retrieve(self, query, callback, *cb_args, **kwargs):
"""Asynchronously download entity from wikidata
Args:
entity (dict): have keys "URI", "Label", "Description"
"""
def do_call():
sparql = SparqlQuery()
results = sparql.query(query)
idle_add(lambda: callback(results, *cb_args, **kwargs))
return None
thread = Thread(target = do_call)
thread.start()
def update_header(self, row, before, *args):
"""See GTK+ Documentation"""
if before:
row.set_header(Separator())
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<template class="LanguageAdd" parent="GtkWindow">
<property name="can_focus">False</property>
<property name="default_width">400</property>
<property name="default_height">300</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">18</property>
<property name="margin_end">18</property>
<property name="margin_top">18</property>
<property name="margin_bottom">18</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkSearchEntry" id="search_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
<property name="placeholder_text" translatable="yes">Search for a language</property>
<signal name="search-changed" handler="search_entry_search_changed_cb" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="vexpand">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">out</property>
<child>
<object class="GtkListBox" id="languages">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Select new language</property>
<child>
<object class="GtkButton" id="cancel">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="cancel_clicked_cb" swapped="no"/>
</object>
</child>
<child>
<object class="GtkButton" id="select">
<property name="label" translatable="yes">Select</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_clicked_cb" swapped="no"/>
<style>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</template>
</interface>
name: daty
version: git
summary: Daty Wikidata Editor
description: |
Daty is a free Wikidata editor adhering to GNOME Human Interface Guidelines,
intended to enable a better editing workflow and faster deployment of requested user features for Wikidata.
Use Daty to search, select, read, batch edit items, script actions, share, visualize proposed changes and bots.
confinement: devmode
base: core18
parts:
offlineimap:
plugin: python
python-version: python3
source: .
stage-packages:
- python-six
apps:
offlineimap:
command: bin/daty
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment