Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new dummy webview backend, fix unit-test launching #3938

Closed
wants to merge 8 commits into from

Conversation

ferdnyc
Copy link
Contributor

@ferdnyc ferdnyc commented Dec 26, 2020

This PR changes the application startup substantially to make it more resilient. Specifically, it:

  1. Creates a new webview_backend.dummy, containing a DummyWebView class derived from QWidget and providing a stub run_js method. This webview can be used in place of the existing WebKit and WebEngine options in situations where the webview is not expected to display anything.
  2. Replaces the old mode="unittest" argument to OpenShotApp and MainWindow with an info variable, info.LAUNCH_MODE. The default value is "gui", and many more things in the startup are made dependent on the value of info.LAUNCH_MODE.
  3. Removes the QApplication configuration previously being done at the top of classes.app, and instead does it at the top of launch.py. This ensures that the necessary settings/imports will be completed before instantiating the QApplication-derived OpenShotApp object.
  4. Updates query_tests.py to set info.LAUNCH_MODE="unittest" and info.WEB_BACKEND="dummy", as well as info.LOG_LEVEL_CONSOLE="WARNING", so that startup will be constrained and logging output will be kept to a minimum during the unit test runs. This prevents crashing due to unnecessarily loaded GUI elements (especially the QML-based QWebEngineView) and keeps the unit test runs streamlined for CI use.
  5. Enhances query_tests.py to process Qt standard command line arguments, and adds -platform minimal to the arguments when the unit tests are run in the Github Actions CI. This is necessary when executing the code in an environment without an X server, and is a lighter alternative to the xvfb virtual-server environment that was previously used.

This PR also incorporates the change from #3937, eliminating the attempts to communicate with Ubuntu Unity.

- The mode= keyword arguments to OpenShotApp and MainWindow are removed
- Instead, a variable info.LAUNCH_MODE is created, defaulting to "gui"
- Many more parts of the startup (font and color settings, backup
  recovery) are made dependent on the value of info.LAUNCH_MODE
- The settings object from OpenShotApp is also passed in to
  ui_util.load_theme(), reducing dependencies on classes.settings

Configure application in launch.py, not app class

Fix indentation of configure_gui

Import correct log object
The test runner will need to be run with '-platform minimal' or
'-platform offscreen' on systems where the default platform can't
be used (e.g. Linux CI containers, where the default is xcb and
an X server connection is required)
# Set Font for any theme
if self.settings.get("theme") != "No Theme":
# Load embedded font
try:
log.info("Setting font to %s" % os.path.join(info.IMAGES_PATH, "fonts", "Ubuntu-R.ttf"))
log.info("Setting font to %s", os.path.join(info.IMAGES_PATH, "fonts", "Ubuntu-R.ttf"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this still need the %s placeholder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does. logging's formatter processes template strings with % escapes, the remaining arguments are the inputs to the formatting.

There's one key difference between passing the format string and inputs as arguments, and doing the string interpolation up front: logging calls benefit from lazy evaluation. If logging is disabled (or the logging.INFO level isn't configured for output), not only will the final, formatted string not be generated, but the os.path.join() won't even be executed, since its output isn't needed.

"Setting font to %s" % os.path.join(info.IMAGES_PATH, "fonts", "Ubuntu-R.ttf") always has to do the os.path.join() and generate the string, in order to pass it to the log.info() call — whether or not it will ultimately be logged.

if callback:
callback("{}")
else:
return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, empty line at end of file 😉

@jonoomph
Copy link
Member

Thanks @ferdnyc ! This looks really nice! I had 1 question, but otherwise, I say merge away once you are ready!

@jonoomph
Copy link
Member

I'm trying to merge in things that look very critical / and not too scary. I want to create a release branch soon. 🤞

@github-actions
Copy link

github-actions bot commented Apr 1, 2021

Merge conflicts have been detected on this PR, please resolve.

@github-actions github-actions bot added the conflicts A PR with unresolved merge conflicts label Apr 1, 2021
@ferdnyc
Copy link
Contributor Author

ferdnyc commented Apr 1, 2021

I believe I have a better way to do this (see ferdnyc/app-launch), so I'm going to close this PR.

@ferdnyc ferdnyc closed this Apr 1, 2021
@ferdnyc ferdnyc deleted the dummy-webview branch January 7, 2022 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflicts A PR with unresolved merge conflicts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants