Skip to content

Commit

Permalink
Code cleanup, PEP8 formatting, and removing unused imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonoomph committed Aug 17, 2015
1 parent 2fd4ffd commit 7dacbc4
Show file tree
Hide file tree
Showing 6 changed files with 455 additions and 472 deletions.
3 changes: 1 addition & 2 deletions src/classes/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
"""

import openshot # Python module for libopenshot (required video editing module installed separately)

from classes.updates import UpdateInterface
from classes.logger import log
from classes.app import get_app
import openshot # Python module for libopenshot (required video editing module installed separately)


class TimelineSync(UpdateInterface):
Expand Down
262 changes: 130 additions & 132 deletions src/windows/models/blender_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,140 +26,138 @@
"""

import os
from urllib.parse import urlparse
from classes import updates
import xml.dom.minidom as xml

from PyQt5.QtCore import Qt
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QMessageBox
import openshot # Python module for libopenshot (required video editing module installed separately)

from classes import info
from classes.logger import log
from classes.settings import SettingStore
from classes.app import get_app
from PyQt5.QtCore import QMimeData, QSize, Qt, QCoreApplication, QPoint, QFileInfo
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QTreeWidget, QApplication, QMessageBox, QTreeWidgetItem, QAbstractItemView
import xml.dom.minidom as xml
import openshot # Python module for libopenshot (required video editing module installed separately)


class BlenderModel():

def update_model(self, clear=True):
log.info("updating effects model.")
app = get_app()
proj = app.project

# Get window to check filters
win = app.window

# Clear all items
if clear:
self.model_paths = {}
self.model.clear()

# Add Headers
self.model.setHorizontalHeaderLabels(["Thumb", "Name" ])

# get a list of files in the OpenShot /effects directory
effects_dir = os.path.join(info.PATH, "blender")
icons_dir = os.path.join(effects_dir, "icons")

for file in os.listdir(effects_dir):
if os.path.isfile(os.path.join(effects_dir, file)) and ".xml" in file:
# Split path
path = os.path.join(effects_dir, file)
(fileBaseName, fileExtension)=os.path.splitext(path)

# load xml effect file
xmldoc = xml.parse(path)

# Get all attributes
title = xmldoc.getElementsByTagName("title")[0].childNodes[0].data
description = xmldoc.getElementsByTagName("description")[0].childNodes[0].data
icon_name = xmldoc.getElementsByTagName("icon")[0].childNodes[0].data
icon_path = os.path.join(icons_dir, icon_name)
category = xmldoc.getElementsByTagName("category")[0].childNodes[0].data
service = xmldoc.getElementsByTagName("service")[0].childNodes[0].data

if not win.actionEffectsShowAll.isChecked():
if win.actionEffectsShowVideo.isChecked():
if not category == "Video":
continue # to next file, didn't match filter
elif win.actionEffectsShowAudio.isChecked():
if not category == "Audio":
continue # to next file, didn't match filter

if win.effectsFilter.text() != "":
if not win.effectsFilter.text().lower() in self.app._tr(title).lower() and not win.effectsFilter.text().lower() in self.app._tr(description).lower():
continue

# Generate thumbnail for file (if needed)
thumb_path = os.path.join(info.CACHE_PATH, icon_name)

# Check if thumb exists
if not os.path.exists(thumb_path):

try:
# Reload this reader
clip = openshot.Clip(icon_path)
reader = clip.Reader()

# Open reader
reader.Open()

# Determine scale of thumbnail
scale = 95.0 / reader.info.width

# Save thumbnail
reader.GetFrame(0).Save(thumb_path, scale)
reader.Close()

except:
# Handle exception
msg = QMessageBox()
msg.setText(app._tr("{} is not a valid image file.".format(filename)))
msg.exec_()
continue

row = []

# Append thumbnail
col = QStandardItem()
col.setIcon(QIcon(thumb_path))
col.setText(self.app._tr(title))
col.setToolTip(self.app._tr(title))
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
row.append(col)

# Append Name
col = QStandardItem("Name")
col.setData(self.app._tr(title), Qt.DisplayRole)
col.setText(self.app._tr(title))
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
row.append(col)

# Append Path
col = QStandardItem("Path")
col.setData(path, Qt.DisplayRole)
col.setText(path)
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
row.append(col)

