OpenShot Video Editor  2.0.0
file_properties.py
Go to the documentation of this file.
1 ##
2 #
3 # @file
4 # @brief This file loads the File Properties 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 locale
31 import xml.dom.minidom as xml
32 import functools
33 
34 from PyQt5.QtCore import *
35 from PyQt5.QtWidgets import *
36 import openshot # Python module for libopenshot (required video editing module installed separately)
37 
38 from classes import info, ui_util, settings
39 from classes.app import get_app
40 from classes.logger import log
41 from classes.metrics import *
42 
43 try:
44  import json
45 except ImportError:
46  import simplejson as json
47 
48 
49 ##
50 # File Properties Dialog
51 class FileProperties(QDialog):
52 
53  # Path to ui file
54  ui_path = os.path.join(info.PATH, 'windows', 'ui', 'file-properties.ui')
55 
56  def __init__(self, file):
57  self.file = file
58 
59  # Create dialog class
60  QDialog.__init__(self)
61 
62  # Load UI from designer
63  ui_util.load_ui(self, self.ui_path)
64 
65  # Init UI
66  ui_util.init_ui(self)
67 
68  # get translations
69  app = get_app()
70  _ = app._tr
71 
72  # Get settings
74 
75  # Track metrics
76  track_metric_screen("file-properties-screen")
77 
78  # Add buttons to interface
79  self.update_button = QPushButton(_('Update'))
80  self.buttonBox.addButton(self.update_button, QDialogButtonBox.AcceptRole)
81  self.buttonBox.addButton(QPushButton(_('Cancel')), QDialogButtonBox.RejectRole)
82 
83  # Dynamically load tabs from settings data
84  self.settings_data = settings.get_settings().get_all_settings()
85 
86  # Get file properties
87  path, filename = os.path.split(self.file.data["path"])
88  baseFilename, ext = os.path.splitext(filename)
89  fps_float = float(self.file.data["fps"]["num"]) / float(self.file.data["fps"]["den"])
90 
91  tags = ""
92  if "tags" in self.file.data.keys():
93  tags = self.file.data["tags"]
94  name = filename
95  if "name" in self.file.data.keys():
96  name = self.file.data["name"]
97 
98  # Populate fields
99  self.txtFileName.setText(name)
100  self.txtTags.setText(tags)
101  self.txtFilePath.setText(os.path.join(path, filename))
102 
103  # Populate video fields
104  self.txtWidth.setValue(self.file.data["width"])
105  self.txtHeight.setValue(self.file.data["height"])
106  self.txtFrameRateNum.setValue(self.file.data["fps"]["num"])
107  self.txtFrameRateDen.setValue(self.file.data["fps"]["den"])
108  self.txtAspectRatioNum.setValue(self.file.data["display_ratio"]["num"])
109  self.txtAspectRatioDen.setValue(self.file.data["display_ratio"]["den"])
110  self.txtPixelRatioNum.setValue(self.file.data["pixel_ratio"]["num"])
111  self.txtPixelRatioDen.setValue(self.file.data["pixel_ratio"]["den"])
112 
113  # Disable Framerate if audio stream found
114  if self.file.data["has_audio"]:
115  self.txtFrameRateNum.setEnabled(False)
116  self.txtFrameRateDen.setEnabled(False)
117 
118  self.txtStartFrame.setMaximum(int(self.file.data["video_length"]))
119  if 'start' not in file.data.keys():
120  self.txtStartFrame.setValue(1)
121  else:
122  self.txtStartFrame.setValue(round(float(file.data["start"]) * fps_float) + 1)
123 
124  self.txtEndFrame.setMaximum(int(self.file.data["video_length"]))
125  if 'end' not in file.data.keys():
126  self.txtEndFrame.setValue(int(self.file.data["video_length"]))
127  else:
128  self.txtEndFrame.setValue(round(float(file.data["end"]) * fps_float) + 1)
129 
130  # Populate video & audio format
131  self.txtVideoFormat.setText(ext.replace(".", ""))
132  self.txtVideoCodec.setText(self.file.data["vcodec"])
133  self.txtAudioCodec.setText(self.file.data["acodec"])
134  self.txtSampleRate.setValue(int(self.file.data["sample_rate"]))
135  self.txtChannels.setValue(int(self.file.data["channels"]))
136  self.txtVideoBitRate.setValue(int(self.file.data["video_bit_rate"]))
137  self.txtAudioBitRate.setValue(int(self.file.data["audio_bit_rate"]))
138 
139  # Populate output field
140  self.txtOutput.setText(json.dumps(file.data, sort_keys=True, indent=4, separators=(',', ': ')))
141 
142  # Add channel layouts
143  channel_layout_index = 0
144  selected_channel_layout_index = 0
145  current_channel_layout = 0
146  if self.file.data["has_audio"]:
147  current_channel_layout = int(self.file.data["channel_layout"])
149  for layout in [(0, _("Unknown")),
150  (openshot.LAYOUT_MONO, _("Mono (1 Channel)")),
151  (openshot.LAYOUT_STEREO, _("Stereo (2 Channel)")),
152  (openshot.LAYOUT_SURROUND, _("Surround (3 Channel)")),
153  (openshot.LAYOUT_5POINT1, _("Surround (5.1 Channel)")),
154  (openshot.LAYOUT_7POINT1, _("Surround (7.1 Channel)"))]:
155  log.info(layout)
156  self.channel_layout_choices.append(layout[0])
157  self.cboChannelLayout.addItem(layout[1], layout[0])
158  if current_channel_layout == layout[0]:
159  selected_channel_layout_index = channel_layout_index
160  channel_layout_index += 1
161 
162  # Select matching channel layout
163  self.cboChannelLayout.setCurrentIndex(selected_channel_layout_index)
164 
165  # Load the interlaced options
166  self.cboInterlaced.clear()
167  self.cboInterlaced.addItem(_("Yes"), "Yes")
168  self.cboInterlaced.addItem(_("No"), "No")
169  if self.file.data["interlaced_frame"]:
170  self.cboInterlaced.setCurrentIndex(0)
171  else:
172  self.cboInterlaced.setCurrentIndex(1)
173 
174  # Switch to 1st page
175  self.toolBox.setCurrentIndex(0)
176 
177  def accept(self):
178  # Update file details
179  self.file.data["name"] = self.txtFileName.text()
180  self.file.data["tags"] = self.txtTags.text()
181 
182  # Update Framerate
183  self.file.data["fps"]["num"] = self.txtFrameRateNum.value()
184  self.file.data["fps"]["den"] = self.txtFrameRateDen.value()
185 
186  # Update start / end frame
187  fps_float = float(self.file.data["fps"]["num"]) / float(self.file.data["fps"]["den"])
188  if self.txtStartFrame.value() != 1 or self.txtEndFrame.value() != self.file.data["video_length"]:
189  self.file.data["start"] = (self.txtStartFrame.value() - 1) / fps_float
190  self.file.data["end"] = (self.txtEndFrame.value() - 1) / fps_float
191 
192  # Save file object
193  self.file.save()
194 
195  # Accept dialog
196  super(FileProperties, self).accept()
197 
198  def reject(self):
199 
200  # Cancel dialog
201  super(FileProperties, self).reject()
def get_app()
Returns the current QApplication instance of OpenShot.
Definition: app.py:55
File Properties Dialog.
def get_settings()
Get the current QApplication&#39;s settings instance.
Definition: settings.py:44
def init_ui(window)
Initialize all child widgets and action of a window or dialog.
Definition: ui_util.py:220
def track_metric_screen(screen_name)
Track a GUI screen being shown.
Definition: metrics.py:96
def load_ui(window, path)
Load a Qt *.ui file, and also load an XML parsed version.
Definition: ui_util.py:66