|
|
@ -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) |
|
|
|