This repository was archived by the owner on Sep 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRecentFilesManager.py
134 lines (101 loc) · 3.44 KB
/
RecentFilesManager.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
#!/usr/bin/python
# -*- coding: latin-1 -*-
# PyQtRibbon: a ribbon library for PyQt
# Copyright (C) 2014 RoadrunnerWMC
# This file is part of PyQtRibbon.
# PyQtRibbon is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# PyQtRibbon is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with PyQtRibbon. If not, see <http://www.gnu.org/licenses/>.
# RecentFilesManager.py
# Contains classes related to the recent files manager
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
Qt = QtCore.Qt
class QRecentFilesManager(QtCore.QObject):
"""
An object that keeps track of paths to recently-opened files
"""
_masterList = []
_maxLength = 10
pathAdded = QtCore.pyqtSignal(str)
def __init__(self, data=None):
"""
Initialize the QRecentFilesManager
"""
QtCore.QObject.__init__(self)
if data != None: self._initFromData(data)
def _initFromData(self, data):
"""
Populate self._masterList from the given string info
"""
data = str(data)
if data[:19] != 'QRecentFilesManager:': return
data = data[19:]
# Split it
newlist = data.split('|')
self._masterList = newlist
def _generateData(self):
"""
Generate string info and return it
"""
# Create a datastr
datastr = 'QRecentFilesManager:'
# Add entries
for entry in self._masterList:
datastr += entry + '|'
# Chop off the last '|'
datastr = datastr[:-1]
# Return it
return datastr
def addPath(self, path):
"""
Add a path to the path list.
Automatically remove duplicates.
"""
if path in (None, 'None', 'none', True, 'True', 'true', False, 'False', 'false', 0, 1, ''): return
path = path.replace('\\', '/')
# Remove it, if it's already there
if path in self._masterList: self._masterList.remove(path)
# Prepend it
new = []
new.append(path)
for other in self._masterList: new.append(other)
if len(new) > self._maxLength: new = new[:self._maxLength]
self._masterList = new
# Emit the pathAdded signal
self.pathAdded.emit(path)
def data(self):
"""
Return data that can later be used to run populateFromData
"""
return self._generateData()
def maxLength(self):
"""
Return the maximum number of paths that can be stored
"""
return self._maxLength
def paths(self):
"""
Return the full list of paths
"""
toReturn = []
for path in self._masterList:
toReturn.append(path)
return toReturn
def populateFromData(self, data):
"""
Populate the filepath list from the data given
"""
self._initFromData(data)
def setMaxLength(self, length):
"""
Set the maximum number of paths that can be stored
"""
self._maxLength = length