Browse Source

Don't let very long path strings extend the main window

master
Nils 3 years ago
parent
commit
92cb80e338
  1. 5
      qtgui/designer/mainwindow.py
  2. 9
      qtgui/designer/mainwindow.ui
  3. 62
      qtgui/quicksessioncontroller.py
  4. 10
      qtgui/waitdialog.py

5
qtgui/designer/mainwindow.py

@ -47,9 +47,10 @@ class Ui_MainWindow(object):
self.verticalLayout_9.addWidget(self.quickNewSession)
self.scrollArea = QtWidgets.QScrollArea(self.page_quickSessionChooser)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setAlignment(QtCore.Qt.AlignCenter)
self.scrollArea.setObjectName("scrollArea")
self.quickSessionChooser = QtWidgets.QWidget()
self.quickSessionChooser.setGeometry(QtCore.QRect(0, 0, 98, 28))
self.quickSessionChooser.setGeometry(QtCore.QRect(0, 0, 893, 607))
self.quickSessionChooser.setObjectName("quickSessionChooser")
self.verticalLayout_7 = QtWidgets.QVBoxLayout(self.quickSessionChooser)
self.verticalLayout_7.setObjectName("verticalLayout_7")
@ -339,7 +340,7 @@ class Ui_MainWindow(object):
self.retranslateUi(MainWindow)
self.mainPageSwitcher.setCurrentIndex(0)
self.tabbyCat.setCurrentIndex(0)
self.quickStackedWidget.setCurrentIndex(1)
self.quickStackedWidget.setCurrentIndex(0)
self.detailedStackedWidget.setCurrentIndex(1)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

9
qtgui/designer/mainwindow.ui

@ -53,7 +53,7 @@
<item>
<widget class="QStackedWidget" name="quickStackedWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="page_quickSessionChooser">
<layout class="QVBoxLayout" name="verticalLayout_9">
@ -75,13 +75,16 @@
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<widget class="QWidget" name="quickSessionChooser">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>98</width>
<height>28</height>
<width>893</width>
<height>607</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">

62
qtgui/quicksessioncontroller.py

