|
1 | 1 | importlogging
|
2 |
| -fromPyQt6.QtWidgetsimportQPushButton,QWidget,QHBoxLayout |
| 2 | +fromPyQt6.QtWidgetsimportQPushButton,QWidget,QHBoxLayout,QMenu,QInputDialog |
3 | 3 | fromPyQt6.QtCoreimportpyqtSignal,Qt,QTimer
|
4 | 4 | fromPyQt6.QtGuiimportQCursor
|
5 | 5 | fromcore.widgets.baseimportBaseWidget
|
@@ -77,7 +77,60 @@ def update_width():
|
77 | 77 | self._animation_timer.timeout.connect(update_width)
|
78 | 78 | self._animation_timer.start(step_duration)
|
79 | 79 |
|
| 80 | +defcontextMenuEvent(self,event): |
| 81 | +menu=QMenu(self) |
| 82 | +menu.setProperty("class","context-menu") |
| 83 | +rename_action=menu.addAction("Rename") |
| 84 | +delete_action=menu.addAction("Delete") |
| 85 | +menu.addSeparator() |
| 86 | +create_action=menu.addAction("Create New Desktop") |
| 87 | + |
| 88 | +rename_action.triggered.connect(self.rename_desktop) |
| 89 | +delete_action.triggered.connect(self.delete_desktop) |
| 90 | +create_action.triggered.connect(self.create_new_desktop) |
| 91 | + |
| 92 | +menu.exec(self.mapToGlobal(event.pos())) |
| 93 | + |
| 94 | +defrename_desktop(self): |
| 95 | +dialog=QInputDialog(self) |
| 96 | +dialog.setWindowFlags(Qt.WindowType.Dialog|Qt.WindowType.CustomizeWindowHint|Qt.WindowType.WindowTitleHint) |
| 97 | +dialog.setWindowTitle("Rename This Desktop") |
| 98 | +dialog.setProperty("class","rename-dialog") |
| 99 | +dialog.setLabelText("Enter name for this desktop") |
| 100 | +# Set the initial text value to the current desktop name or fallback to its index |
| 101 | +current_name=VirtualDesktop(self.workspace_index).name.strip() |
| 102 | +ifnotcurrent_name: |
| 103 | +current_name=str(self.workspace_index) |
| 104 | +dialog.setTextValue(current_name) |
| 105 | +dialog.move(QCursor.pos()) |
| 106 | +ok=dialog.exec() |
| 107 | +new_name=dialog.textValue().strip() |
| 108 | +ifokandnew_name: |
| 109 | +try: |
| 110 | +VirtualDesktop(self.workspace_index).rename(new_name) |
| 111 | +ifisinstance(self.parent_widget,WorkspaceWidget): |
| 112 | +self.parent_widget.on_update_desktops() |
| 113 | +exceptExceptionase: |
| 114 | +logging.exception(f"Failed to rename desktop:{e}") |
| 115 | +else: |
| 116 | +logging.info("No name entered. Rename cancelled.") |
| 117 | + |
| 118 | +defdelete_desktop(self): |
| 119 | +try: |
| 120 | +VirtualDesktop(self.workspace_index).remove() |
| 121 | +ifisinstance(self.parent_widget,WorkspaceWidget): |
| 122 | +self.parent_widget.on_update_desktops() |
| 123 | +exceptExceptionase: |
| 124 | +logging.exception(f"Failed to delete desktop:{e}") |
80 | 125 |
|
| 126 | +defcreate_new_desktop(self): |
| 127 | +try: |
| 128 | +VirtualDesktop.create() |
| 129 | +ifisinstance(self.parent_widget,WorkspaceWidget): |
| 130 | +self.parent_widget.on_update_desktops() |
| 131 | +exceptExceptionase: |
| 132 | +logging.exception("Failed to create new desktop",exc_info=e) |
| 133 | + |
81 | 134 | classWorkspaceWidget(BaseWidget):
|
82 | 135 | d_signal_virtual_desktop_changed=pyqtSignal(dict)
|
83 | 136 | d_signal_virtual_desktop_update=pyqtSignal(dict)
|
@@ -145,6 +198,13 @@ def _on_update_desktops(self):
|
145 | 198 | self._virtual_desktops=self._virtual_desktops_check
|
146 | 199 | self._curr_workspace_index=self._curr_workspace_index_check
|
147 | 200 | self._add_or_remove_buttons()
|
| 201 | +# Refresh names for all existing buttons |
| 202 | +forbuttoninself._workspace_buttons: |
| 203 | +ws_label,ws_active_label=self._get_workspace_label(button.workspace_index) |
| 204 | +button.default_label=ws_label |
| 205 | +button.active_label=ws_active_label |
| 206 | +button.workspace_name=VirtualDesktop(button.workspace_index).name |
| 207 | +self._update_button(button) |
148 | 208 |
|
149 | 209 | def_clear_container_layout(self):
|
150 | 210 | foriinreversed(range(self._workspace_container_layout.count())):
|
@@ -199,11 +259,16 @@ def _add_or_remove_buttons(self) -> None:
|
199 | 259 |
|
200 | 260 |
|
201 | 261 | def_get_workspace_label(self,workspace_index):
|
| 262 | +ws_name=VirtualDesktop(workspace_index).name |
| 263 | +ifnotws_nameornotws_name.strip(): |
| 264 | +ws_name=f"{workspace_index}" |
202 | 265 | label=self._label_workspace_btn.format(
|
203 |
| -index=workspace_index |
| 266 | +index=workspace_index, |
| 267 | +name=ws_name |
204 | 268 | )
|
205 | 269 | active_label=self._label_workspace_active_btn.format(
|
206 |
| -index=workspace_index |
| 270 | +index=workspace_index, |
| 271 | +name=ws_name |
207 | 272 | )
|
208 | 273 | returnlabel,active_label
|
209 | 274 |
|
|