forked from Answeror/lit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecent.py
45 lines (35 loc) · 1.15 KB
/
recent.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from files import Files
from win32com.shell import shell, shellcon
import os
from fs.osfs import OSFS
class Recent(Files):
def __init__(self):
super(Recent, self).__init__()
self._paths = []
# http://python.6.n6.nabble.com/Access-Most-Recently-Used-MRU-entries-td1953541.html
self.mru_path = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_RECENT, 0)
self.mrufs = OSFS(self.mru_path)
self.watcher = None
def setup(self):
self._update_path()
self.watcher = self.mrufs.add_watcher(lambda e: self._update_path())
def _update_path(self):
self._paths = sorted(
[os.path.join(self.mru_path, f) for f in self.mrufs.listdir()],
key=os.path.getmtime,
reverse=True
)
self.path_list_changed()
def teardown(self):
if self.watcher:
self.mrufs.del_watcher(self.watcher)
@property
def paths(self):
return self._paths
@property
def name(self):
return 're'
def lit(self, *args, **kargs):
return super(Recent, self).lit(*args, **kargs)