Add files via upload

From Dialog to DockWidget. Adding nicer placement of input fields
This commit is contained in:
Ananke 2022-07-12 19:56:02 +02:00 committed by GitHub
parent 92f9c5d938
commit 1f4c0672a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -86,6 +86,10 @@ class textforart:
class DockerLinkGrepper(DockWidget): class DockerLinkGrepper(DockWidget):
global link
global html
global linkdata
global content
# svg # svg
@ -113,39 +117,6 @@ class DockerLinkGrepper(DockWidget):
</svg>'''.encode('utf-8') </svg>'''.encode('utf-8')
return(svg) return(svg)
coffee = '''\
<svg xmlns="http://www.w3.org/2000/svg" width="800px" height="600px" viewBox="0 0 24 24" fill="#000000">
<path d="M0 0h24v24H0V0z" fill="none"/>
<path d="M4 19h16v2H4zM20 3H4v10c0 2.21 1.79 4 4 4h6c2.21 0 4-1.79 4-4v-3h2c1.11 0 2-.9 2-2V5c0-1.11-.89-2-2-2zm-4 10c0 1.1-.9 2-2 2H8c-1.1 0-2-.9-2-2V5h10v8zm4-5h-2V5h2v3z"/>
<text x="0.2" y="22.5" font-size="0.1em">𝕶𝖗𝖎𝖙𝖆 𝖓𝖊𝖊𝖉𝖘 𝖒𝖔𝖔𝖗𝖊 𝕮𝖔𝖋𝖋𝖊𝖊!</text>
</svg>'''.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): def add_svg(svg):
clipboard = QGuiApplication.clipboard() clipboard = QGuiApplication.clipboard()
mime_data = QMimeData() mime_data = QMimeData()
@ -171,108 +142,117 @@ class DockerLinkGrepper(DockWidget):
add_svg(svg) add_svg(svg)
# add button and layout for button def __init__(self):
layoutForButtons = QHBoxLayout() super().__init__()
newButton = QPushButton("load text") self.setWindowTitle("Url to Art")
layoutForButtons.addWidget(newButton) mainWidget = QWidget(self)
#layoutForButtons.addSpacing(200) self.setWidget(mainWidget)
# label # add button and layout for button
nameLabel = QLabel() layoutForButtons = QHBoxLayout()
nameLabel.setText('Please input a link:') newButton = QPushButton("load text", mainWidget)
layoutForButtons.addWidget(nameLabel) newButton.move(100, 700)
layoutForButtons.addWidget(newButton)
#input field # label
line = QLineEdit() nameLabel = QLabel()
line.setPlaceholderText("URL") nameLabel.setText('Please input a link:')
line.setMinimumWidth(300)
line.setFont(QFont("console",8)) # change font #layoutForButtons.addWidget(nameLabel)
layoutForButtons.addWidget(line)
#input field
line = QLineEdit()
line.setPlaceholderText("URL")
line.setMinimumWidth(300)
line.setFont(QFont("console",8)) # change font
layoutForButtons.addWidget(line)
# write some actions # write some actions
clicked = 'Button clicked' clicked = 'Button clicked'
newButton.clicked.connect(newButtonIsClicked) parser = MyHTMLParser()
content = line.text()
#add a checkbox
newCheckbox = QCheckBox()
newCheckbox.setText('realise input')
layoutForButtons.addWidget(newCheckbox)
mainWidget.setLayout(layoutForButtons)
mainWidget.layout().addWidget(newButton)
#add a checkbox newButton.clicked.connect(lambda: newCheckbox.setCheckState(2))
newCheckbox = QCheckBox() newCheckbox.clicked.connect(lambda: parser.feed(urllib.request.urlopen(content).read().decode()))
newCheckbox.setText('realise input') #parser.feed(urllib.request.urlopen(content).read().decode())
link = layoutForButtons.addWidget(newCheckbox) #link = urllib.request.urlopen(content).read().decode()
linkdata = parser.data
# create dialog and show it # language
newDialog = QDialog() language = ''
newDialog.setLayout(layoutForButtons)
newDialog.setWindowTitle("Loader")
newDialog.exec_() # show the dialog
# language # filtering parsed text
language = '' 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)
# filtering parsed text #print(text)
text = "" # create textblob
for phrases in linkdata: blob = TextBlob(text)
#print (phrases) #print(blob.tags)
#print('pre: ' + phrases)
phrases = phrases.rstrip("\n\r+0-9[]()+")
#print('after: ' + phrases)
# skip unwanted characters
text = text + phrases
#print('get: ' + phrases)
#print(text) for w in blob.words:
# create textblob if re.match(r"and", w):
blob = TextBlob(text) language = 'en'
#print(blob.tags) elif re.match(r"und", w):
language = 'de'
for w in blob.words: #print(language)
if re.match(r"and", w): if language == 'de':
language = 'en' blob = TextBlobDE(text)
elif re.match(r"und", w):
language = 'de'
#print(language) sentence_lens = []
if language == 'de': commas = []
blob = TextBlobDE(text) polarity = []
sentence_lens = [] # print polarity of sentences
commas = [] for sentence in blob.sentences:
polarity = []
# print polarity of sentences # length of sentences
for sentence in blob.sentences: sentence_lens.append(len(sentence))
# length of sentences # number of commas
sentence_lens.append(len(sentence)) commas.append(len(re.findall(',', str(sentence))))
# number of commas # polarity
commas.append(len(re.findall(',', str(sentence)))) polarity.append(sentence.sentiment.polarity)
# polarity # init new textforart object
polarity.append(sentence.sentiment.polarity) art = textforart(language, sentence_lens, blob.sentences, commas, polarity)
# init new textforart object # make art out of 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")
# width: 0 - 700 #stroke = "rgb(255, 255, 255)"
# height: 0 - 700 #stroke = "rgb(255, 254, 94.)"
# fill color:#000000 # stroke color:#000000 #fill = "rgb(255, 255, 255)"
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)" # define with of svg
#stroke = "rgb(255, 254, 94.)" heigh = 700- (10000*art.mean_sentences_polarity)
#fill = "rgb(255, 255, 255)" width = 700*art.mean_number_commas
# define with of svg svg = design_svg(stroke, fill, 700, 700)
heigh = 700- (10000*art.mean_sentences_polarity) create_svg(svg)
width = 700*art.mean_number_commas
svg = design_svg(stroke, fill, 700, 700)
create_svg(svg)
def canvasChanged(self, canvas): def canvasChanged(self, canvas):
pass pass