tenseleyflow/wulftp / f1d2c88

Browse files

resolve focus issues stable

Authored by espadonne
SHA
f1d2c88aaca97787e9e5a2a3f69f6b3df97206bb
Parents
7f3ab12
Tree
f7d0649

2 changed files

StatusFile+-
M src/wulftp/ui/components.py 35 9
M src/wulftp/ui/main_window.py 6 7
src/wulftp/ui/components.pymodified
@@ -9,7 +9,7 @@ from PyQt6.QtWidgets import (
99
     QWidget, QToolBar, QLabel, QComboBox, QLineEdit,
1010
     QPushButton, QHBoxLayout, QVBoxLayout, QTreeView,
1111
     QHeaderView, QSizePolicy, QAbstractItemView,
12
-    QMenu
12
+    QMenu, QApplication
1313
 )
1414
 
1515
 from ..core import Icons, AppConfig, Styles
@@ -338,19 +338,36 @@ class LocalFilePane(FilePane):
338338
         # Connect double-click handler
339339
         self.tree_view.doubleClicked.connect(self._on_double_click)
340340
         
341
+        # Set focus policy
342
+        self.tree_view.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
343
+        
341344
     def _on_double_click(self, index: QModelIndex):
342345
         """Handle double-click on local file."""
343346
         if self.model.isDir(index):
347
+            # Store current focus widget
348
+            focus_widget = QApplication.focusWidget()
349
+            
344350
             self.tree_view.setRootIndex(index)
345351
             self.set_path(self.model.filePath(index))
346352
             
353
+            # Restore focus
354
+            if focus_widget:
355
+                focus_widget.setFocus()
356
+            
347357
     def navigate_up(self):
348358
         """Navigate up one directory."""
359
+        # Store current focus widget
360
+        focus_widget = QApplication.focusWidget()
361
+        
349362
         current = self.tree_view.rootIndex()
350363
         parent = self.model.parent(current)
351364
         if parent.isValid():
352365
             self.tree_view.setRootIndex(parent)
353366
             self.set_path(self.model.filePath(parent))
367
+        
368
+        # Restore focus
369
+        if focus_widget:
370
+            focus_widget.setFocus()
354371
             
355372
     def navigate_home(self):
356373
         """Navigate to home directory."""
@@ -358,10 +375,6 @@ class LocalFilePane(FilePane):
358375
         self.tree_view.setRootIndex(home_index)
359376
         self.set_path(QDir.homePath())
360377
         
361
-        # Restore focus after navigation
362
-        self.window().raise_()
363
-        self.window().activateWindow()
364
-        
365378
     def get_selected_items(self) -> List[Tuple[str, bool]]:
366379
         """Get selected items as list of (path, is_dir) tuples."""
367380
         items = []
@@ -422,6 +435,9 @@ class RemoteFilePane(FilePane):
422435
         # Connect double-click handler
423436
         self.tree_view.doubleClicked.connect(self._on_double_click)
424437
         
438
+        # Set focus policy
439
+        self.tree_view.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
440
+        
425441
         # Start disabled until connected
426442
         self.setEnabled(False)
427443
     
@@ -440,17 +456,31 @@ class RemoteFilePane(FilePane):
440456
     def _on_double_click(self, index: QModelIndex):
441457
         """Handle double-click on remote file."""
442458
         if self.model.isDir(index):
459
+            # Store current focus widget
460
+            focus_widget = QApplication.focusWidget()
461
+            
443462
             path = self.model.filePath(index)
444463
             self.model.set_root_path(path)
445464
             self.set_path(path)
446465
             
466
+            # Restore focus
467
+            if focus_widget:
468
+                focus_widget.setFocus()
469
+            
447470
     def navigate_up(self):
448471
         """Navigate up one directory."""
472
+        # Store current focus widget
473
+        focus_widget = QApplication.focusWidget()
474
+        
449475
         current_path = self.model.rootPath()
450476
         if current_path and current_path != "/":
451477
             parent_path = os.path.dirname(current_path)
452478
             self.model.set_root_path(parent_path)
453479
             self.set_path(parent_path)
480
+        
481
+        # Restore focus
482
+        if focus_widget:
483
+            focus_widget.setFocus()
454484
             
455485
     def navigate_home(self):
456486
         """Navigate to home directory."""
@@ -465,10 +495,6 @@ class RemoteFilePane(FilePane):
465495
                 self.model.set_root_path("/")
466496
                 self.set_path("/")
467497
                 
468
-        # Restore focus after navigation
469
-        self.window().raise_()
470
-        self.window().activateWindow()
471
-                
472498
     def get_selected_items(self) -> List[Tuple[str, bool, str]]:
473499
         """Get selected items as list of (path, is_dir, name) tuples."""
474500
         items = []
src/wulftp/ui/main_window.pymodified
@@ -83,13 +83,9 @@ class WulFTPClient(QMainWindow):
8383
         # Initial state
8484
         self._update_connection_state(False)
8585
         self._update_button_states()
86
-
87
-    def _restore_focus(self):
88
-        """Restore window focus - used after dialogs and operations."""
89
-        # Only restore focus if we don't currently have it
90
-        if not self.isActiveWindow():
91
-            self.raise_()
92
-            self.activateWindow()
86
+        
87
+        # Set focus policy to prevent focus loss
88
+        self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
9389
 
9490
     def _create_status_bar(self):
9591
         """Create the status bar."""
@@ -234,6 +230,9 @@ class WulFTPClient(QMainWindow):
234230
                 AppConfig.MSG_CONNECTED.format(params["hostname"]), 
235231
                 AppConfig.STATUS_MESSAGE_TIMEOUT
236232
             )
233
+            
234
+            # Set focus to remote pane after connection
235
+            self.remote_pane.tree_view.setFocus()
237236
 
238237
         except Exception as e:
239238
             fast_message(self, "Connection Error", str(e), "error")