From 512af67ff872ddcd2dc495a8c645aca4279bc6dc Mon Sep 17 00:00:00 2001 From: Ananke Date: Mon, 18 Jul 2022 20:12:50 +0200 Subject: [PATCH] Add files via upload Creation of SVGs from DockWidget ist working now. Adding aditional SVGs for more diversity. --- wordart/classes.py | 64 +++++++++++ wordart/svg_vorlagen.py | 244 +++++++++++++++++++++++++++++++++++++++- wordart/wordart.py | 135 ++++++++-------------- 3 files changed, 354 insertions(+), 89 deletions(-) diff --git a/wordart/classes.py b/wordart/classes.py index 70dafe3..4d43c75 100644 --- a/wordart/classes.py +++ b/wordart/classes.py @@ -1,6 +1,11 @@ from krita import * +from textblob import TextBlob +from textblob_de import TextBlobDE +import re from html.parser import HTMLParser import urllib.request +from wordart.svg_vorlagen import * + # define class HTML-Parser class MyHTMLParser(HTMLParser): @@ -22,6 +27,7 @@ class MyHTMLParser(HTMLParser): if self.capture: self.data.append(data) + # define object/class for analysis class textforart: @@ -104,3 +110,61 @@ def create_svg(svg): layer = doc.createVectorLayer('ColorSVG') layer.setName('ColorSVG') add_svg(svg) + + +def makeart(content, parser): + + parser.feed(urllib.request.urlopen(content).read().decode()) + linkdata = parser.data + + if linkdata is not None: + # language + language = '' + + # filtering parsed text + text = "" + for phrases in linkdata: + phrases = phrases.rstrip("\n\r+0-9[]()+") + # skip unwanted characters + text = text + phrases + + # create textblob + blob = TextBlob(text) + + # language? + for w in blob.words: + if re.match(r"and", w): + language = 'en' + elif re.match(r"und", w): + language = 'de' + + 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 + # 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)) + ")" + + # define with of svg + heigh = 700- (10*art.mean_sentences_polarity) + width = 700*art.mean_number_commas + + svg = design_svg(stroke, fill, heigh, width) + create_svg(svg) diff --git a/wordart/svg_vorlagen.py b/wordart/svg_vorlagen.py index ddcc076..96f4f37 100644 --- a/wordart/svg_vorlagen.py +++ b/wordart/svg_vorlagen.py @@ -9,7 +9,7 @@ import re from krita import * import sip -# svg +# svg sight def design_svg(strokecolor, fillcolor, width, height): trans = str(((800 - height)/2) - 80) #print (trans) @@ -17,9 +17,8 @@ def design_svg(strokecolor, fillcolor, width, height): svg = f''' - + width="{width}" height="{height}" viewBox="0 0 302.623 302.623" stroke="{strokecolor}" fill="{fillcolor}" style="enable-background:new 0 0 302.623 302.623;" + xml:space="preserve"> + + + + + + + + + '''.encode('utf-8') + return(svg) + + +# svg smell +def design_svg3(strokecolor, fillcolor, width, height): + trans = str(((800 - height)/2) - 80) + svg = f''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + '''.encode('utf-8') + return(svg) + + +# svg touch +def design_svg4(strokecolor, fillcolor, width, height): + trans = str(((800 - height)/2) - 80) + svg = f''' + + + + + + '''.encode('utf-8') + return(svg) + +# svg taste +def design_svg5(strokecolor, fillcolor, width, height): + trans = str(((800 - height)/2) - 80) + svg = f''' + + + + + + '''.encode('utf-8') + return(svg) + diff --git a/wordart/wordart.py b/wordart/wordart.py index 2081b0a..0ee00b0 100644 --- a/wordart/wordart.py +++ b/wordart/wordart.py @@ -3,17 +3,35 @@ import sys import re from krita import * -from textblob import TextBlob -from textblob_de import TextBlobDE - from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import * +from html.parser import HTMLParser +import urllib.request +from wordart.classes import * +from wordart.svg_vorlagen import * -from .classes import * -from .svg_vorlagen 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) + class DockerLinkGrepper(DockWidget): global link @@ -48,9 +66,7 @@ class DockerLinkGrepper(DockWidget): # write some actions - clicked = 'Button clicked' - parser = MyHTMLParser() - content = line.text() + clicked = 'Button clicked' #add a checkbox newCheckbox = QCheckBox() @@ -58,82 +74,31 @@ class DockerLinkGrepper(DockWidget): layoutForButtons.addWidget(newCheckbox) mainWidget.setLayout(layoutForButtons) mainWidget.layout().addWidget(newButton) - - newButton.clicked.connect(lambda: newCheckbox.setCheckState(2)) - newCheckbox.clicked.connect(lambda: parser.feed(urllib.request.urlopen(content).read().decode())) - #parser.feed(urllib.request.urlopen(content).read().decode()) - #link = urllib.request.urlopen(content).read().decode() - linkdata = parser.data - - # 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(self, 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) - + + #newButton.clicked.connect(lambda: newCheckbox.setCheckState(2)) + newButton.clicked.connect(lambda: newButtonIsClicked()) + #newButton.clicked.connect(lambda: makeart(content, parser)) + + #newCheckbox.clicked.connect(lambda: parser.feed(urllib.request.urlopen(content).read().decode())) + #newButton.clicked.connect(self.newButtonIsClicked(content)) + + #global parser + #parser = MyHTMLParser() + #if line.text(): + #makeart(line.text(), parser) + #newCheckbox.clicked.connect(makeart(content, parser)) + + def newButtonIsClicked(): + # text = 'Welcome fellow human beeing ^.^ + # aktivate Checkbox if input is done + newCheckbox.setCheckState(2) + if line.text(): + parser = MyHTMLParser() + makeart(line.text(), parser) + + else: + newCheckbox.setCheckState(1) + def canvasChanged(self, canvas): - pass - + pass