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  self.btnBrowse.clicked.connect(self.browsePath)
103 
104  # Populate video fields
105  self.txtWidth.setValue(self.file.data["width"])
106  self.txtHeight.setValue(self.file.data["height"])
107  self.txtFrameRateNum.setValue(self.file.data["fps"]["num"])
108  self.txtFrameRateDen.setValue(self.file.data["fps"]["den"])
109  self.txtAspectRatioNum.setValue(self.file.data["display_ratio"]["num"])
110  self.txtAspectRatioDen.setValue(self.file.data["display_ratio"]["den"])
111  self.txtPixelRatioNum.setValue(self.file.data["pixel_ratio"]["num"])
112  self.txtPixelRatioDen.setValue(self.file.data["pixel_ratio"]["den"])
113 
114  # Disable Framerate if audio stream found
115  if self.file.data["has_audio"]:
116  self.txtFrameRateNum.setEnabled(False)
117  self.txtFrameRateDen.setEnabled(False)
118 
119  self.txtStartFrame.setMaximum(int(self.file.data["video_length"]))
120  if 'start' not in file.data.keys():
121  self.txtStartFrame.setValue(1)
122  else:
123  self.txtStartFrame.setValue(round(float(file.data["start"]) * fps_float) + 1)
124 
125  self.txtEndFrame.setMaximum(int(self.file.data["video_length"]))
126  if 'end' not in file.data.keys():
127  self.txtEndFrame.setValue(int(self.file.data["video_length"]))
128  else:
129  self.txtEndFrame.setValue(round(float(file.data["end"]) * fps_float) + 1)
130 
131  # Populate video & audio format
132  self.txtVideoFormat.setText(ext.replace(".", ""))
133  self.txtVideoCodec.setText(self.file.data["vcodec"])
134  self.txtAudioCodec.setText(self.file.data["acodec"])
135  self.txtSampleRate.setValue(int(self.file.data["sample_rate"]))
136  self.txtChannels.setValue(int(self.file.data["channels"]))
137  self.txtVideoBitRate.setValue(int(self.file.data["video_bit_rate"]))
138  self.txtAudioBitRate.setValue(int(self.file.data["audio_bit_rate"]))
139 
140  # Populate output field
141  self.txtOutput.setText(json.dumps(file.data, sort_keys=True, indent=4, separators=(',', ': ')))
142 
143  # Add channel layouts
144  channel_layout_index = 0
145  selected_channel_layout_index = 0
146  current_channel_layout = 0
147  if self.file.data["has_audio"]:
148  current_channel_layout = int(self.file.data["channel_layout"])
150  for layout in [(0, _("Unknown")),
151  (openshot.LAYOUT_MONO, _("Mono (1 Channel)")),
152  (openshot.LAYOUT_STEREO, _("Stereo (2 Channel)")),
153  (openshot.LAYOUT_SURROUND, _("Surround (3 Channel)")),
154  (openshot.LAYOUT_5POINT1, _("Surround (5.1 Channel)")),
155  (openshot.LAYOUT_7POINT1, _("Surround (7.1 Channel)"))]:
156  log.info(layout)
157  self.channel_layout_choices.append(layout[0])
158  self.cboChannelLayout.addItem(layout[1], layout[0])
159  if current_channel_layout == layout[0]:
160  selected_channel_layout_index = channel_layout_index
161  channel_layout_index += 1
162 
163  # Select matching channel layout
164  self.cboChannelLayout.setCurrentIndex(selected_channel_layout_index)
165 
166  # Load the interlaced options
167  self.cboInterlaced.clear()
168  self.cboInterlaced.addItem(_("Yes"), "Yes")
169  self.cboInterlaced.addItem(_("No"), "No")
170  if self.file.data["interlaced_frame"]:
171  self.cboInterlaced.setCurrentIndex(0)
172  else:
173  self.cboInterlaced.setCurrentIndex(1)
174 
175  # Switch to 1st page
176  self.toolBox.setCurrentIndex(0)
177 
178  def browsePath(self):
179  # get translations
180  app = get_app()
181  _ = app._tr
182 
183  starting_folder, filename = os.path.split(self.file.data["path"])
184  newFilePath = QFileDialog.getOpenFileName(None,(_("Locate media file: %s") % filename), starting_folder)
185  self.txtFilePath.setText(newFilePath[0])
186 
187  def accept(self):
188  # Update file details
189  self.file.data["name"] = self.txtFileName.text()
190  self.file.data["tags"] = self.txtTags.text()
191 
192  #experimental: update file path
193  self.file.data["path"] = self.txtFilePath.text()
194 
195  # Update Framerate
196  self.file.data["fps"]["num"] = self.txtFrameRateNum.value()
197  self.file.data["fps"]["den"] = self.txtFrameRateDen.value()
198 
199  # Update start / end frame
200  fps_float = float(self.file.data["fps"]["num"]) / float(self.file.data["fps"]["den"])
201  if self.txtStartFrame.value() != 1 or self.txtEndFrame.value() != self.file.data["video_length"]:
202  self.file.data["start"] = (self.txtStartFrame.value() - 1) / fps_float
203  self.file.data["end"] = (self.txtEndFrame.value() - 1) / fps_float
204 
205  # Save file object
206  self.file.save()
207 
208  # Accept dialog
209  super(FileProperties, self).accept()
210 
211  def reject(self):
212 
213  # Cancel dialog
214  super(FileProperties, self).reject()
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
def load_ui
Load a Qt *.ui file, and also load an XML parsed version.
Definition: ui_util.py:66
File Properties Dialog.
def init_ui
Initialize all child widgets and action of a window or dialog.
Definition: ui_util.py:215
def get_settings
Get the current QApplication's settings instance.
Definition: settings.py:44