This repository has been archived by the owner on Dec 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfk-tiedotin.py
executable file
·174 lines (123 loc) · 5.98 KB
/
fk-tiedotin.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
from PyQt5 import QtCore, QtGui
from PyQt5.QtCore import QDateTime
from PyQt5.QtWidgets import (QApplication, QDialog, QGridLayout, QGroupBox,
QRadioButton, QHBoxLayout, QVBoxLayout, QStyleFactory, QLineEdit,
QTextEdit, QLabel, QPushButton, QTabWidget, QWidget, QButtonGroup,
QDateEdit, QCheckBox, QShortcut, QTextBrowser)
from database import saveEntry
import pyperclip
class MainWindow(QDialog):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.createCategorySelectionGroupBox()
self.createTextEditLayout()
self.createButtonLayout()
mainLayout = QGridLayout()
mainLayout.addLayout(self.categorySelectionLayout, 0, 0)
mainLayout.addLayout(self.textEditLayout, 1, 0)
mainLayout.addLayout(self.buttonLayout, 2, 0)
self.setLayout(mainLayout)
# some hotkey bindings
QShortcut(QtGui.QKeySequence( "Ctrl+H" ), self).activated.connect(self.copyContentToHeader)
QShortcut(QtGui.QKeySequence( "Ctrl+X" ), self).activated.connect(self.clear)
QShortcut(QtGui.QKeySequence( "Ctrl+B" ), self).activated.connect(self.copyContentToTextArea)
QShortcut(QtGui.QKeySequence( "Ctrl+S" ), self).activated.connect(self.save)
QShortcut(QtGui.QKeySequence( "Ctrl+Q" ), self).activated.connect(self.close)
#QShortcut(QtGui.QKeySequence( "Ctrl+M" ), self).activated.connect(self.hide)
QApplication.setStyle(QStyleFactory.create("cleanlooks"))
self.setWindowTitle("Fk-tiedotin")
def createCategorySelectionGroupBox(self):
self.languageCheckBox = QCheckBox("Text in English", self)
self.languageCheckBox.stateChanged.connect(self.languageCheckBoxClicked)
categorySelectionGroupBox = QGroupBox("Category")
self.categorySelectionButtonGroup = QButtonGroup()
self.radioButton1 = QRadioButton("Killan tapahtumat")
self.radioButton2 = QRadioButton("Muut tapahtumat")
self.radioButton3 = QRadioButton("Yleistä")
self.radioButton4 = QRadioButton("Opinnot")
self.radioButton1.setChecked(True)
self.categorySelectionButtonGroup.addButton(self.radioButton1)
self.categorySelectionButtonGroup.addButton(self.radioButton2)
self.categorySelectionButtonGroup.addButton(self.radioButton3)
self.categorySelectionButtonGroup.addButton(self.radioButton4)
buttonLayout = QVBoxLayout()
buttonLayout.addWidget(self.radioButton1)
buttonLayout.addWidget(self.radioButton2)
buttonLayout.addWidget(self.radioButton3)
buttonLayout.addWidget(self.radioButton4)
categorySelectionGroupBox.setLayout(buttonLayout)
self.dateEdit = QDateEdit()
self.dateEdit.setDateTime(QDateTime.currentDateTime())
self.dateEdit.setCalendarPopup(True)
dateLabel = QLabel("Date")
dateLabel.setBuddy(self.dateEdit)
self.categorySelectionLayout = QVBoxLayout()
self.categorySelectionLayout.addWidget(self.languageCheckBox)
self.categorySelectionLayout.addWidget(categorySelectionGroupBox)
self.categorySelectionLayout.addWidget(dateLabel)
self.categorySelectionLayout.addWidget(self.dateEdit)
def languageCheckBoxClicked(self,state):
if state == QtCore.Qt.Checked:
self.radioButton1.setText("Guild's events")
self.radioButton2.setText("Other events")
self.radioButton3.setText("General")
self.radioButton4.setText("Studies")
else:
self.radioButton1.setText("Killan tapahtumat")
self.radioButton2.setText("Muut tapahtumat")
self.radioButton3.setText("Yleistä")
self.radioButton4.setText("Opinnot")
def copyContentToHeader(self):
self.headerLineEdit.setText(pyperclip.paste())
def copyContentToTextArea(self):
self.contentTextEdit.setText(pyperclip.paste())
#def hide(self):
# self.headerLineEdit.hide()
# self.textBrowser = QTextBrowser()
# self.textBrowser.setGeometry(QtCore.QRect(390, 10, 531, 681))
# self.textBrowser.setObjectName("textBrowser")
# self.textBrowser.show()
def createTextEditLayout(self):
self.textEditLayout = QVBoxLayout()
self.headerLineEdit = QLineEdit()
self.contentTextEdit = QTextEdit()
headerLabel = QLabel("Header")
headerLabel.setBuddy(self.headerLineEdit)
contentLabel = QLabel("Content")
contentLabel.setBuddy(self.contentTextEdit)
self.textEditLayout.addWidget(headerLabel)
self.textEditLayout.addWidget(self.headerLineEdit)
self.textEditLayout.addWidget(contentLabel)
self.textEditLayout.addWidget(self.contentTextEdit)
def createButtonLayout(self):
self.buttonLayout = QHBoxLayout()
savePushButton = QPushButton("Save")
savePushButton.clicked.connect(self.save)
clearPushButton = QPushButton("Clear")
clearPushButton.clicked.connect(self.clear)
self.buttonLayout.addWidget(clearPushButton)
self.buttonLayout.addStretch(1)
self.buttonLayout.addWidget(savePushButton)
def save(self):
category = self.categorySelectionButtonGroup.checkedButton().text()
date = [self.dateEdit.date().day(), self.dateEdit.date().month(), self.dateEdit.date().year()]
header = self.headerLineEdit.text()
content = self.contentTextEdit.toPlainText()
saveEntry({
'category': category,
'date': date,
'header': header,
'content': content
}, self.languageCheckBox.isChecked())
self.clear()
def clear(self):
self.headerLineEdit.clear()
self.contentTextEdit.clear()
self.languageCheckBox.setCheckState(0)
self.dateEdit.setDateTime(QDateTime.currentDateTime())
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
tiedotin = MainWindow()
tiedotin.show()
sys.exit(app.exec_())