Skip to main content

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.

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:

	self.settings.setValue("recent_files", self._recent_files.items)

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

recent_items_list-1.0.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

recent_items_list-1.0.0-py2.py3-none-any.whl (13.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file recent_items_list-1.0.0.tar.gz.

File metadata

  • Download URL: recent_items_list-1.0.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for recent_items_list-1.0.0.tar.gz
Algorithm Hash digest
SHA256 30d46674aff0c50a7c59e448b8dfbef6460f2de8a1a2d92b41574dece484eed7
MD5 96e7479c10f81a32adb247b530afaead
BLAKE2b-256 0e0889bc557732cf273e82e58f293919650fcaaed34348d780cabce6985cf976

See more details on using hashes here.

File details

Details for the file recent_items_list-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for recent_items_list-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f17ded3317277805ca9e1855389d037d78b01e39bc542d3d039b1113ba3c5cd3
MD5 6e63ad78017ae384709767f1c2dd7811
BLAKE2b-256 cce324db611e7553a117a02815a04f06640ebe2f7cfaec0d6fa798a220cf6049

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page