Browse Source

Redesign hidden start: Now it is a command line option that can be combined with the new 'continue last session' one

master
Nils 5 years ago
parent
commit
f4854a1ea7
  1. 3
      engine/api.py
  2. 39
      engine/start.py
  3. 51
      qtgui/mainwindow.py

3
engine/api.py

@ -180,6 +180,9 @@ def startEngine():
if PATHS["startupSession"]:
logger.info(f"Got start-session as command line parameter. Opening: {PATHS['startupSession']}")
sessionOpen(PATHS["startupSession"])
PATHS["continueLastSession"] = None #just in case
#Info
def sessionRoot():

39
engine/start.py

@ -42,7 +42,9 @@ parser.add_argument("-V", "--verbose", action='store_true', help="(Development)
parser.add_argument("-u", "--url", action='store', dest="url", help="Force URL for the session. If there is already a running session we will connect to it. Otherwise we will start one there. Default is local host with random port. Example: osc.udp://myhost.localdomain:14294/")
parser.add_argument("--nsm-url", action='store', dest="url", help="Same as --url.")
parser.add_argument("-s", "--session", action='store', dest="session", help="Session to open on startup.")
parser.add_argument("-s", "--session", action='store', dest="session", help="Session to open on startup. Overrides --continue")
parser.add_argument("-c", "--continue", action='store_true', dest="continueLastSession", help="Autostart last active session.")
parser.add_argument("-i", "--hide", action='store_true', dest="starthidden", help="Start GUI hidden in tray, only if tray available on system.")
parser.add_argument("--session-root", action='store', dest="sessionRoot", help="Root directory of all sessions. Defaults to '$HOME/NSM Sessions'")
args = parser.parse_args()
@ -59,7 +61,7 @@ else:
logger = logging.getLogger(__name__)
logger.info("import")
"""set up python search path before the program starts and cbox gets imported.
"""set up python search path before the program starts
We need to be earliest, so let's put it here.
This is influence during compiling by creating a temporary file "compiledprefix.py".
Nuitka complies that in, when make is finished we delete it.
@ -82,8 +84,6 @@ except ModuleNotFoundError as e:
logger.info("Compiled version: {}".format(compiledVersion))
cboxSharedObjectVersionedName = "lib"+METADATA["shortName"]+".so." + METADATA["version"]
if compiledVersion:
PATHS={ #this gets imported
"root": "",
@ -95,26 +95,11 @@ if compiledVersion:
"sessionRoot": args.sessionRoot,
"url": args.url,
"startupSession": args.session,
#"lib": os.path.join(prefix, "lib", METADATA["shortName"]), #cbox is found via the PYTHONPATH
"startHidden": args.starthidden, #bool
"continueLastSession": args.continueLastSession, #bool
}
cboxSharedObjectPath = os.path.join(prefix, "lib", METADATA["shortName"], cboxSharedObjectVersionedName)
_root = os.path.dirname(__file__)
_root = os.path.abspath(os.path.join(_root, ".."))
fallback_cboxSharedObjectPath = os.path.join(_root, "site-packages", cboxSharedObjectVersionedName)
#Local version has higher priority
if os.path.exists(fallback_cboxSharedObjectPath): #we are not yet installed, look in the source site-packages dir
os.environ["CALFBOXLIBABSPATH"] = fallback_cboxSharedObjectPath
elif os.path.exists(cboxSharedObjectPath): #we are installed
os.environ["CALFBOXLIBABSPATH"] = cboxSharedObjectPath
else:
pass
#no support for system-wide cbox in compiled mode. Error handling at the bottom of the file
else:
_root = os.path.dirname(__file__)
@ -129,17 +114,9 @@ else:
"sessionRoot": args.sessionRoot,
"url": args.url,
"startupSession": args.session,
#"lib": "", #use only system paths
"startHidden": args.starthidden, #bool
"continueLastSession": args.continueLastSession, #bool
}
if os.path.exists (os.path.join(_root, "site-packages", cboxSharedObjectVersionedName)):
os.environ["CALFBOXLIBABSPATH"] = os.path.join(_root, "site-packages", cboxSharedObjectVersionedName)
#else use system-wide.
if os.path.exists (os.path.join(_root, "site-packages", "calfbox", "cbox.py")):
#add to the front to have higher priority than system site-packages
logger.info("Will attempt to start with local calfbox python module: {}".format(os.path.join(_root, "site-packages", "calfbox", "cbox.py")))
sys.path.insert(0, os.path.join(os.path.join(_root, "site-packages")))
#else try to use system-wide calfbox. Check for this and if the .so exists at the end of this file.
logger.info("PATHS: {}".format(PATHS))

