From 44ade113e4f5f00eea5614159d1a138d8f6dcdda Mon Sep 17 00:00:00 2001 From: Ananke Date: Mon, 11 Jul 2022 20:51:43 +0200 Subject: [PATCH] Add files via upload first upload..there are still things to do.. --- wordart.desktop | 8 + wordart/ButtonArt.py | 302 ++++++++++++++++++++ wordart/README.md | 2 + wordart/__init__.py | 12 + wordart/__pycache__/__ini__.cpython-37.pyc | Bin 0 -> 168 bytes wordart/__pycache__/__init__.cpython-37.pyc | Bin 0 -> 243 bytes wordart/__pycache__/wordart.cpython-37.pyc | Bin 0 -> 1577 bytes wordart/svg_vorlagen.py | 35 +++ wordart/wordart.py | 279 ++++++++++++++++++ wordart/wordartManual.html | 12 + 10 files changed, 650 insertions(+) create mode 100644 wordart.desktop create mode 100644 wordart/ButtonArt.py create mode 100644 wordart/README.md create mode 100644 wordart/__init__.py create mode 100644 wordart/__pycache__/__ini__.cpython-37.pyc create mode 100644 wordart/__pycache__/__init__.cpython-37.pyc create mode 100644 wordart/__pycache__/wordart.cpython-37.pyc create mode 100644 wordart/svg_vorlagen.py create mode 100644 wordart/wordart.py create mode 100644 wordart/wordartManual.html diff --git a/wordart.desktop b/wordart.desktop new file mode 100644 index 0000000..41c69f4 --- /dev/null +++ b/wordart.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Type=Service +ServiceTypes=Krita/PythonPlugin +X-KDE-Library=wordart +X-Python-2-Compatible=false +X-Krita-Manual=wordartManual.html +Name=wordart +Comment=url to art diff --git a/wordart/ButtonArt.py b/wordart/ButtonArt.py new file mode 100644 index 0000000..55e1312 --- /dev/null +++ b/wordart/ButtonArt.py @@ -0,0 +1,302 @@ +# importing libraries +import sys +import re +import sqlite3 +from krita import * +from textblob import TextBlob +from textblob_de import TextBlobDE +from html.parser import HTMLParser +import urllib.request + +from PIL import ImageColor +from PyQt5.QtWidgets import * +from PyQt5.QtGui import * +from PyQt5.QtCore import * + + +# svg +def design_svg(strokecolor, fillcolor, width, height): + trans = str(((800 - height)/2) - 80) + print (trans) + #print(f'''stroke="{strokecolor}" fill="{fillcolor}"''') + svg = f''' + + + + + + + + + + '''.encode('utf-8') + return(svg) + +coffee = '''\ + + + + ๐•ถ๐–—๐–Ž๐–™๐–† ๐–“๐–Š๐–Š๐–‰๐–˜ ๐–’๐–”๐–”๐–—๐–Š ๐•ฎ๐–”๐–‹๐–‹๐–Š๐–Š! +'''.encode('utf-8') + +# define object/class for analysis +class textforart: + + def __init__(self, language = 'en', sentences_lens = [], sentences = [], commas = [], polarity = []): + # Sprache + self.language = language + + # Satz + self.senctences = sentences + + # Sentence lengthes + self.sentences_lens = sentence_lens + + # Commas + self.commas = commas + + # Bewertung + self.polarity = polarity + + # Komplezitรคt + self.complexity = '' + + + # Satzlรคnge + self.sentence_number = len(sentences) + self.min_sentence_length = min(sentences_lens) + self.max_sentence_length = max(sentences_lens) + self.mean_sentence_length = sum(sentences_lens) / len(sentences) + + # Kommas + self.number_commas = len(commas) + self.min_number_commas = min(commas) + self.max_number_commas = max(commas) + self.mean_number_commas = len(commas)/ len(sentences) + + # Bewertung + self.sum_sentences_polarity = sum(polarity) + self.min_sentences_polarity = min(polarity) + self.max_sentences_polarity = max(polarity) + self.mean_sentences_polarity = sum(polarity) / len(sentences) + + # Schรคtzer fรผr Komplexitรคt + self.max_complexity = 0 + self.min_complexity = 0 + self.mean_complexity = 0 + + # signatur Word -> mean purpose + self.signatur_word = '' + +recording = 0 + +# define class HTML-Parser +class MyHTMLParser(HTMLParser): + + def __init__(self): + super().__init__() + self.data = [] + self.capture = False + + def handle_starttag(self, tag, attrs): + if tag in ('p', 'h1'): + self.capture = True + + def handle_endtag(self, tag): + if tag in ('p', 'h1'): + self.capture = False + + def handle_data(self, data): + if self.capture: + self.data.append(data) + + +def newButtonIsClicked(self): + # text = 'Welcome fellow human beeing ^.^' + # print(text) + content = line.text() + + # aktivate Checkbox if input is done + if line.text(): + newCheckbox.setCheckState(2) + parser = MyHTMLParser() + link = urllib.request.urlopen(content).read().decode() + html = parser.feed(link) + global linkdata + # get data, remove newline + linkdata = parser.data + #print(linkdata) + newDialog.close() + else: + newCheckbox.setCheckState(0) + print('Please insert a valid Link! Thank you..') + return + + # print(content) + +# +def add_svg(svg): + clipboard = QGuiApplication.clipboard() + mime_data = QMimeData() + mime_data.setData('image/svg+xml', svg) + clipboard.setMimeData(mime_data) + Application.action('edit_paste').trigger() + +def create_svg(svg): + app = Krita.instance() + # Document open? + #if app.activeDocument(): + #print("aktive document") + #doc = app.activeDocument() + #else: + #print("create document") + #doc = app.createDocument(800, 600, 'SVGA Test', 'RGBA', 'U8', '', 120.0) + #app.activeWindow().addView(doc) + + doc = app.createDocument(800, 600, 'SVGA Test', 'RGBA', 'U8', '', 120.0) + app.activeWindow().addView(doc) + layer = doc.createVectorLayer('ColorSVG') + layer.setName('ColorSVG') + add_svg(svg) + + +# add button and layout for button +layoutForButtons = QHBoxLayout() +newButton = QPushButton("load text") +layoutForButtons.addWidget(newButton) +#layoutForButtons.addSpacing(200) + +# label +nameLabel = QLabel() +nameLabel.setText('Please input a link:') +layoutForButtons.addWidget(nameLabel) + +#input field +line = QLineEdit() +line.setPlaceholderText("URL") +line.setMinimumWidth(300) +line.setFont(QFont("console",8)) # change font +layoutForButtons.addWidget(line) + + +# write some actions +clicked = 'Button clicked' +newButton.clicked.connect(newButtonIsClicked) + + +#add a checkbox +newCheckbox = QCheckBox() +newCheckbox.setText('realise input') +link = layoutForButtons.addWidget(newCheckbox) + +# create dialog and show it +newDialog = QDialog() +newDialog.setLayout(layoutForButtons) +newDialog.setWindowTitle("Loader") +newDialog.exec_() # show the dialog + +# language +language = '' + +# filtering parsed text +text = "" +for phrases in linkdata: + #print (phrases) + #print('pre: ' + phrases) + phrases = phrases.rstrip("\n\r+0-9[]()+") + #print('after: ' + phrases) + # skip unwanted characters + text = text + phrases + #print('get: ' + phrases) + +#print(text) +# create textblob +blob = TextBlob(text) +#print(blob.tags) + +for w in blob.words: + if re.match(r"and", w): + language = 'en' + elif re.match(r"und", w): + language = 'de' + +#print(language) +if language == 'de': + blob = TextBlobDE(text) + + +sentence_lens = [] +commas = [] +polarity = [] + +# number of sentences +# print (len(blob.sentences)) + + + +#print(art.sentence_number) + +#artob.sentenc_number + +# print polarity of sentences +for sentence in blob.sentences: + + # length of sentences + sentence_lens.append(len(sentence)) + + # number of commas + commas.append(len(re.findall(',', str(sentence)))) + + # polarity + polarity.append(sentence.sentiment.polarity) + +# init new textforart object +art = textforart(language, sentence_lens, blob.sentences, commas, polarity) + +print(art.mean_sentence_length) +print(art.mean_number_commas) +print(art.min_number_commas) +print(art.max_number_commas) +print(art.mean_sentences_polarity) +print(art.max_sentences_polarity) +print(art.min_sentences_polarity) + +#print(blob.ngrams(n=1)) + +#print(blob.words) + + +# make art out of object + +# width: 0 - 700 +# height: 0 - 700 +# fill color:#000000 # stroke color:#000000 +stroke = "rgb(" + str(round(125*(1/art.mean_number_commas))) + ", " + str(round(125 - art.min_sentences_polarity)) + ", " + str(round(125 - art.max_sentences_polarity)) + ")" +fill = "rgb(" + str(round(125*(1/art.mean_number_commas))) + ", " + str(round(125 - art.min_sentences_polarity)) + ", " + str(round(125 - art.max_sentences_polarity)) + ")" +#ImageColor.getcolor("#23a9dd", "RGB") + +#stroke = "rgb(255, 255, 255)" +#stroke = "rgb(255, 254, 94.)" +#fill = "rgb(255, 255, 255)" + +print(stroke) +print(fill) + + +# define with of svg +heigh = 700- (10000*art.mean_sentences_polarity) +width = 700*art.mean_number_commas + +svg = design_svg(stroke, fill, 700, 700) +create_svg(svg) + +#print(textblob) + + diff --git a/wordart/README.md b/wordart/README.md new file mode 100644 index 0000000..562d102 --- /dev/null +++ b/wordart/README.md @@ -0,0 +1,2 @@ +# Art +# Art diff --git a/wordart/__init__.py b/wordart/__init__.py new file mode 100644 index 0000000..b4521c5 --- /dev/null +++ b/wordart/__init__.py @@ -0,0 +1,12 @@ +from krita import DockWidgetFactory, DockWidgetFactoryBase +from wordart.wordart import * + +DOCKER_ID = 'DockerLinkGrepper' +instance = Krita.instance() + +dock_widget_factory = DockWidgetFactory(DOCKER_ID, + DockWidgetFactoryBase.DockRight, + DockerLinkGrepper) + +instance.addDockWidgetFactory(dock_widget_factory) + diff --git a/wordart/__pycache__/__ini__.cpython-37.pyc b/wordart/__pycache__/__ini__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1247463105697029c16ed861e73eb7fece03ac16 GIT binary patch literal 168 zcmZ?b<>g`kf-go}lEi@YV-N=hn1BoiATH(s5-AKRj5!P;3@J>(44TX@8G%BYjJFuI z{D35Td45q!Vo}LTh9VZAIGFflsh^Rbo2s9jlUS6fua}dboS36uoRL_Rs-InyS(2z< kPzj--diCSuGxIXzg`kg0m4@k`jURV-N=hSb+=&ATCw|5-AKRj5!Rsj8Tk?45>^Dm=`iEU`b_! zu$mbc0!34pf*CZKUorv}Yck&A_N{cSC`rvL&dksA(`3EHUY=i+l2}wy!~~ST#p+#@ zS(12*BQvkKBrz{J^%hTJN(x;4N`@kKpeiu&%St~ZKQ~oBIVZ6wQC}}7KRGc+zc?eY uC{;fjWQKl0C4`2WuOAdHpf>r{G=FlPtTDwVFKsKzzZ2(;s>m_ZiMeVvI z1zUo0vVpwD`q+D)hCoj}Dpp*sR=L_o=oKOsv9A%asdHsdT;jYzefI-+qCQsmNvx%6*rgyI zfk4p&6Ev~jqZ3Rpv97&|{T?}Jq9fR`F*ZQc$~TFn?d92) zIlE=-9nf|1kBD8`JNX0R+{z!zZQ_#J)qU@dwi3uCdIL0rmXeHD7>tI!?u20qb+X^nH}86eMkXRWO>oLi8*N!+AnA1I{!V}lV!T=pFm z!~h}bkFkWiRt?FM(^JYRF^Q!#mb?LRp(h+c*@>!MBq_-*R4pFI33P-BBSB?vRE%NP5^gUu7mTXYTZvjJk^!xk`NB?>g#)bIJirD z@XR2H=Y#+F_8%)(EY2xcUKl26BEwMC$8QsIN~PLl(K1`eml-c87HUgS`PNjkpAleL zE|oQw$~(wXqfpK9&%4>>$oMIL9wq5dNyM^KFdQz#w1}e`DZQw~h>#MlHXcRClz}yx z(?V>H0eoJCJGqnVkjN4AifW8UNlIUkL@EdRgsKi$4p|h_X~y8*&7lp@?L&3*#T>BY zRB88@St^wa0I<}{=HUUbs5-al{UY{?t^%CBDUD}PoN9vEY>r{0L1#c&S*EV65&@&k zybWSO+fgDJRSvzRao^%CK;s>l;OS|EA+&-JVQAWeZ)uzEBYjAG0~5l&<>9s!U>^rg zfIYbGz&11PfKHk*EGs=?7Zqf0<` + + + + + + + + + + '''.encode('utf-8') + return(svg) diff --git a/wordart/wordart.py b/wordart/wordart.py new file mode 100644 index 0000000..7ef6cf0 --- /dev/null +++ b/wordart/wordart.py @@ -0,0 +1,279 @@ +# importing libraries +import sys +import re +import sqlite3 +from krita import * +from textblob import TextBlob +from textblob_de import TextBlobDE +from html.parser import HTMLParser +import urllib.request + +from PIL import ImageColor +from PyQt5.QtWidgets import * +from PyQt5.QtGui import * +from PyQt5.QtCore import * + + +# define class HTML-Parser +class MyHTMLParser(HTMLParser): + + def __init__(self): + super().__init__() + self.data = [] + self.capture = False + + def handle_starttag(self, tag, attrs): + if tag in ('p', 'h1'): + self.capture = True + + def handle_endtag(self, tag): + if tag in ('p', 'h1'): + self.capture = False + + def handle_data(self, data): + if self.capture: + self.data.append(data) + + +# define object/class for analysis +class textforart: + + def __init__(self, language = 'en', sentences_lens = [], sentences = [], commas = [], polarity = []): + # Sprache + self.language = language + + # Satz + self.senctences = sentences + + # Sentence lengthes + self.sentences_lens = sentence_lens + + # Commas + self.commas = commas + + # Bewertung + self.polarity = polarity + + # Komplezitรคt + self.complexity = '' + + + # Satzlรคnge + self.sentence_number = len(sentences) + self.min_sentence_length = min(sentences_lens) + self.max_sentence_length = max(sentences_lens) + self.mean_sentence_length = sum(sentences_lens) / len(sentences) + + # Kommas + self.number_commas = len(commas) + self.min_number_commas = min(commas) + self.max_number_commas = max(commas) + self.mean_number_commas = len(commas)/ len(sentences) + + # Bewertung + self.sum_sentences_polarity = sum(polarity) + self.min_sentences_polarity = min(polarity) + self.max_sentences_polarity = max(polarity) + self.mean_sentences_polarity = sum(polarity) / len(sentences) + + # Schรคtzer fรผr Komplexitรคt + self.max_complexity = 0 + self.min_complexity = 0 + self.mean_complexity = 0 + + # signatur Word -> mean purpose + self.signatur_word = '' + + +class DockerLinkGrepper(DockWidget): + + + # svg + def design_svg(strokecolor, fillcolor, width, height): + trans = str(((800 - height)/2) - 80) + print (trans) + #print(f'''stroke="{strokecolor}" fill="{fillcolor}"''') + svg = f''' + + + + + + + + + + '''.encode('utf-8') + return(svg) + + coffee = '''\ + + + + ๐•ถ๐–—๐–Ž๐–™๐–† ๐–“๐–Š๐–Š๐–‰๐–˜ ๐–’๐–”๐–”๐–—๐–Š ๐•ฎ๐–”๐–‹๐–‹๐–Š๐–Š! + '''.encode('utf-8') + + + recording = 0 + + + + def newButtonIsClicked(self): + text = 'Welcome fellow human beeing ^.^' + print(text) + #content = line.text() + + # aktivate Checkbox if input is done + #if line.text(): + # newCheckbox.setCheckState(2) + #parser = MyHTMLParser() + #link = urllib.request.urlopen(content).read().decode() + #html = parser.feed(link) + #global linkdata + # get data, remove newline + #linkdata = parser.data + #print(linkdata) + #newDialog.close() + #else: + #newCheckbox.setCheckState(0) + #print('Please insert a valid Link! Thank you..') + #return + + def add_svg(svg): + clipboard = QGuiApplication.clipboard() + mime_data = QMimeData() + mime_data.setData('image/svg+xml', svg) + clipboard.setMimeData(mime_data) + Application.action('edit_paste').trigger() + + def create_svg(svg): + app = Krita.instance() + # Document open? + #if app.activeDocument(): + #print("aktive document") + #doc = app.activeDocument() + #else: + #print("create document") + #doc = app.createDocument(800, 600, 'SVGA Test', 'RGBA', 'U8', '', 120.0) + #app.activeWindow().addView(doc) + + doc = app.createDocument(800, 600, 'SVGA Test', 'RGBA', 'U8', '', 120.0) + app.activeWindow().addView(doc) + layer = doc.createVectorLayer('ColorSVG') + layer.setName('ColorSVG') + add_svg(svg) + + + # add button and layout for button + layoutForButtons = QHBoxLayout() + newButton = QPushButton("load text") + layoutForButtons.addWidget(newButton) + #layoutForButtons.addSpacing(200) + + # label + nameLabel = QLabel() + nameLabel.setText('Please input a link:') + layoutForButtons.addWidget(nameLabel) + + #input field + line = QLineEdit() + line.setPlaceholderText("URL") + line.setMinimumWidth(300) + line.setFont(QFont("console",8)) # change font + layoutForButtons.addWidget(line) + + + # write some actions + clicked = 'Button clicked' + newButton.clicked.connect(newButtonIsClicked) + + + #add a checkbox + newCheckbox = QCheckBox() + newCheckbox.setText('realise input') + link = layoutForButtons.addWidget(newCheckbox) + + # create dialog and show it + newDialog = QDialog() + newDialog.setLayout(layoutForButtons) + newDialog.setWindowTitle("Loader") + newDialog.exec_() # show the dialog + + # language + language = '' + + # filtering parsed text + text = "" + for phrases in linkdata: + #print (phrases) + #print('pre: ' + phrases) + phrases = phrases.rstrip("\n\r+0-9[]()+") + #print('after: ' + phrases) + # skip unwanted characters + text = text + phrases + #print('get: ' + phrases) + + #print(text) + # create textblob + blob = TextBlob(text) + #print(blob.tags) + + for w in blob.words: + if re.match(r"and", w): + language = 'en' + elif re.match(r"und", w): + language = 'de' + + #print(language) + if language == 'de': + blob = TextBlobDE(text) + + sentence_lens = [] + commas = [] + polarity = [] + + # print polarity of sentences + for sentence in blob.sentences: + + # length of sentences + sentence_lens.append(len(sentence)) + + # number of commas + commas.append(len(re.findall(',', str(sentence)))) + + # polarity + polarity.append(sentence.sentiment.polarity) + + # init new textforart object + art = textforart(language, sentence_lens, blob.sentences, commas, polarity) + + # make art out of object + + # width: 0 - 700 + # height: 0 - 700 + # fill color:#000000 # stroke color:#000000 + stroke = "rgb(" + str(round(125*(1/art.mean_number_commas))) + ", " + str(round(125 - art.min_sentences_polarity)) + ", " + str(round(125 - art.max_sentences_polarity)) + ")" + fill = "rgb(" + str(round(125*(1/art.mean_number_commas))) + ", " + str(round(125 - art.min_sentences_polarity)) + ", " + str(round(125 - art.max_sentences_polarity)) + ")" + #ImageColor.getcolor("#23a9dd", "RGB") + + #stroke = "rgb(255, 255, 255)" + #stroke = "rgb(255, 254, 94.)" + #fill = "rgb(255, 255, 255)" + + # define with of svg + heigh = 700- (10000*art.mean_sentences_polarity) + width = 700*art.mean_number_commas + + svg = design_svg(stroke, fill, 700, 700) + create_svg(svg) + + def canvasChanged(self, canvas): + pass + diff --git a/wordart/wordartManual.html b/wordart/wordartManual.html new file mode 100644 index 0000000..c42a23b --- /dev/null +++ b/wordart/wordartManual.html @@ -0,0 +1,12 @@ + + + + +Word Art + + +

Word Art

+

This is a python plugin for in Krita to automatically draw SVGs.

+

The source code can be found at