-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
187 lines (143 loc) · 5.34 KB
/
GUI.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
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
import bdd as BDD
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QSystemTrayIcon, QMenu, QAction, QLineEdit, QLabel, QTableWidget, QGridLayout, QTableWidgetItem
from PyQt5.QtGui import QIcon
import signal
from controller import *
signal.signal(signal.SIGINT, signal.SIG_DFL)
class WinNewEntry(QWidget):
def __init__(self, controller):
super().__init__()
self.initUI()
self.controller = controller
def initUI(self):
self.setGeometry(200,200,500,200)
self.setWindowTitle('Tag Indexer: Add an entry')
lblURL = QLabel('URL:', self)
lblTags = QLabel('Tags:', self)
lblTags.setToolTip('À séparer par des virgules')
self.champURL = QLineEdit(self)
self.champURL.returnPressed.connect(self.save)
self.champTags = QLineEdit(self)
self.champTags.returnPressed.connect(self.save)
btnEnr = QPushButton('Enregistrer',self)
btnEnr.clicked.connect(self.save)
btnAnnul = QPushButton('Annuler',self)
btnAnnul.clicked.connect(self.hide)
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(lblURL, 0,0)
grid.addWidget(self.champURL, 0, 3, 1, 6)
grid.addWidget(lblTags, 4, 0)
grid.addWidget(self.champTags, 4, 3, 1, 6)
grid.addWidget(btnAnnul, 9, 7)
grid.addWidget(btnEnr, 9, 8)
self.setLayout(grid)
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.hide()
def closeEvent(self, e):
self.hide()
e.ignore()
def save(self):
tags = self.champTags.text().split(",")
tags = [i for i in map(lambda s: s.rstrip(" \t").lstrip(" \t"), tags)]
e = NewDataEvent(self.champURL.text(), tags)
self.champURL.setText('')
self.champTags.setText('')
self.hide()
self.controller.notify(e)
def cancel(self):
self.champURL.setText('')
self.champTags.setText('')
self.hide()
class WinList(QWidget):
def __init__(self, controller):
super().__init__()
self.controller = controller
self.controller.addObserver(self)
self.initUI()
def initUI(self):
self.setGeometry(200,200,600,280)
self.setWindowTitle('Tag Indexer: List')
self.tab = QTableWidget(self)
self.tab.showGrid = False
self.tab.horizontalHeader().setSectionResizeMode(1)
self.tab.setColumnCount(3)
self.tab.cellChanged.connect(self.getMod)
lblRecherche = QLabel('Recherche: ', self)
btnRecherche = QPushButton('Rechercher', self)
btnRecherche.clicked.connect(self.rechercher)
self.recherche = QLineEdit()
self.recherche.returnPressed.connect(self.rechercher)
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(lblRecherche, 0,0)
grid.addWidget(btnRecherche, 0, 8)
grid.addWidget(self.recherche, 0, 1, 1, 7)
grid.addWidget(self.tab,4,0, 6,9)
self.tab.setHorizontalHeaderLabels(('URL','Tags','Date d\'ajout'))
self.setLayout(grid)
self.controller.notify(GetAllEvent())
def addLine(self, url, tags, date):
l = self.tab.rowCount()
self.tab.setRowCount(l+1)
self.tab.setItem(l, 0, QTableWidgetItem(url))
self.tab.setItem(l, 1, QTableWidgetItem(tags))
self.tab.setItem(l, 2, QTableWidgetItem(date))
def vider(self):
self.tab.setRowCount(0)
def rechercher(self):
self.vider()
s = self.recherche.text()
if s == "":
e = GetAllEvent()
else:
e = SearchEvent(s)
self.controller.notify(e)
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.hide()
def closeEvent(self, e):
self.hide()
e.ignore()
def notify(self, e):
if type(e) is UpdateListEvent:
if e.add:
self.addLine(e.data, ', '.join(e.tags), e.date)
def getMod(self):
if(self.tab.currentRow(), self.tab.currentColumn()) != (-1, -1):
print(self.tab.currentRow(),self.tab.currentColumn(),self.tab.currentItem().text())
class Icon(QWidget):
def __init__(self, app, newEntry, listWin):
super().__init__()
self.newEntry = newEntry
self.listWin = listWin
self.app = app
self.initUI()
def initUI(self):
menu = QMenu()
Ajouter = QAction(QIcon(''), '&Ajouter un tag', menu)
Ajouter.triggered.connect(self.newEntry.show)
menu.addAction(Ajouter)
ouvrir = QAction(QIcon(''), '&Ouvrir', menu)
ouvrir.triggered.connect(self.listWin.show)
menu.addAction(ouvrir)
Quitter = QAction(QIcon(''), '&Quitter', menu)
Quitter.triggered.connect(self.app.exit)
menu.addAction(Quitter)
self.icon = QSystemTrayIcon()
self.icon.setIcon(QIcon('./icone.png'))
self.icon.setContextMenu(menu)
self.icon.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ListWindow = WinList()
NewEntryWindow = WinNewEntry()
#NewEntryWindow.show()
#ListWindow.show()
icon = Icon()
sys.exit(app.exec_())