src/eric7/UI/UserInterface.py

branch
eric7-maintenance
changeset 10534
783d835d7fe4
parent 10460
3b34efa2857c
parent 10518
1682f3203ae5
child 10616
4aa36fcd4a30
equal deleted inserted replaced
10461:5fbbda78c175 10534:783d835d7fe4
7 Module implementing the main user interface. 7 Module implementing the main user interface.
8 """ 8 """
9 9
10 import contextlib 10 import contextlib
11 import datetime 11 import datetime
12 import enum
12 import functools 13 import functools
13 import getpass 14 import getpass
14 import json 15 import json
15 import logging 16 import logging
16 import os 17 import os
172 """ 173 """
173 self.buffer += str(s) 174 self.buffer += str(s)
174 self.__nWrite(self.__bufferedWrite()) 175 self.__nWrite(self.__bufferedWrite())
175 176
176 177
178 class UserInterfaceSide(enum.Enum):
179 """
180 Class defining the supported sides of the user interface.
181 """
182
183 Left = 1
184 Bottom = 2
185 Right = 3
186
187
177 class UserInterface(EricMainWindow): 188 class UserInterface(EricMainWindow):
178 """ 189 """
179 Class implementing the main user interface. 190 Class implementing the main user interface.
180 191
181 @signal appendStderr(str) emitted to write data to stderr logger 192 @signal appendStderr(str) emitted to write data to stderr logger
198 mainPasswordChanged = pyqtSignal(str, str) 209 mainPasswordChanged = pyqtSignal(str, str)
199 onlineStateChanged = pyqtSignal(bool) 210 onlineStateChanged = pyqtSignal(bool)
200 211
201 maxFilePathLen = 100 212 maxFilePathLen = 100
202 maxMenuFilePathLen = 75 213 maxMenuFilePathLen = 75
203
204 LeftSide = 1
205 BottomSide = 2
206 RightSide = 3
207 214
208 ErrorLogFileName = "eric7_error.log" 215 ErrorLogFileName = "eric7_error.log"
209 216
210 def __init__( 217 def __init__(
211 self, 218 self,
575 if self.irc is not None: 582 if self.irc is not None:
576 self.irc.autoConnected.connect(self.__ircAutoConnected) 583 self.irc.autoConnected.connect(self.__ircAutoConnected)
577 584
578 if self.pipWidget is not None: 585 if self.pipWidget is not None:
579 self.preferencesChanged.connect(self.pipWidget.preferencesChanged) 586 self.preferencesChanged.connect(self.pipWidget.preferencesChanged)
587
588 if self.microPythonWidget is not None:
589 self.microPythonWidget.aboutToDisconnect.connect(
590 self.viewmanager.closeDeviceEditors
591 )
580 592
581 # create the toolbar manager object 593 # create the toolbar manager object
582 self.toolbarManager = EricToolBarManager(self, self) 594 self.toolbarManager = EricToolBarManager(self, self)
583 self.toolbarManager.setMainWindow(self) 595 self.toolbarManager.setMainWindow(self)
584 self.preferencesChanged.connect(self.toolbarManager.preferencesChanged) 596 self.preferencesChanged.connect(self.toolbarManager.preferencesChanged)
1078 self.hToolboxDock, 1090 self.hToolboxDock,
1079 Qt.DockWidgetArea.BottomDockWidgetArea, 1091 Qt.DockWidgetArea.BottomDockWidgetArea,
1080 self.hToolbox, 1092 self.hToolbox,
1081 self.tr("Horizontal Toolbox"), 1093 self.tr("Horizontal Toolbox"),
1082 ) 1094 )
1095 self.hToolbox.currentChanged.connect(self.__hToolboxCurrentChanged)
1083 1096
1084 # Create the right toolbox 1097 # Create the right toolbox
1085 self.rToolboxDock = self.__createDockWindow("rToolboxDock") 1098 self.rToolboxDock = self.__createDockWindow("rToolboxDock")
1086 self.rToolbox = EricVerticalToolBox(self.rToolboxDock) 1099 self.rToolbox = EricVerticalToolBox(self.rToolboxDock)
1087 self.__setupDockWindow( 1100 self.__setupDockWindow(
1261 # Create the bottom sidebar 1274 # Create the bottom sidebar
1262 self.bottomSidebar = EricSideBar( 1275 self.bottomSidebar = EricSideBar(
1263 EricSideBarSide.SOUTH, Preferences.getUI("IconBarSize") 1276 EricSideBarSide.SOUTH, Preferences.getUI("IconBarSize")
1264 ) 1277 )
1265 self.bottomSidebar.setIconBarColor(Preferences.getUI("IconBarColor")) 1278 self.bottomSidebar.setIconBarColor(Preferences.getUI("IconBarColor"))
1279 self.bottomSidebar.currentChanged.connect(self.__bottomSidebarCurrentChanged)
1266 1280
1267 # Create the right sidebar 1281 # Create the right sidebar
1268 if Preferences.getUI("CombinedLeftRightSidebar"): 1282 if Preferences.getUI("CombinedLeftRightSidebar"):
1269 # combine left and right sidebar on the left side 1283 # combine left and right sidebar on the left side
1270 self.rightSidebar = None 1284 self.rightSidebar = None
1465 def addSideWidget(self, side, widget, icon, label): 1479 def addSideWidget(self, side, widget, icon, label):
1466 """ 1480 """
1467 Public method to add a widget to the sides. 1481 Public method to add a widget to the sides.
1468 1482
1469 @param side side to add the widget to 1483 @param side side to add the widget to
1470 @type int (one of UserInterface.LeftSide, UserInterface.BottomSide, 1484 @type UserInterfaceSide
1471 UserInterface.RightSide)
1472 @param widget reference to the widget to add 1485 @param widget reference to the widget to add
1473 @type QWidget 1486 @type QWidget
1474 @param icon icon to be used 1487 @param icon icon to be used
1475 @type QIcon 1488 @type QIcon
1476 @param label label text to be shown 1489 @param label label text to be shown
1477 @type str 1490 @type str
1478 """ 1491 """
1479 if side in [ 1492 if self.__layoutType == "Toolboxes":
1480 UserInterface.LeftSide, 1493 if side == UserInterfaceSide.Left:
1481 UserInterface.BottomSide, 1494 self.lToolbox.addItem(widget, icon, label)
1482 UserInterface.RightSide, 1495 elif side == UserInterfaceSide.Bottom:
1483 ]: 1496 self.hToolbox.addItem(widget, icon, label)
1484 if self.__layoutType == "Toolboxes": 1497 elif side == UserInterfaceSide.Right:
1485 if side == UserInterface.LeftSide: 1498 self.rToolbox.addItem(widget, icon, label)
1486 self.lToolbox.addItem(widget, icon, label) 1499 elif self.__layoutType == "Sidebars":
1487 elif side == UserInterface.BottomSide: 1500 if side == UserInterfaceSide.Left:
1488 self.hToolbox.addItem(widget, icon, label) 1501 self.leftSidebar.addTab(widget, icon, label)
1489 elif side == UserInterface.RightSide: 1502 elif side == UserInterfaceSide.Bottom:
1490 self.rToolbox.addItem(widget, icon, label) 1503 self.bottomSidebar.addTab(widget, icon, label)
1491 elif self.__layoutType == "Sidebars": 1504 elif side == UserInterfaceSide.Right:
1492 if side == UserInterface.LeftSide: 1505 if self.rightSidebar:
1506 self.rightSidebar.addTab(widget, icon, label)
1507 else:
1493 self.leftSidebar.addTab(widget, icon, label) 1508 self.leftSidebar.addTab(widget, icon, label)
1494 elif side == UserInterface.BottomSide:
1495 self.bottomSidebar.addTab(widget, icon, label)
1496 elif side == UserInterface.RightSide:
1497 if self.rightSidebar:
1498 self.rightSidebar.addTab(widget, icon, label)
1499 else:
1500 self.leftSidebar.addTab(widget, icon, label)
1501 1509
1502 def removeSideWidget(self, widget): 1510 def removeSideWidget(self, widget):
1503 """ 1511 """
1504 Public method to remove a widget added using addSideWidget(). 1512 Public method to remove a widget added using addSideWidget().
1505 1513
1553 self.hToolboxDock.raise_() 1561 self.hToolboxDock.raise_()
1554 elif self.__layoutType == "Sidebars": 1562 elif self.__layoutType == "Sidebars":
1555 self.bottomSidebar.show() 1563 self.bottomSidebar.show()
1556 self.bottomSidebar.setCurrentWidget(self.logViewer) 1564 self.bottomSidebar.setCurrentWidget(self.logViewer)
1557 self.bottomSidebar.raise_() 1565 self.bottomSidebar.raise_()
1566 else:
1567 if self.__layoutType == "Toolboxes":
1568 logViewerIndex = self.hToolbox.indexOf(self.logViewer)
1569 if self.hToolbox.currentIndex() != logViewerIndex:
1570 self.hToolbox.setTabIcon(
1571 logViewerIndex, EricPixmapCache.getIcon("logViewerNew")
1572 )
1573 elif self.__layoutType == "Sidebars":
1574 logViewerIndex = self.bottomSidebar.indexOf(self.logViewer)
1575 if self.bottomSidebar.currentIndex() != logViewerIndex:
1576 self.bottomSidebar.setTabIcon(
1577 logViewerIndex, EricPixmapCache.getIcon("sbLogViewerNew96")
1578 )
1558 1579
1559 def __openOnStartup(self, startupType=None): 1580 def __openOnStartup(self, startupType=None):
1560 """ 1581 """
1561 Private method to open the last file, project or multiproject. 1582 Private method to open the last file, project or multiproject.
1562 1583
1798 if project is not None: 1819 if project is not None:
1799 self.capProject = project 1820 self.capProject = project
1800 1821
1801 if self.passiveMode: 1822 if self.passiveMode:
1802 if not self.capProject and not self.capEditor: 1823 if not self.capProject and not self.capEditor:
1803 self.setWindowTitle(self.tr("{0} - Passive Mode").format(Program)) 1824 self.setWindowTitle(self.tr("{0} - Passive Mode").format("eric-ide"))
1804 elif self.capProject and not self.capEditor: 1825 elif self.capProject and not self.capEditor:
1805 self.setWindowTitle( 1826 self.setWindowTitle(
1806 self.tr("{0} - {1} - Passive Mode").format(self.capProject, Program) 1827 self.tr("{0} - {1} - Passive Mode").format(
1828 self.capProject, "eric-ide"
1829 )
1807 ) 1830 )
1808 elif not self.capProject and self.capEditor: 1831 elif not self.capProject and self.capEditor:
1809 self.setWindowTitle( 1832 self.setWindowTitle(
1810 self.tr("{0} - {1} - Passive Mode").format(self.capEditor, Program) 1833 self.tr("{0} - {1} - Passive Mode").format(
1834 self.capEditor, "eric-ide"
1835 )
1811 ) 1836 )
1812 else: 1837 else:
1813 self.setWindowTitle( 1838 self.setWindowTitle(
1814 self.tr("{0} - {1} - {2} - Passive Mode").format( 1839 self.tr("{0} - {1} - {2} - Passive Mode").format(
1815 self.capProject, self.capEditor, Program 1840 self.capProject, self.capEditor, "eric-ide"
1816 ) 1841 )
1817 ) 1842 )
1818 else: 1843 else:
1819 if not self.capProject and not self.capEditor: 1844 if not self.capProject and not self.capEditor:
1820 self.setWindowTitle(Program) 1845 self.setWindowTitle("eric-ide")
1821 elif self.capProject and not self.capEditor: 1846 elif self.capProject and not self.capEditor:
1822 self.setWindowTitle("{0} - {1}".format(self.capProject, Program)) 1847 self.setWindowTitle("{0} - {1}".format(self.capProject, "eric-ide"))
1823 elif not self.capProject and self.capEditor: 1848 elif not self.capProject and self.capEditor:
1824 self.setWindowTitle("{0} - {1}".format(self.capEditor, Program)) 1849 self.setWindowTitle("{0} - {1}".format(self.capEditor, "eric-ide"))
1825 else: 1850 else:
1826 self.setWindowTitle( 1851 self.setWindowTitle(
1827 "{0} - {1} - {2}".format(self.capProject, self.capEditor, Program) 1852 "{0} - {1} - {2}".format(
1853 self.capProject, self.capEditor, "eric-ide"
1854 )
1828 ) 1855 )
1829 1856
1830 def __initActions(self): 1857 def __initActions(self):
1831 """ 1858 """
1832 Private method to define the user interface actions. 1859 Private method to define the user interface actions.
5592 Private slot to handle the activation of the Log Viewer. 5619 Private slot to handle the activation of the Log Viewer.
5593 """ 5620 """
5594 if self.__layoutType == "Toolboxes": 5621 if self.__layoutType == "Toolboxes":
5595 self.hToolboxDock.show() 5622 self.hToolboxDock.show()
5596 self.hToolbox.setCurrentWidget(self.logViewer) 5623 self.hToolbox.setCurrentWidget(self.logViewer)
5624 self.hToolbox.setTabIcon(
5625 self.hToolbox.currentIndex(),
5626 EricPixmapCache.getIcon("logViewer"),
5627 )
5597 elif self.__layoutType == "Sidebars": 5628 elif self.__layoutType == "Sidebars":
5598 self.bottomSidebar.show() 5629 self.bottomSidebar.show()
5599 self.bottomSidebar.setCurrentWidget(self.logViewer) 5630 self.bottomSidebar.setCurrentWidget(self.logViewer)
5631 self.bottomSidebar.setTabIcon(
5632 self.bottomSidebar.currentIndex(),
5633 EricPixmapCache.getIcon("sbLogViewer96"),
5634 )
5600 self.logViewer.setFocus(Qt.FocusReason.ActiveWindowFocusReason) 5635 self.logViewer.setFocus(Qt.FocusReason.ActiveWindowFocusReason)
5601 5636
5602 def __activateTaskViewer(self): 5637 def __activateTaskViewer(self):
5603 """ 5638 """
5604 Private slot to handle the activation of the Task Viewer. 5639 Private slot to handle the activation of the Task Viewer.
5677 ) 5712 )
5678 else: 5713 else:
5679 if hasFocus: 5714 if hasFocus:
5680 self.__activateViewmanager() 5715 self.__activateViewmanager()
5681 5716
5717 @pyqtSlot(int)
5718 def __hToolboxCurrentChanged(self, index):
5719 """
5720 Private slot handling a change of the current index of the Horizontal Toolbox.
5721
5722 @param index current index of the horizontal toolbox
5723 @type int
5724 """
5725 if index == self.hToolbox.indexOf(self.logViewer):
5726 self.hToolbox.setTabIcon(index, EricPixmapCache.getIcon("logViewer"))
5727
5682 def __toggleLeftSidebar(self): 5728 def __toggleLeftSidebar(self):
5683 """ 5729 """
5684 Private slot to handle the toggle of the left sidebar window. 5730 Private slot to handle the toggle of the left sidebar window.
5685 """ 5731 """
5686 hasFocus = self.leftSidebar.currentWidget().hasFocus() 5732 hasFocus = self.leftSidebar.currentWidget().hasFocus()
5718 Qt.FocusReason.ActiveWindowFocusReason 5764 Qt.FocusReason.ActiveWindowFocusReason
5719 ) 5765 )
5720 else: 5766 else:
5721 if hasFocus: 5767 if hasFocus:
5722 self.__activateViewmanager() 5768 self.__activateViewmanager()
5769
5770 @pyqtSlot(int)
5771 def __bottomSidebarCurrentChanged(self, index):
5772 """
5773 Private slot handling a change of the current index of the Bottom Sidebar.
5774
5775 @param index current index of the bottom sidebar
5776 @type int
5777 """
5778 if index == self.bottomSidebar.indexOf(self.logViewer):
5779 self.bottomSidebar.setTabIcon(
5780 index, EricPixmapCache.getIcon("sbLogViewer96")
5781 )
5723 5782
5724 def activateCooperationViewer(self): 5783 def activateCooperationViewer(self):
5725 """ 5784 """
5726 Public slot to handle the activation of the cooperation window. 5785 Public slot to handle the activation of the cooperation window.
5727 """ 5786 """
8341 the configuration dialog is shown. 8400 the configuration dialog is shown.
8342 """ 8401 """
8343 if not Preferences.isConfigured(): 8402 if not Preferences.isConfigured():
8344 self.__initDebugToolbarsLayout() 8403 self.__initDebugToolbarsLayout()
8345 8404
8346 if Preferences.hasEric6Configuration(): 8405 EricMessageBox.information(
8347 yes = EricMessageBox.yesNo( 8406 self,
8348 self, 8407 self.tr("First time usage"),
8349 self.tr("First time usage"), 8408 self.tr(
8350 self.tr( 8409 """eric has not been configured yet. """
8351 "eric7 has not been configured yet but an eric6" 8410 """The configuration dialog will be started."""
8352 " configuration was found. Shall this be" 8411 ),
8353 " imported?" 8412 )
8354 ),
8355 yesDefault=True,
8356 )
8357 if yes:
8358 Preferences.importEric6Configuration()
8359 else:
8360 EricMessageBox.information(
8361 self,
8362 self.tr("First time usage"),
8363 self.tr(
8364 """eric has not been configured yet. """
8365 """The configuration dialog will be started."""
8366 ),
8367 )
8368
8369 self.showPreferences() 8413 self.showPreferences()
8370 Preferences.setConfigured() 8414 Preferences.setConfigured()
8371 8415
8372 def checkProjectsWorkspace(self): 8416 def checkProjectsWorkspace(self):
8373 """ 8417 """

eric ide

mercurial