-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDocument.py
More file actions
82 lines (68 loc) · 2.7 KB
/
Document.py
File metadata and controls
82 lines (68 loc) · 2.7 KB
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
import fnmatch
import os
from PyQt5.QtGui import (QStandardItemModel, QStandardItem, QColor, QFont)
from PyQt5.QtWidgets import QListView
from Resources.ResourcePdf import ResourcePdf
class Document:
def __init__(self):
self.isOpen = 0
self.docLength = 0
self.docList = []
self.formats = ['*.pdf']
self.initUI()
def destroy(self):
self.list.close()
return -1
def initUI(self):
self.list = QListView()
self.list.setWindowTitle("Documents")
self.list.setMinimumSize(300, 400)
self.list.setSpacing(10)
self.model = QStandardItemModel(self.list)
self.resourcePdf = ResourcePdf()
for root, dirs, files in os.walk("Documents"):
for extensions in self.formats:
for filename in fnmatch.filter(files, extensions):
item = QStandardItem(filename)
item.setFont(QFont(filename, 10))
self.model.appendRow(item)
self.docList.append(item)
self.docLength = len(self.docList)
self.currentItem = 1
self.prevItem = self.docLength
if len(self.docList) != 0:
self.docList[0].setBackground(QColor(97, 138, 204))
self.list.setModel(self.model)
self.list.show()
def nextItem(self):
if len(self.docList) != 0:
if self.currentItem == self.docLength:
self.prevItem = self.docLength
self.currentItem = 1
else:
self.prevItem = self.currentItem
self.currentItem = self.currentItem + 1
self.docList[self.prevItem - 1].setBackground(QColor(35, 38, 41))
self.docList[self.currentItem - 1].setBackground(QColor(97, 138, 204))
# def previousItem(self):
# if len(self.docList) != 0:
# if self.currentItem == 1:
# self.prevItem = 1
# self.currentItem = self.docLength
# else:
# self.prevItem = self.currentItem
# self.currentItem = self.currentItem - 1
# self.docList[self.prevItem - 1].setBackground(QColor(35, 38, 41))
# self.docList[self.currentItem - 1].setBackground(QColor(97, 138, 204))
def Open(self):
if len(self.docList) != 0:
self.resourcePdf.Open(self.docList[self.currentItem - 1].text())
return True
else:
return False
def scrollDown(self):
self.resourcePdf.scrollDown()
def scrollUp(self):
self.resourcePdf.scrollUp()
def Close(self):
self.resourcePdf.Terminate()