OpenShot Video Editor  2.0.0
profile.py
Go to the documentation of this file.
1 ##
2 #
3 # @file
4 # @brief This file loads the Choose Profile dialog
5 # @author Jonathan Thomas <jonathan@openshot.org>
6 #
7 # @section LICENSE
8 #
9 # Copyright (c) 2008-2018 OpenShot Studios, LLC
10 # (http://www.openshotstudios.com). This file is part of
11 # OpenShot Video Editor (http://www.openshot.org), an open-source project
12 # dedicated to delivering high quality video editing and animation solutions
13 # to the world.
14 #
15 # OpenShot Video Editor is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation, either version 3 of the License, or
18 # (at your option) any later version.
19 #
20 # OpenShot Video Editor is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
27 #
28 
29 import os
30 import sys
31 import functools
32 
33 from PyQt5.QtCore import *
34 from PyQt5.QtGui import QIcon, QStandardItemModel, QStandardItem
35 from PyQt5.QtWidgets import *
36 from PyQt5 import uic
37 import openshot # Python module for libopenshot (required video editing module installed separately)
38 
39 from classes import info, ui_util, settings, qt_types, updates
40 from classes.app import get_app
41 from classes.logger import log
42 from classes.metrics import *
43 
44 
45 ##
46 # Choose Profile Dialog
47 class Profile(QDialog):
48 
49  # Path to ui file
50  ui_path = os.path.join(info.PATH, 'windows', 'ui', 'profile.ui')
51 
52  def __init__(self):
53 
54  # Create dialog class
55  QDialog.__init__(self)
56 
57  # Load UI from designer
58  ui_util.load_ui(self, self.ui_path)
59 
60  # Init UI
61  ui_util.init_ui(self)
62 
63  # get translations
64  app = get_app()
65  _ = app._tr
66 
67  # Get settings
69 
70  # Pause playback (to prevent crash since we are fixing to change the timeline's max size)
71  get_app().window.actionPlay_trigger(None, force="pause")
72 
73  # Track metrics
74  track_metric_screen("profile-screen")
75 
76  # Loop through profiles
77  self.profile_names = []
78  self.profile_paths = {}
79  for profile_folder in [info.USER_PROFILES_PATH, info.PROFILES_PATH]:
80  for file in os.listdir(profile_folder):
81  # Load Profile
82  profile_path = os.path.join(profile_folder, file)
83  profile = openshot.Profile(profile_path)
84 
85  # Add description of Profile to list
86  profile_name = "%s (%sx%s)" % (profile.info.description, profile.info.width, profile.info.height)
87  self.profile_names.append(profile_name)
88  self.profile_paths[profile_name] = profile_path
89 
90  # Sort list
91  self.profile_names.sort()
92 
93  # Loop through sorted profiles
94  box_index = 0
95  selected_index = 0
96  for profile_name in self.profile_names:
97 
98  # Add to dropdown
99  self.cboProfile.addItem(profile_name, self.profile_paths[profile_name])
100 
101  # Set default (if it matches the project)
102  if app.project.get(['profile']) in profile_name:
103  selected_index = box_index
104 
105  # increment item counter
106  box_index += 1
107 
108 
109  # Connect signal
110  self.cboProfile.currentIndexChanged.connect(functools.partial(self.dropdown_index_changed, self.cboProfile))
111 
112  # Set current item (from project)
113  self.cboProfile.setCurrentIndex(selected_index)
114 
115  def dropdown_index_changed(self, widget, index):
116  # Get profile path
117  value = self.cboProfile.itemData(index)
118  log.info(value)
119 
120  # Load profile
121  profile = openshot.Profile(value)
122 
123  # Set labels
124  self.lblSize.setText("%sx%s" % (profile.info.width, profile.info.height))
125  self.lblFPS.setText("%0.2f" % (profile.info.fps.num / profile.info.fps.den))
126  self.lblOther.setText("DAR: %s/%s, SAR: %s/%s, Interlaced: %s" % (profile.info.display_ratio.num, profile.info.display_ratio.den, profile.info.pixel_ratio.num, profile.info.pixel_ratio.den, profile.info.interlaced_frame))
127 
128  # Get current FPS (prior to changing)
129  current_fps = get_app().project.get(["fps"])
130  current_fps_float = float(current_fps["num"]) / float(current_fps["den"])
131  new_fps_float = float(profile.info.fps.num) / float(profile.info.fps.den)
132  fps_factor = new_fps_float / current_fps_float
133 
134  # Update timeline settings
135  get_app().updates.update(["profile"], profile.info.description)
136  get_app().updates.update(["width"], profile.info.width)
137  get_app().updates.update(["height"], profile.info.height)
138  get_app().updates.update(["fps"], {"num" : profile.info.fps.num, "den" : profile.info.fps.den})
139 
140  # Rescale all keyframes and reload project
141  if fps_factor != 1.0:
142  get_app().project.rescale_keyframes(fps_factor)
143 
144  # Force ApplyMapperToClips to apply these changes
145  get_app().window.timeline_sync.timeline.ApplyMapperToClips()
146 
147  # Update Window Title
148  get_app().window.SetWindowTitle(profile.info.description)
149 
150  # Update max size (to size of video preview viewport)
151  viewport_rect = get_app().window.videoPreview.centeredViewport(get_app().window.videoPreview.width(), get_app().window.videoPreview.height())
152  get_app().window.timeline_sync.timeline.SetMaxSize(viewport_rect.width(), viewport_rect.height())
153 
154  # Refresh frame (since size of preview might have changed)
155  QTimer.singleShot(500, get_app().window.refreshFrameSignal.emit)
def track_metric_screen
Track a GUI screen being shown.
Definition: metrics.py:96
def get_app
Returns the current QApplication instance of OpenShot.
Definition: app.py:55
Choose Profile Dialog.
Definition: profile.py:47
def load_ui
Load a Qt *.ui file, and also load an XML parsed version.
Definition: ui_util.py:66
tuple ui_path
Definition: profile.py:50
def init_ui
Initialize all child widgets and action of a window or dialog.
Definition: ui_util.py:215
def dropdown_index_changed
Definition: profile.py:115
def get_settings
Get the current QApplication's settings instance.
Definition: settings.py:44