OpenShot Video Editor  2.0.0
changelog_treeview.py
Go to the documentation of this file.
1 ##
2 #
3 # @file
4 # @brief This file contains the changelog treeview, used by the about window
5 # @author Noah Figg <eggmunkee@hotmail.com>
6 # @author Jonathan Thomas <jonathan@openshot.org>
7 #
8 # @section LICENSE
9 #
10 # Copyright (c) 2008-2018 OpenShot Studios, LLC
11 # (http://www.openshotstudios.com). This file is part of
12 # OpenShot Video Editor (http://www.openshot.org), an open-source project
13 # dedicated to delivering high quality video editing and animation solutions
14 # to the world.
15 #
16 # OpenShot Video Editor is free software: you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation, either version 3 of the License, or
19 # (at your option) any later version.
20 #
21 # OpenShot Video Editor is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
28 #
29 
30 import os
31 import webbrowser
32 from urllib.parse import urlparse
33 from functools import partial
34 
35 from PyQt5.QtCore import QSize, Qt, QPoint
36 from PyQt5.QtWidgets import QListView, QTreeView, QMessageBox, QAbstractItemView, QMenu, QSizePolicy, QHeaderView, QApplication
37 from PyQt5.QtGui import QCursor
38 
39 from classes.logger import log
40 from classes.app import get_app
41 from windows.models.changelog_model import ChangelogModel
42 
43 try:
44  import json
45 except ImportError:
46  import simplejson as json
47 
48 
49 ##
50 # A ListView QWidget used on the changelog window
51 class ChangelogTreeView(QTreeView):
52  def resize_contents(self):
53  pass
54 
55  def refresh_view(self, filter=None):
56  self.changelog_model.update_model(filter=filter)
57 
58  # Format columns
59  self.header().setSectionResizeMode(0, QHeaderView.Fixed)
60  self.header().setSectionResizeMode(1, QHeaderView.Fixed)
61  self.setColumnWidth(0, 70)
62  self.setColumnWidth(1, 85)
63  self.setColumnWidth(2, 125)
64  self.setColumnWidth(3, 200)
65 
66  def contextMenuEvent(self, event):
67  log.info('contextMenuEvent')
68 
69  # Get data model and selection
70  model = self.changelog_model.model
71  row = self.indexAt(event.pos()).row()
72  if row != -1:
73  selected_hash = model.item(row, 0).text()
74 
75  menu = QMenu(self)
76  copy_action = menu.addAction("Copy Hash")
77  copy_action.triggered.connect(partial(self.CopyHashMenuTriggered, selected_hash))
78  github_action = menu.addAction("View on GitHub")
79  github_action.triggered.connect(partial(self.ChangelogMenuTriggered, selected_hash))
80  menu.popup(QCursor.pos())
81 
82  def CopyHashMenuTriggered(self, hash=""):
83  log.info("CopyHashMenuTriggered")
84  clipboard = QApplication.clipboard()
85  clipboard.setText(hash)
86 
87  def ChangelogMenuTriggered(self, hash=""):
88  log.info("ChangelogMenuTriggered")
89 
90  try:
91  webbrowser.open(self.commit_url % hash)
92  except:
93  pass
94 
95  def __init__(self, commits, commit_url, *args):
96  # Invoke parent init
97  QListView.__init__(self, *args)
98 
99  # Get a reference to the window object
100  self.win = get_app().window
101 
102  # Get Model data
103  self.changelog_model = ChangelogModel(commits)
104  self.selected = []
105 
106  # Setup header columns
107  self.setModel(self.changelog_model.model)
108  self.setIndentation(0)
109  self.setSelectionBehavior(QTreeView.SelectRows)
110  self.setSelectionBehavior(QAbstractItemView.SelectRows)
111  self.setSelectionMode(QAbstractItemView.ExtendedSelection)
112  self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
113  self.setWordWrap(True)
114  self.setStyleSheet('QTreeView::item { padding-top: 2px; }')
115  self.commit_url = commit_url
116 
117  # Refresh view
118  self.refresh_view()
119 
120  # setup filter events
121  app = get_app()
A ListView QWidget used on the changelog window.
def get_app
Returns the current QApplication instance of OpenShot.
Definition: app.py:55