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-2016 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  # Track metrics
71  track_metric_screen("profile-screen")
72 
73  # Loop through profiles
74  self.profile_names = []
75  self.profile_paths = {}
76  for profile_folder in [info.USER_PROFILES_PATH, info.PROFILES_PATH]:
77  for file in os.listdir(profile_folder):
78  # Load Profile
79  profile_path = os.path.join(profile_folder, file)
80  profile = openshot.Profile(profile_path)
81 
82  # Add description of Profile to list
83  self.profile_names.append(profile.info.description)
84  self.profile_paths[profile.info.description] = profile_path
85 
86  # Sort list
87  self.profile_names.sort()
88 
89  # Loop through sorted profiles
90  box_index = 0
91  selected_index = 0
92  for profile_name in self.profile_names:
93 
94  # Add to dropdown
95  self.cboProfile.addItem(profile_name, self.profile_paths[profile_name])
96 
97  # Set default (if it matches the project)
98  if app.project.get(['profile']) == profile_name:
99  selected_index = box_index
100 
101  # increment item counter
102  box_index += 1
103 
104 
105  # Connect signal
106  self.cboProfile.currentIndexChanged.connect(functools.partial(self.dropdown_index_changed, self.cboProfile))
107 
108  # Set current item (from project)
109  self.cboProfile.setCurrentIndex(selected_index)
110 
111  def dropdown_index_changed(self, widget, index):
112  # Get profile path
113  value = self.cboProfile.itemData(index)
114  log.info(value)
115 
116  # Load profile
117  profile = openshot.Profile(value)
118 
119  # Set labels
120  self.lblSize.setText("%sx%s" % (profile.info.width, profile.info.height))
121  self.lblFPS.setText("%0.2f" % (profile.info.fps.num / profile.info.fps.den))
122  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))
123 
124  # Update timeline settings
125  get_app().updates.update(["profile"], profile.info.description)
126  get_app().updates.update(["width"], profile.info.width)
127  get_app().updates.update(["height"], profile.info.height)
128  get_app().updates.update(["fps"], {"num" : profile.info.fps.num, "den" : profile.info.fps.den})
129 
130  # Force ApplyMapperToClips to apply these changes
131  get_app().window.timeline_sync.timeline.ApplyMapperToClips()
132 
133  # Update Window Title
134  get_app().window.SetWindowTitle(profile.info.description)
def get_app()
Returns the current QApplication instance of OpenShot.
Definition: app.py:54
Choose Profile Dialog.
Definition: profile.py:47
def __init__(self)
Definition: profile.py:52
def get_settings()
Get the current QApplication&#39;s settings instance.
Definition: settings.py:43
def init_ui(window)
Initialize all child widgets and action of a window or dialog.
Definition: ui_util.py:200
def dropdown_index_changed(self, widget, index)
Definition: profile.py:111
def track_metric_screen(screen_name)
Track a GUI screen being shown.
Definition: metrics.py:94
def load_ui(window, path)
Load a Qt *.ui file, and also load an XML parsed version.
Definition: ui_util.py:65