Skip to content

Commit f7d3ea8

Browse files
committed
Add Desktop in shortcuts
1 parent e654ee6 commit f7d3ea8

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Changelog
117117

118118
- tkfilebrowser 2.2.3
119119
* Fix FileNotFoundError if initialdir does not exist
120+
* Add Desktop in shortcuts (if found)
120121

121122
- tkfilebrowser 2.2.2
122123
* Fix ValueError in after_cancel with Python 3.6.5

changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Changelog
88

99
- tkfilebrowser 2.2.3
1010
* Fix FileNotFoundError if initialdir does not exist
11+
* Add Desktop in shortcuts (if found)
1112

1213
- tkfilebrowser 2.2.2
1314
* Fix ValueError in after_cancel with Python 3.6.5

tkfilebrowser/filebrowser.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
"""
2222
# TODO: fix filetype display for extensions like .tar.xz
2323
# TODO: improve extension change
24-
# TODO: show desktop in shortcuts
24+
2525

2626
import psutil
27+
from subprocess import check_output
2728
from os import walk, mkdir, stat, access, W_OK
2829
from os.path import exists, join, getmtime, realpath, split, expanduser, \
2930
abspath, isabs, splitext, dirname, getsize, isdir, isfile, islink
@@ -280,10 +281,12 @@ def __init__(self, parent, initialdir="", initialfile="", mode="openfile",
280281
self.left_tree.configure(yscrollcommand=scroll_left.set)
281282

282283
# --- list devices and bookmarked locations
284+
# recent
283285
self.left_tree.insert("", "end", iid="recent", text=_("Recent"),
284286
image=self.im_recent)
285287
wrapper.add_tooltip("recent", _("Recently used"))
286288

289+
# devices
287290
devices = psutil.disk_partitions()
288291

289292
for d in devices:
@@ -295,10 +298,25 @@ def __init__(self, parent, initialdir="", initialfile="", mode="openfile",
295298
self.left_tree.insert("", "end", iid=m, text=txt,
296299
image=self.im_drive)
297300
wrapper.add_tooltip(m, m)
301+
302+
# home
298303
home = expanduser("~")
299304
self.left_tree.insert("", "end", iid=home, image=self.im_home,
300305
text=split(home)[-1])
301306
wrapper.add_tooltip(home, home)
307+
308+
# desktop
309+
try:
310+
desktop = check_output(['xdg-users-dir', 'DESKTOP']).decode().strip()
311+
except FileNotFoundError:
312+
# xdg-users-dir' not installed
313+
desktop = join(home, 'Desktop')
314+
if exists(desktop):
315+
self.left_tree.insert("", "end", iid=desktop, image=self.im_folder,
316+
text=split(desktop)[-1])
317+
wrapper.add_tooltip(desktop, desktop)
318+
319+
# bookmarks
302320
path_bm = join(home, ".config", "gtk-3.0", "bookmarks")
303321
path_bm2 = join(home, ".gtk-bookmarks") # old location
304322
if exists(path_bm):

0 commit comments

Comments
 (0)