eric6/E5Gui/E5ToolBarDialog.py

changeset 8143
2c730d5fd177
parent 7923
91e843545d9a
child 8207
d359172d11be
equal deleted inserted replaced
8141:27f636beebad 8143:2c730d5fd177
43 43
44 class E5ToolBarDialog(QDialog, Ui_E5ToolBarDialog): 44 class E5ToolBarDialog(QDialog, Ui_E5ToolBarDialog):
45 """ 45 """
46 Class implementing a toolbar configuration dialog. 46 Class implementing a toolbar configuration dialog.
47 """ 47 """
48 ActionIdRole = Qt.UserRole 48 ActionIdRole = Qt.ItemDataRole.UserRole
49 WidgetActionRole = Qt.UserRole + 1 49 WidgetActionRole = Qt.ItemDataRole.UserRole + 1
50 50
51 def __init__(self, toolBarManager, parent=None): 51 def __init__(self, toolBarManager, parent=None):
52 """ 52 """
53 Constructor 53 Constructor
54 54
75 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) 75 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow"))
76 self.leftButton.setIcon(UI.PixmapCache.getIcon("1leftarrow")) 76 self.leftButton.setIcon(UI.PixmapCache.getIcon("1leftarrow"))
77 self.rightButton.setIcon(UI.PixmapCache.getIcon("1rightarrow")) 77 self.rightButton.setIcon(UI.PixmapCache.getIcon("1rightarrow"))
78 78
79 self.__restoreDefaultsButton = self.buttonBox.button( 79 self.__restoreDefaultsButton = self.buttonBox.button(
80 QDialogButtonBox.RestoreDefaults) 80 QDialogButtonBox.StandardButton.RestoreDefaults)
81 self.__resetButton = self.buttonBox.button(QDialogButtonBox.Reset) 81 self.__resetButton = self.buttonBox.button(
82 QDialogButtonBox.StandardButton.Reset)
82 83
83 self.actionsTree.header().hide() 84 self.actionsTree.header().hide()
84 self.__separatorText = self.tr("--Separator--") 85 self.__separatorText = self.tr("--Separator--")
85 itm = QTreeWidgetItem(self.actionsTree, [self.__separatorText]) 86 itm = QTreeWidgetItem(self.actionsTree, [self.__separatorText])
86 self.actionsTree.setCurrentItem(itm) 87 self.actionsTree.setCurrentItem(itm)
89 categoryItem = QTreeWidgetItem(self.actionsTree, [category]) 90 categoryItem = QTreeWidgetItem(self.actionsTree, [category])
90 for action in self.__manager.categoryActions(category): 91 for action in self.__manager.categoryActions(category):
91 item = QTreeWidgetItem(categoryItem) 92 item = QTreeWidgetItem(categoryItem)
92 item.setText(0, action.text()) 93 item.setText(0, action.text())
93 item.setIcon(0, action.icon()) 94 item.setIcon(0, action.icon())
94 item.setTextAlignment(0, Qt.AlignLeft | Qt.AlignVCenter) 95 item.setTextAlignment(
96 0,
97 Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter
98 )
95 item.setData(0, E5ToolBarDialog.ActionIdRole, int(id(action))) 99 item.setData(0, E5ToolBarDialog.ActionIdRole, int(id(action)))
96 item.setData(0, E5ToolBarDialog.WidgetActionRole, False) 100 item.setData(0, E5ToolBarDialog.WidgetActionRole, False)
97 if self.__manager.isWidgetAction(action): 101 if self.__manager.isWidgetAction(action):
98 item.setData(0, E5ToolBarDialog.WidgetActionRole, True) 102 item.setData(0, E5ToolBarDialog.WidgetActionRole, True)
99 item.setData(0, Qt.TextColorRole, QColor(Qt.blue)) 103 item.setData(0, Qt.ItemDataRole.TextColorRole,
104 QColor(Qt.GlobalColor.blue))
100 self.__widgetActionToToolBarItemID[id(action)] = None 105 self.__widgetActionToToolBarItemID[id(action)] = None
101 categoryItem.setExpanded(True) 106 categoryItem.setExpanded(True)
102 107
103 for tbID, actions in list(self.__manager.toolBarsActions().items()): 108 for tbID, actions in list(self.__manager.toolBarsActions().items()):
104 tb = self.__manager.toolBarById(tbID) 109 tb = self.__manager.toolBarById(tbID)
120 tbItem.actionIDs = actionIDs 125 tbItem.actionIDs = actionIDs
121 self.toolbarComboBox.addItem(tb.windowTitle(), int(id(tbItem))) 126 self.toolbarComboBox.addItem(tb.windowTitle(), int(id(tbItem)))
122 if default: 127 if default:
123 self.toolbarComboBox.setItemData( 128 self.toolbarComboBox.setItemData(
124 self.toolbarComboBox.count() - 1, 129 self.toolbarComboBox.count() - 1,
125 QColor(Qt.darkGreen), Qt.ForegroundRole) 130 QColor(Qt.GlobalColor.darkGreen),
131 Qt.ItemDataRole.ForegroundRole)
126 self.toolbarComboBox.model().sort(0) 132 self.toolbarComboBox.model().sort(0)
127 133
128 self.toolbarComboBox.currentIndexChanged[int].connect( 134 self.toolbarComboBox.currentIndexChanged[int].connect(
129 self.__toolbarComboBox_currentIndexChanged) 135 self.__toolbarComboBox_currentIndexChanged)
130 self.toolbarComboBox.setCurrentIndex(0) 136 self.toolbarComboBox.setCurrentIndex(0)
136 """ 142 """
137 name, ok = QInputDialog.getText( 143 name, ok = QInputDialog.getText(
138 self, 144 self,
139 self.tr("New Toolbar"), 145 self.tr("New Toolbar"),
140 self.tr("Toolbar Name:"), 146 self.tr("Toolbar Name:"),
141 QLineEdit.Normal) 147 QLineEdit.EchoMode.Normal)
142 if ok and name: 148 if ok and name:
143 if self.toolbarComboBox.findText(name) != -1: 149 if self.toolbarComboBox.findText(name) != -1:
144 # toolbar with this name already exists 150 # toolbar with this name already exists
145 E5MessageBox.critical( 151 E5MessageBox.critical(
146 self, 152 self,
196 oldName = self.toolbarComboBox.currentText() 202 oldName = self.toolbarComboBox.currentText()
197 newName, ok = QInputDialog.getText( 203 newName, ok = QInputDialog.getText(
198 self, 204 self,
199 self.tr("Rename Toolbar"), 205 self.tr("Rename Toolbar"),
200 self.tr("New Toolbar Name:"), 206 self.tr("New Toolbar Name:"),
201 QLineEdit.Normal, 207 QLineEdit.EchoMode.Normal,
202 oldName) 208 oldName)
203 if ok and newName: 209 if ok and newName:
204 if oldName == newName: 210 if oldName == newName:
205 return 211 return
206 if self.toolbarComboBox.findText(newName) != -1: 212 if self.toolbarComboBox.findText(newName) != -1:
262 item.setText(self.__separatorText) 268 item.setText(self.__separatorText)
263 else: 269 else:
264 action = self.__manager.actionById(actionID) 270 action = self.__manager.actionById(actionID)
265 item.setText(action.text()) 271 item.setText(action.text())
266 item.setIcon(action.icon()) 272 item.setIcon(action.icon())
267 item.setTextAlignment(Qt.AlignLeft | Qt.AlignVCenter) 273 item.setTextAlignment(Qt.AlignmentFlag.AlignLeft |
274 Qt.AlignmentFlag.AlignVCenter)
268 item.setData(E5ToolBarDialog.ActionIdRole, int(id(action))) 275 item.setData(E5ToolBarDialog.ActionIdRole, int(id(action)))
269 item.setData(E5ToolBarDialog.WidgetActionRole, False) 276 item.setData(E5ToolBarDialog.WidgetActionRole, False)
270 if self.__manager.isWidgetAction(action): 277 if self.__manager.isWidgetAction(action):
271 item.setData(E5ToolBarDialog.WidgetActionRole, True) 278 item.setData(E5ToolBarDialog.WidgetActionRole, True)
272 item.setData(Qt.TextColorRole, QColor(Qt.blue)) 279 item.setData(Qt.ItemDataRole.TextColorRole,
280 QColor(Qt.GlobalColor.blue))
273 self.toolbarActionsList.setCurrentRow(0) 281 self.toolbarActionsList.setCurrentRow(0)
274 282
275 self.__setupButtons() 283 self.__setupButtons()
276 284
277 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) 285 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
364 actionID = self.actionsTree.currentItem().data( 372 actionID = self.actionsTree.currentItem().data(
365 0, E5ToolBarDialog.ActionIdRole) 373 0, E5ToolBarDialog.ActionIdRole)
366 action = self.__manager.actionById(actionID) 374 action = self.__manager.actionById(actionID)
367 item.setText(action.text()) 375 item.setText(action.text())
368 item.setIcon(action.icon()) 376 item.setIcon(action.icon())
369 item.setTextAlignment(Qt.AlignLeft | Qt.AlignVCenter) 377 item.setTextAlignment(Qt.AlignmentFlag.AlignLeft |
378 Qt.AlignmentFlag.AlignVCenter)
370 item.setData(E5ToolBarDialog.ActionIdRole, int(id(action))) 379 item.setData(E5ToolBarDialog.ActionIdRole, int(id(action)))
371 item.setData(E5ToolBarDialog.WidgetActionRole, False) 380 item.setData(E5ToolBarDialog.WidgetActionRole, False)
372 if self.__manager.isWidgetAction(action): 381 if self.__manager.isWidgetAction(action):
373 item.setData(E5ToolBarDialog.WidgetActionRole, True) 382 item.setData(E5ToolBarDialog.WidgetActionRole, True)
374 item.setData(Qt.TextColorRole, QColor(Qt.blue)) 383 item.setData(Qt.ItemDataRole.TextColorRole,
384 QColor(Qt.GlobalColor.blue))
375 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] 385 oldTbItemID = self.__widgetActionToToolBarItemID[actionID]
376 if oldTbItemID is not None: 386 if oldTbItemID is not None:
377 self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID) 387 self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID)
378 self.__toolbarItems[oldTbItemID].isChanged = True 388 self.__toolbarItems[oldTbItemID].isChanged = True
379 self.__toolBarItemToWidgetActionID[oldTbItemID].remove( 389 self.__toolBarItemToWidgetActionID[oldTbItemID].remove(
393 """ 403 """
394 Private slot called, when a button of the button box was clicked. 404 Private slot called, when a button of the button box was clicked.
395 405
396 @param button reference to the button clicked (QAbstractButton) 406 @param button reference to the button clicked (QAbstractButton)
397 """ 407 """
398 if button == self.buttonBox.button(QDialogButtonBox.Cancel): 408 if button == self.buttonBox.button(
409 QDialogButtonBox.StandardButton.Cancel
410 ):
399 self.reject() 411 self.reject()
400 elif button == self.buttonBox.button(QDialogButtonBox.Apply): 412 elif button == self.buttonBox.button(
413 QDialogButtonBox.StandardButton.Apply
414 ):
401 self.__saveToolBars() 415 self.__saveToolBars()
402 self.__setupButtons() 416 self.__setupButtons()
403 elif button == self.buttonBox.button(QDialogButtonBox.Ok): 417 elif button == self.buttonBox.button(
418 QDialogButtonBox.StandardButton.Ok
419 ):
404 self.__saveToolBars() 420 self.__saveToolBars()
405 self.accept() 421 self.accept()
406 elif button == self.buttonBox.button(QDialogButtonBox.Reset): 422 elif button == self.buttonBox.button(
423 QDialogButtonBox.StandardButton.Reset
424 ):
407 self.__resetCurrentToolbar() 425 self.__resetCurrentToolbar()
408 self.__setupButtons() 426 self.__setupButtons()
409 elif button == self.buttonBox.button(QDialogButtonBox.RestoreDefaults): 427 elif button == self.buttonBox.button(
428 QDialogButtonBox.StandardButton.RestoreDefaults
429 ):
410 self.__restoreCurrentToolbarToDefault() 430 self.__restoreCurrentToolbarToDefault()
411 self.__setupButtons() 431 self.__setupButtons()
412 432
413 def __saveToolBars(self): 433 def __saveToolBars(self):
414 """ 434 """

eric ide

mercurial