51
qtgui/mainwindow.py

@ -80,13 +80,17 @@ class RecentlyOpenedSessions(object):
self.data = []
def load(self, dataFromQtSettings):
"""Handle qt settings load, working around everything it has"""
"""Handle qt settings load.
triggered by restoreWindowSettings in mainWindow init"""
if dataFromQtSettings:
for name in dataFromQtSettings:
self.add(name)
def add(self, nsmSessionName:str):
if nsmSessionName in self.data:
#Just sort
self.data.remove(nsmSessionName)
self.data.append(nsmSessionName)
return
self.data.append(nsmSessionName)
@ -94,12 +98,21 @@ class RecentlyOpenedSessions(object):
self.data.pop(0)
assert len(self.data) <= 3, len(self.data)
def get(self)->list:
"""List of nsmSessionName strings"""
sessionList = api.sessionList()
self.data = [n for n in self.data if n in sessionList]
return self.data
def last(self)->str:
"""Return the last active session.
Useful for continue-mode command line arg.
"""
if self.data:
return self.get()[-1]
else:
return None
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
@ -119,7 +132,6 @@ class MainWindow(QtWidgets.QMainWindow):
SettingsDialog.loadFromSettingsAndSendToEngine() #set blacklist, whitelist for programdatabase and addtional executable paths for environment
#TODO: Hide information tab until the feature is ready
self.ui.tabbyCat.removeTab(2)
self.programIcons = {} #executableName:QIcon. Filled by self.updateProgramDatabase
@ -136,7 +148,22 @@ class MainWindow(QtWidgets.QMainWindow):
#Starting the engine sends initial GUI data. Every window and widget must be ready to receive callbacks here
api.eventLoop.start()
api.startEngine()
self.restoreWindowSettings() #includes show/hide
self.restoreWindowSettings() #populates recentlyOpenedSessions
if PATHS["startHidden"] and self.systemTray.available:
logger.info("Starting hidden")
self.toggleVisible(force=False)
else:
logger.info("Starting visible")
self.toggleVisible(force=True)
if PATHS["continueLastSession"]: #will be None if --sesion NAME was given as command line parameter and --continue on top.
continueSession = self.recentlyOpenedSessions.last()
if continueSession:
logger.info(f"Got continue session as command line parameter. Opening: {continueSession}")
api.sessionOpen(continueSession)
else:
logger.info(f"Got continue session as command line parameter but there is no session available.")
#Handle the application data cache. If not present instruct the engine to build one.
#This is also needed by the prompt in sessionController
@ -235,19 +262,21 @@ class MainWindow(QtWidgets.QMainWindow):
self.recentlyOpenedSessions.add(nsmSessionExportDict["nsmSessionName"])
def toggleVisible(self, force:bool=None):
if force:
newState = force
else:
if force is None:
newState = not self.isVisible()
else:
newState = force
if newState:
logger.info("Show")
self.restoreWindowSettings()
self.show()
self.setVisible(True)
else:
logger.info("Hide")
self.storeWindowSettings()
self.hide()
self.setVisible(False)
#self.systemTray.buildContextMenu() #Don't. This crashes Qt through some delayed execution of who knows what. Workaround: tray context menu now say "Show/Hide" and not only the actual state.
def _askBeforeQuit(self, nsmSessionName):
@ -333,7 +362,6 @@ class MainWindow(QtWidgets.QMainWindow):
if widget.success:
self.updateProgramDatabase()
def storeWindowSettings(self):
"""Window state is not saved in the real save file. That would lead to portability problems
between computers, like different screens and resolutions.
@ -345,7 +373,7 @@ class MainWindow(QtWidgets.QMainWindow):
settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"])
settings.setValue("geometry", self.saveGeometry())
settings.setValue("windowState", self.saveState())
settings.setValue("visible", self.isVisible())
#settings.setValue("visible", self.isVisible()) Deprecated. see restoreWindowSettings
settings.setValue("recentlyOpenedSessions", self.recentlyOpenedSessions.get())
settings.setValue("tab", self.ui.tabbyCat.currentIndex())
@ -373,11 +401,14 @@ class MainWindow(QtWidgets.QMainWindow):
else:
actions[key](settings.value(key))
#Deprecated. Always open the GUI when started normally, saving minimzed has little value.
#Instead we introduced a command line options and .desktop option to auto-load the last session and start Argodejo GUI hidden.
"""
if self.systemTray.available and settings.contains("visible") and settings.value("visible") == "false":
self.setVisible(False)
else:
self.setVisible(True) #This is also the default state if there is no config
"""
class SessionController(object):
"""Controls the StackWidget that contains the Session Tree, Open Session/Client and their

Loading…
Cancel
Save