# Append Service
col = QStandardItem("Service")
col.setData(service, Qt.DisplayRole)
col.setText(service)
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
row.append(col)

# Append ROW to MODEL (if does not already exist in model)
if not path in self.model_paths:
self.model.appendRow(row)
self.model_paths[path] = path

# Process events in QT (to keep the interface responsive)
app.processEvents()

def __init__(self, *args):

# Create standard model
self.app = get_app()
self.model = QStandardItemModel()
self.model.setColumnCount(4)
self.model_paths = {}
def update_model(self, clear=True):
log.info("updating effects model.")
app = get_app()

# Get window to check filters
win = app.window

# Clear all items
if clear:
self.model_paths = {}
self.model.clear()

# Add Headers
self.model.setHorizontalHeaderLabels(["Thumb", "Name"])

# get a list of files in the OpenShot /effects directory
effects_dir = os.path.join(info.PATH, "blender")
icons_dir = os.path.join(effects_dir, "icons")

for file in os.listdir(effects_dir):
if os.path.isfile(os.path.join(effects_dir, file)) and ".xml" in file:
# Split path
path = os.path.join(effects_dir, file)
(fileBaseName, fileExtension) = os.path.splitext(path)

# load xml effect file
xmldoc = xml.parse(path)

# Get all attributes
title = xmldoc.getElementsByTagName("title")[0].childNodes[0].data
description = xmldoc.getElementsByTagName("description")[0].childNodes[0].data
icon_name = xmldoc.getElementsByTagName("icon")[0].childNodes[0].data
icon_path = os.path.join(icons_dir, icon_name)
category = xmldoc.getElementsByTagName("category")[0].childNodes[0].data
service = xmldoc.getElementsByTagName("service")[0].childNodes[0].data

if not win.actionEffectsShowAll.isChecked():
if win.actionEffectsShowVideo.isChecked():
if not category == "Video":
continue # to next file, didn't match filter
elif win.actionEffectsShowAudio.isChecked():
if not category == "Audio":
continue # to next file, didn't match filter

if win.effectsFilter.text() != "":
if not win.effectsFilter.text().lower() in self.app._tr(title).lower() and not win.effectsFilter.text().lower() in self.app._tr(description).lower():
continue

# Generate thumbnail for file (if needed)
thumb_path = os.path.join(info.CACHE_PATH, icon_name)

# Check if thumb exists
if not os.path.exists(thumb_path):

try:
# Reload this reader
clip = openshot.Clip(icon_path)
reader = clip.Reader()

# Open reader
reader.Open()

# Determine scale of thumbnail
scale = 95.0 / reader.info.width

# Save thumbnail
reader.GetFrame(0).Save(thumb_path, scale)
reader.Close()

except:
# Handle exception
msg = QMessageBox()
msg.setText(app._tr("{} is not a valid image file.".format(icon_path)))
msg.exec_()
continue

row = []

# Append thumbnail
col = QStandardItem()
col.setIcon(QIcon(thumb_path))
col.setText(self.app._tr(title))
col.setToolTip(self.app._tr(title))
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
row.append(col)

# Append Name
col = QStandardItem("Name")
col.setData(self.app._tr(title), Qt.DisplayRole)
col.setText(self.app._tr(title))
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
row.append(col)

# Append Path
col = QStandardItem("Path")
col.setData(path, Qt.DisplayRole)
col.setText(path)
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
row.append(col)

# Append Service
col = QStandardItem("Service")
col.setData(service, Qt.DisplayRole)
col.setText(service)
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
row.append(col)

# Append ROW to MODEL (if does not already exist in model)
if not path in self.model_paths:
self.model.appendRow(row)
self.model_paths[path] = path

# Process events in QT (to keep the interface responsive)
app.processEvents()

def __init__(self, *args):

# Create standard model
self.app = get_app()
self.model = QStandardItemModel()
self.model.setColumnCount(4)
self.model_paths = {}
2 changes: 1 addition & 1 deletion src/windows/models/effects_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,4 @@ def __init__(self, *args):
self.app = get_app()
self.model = EffectsStandardItemModel()
self.model.setColumnCount(5)
self.model_names = {}
self.model_names = {}
Loading

0 comments on commit 7dacbc4

Please sign in to comment.