RecentItemsList acts like a list, except that calling the "bump()" method on it
Project description
recent_items_list
RecentItemsList acts like a list, except that calling the "bump()" method on it bumps an item to the beginning of the list.
By default, only the last 10 items are kept in the list. If a new item is "bumped" to the beginning of a RecentItemsList that already has 10 items, the item at the end of the list is dropped. You can change this by setting the "maxlen" property on an instance of RecentItemsList.
When
Example:
In init:
self._recent_files = RecentItemsList(self.settings.value("recent_files", defaultValue = []))
self.menuOpen_Recent.aboutToShow.connect(self.fill_recent_files)
Filling a menu:
@pyqtSlot()
def fill_recent_files(self):
self.menuOpen_Recent.clear()
actions = []
for filename in self._recent_files:
action = QAction(filename, self)
action.triggered.connect(partial(self.load_file, filename))
actions.append(action)
self.menuOpen_Recent.addActions(actions)
When item is found:
self._recent_files.bump(filename)
When item is missing:
self._recent_files.remove(filename)
Save to QSettings:
self.settings.setValue("recent_files", self._recent_files.items)
Auto-save
Optionally, you provide a callback which will be called whenever the list changes:
self._recent_files = RecentItemsList(self.settings.value("recent_files", defaultValue = []))
self._recent_files.on_change(self.save_recent_files)
def save_recent_files(self, items):
self.settings.setValue("recent_files", items)
Another implementation:
def recent_files():
global RECENT_FILES
def sync(items):
settings().setValue(KEY_RECENT_FILES, items)
if RECENT_FILES is None:
RECENT_FILES = RecentItemsList(settings().value(KEY_RECENT_FILES, []))
RECENT_FILES.on_change(sync)
return RECENT_FILES
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file recent_items_list-1.1.0.tar.gz.
File metadata
- Download URL: recent_items_list-1.1.0.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57cdc671b850b19fa9975f126c796410a7d76eb91e8ca11bec6f0d67d87e1db8
|
|
| MD5 |
d36f983ae96e4a9acdad9642207e4118
|
|
| BLAKE2b-256 |
302d8fc326d1b3e5297e02f3e06f0f29769a6922955a09e08237641224be141d
|
File details
Details for the file recent_items_list-1.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: recent_items_list-1.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5336bd88eb1afbe3b8bb13efbf080e6195a1dba99eb740136893e017b82f8cec
|
|
| MD5 |
67431c3624bb0db45b9ac2ba6d5ed737
|
|
| BLAKE2b-256 |
227e14457a50cb275a51713ac216539020770abceb99e381bae9e41bd9659fb6
|