@@ -115,7 +115,6 @@ def __init__(self, path=None, is_desktop_window=False):
115
115
self .timer .start (5000 )
116
116
self .update_status_bar ()
117
117
118
-
119
118
# Watch for changes in the directory
120
119
self .file_watcher = QFileSystemWatcher ()
121
120
self .file_watcher .directoryChanged .connect (self .directory_changed )
@@ -254,8 +253,6 @@ def init_menu_bar(self):
254
253
up_and_close_current_action .setShortcut ("Shift+Ctrl+Up" )
255
254
up_and_close_current_action .triggered .connect (self .open_parent_and_close_current )
256
255
if not os .path .exists (parent ) or os .path .normpath (self .path ) == os .path .normpath (QDir .rootPath ()):
257
- # or (os.path.normpath(os.path.dirname(self.path)) == os.path.normpath(QDir.homePath()) and os.path.basename(self.path) == "Desktop") \
258
- # or (os.path.normpath(os.path.dirname(os.path.dirname(self.path))) == os.path.normpath(QDir.homePath()) and os.path.basename(os.path.dirname(self.path)) == "Desktop"):
259
256
up_action .setDisabled (True )
260
257
up_and_close_current_action .setDisabled (True )
261
258
if self .is_desktop_window == True :
@@ -272,7 +269,7 @@ def init_menu_bar(self):
272
269
go_menu .addAction (start_menu_action )
273
270
# View Menu
274
271
view_menu = self .menu_bar .addMenu ("View" )
275
- if os .path .normpath (os . path . dirname ( self .path )) == os . path . normpath ( QDir . homePath ()) and os . path . basename ( self . path ) == "Desktop" :
272
+ if os .path .normpath (self .path ) == get_desktop_directory () :
276
273
align_items_desktop_action = QAction ("Align Items" , self )
277
274
align_items_desktop_action .triggered .connect (self .align_items_desktop )
278
275
view_menu .addAction (align_items_desktop_action )
@@ -293,9 +290,13 @@ def init_menu_bar(self):
293
290
294
291
# Help Menu
295
292
help_menu = self .menu_bar .addMenu ("Help" )
293
+
296
294
about_action = QAction ("About" , self )
297
295
about_action .triggered .connect (self .show_about )
298
296
help_menu .addAction (about_action )
297
+ help_menu .addSeparator
298
+ if "log_console" in sys .modules :
299
+ app .log_console .add_menu_items (help_menu , self )
299
300
300
301
def open_parent (self ):
301
302
# TODO: Detect whether the Shift key is pressed; if yes; if yes, close the current window if it is not the fullscreen desktop window
@@ -329,7 +330,7 @@ def adjust_window_size(self):
329
330
self .resize (max_x , max_y )
330
331
331
332
def populate_items (self ):
332
- if os .path .normpath (os . path . dirname ( self .path )) == os . path . normpath ( QDir . homePath ()) and os . path . basename ( self . path ) == "Desktop" :
333
+ if os .path .normpath (self .path ) == get_desktop_directory () :
333
334
334
335
# Add every disk in the system
335
336
print ("Adding disks" )
@@ -359,7 +360,7 @@ def populate_items(self):
359
360
if entry == app .desktop_settings_file :
360
361
continue
361
362
# ~/Desktop is a special case; we don't want to show it
362
- if self .path == QDir . homePath ( ) and entry == "Desktop" :
363
+ if self .path == os . path . basename ( get_desktop_directory () ) and entry == "Desktop" :
363
364
continue
364
365
entry_path = os .path .join (self .path , entry )
365
366
is_directory = os .path .isdir (entry_path )
@@ -608,6 +609,8 @@ def dropEvent(self, event):
608
609
event .ignore ()
609
610
610
611
def align_items (self ):
612
+ if not self .items :
613
+ return
611
614
num_columns = self .width () // self .item_width_for_positioning
612
615
current_column = 0
613
616
current_row = 0
@@ -641,6 +644,8 @@ def align_items(self):
641
644
self .update_container_size ()
642
645
643
646
def align_items_staggered (self ):
647
+ if not self .items :
648
+ return
644
649
num_columns = self .width () // self .item_width_for_positioning
645
650
line_height = int (self .line_height - 0.5 * app .icon_size )
646
651
current_column = 0
@@ -686,6 +691,8 @@ def align_items_staggered(self):
686
691
self .update_container_size ()
687
692
688
693
def align_items_desktop (self ):
694
+ if not self .items :
695
+ return
689
696
num_rows = (self .height () // self .line_height ) - 1
690
697
current_column = 0
691
698
current_row = 0
@@ -719,6 +726,8 @@ def align_items_desktop(self):
719
726
current_column += 1
720
727
721
728
def align_items_circle (self ):
729
+ if not self .items :
730
+ return
722
731
radius = self .width () // 2 - self .horizontal_spacing - self .item_width_for_positioning // 2
723
732
724
733
# Calculate the center of the circle
@@ -767,7 +776,8 @@ def __init__(self, path, is_directory, position, parent=None):
767
776
self .position = position
768
777
769
778
icon_provider = QFileIconProvider ()
770
- if self .path == os .path .normpath (os .path .join (QDir .homePath (), "Desktop" , app .trash_name )):
779
+ # Trash
780
+ if self .path == os .path .normpath (get_desktop_directory () + "/" + app .trash_name ):
771
781
icon = icon_provider .icon (QFileIconProvider .IconType .Trashcan ).pixmap (app .icon_size , app .icon_size )
772
782
else :
773
783
icon = icon_provider .icon (QFileInfo (self .path )).pixmap (app .icon_size , app .icon_size )
@@ -947,6 +957,17 @@ def open(self, event):
947
957
else :
948
958
os .system (f"xdg-open \" { self .path } \" " )
949
959
960
+ def get_desktop_directory ():
961
+ """Get the desktop directory of the user."""
962
+ if sys .platform == "win32" :
963
+ from win32com .client import Dispatch
964
+ shell = Dispatch ("WScript.Shell" )
965
+ desktop = os .path .normpath (shell .SpecialFolders ("Desktop" ))
966
+ else :
967
+ desktop = QDir .homePath () + "/Desktop"
968
+ return os .path .normpath (desktop )
969
+
970
+
950
971
if __name__ == "__main__" :
951
972
app = QApplication (sys .argv )
952
973
if sys .platform == "win32" :
@@ -955,10 +976,22 @@ def open(self, event):
955
976
app .desktop_settings_file = ".DS_Spatial"
956
977
app .trash_name = "Trash"
957
978
app .icon_size = 32
958
-
979
+
980
+ # Output not only to the console but also to the GUI
981
+ try :
982
+ import log_console
983
+ except ImportError :
984
+ pass
985
+ if "log_console" in sys .modules :
986
+ app .log_console = log_console .ConsoleOutputStream ()
987
+ sys .stdout = log_console .Tee (sys .stdout , app .log_console )
988
+ sys .stderr = log_console .Tee (sys .stderr , app .log_console )
989
+
990
+
991
+
959
992
for screen in QApplication .screens ():
960
993
# TODO: Possibly only create the desktop window on the primary screen and just show a background image on the other screens
961
- desktop = SpatialFiler (os . path . normpath ( QDir . homePath () + "/Desktop" ), is_desktop_window = True )
994
+ desktop = SpatialFiler (get_desktop_directory ( ), is_desktop_window = True )
962
995
desktop .move (screen .geometry ().x (), screen .geometry ().y ())
963
996
desktop .resize (screen .geometry ().width (), screen .geometry ().height ())
964
997
desktop .setWindowFlags (Qt .WindowType .FramelessWindowHint )
@@ -978,7 +1011,6 @@ def open(self, event):
978
1011
windows_wallpaper_path = os .path .normpath (shell .RegRead ("HKEY_CURRENT_USER\\ Control Panel\\ Desktop\\ Wallpaper" )).replace ("\\ " , "/" )
979
1012
print ("Windows wallpaper path:" , windows_wallpaper_path )
980
1013
if windows_wallpaper_path != "." and os .path .exists (windows_wallpaper_path ):
981
- # Set the background image of the window
982
1014
p = desktop .container .palette ()
983
1015
p .setBrush (desktop .container .backgroundRole (), QBrush (QPixmap (windows_wallpaper_path ).scaled (desktop .width (), desktop .height (), Qt .AspectRatioMode .KeepAspectRatioByExpanding )))
984
1016
desktop .container .setPalette (p )
0 commit comments