OpenShot Video Editor  2.0.0
titles_listview.py
Go to the documentation of this file.
1 ##
2 #
3 # @file
4 # @brief This file contains the titles treeview, used by the title editor window
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 from PyQt5.QtCore import QSize, QPoint, QTimer, Qt
30 from PyQt5.QtGui import *
31 from PyQt5.QtWidgets import QListView, QMenu
32 
33 from classes.app import get_app
34 from windows.models.titles_model import TitlesModel
35 
36 try:
37  import json
38 except ImportError:
39  import simplejson as json
40 
41 
42 ##
43 # A QListView QWidget used on the title editor window
44 class TitlesListView(QListView):
45 
46  def currentChanged(self, selected, deselected):
47  # Get selected item
48  self.selected = selected
49  self.deselected = deselected
50 
51  # Get translation object
52  _ = get_app()._tr
53 
54  # Get all selected rows items
55  if self.title_model.model.itemFromIndex(self.selected):
56  ItemRow = self.title_model.model.itemFromIndex(self.selected).row()
57  title_path = self.title_model.model.item(ItemRow, 2).text()
58 
59  # Display title in graphicsView
60  self.win.filename = title_path
61 
62  # Create temp version of title
63  self.win.create_temp_title(title_path)
64 
65  # Add all widgets for editing
66  self.win.load_svg_template()
67 
68  # Display temp image (slight delay to allow screen to be shown first)
69  QTimer.singleShot(50, self.win.display_svg)
70 
71  def refresh_view(self):
72  self.title_model.update_model()
73 
74  def __init__(self, *args):
75  # Invoke parent init
76  QListView.__init__(self, *args)
77 
78  # Get a reference to the window object
79  self.app = get_app()
80  self.win = args[0]
81 
82  # Get Model data
83  self.title_model = TitlesModel()
84 
85  # Setup header columns
86  self.setModel(self.title_model.model)
87  self.setIconSize(QSize(131, 108))
88  self.setGridSize(QSize(102, 92))
89  self.setViewMode(QListView.IconMode)
90  self.setResizeMode(QListView.Adjust)
91  self.setUniformItemSizes(True)
92  self.setWordWrap(True)
93  self.setTextElideMode(Qt.ElideRight)
94  self.setStyleSheet('QListView::item { padding-top: 2px; }')
95 
96  # Refresh view
97  self.refresh_view()
def get_app()
Returns the current QApplication instance of OpenShot.
Definition: app.py:55
A QListView QWidget used on the title editor window.
def currentChanged(self, selected, deselected)