@ -39,16 +39,22 @@ class SessionButton(QtWidgets.QPushButton):
self.sessionDict = sessionDict
super().__init__(sessionDict["nsmSessionName"])
self.clicked.connect(self.openSession)
#self.setFlat(True)
font = self.font()
font.setPixelSize(font.pixelSize() * 1.2 )
self.setFont(font)
#width = self.fontMetrics().boundingRect(sessionDict["nsmSessionName"]).width()+10
#width = self.fontMetrics().boundingRect(longestSessionName).width()+10
#width = parent.geometry().width()
#self.setFixedSize(width, 40)
self.setFixedHeight(40)
font = self.font()
font.setPixelSize(font.pixelSize() * 1.2 )
self.setFont(font)
def openSession(self):
name = self.sessionDict["nsmSessionName"]
api.sessionOpen(name)
name = self.sessionDict["nsmSessionName"]
api.sessionOpen(name)
class QuickSessionController(object):
"""Controls the widget, but does not subclass"""
@ -56,52 +62,66 @@ class QuickSessionController(object):
def __init__(self, mainWindow):
self.mainWindow = mainWindow
self.layout = mainWindow.ui.quickSessionChooser.layout()
#self.layout.setAlignment(QtCore.Qt.AlignHCenter)
newSessionButton = mainWindow.ui.quickNewSession
font = newSessionButton.font()
font.setPixelSize(font.pixelSize() * 1.4)
font = newSessionButton.font()
font.setPixelSize(font.pixelSize() * 1.4)
newSessionButton.setFont(font)
newSessionButton.setFixedHeight(40)
newSessionButton.setFocus(True) #Enter on program start creates a new session.
newSessionButton.clicked.connect(self._newTimestampSession)
newSessionButton.clicked.connect(self._newTimestampSession)
api.callbacks.sessionsChanged.append(self._reactCallback_sessionsChanged)
#self.layout.geometry().width() #very small
#self.mainWindow.ui.quickSessionChooser.geometry().width() #too small
#self.mainWindow.ui.scrollArea.geometry().width()
#mainWindow.geometry().width()
logger.info("Quick Session Chooser ready")
def _clear(self):
"""Clear everything but the spacer item"""
for child in self.mainWindow.ui.quickSessionChooser.children():
if type(child) is SessionButton:
for child in self.mainWindow.ui.quickSessionChooser.children():
if type(child) is SessionButton:
self.layout.removeWidget(child)
child.setParent(None)
del child
def _reactCallback_sessionsChanged(self, sessionDicts:list):
"""Main callback for new, added, removed, moved sessions etc."""
logger.info("Rebuilding session buttons")
logger.info("Rebuilding session buttons")
self._clear() #except the space
spacer = self.layout.takeAt(0)
#longestSessionName = ""
#for sessionDict in sessionDicts:
# if len(sessionDict["nsmSessionName"]) > len(longestSessionName):
# longestSessionName = sessionDict["nsmSessionName"]
for sessionDict in sorted(sessionDicts, key=lambda d: d["nsmSessionName"]):
self.layout.addWidget(SessionButton(sessionDict))
self.layout.addWidget(SessionButton(sessionDict))
#Finally add vertical spacer
#spacerItem = QtWidgets.QSpacerItem(1, 1, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) #int w, int h, QSizePolicy::Policy hPolicy = QSizePolicy::Minimum, QSizePolicy::Policy vPolicy = QSizePolicy::Minimum
self.layout.addItem(spacer)
self.layout.addItem(spacer)
def _newTimestampSession(self):
def _newTimestampSession(self):
nsmExecutables = api.getNsmExecutables() #type set, cached, very fast.
con = METADATA["preferredClients"]["data"]
con = METADATA["preferredClients"]["data"]
data = METADATA["preferredClients"]["connections"]
startclients = []
startclients = []
if con in nsmExecutables:
startclients.append(con)
startclients.append(con)
if data in nsmExecutables:
startclients.append(data)
#now = datetime.datetime.now().replace(second=0, microsecond=0).isoformat()[:-3]
now = datetime.datetime.now().replace(microsecond=0).isoformat()
name = now
api.sessionNew(name, startclients)
name = now
api.sessionNew(name, startclients)

10
qtgui/waitdialog.py

@ -58,12 +58,13 @@ class WaitDialog(object):
logger.info(f"Starting blocking message for {longRunningFunction}")
self.mainWindow = mainWindow
self.mainWindow.ui.messageLabel.setText(text)
#self.mainWindow.ui.messageLabel.setWordWrap(True) #qt segfault! maybe something with threads... don't care. We truncate now, see below.
self.mainWindow.ui.mainPageSwitcher.setCurrentIndex(1) #1 is messageLabel 0 is the tab widget
self.mainWindow.ui.menubar.setEnabled(False) #TODO: this will leave the options in the TrayIcon menu available.. but well, who cares...
def wrap():
longRunningFunction(self.progressInfo)
wt = WaitThread(mainWindow, wrap)
#wt.finished.connect(self.threadDone) #does NOT trigger
wt.start()
@ -71,9 +72,10 @@ class WaitDialog(object):
self.mainWindow.qtApp.processEvents()
self.mainWindow.ui.menubar.setEnabled(True)
self.mainWindow.ui.mainPageSwitcher.setCurrentIndex(0) #1 is messageLabel 0 is the tab widget
self.mainWindow.ui.mainPageSwitcher.setCurrentIndex(0) #1 is messageLabel 0 is the tab widget
def progressInfo(self, path:str):
self.mainWindow.ui.messageLabel.setText(self.text + "\n\n" + path)
#paths can be very long. They will destroy our complete layout if unchecked. we truncate to -80
self.mainWindow.ui.messageLabel.setText(self.text + "\n\n" + path[-80:])

Loading…
Cancel
Save