Esempio n. 1
0
File: cli.py Progetto: M3TIOR/ideads
def main(*argv, test_widget=_PySide2StyleTestWidget):
	"""The main application of this library. Made available as a function
	for other scripts to extend it's function.

	Args:
		*argv: The command line arguments to supply to the program supplied as
			strings. If this is empty, `sys.argv` is used.
		test_widget (:obj:`QWidget`, optional): Any PySide2 compliant widget
			that will be used as the main display window once the program is
			initalized. By default this is an instance of `PySide2StyleTestWidget`.
	"""
	# NOTE:
	# 	Even though this won't be using any alternative UIs I'm going to
	#	write it as if there will be one. Just so it's done and I can
	#	copy and paste this code elsewhere if I want to.

	# Init qt-app as global so it can be used to parse arguments and collect
	# opperational data which can be used by other UI implementations.
	qt_application = QApplication(list(*argv) if len(argv) else sys.argv)
	qt_application.setApplicationName("pyside2-style-test")
	qt_application.setApplicationVersion(__version__)

	parser = argparse.ArgumentParser(
		description="""A QSS preview script.""",
		epilog="""NOTE: if specifying a stylesheet via the command line using
		the --stylesheet option, be aware that it will be overriden by whatever
		stylesheet you load after the file prompt or by the positional argument.
		One of which is required for the program to run."""
	)
	parser.add_argument("--file",
		help="the stylesheet you want to test",
		required=True,
	)

	arguments = parser.parse_args(qt_application.arguments()[1:])

	GUI = test_widget(arguments.file)
	GUI.show()

	# Hand off control of signal processing to Qt. This function is
	# blocking and only returns when the user exits from the GUI.
	#
	# XXX:
	#	(ONLY APPLIES TO MULTITHREADING AND THE REFS ARE ONLY
	#	INACCESSABLE INSIDE THE ASYNC FUNCTIONS)
	#
	#	This function must be called within the function that initializes
	#	all our graphical elements. Otherwise their references are destroyed
	#	by the trash collector and any other threads we made using those
	#	will crash.
	qt_application.exec_()