-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminds_ui.py
executable file
·57 lines (45 loc) · 1.42 KB
/
minds_ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import\
QApplication,\
QWidget,\
QPlainTextEdit,\
QGridLayout,\
QShortcut
from PyQt5.QtGui import QKeySequence
from PyQt5.QtCore import pyqtSlot
from mindsapi import mindsapi
import sys
import subprocess
def run(cmd):
result = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
return result.stdout.readline().decode('utf8')
class App(QWidget):
def __init__(self):
super().__init__()
config = mindsapi.MindsAPI.get_config()
self.api = mindsapi.MindsAPI(
config['minds']['user'],
config['minds']['password'])
self.api.login()
self.title = 'Post to Minds'
self.setWindowTitle(self.title)
self.textbox = QPlainTextEdit(self)
self.shortcut = QShortcut(QKeySequence("Ctrl+Return"), self)
self.shortcut.activated.connect(self.on_click)
grid = QGridLayout()
grid.setSpacing(0)
grid.addWidget(self.textbox)
self.setLayout(grid)
self.setGeometry(100, 100, 300, 200)
self.show()
@pyqtSlot()
def on_click(self):
text = self.textbox.toPlainText()
text = text.replace("'", "’")
run("echo '" + text + "' | ./post_text2image.py")
self.textbox.setPlainText("")
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())