OpenShot Video Editor  2.0.0
app.py
Go to the documentation of this file.
1 ##
2 #
3 # @file
4 # @brief This file creates the QApplication, and displays the main window
5 # @author Noah Figg <eggmunkee@hotmail.com>
6 # @author Jonathan Thomas <jonathan@openshot.org>
7 # @author olivier Girard <eolinwen@gmail.com>
8 #
9 # @section LICENSE
10 #
11 # Copyright (c) 2008-2016 OpenShot Studios, LLC
12 # (http://www.openshotstudios.com). This file is part of
13 # OpenShot Video Editor (http://www.openshot.org), an open-source project
14 # dedicated to delivering high quality video editing and animation solutions
15 # to the world.
16 #
17 # OpenShot Video Editor is free software: you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation, either version 3 of the License, or
20 # (at your option) any later version.
21 #
22 # OpenShot Video Editor is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
26 #
27 # You should have received a copy of the GNU General Public License
28 # along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29 #
30 
31 import os
32 import platform
33 from uuid import uuid4
34 from PyQt5.QtWidgets import QApplication, QStyleFactory
35 from PyQt5.QtGui import QPalette, QColor, QFontDatabase, QFont
36 from PyQt5.QtCore import Qt
37 from PyQt5.QtCore import QT_VERSION_STR
38 from PyQt5.Qt import PYQT_VERSION_STR
39 
40 from classes.logger import log
41 from classes import info, settings, project_data, updates, language, ui_util, logger_libopenshot
42 import openshot
43 
44 
45 try:
46  # Enable High-DPI resolutions
47  QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
48 except AttributeError:
49  pass # Quitely fail for older Qt5 versions
50 
51 
52 ##
53 # Returns the current QApplication instance of OpenShot
54 def get_app():
55  return QApplication.instance()
56 
57 
58 ##
59 # This class is the primary QApplication for OpenShot
60 class OpenShotApp(QApplication):
61 
62  def __init__(self, *args):
63  QApplication.__init__(self, *args)
64 
65  # Log some basic system info
66  try:
67  v = openshot.GetVersion()
68  log.info("openshot-qt version: %s" % info.VERSION)
69  log.info("libopenshot version: %s" % v.ToString())
70  log.info("platform: %s" % platform.platform())
71  log.info("processor: %s" % platform.processor())
72  log.info("machine: %s" % platform.machine())
73  log.info("python version: %s" % platform.python_version())
74  log.info("qt5 version: %s" % QT_VERSION_STR)
75  log.info("pyqt5 version: %s" % PYQT_VERSION_STR)
76  except:
77  pass
78 
79  # Setup appication
80  self.setApplicationName('openshot')
81  self.setApplicationVersion(info.SETUP['version'])
82 
83  # Init settings
85  try:
86  self.settings.load()
87  except Exception as ex:
88  log.error("Couldn't load user settings. Exiting.\n{}".format(ex))
89  exit()
90 
91  # Init translation system
93 
94  # Tests of project data loading/saving
96 
97  # Init Update Manager
99 
100  # It is important that the project is the first listener if the key gets update
101  self.updates.add_listener(self.project)
102 
103  # Load ui theme if not set by OS
105 
106  # Start libopenshot logging thread
108  self.logger_libopenshot.start()
109 
110  # Track which dockable window received a context menu
112 
113  # Set unique install id (if blank)
114  if not self.settings.get("unique_install_id"):
115  self.settings.set("unique_install_id", str(uuid4()))
116 
117  # Track 1st launch metric
118  import classes.metrics
119  classes.metrics.track_metric_screen("initial-launch-screen")
120 
121  # Set Font for any theme
122  if self.settings.get("theme") != "No Theme":
123  # Load embedded font
124  try:
125  log.info("Setting font to %s" % os.path.join(info.IMAGES_PATH, "fonts", "Ubuntu-R.ttf"))
126  font_id = QFontDatabase.addApplicationFont(os.path.join(info.IMAGES_PATH, "fonts", "Ubuntu-R.ttf"))
127  font_family = QFontDatabase.applicationFontFamilies(font_id)[0]
128  font = QFont(font_family)
129  font.setPointSizeF(10.5)
130  QApplication.setFont(font)
131  except Exception as ex:
132  log.error("Error setting Ubuntu-R.ttf QFont: %s" % str(ex))
133 
134  # Set Experimental Dark Theme
135  if self.settings.get("theme") == "Humanity: Dark":
136  # Only set if dark theme selected
137  log.info("Setting custom dark theme")
138  self.setStyle(QStyleFactory.create("Fusion"))
139 
140  darkPalette = self.palette()
141  darkPalette.setColor(QPalette.Window, QColor(53, 53, 53))
142  darkPalette.setColor(QPalette.WindowText, Qt.white)
143  darkPalette.setColor(QPalette.Base, QColor(25, 25, 25))
144  darkPalette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
145  darkPalette.setColor(QPalette.ToolTipBase, Qt.white)
146  darkPalette.setColor(QPalette.ToolTipText, Qt.white)
147  darkPalette.setColor(QPalette.Text, Qt.white)
148  darkPalette.setColor(QPalette.Button, QColor(53, 53, 53))
149  darkPalette.setColor(QPalette.ButtonText, Qt.white)
150  darkPalette.setColor(QPalette.BrightText, Qt.red)
151  darkPalette.setColor(QPalette.Highlight, QColor(42, 130, 218))
152  darkPalette.setColor(QPalette.HighlightedText, Qt.black)
153  darkPalette.setColor(QPalette.Disabled, QPalette.Text, QColor(104, 104, 104))
154  self.setPalette(darkPalette)
155  self.setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 0px solid white; }")
156 
157  # Create main window
158  from windows.main_window import MainWindow
159  self.window = MainWindow()
160 
161  log.info('Process command-line arguments: %s' % args)
162  if len(args[0]) == 2:
163  path = args[0][1]
164  if ".osp" in path:
165  # Auto load project passed as argument
166  self.window.open_project(path)
167  else:
168  # Auto import media file
169  self.window.filesTreeView.add_file(path)
170 
171  # Reset undo/redo history
172  self.updates.reset()
173  self.window.updateStatusChanged(False, False)
174 
175  def _tr(self, message):
176  return self.translate("", message)
177 
178  # Start event loop
179  ##
180  # Start the primary Qt event loop for the interface
181  def run(self):
182 
183  res = self.exec_()
184 
185  try:
186  self.settings.save()
187  except Exception as ex:
188  log.error("Couldn't save user settings on exit.\n{}".format(ex))
189 
190  # return exit result
191  return res
This class is used to track and distribute changes to listeners.
Definition: updates.py:115
def get_app()
Returns the current QApplication instance of OpenShot.
Definition: app.py:54
def init_language()
Find the current locale, and install the correct translators.
Definition: language.py:42
def run(self)
Start the primary Qt event loop for the interface.
Definition: app.py:181
def __init__(self, args)
Definition: app.py:62
logger_libopenshot
Definition: app.py:107
This class is the primary QApplication for OpenShot.
Definition: app.py:60
context_menu_object
Definition: app.py:111
def load_theme()
Load the current OS theme, or fallback to a default one.
Definition: ui_util.py:47
This class allows advanced searching of data structure, implements changes interface.
Definition: project_data.py:45
This class only allows setting pre-existing keys taken from default settings file, and merges user settings on load, assumes default OS dir.
Definition: settings.py:50