0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

fix: bec-gui-server script: fix logic with __name__ == '__main__'

When started with "bec-gui-server" entry point, __name__ is
"bec_widgets.cli.server".
When started with "python -m bec_widgets.cli.server", __name__ is
"__main__".
So, better to not rely on __name__ at all.
This commit is contained in:
2024-12-16 11:58:43 +01:00
committed by wakonig_k
parent 2742a3c6cf
commit 6f2eb6b4cd

View File

@ -181,14 +181,8 @@ def main():
import bec_widgets import bec_widgets
bec_logger.level = bec_logger.LOGLEVEL.DEBUG
if __name__ != "__main__":
# if not running as main, set the log level to critical
# pylint: disable=protected-access
bec_logger._stderr_log_level = bec_logger.LOGLEVEL.CRITICAL
parser = argparse.ArgumentParser(description="BEC Widgets CLI Server") parser = argparse.ArgumentParser(description="BEC Widgets CLI Server")
parser.add_argument("--id", type=str, help="The id of the server") parser.add_argument("--id", type=str, default="test", help="The id of the server")
parser.add_argument( parser.add_argument(
"--gui_class", "--gui_class",
type=str, type=str,
@ -223,8 +217,10 @@ def main():
with redirect_stdout(SimpleFileLikeFromLogOutputFunc(logger.info)): with redirect_stdout(SimpleFileLikeFromLogOutputFunc(logger.info)):
with redirect_stderr(SimpleFileLikeFromLogOutputFunc(logger.error)): with redirect_stderr(SimpleFileLikeFromLogOutputFunc(logger.error)):
app = QApplication(sys.argv) app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(False) # set close on last window, only if not under control of client ;
app.setApplicationName("BEC Figure") # indeed, Qt considers a hidden window a closed window, so if all windows
# are hidden by default it exits
app.setQuitOnLastWindowClosed(not args.hide)
module_path = os.path.dirname(bec_widgets.__file__) module_path = os.path.dirname(bec_widgets.__file__)
icon = QIcon() icon = QIcon()
icon.addFile( icon.addFile(
@ -261,6 +257,5 @@ def main():
sys.exit(app.exec()) sys.exit(app.exec())
if __name__ == "__main__": # pragma: no cover if __name__ == "__main__":
sys.argv = ["bec_widgets.cli.server", "--id", "e2860", "--gui_class", "BECDockArea"]
main() main()