From 0b8dcf51882afaebae9abf5ff3d34786d5dbcea2 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Thu, 4 Oct 2018 12:10:14 -0400 Subject: [PATCH 1/6] Title Editor: Track and reuse selected colors Open the color picker dialog with the previously selected color for that element already set as the default, instead of resetting to white every time. --- src/windows/title_editor.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/windows/title_editor.py b/src/windows/title_editor.py index a1576213bd..0055b685ea 100644 --- a/src/windows/title_editor.py +++ b/src/windows/title_editor.py @@ -86,8 +86,8 @@ def __init__(self, edit_file_path=None, duplicate=False): imp = minidom.getDOMImplementation() self.xmldoc = imp.createDocument(None, "any", None) - self.bg_color_code = "" - self.font_color_code = "#ffffff" + self.bg_color_code = QtGui.QColor(Qt.black) + self.font_color_code = QtGui.QColor(Qt.white) self.bg_style_string = "" self.title_style_string = "" @@ -317,13 +317,14 @@ def btnFontColor_clicked(self): _ = app._tr # Get color from user - col = QColorDialog.getColor(Qt.white, self, _("Select a Color"), + col = QColorDialog.getColor(self.font_color_code, self, _("Select a Color"), QColorDialog.DontUseNativeDialog | QColorDialog.ShowAlphaChannel) # Update SVG colors if col.isValid(): self.btnFontColor.setStyleSheet("background-color: %s" % col.name()) self.set_font_color_elements(col.name(), col.alphaF()) + self.font_color_code = col # Something changed, so update temp SVG self.writeToFile(self.xmldoc) @@ -336,13 +337,14 @@ def btnBackgroundColor_clicked(self): _ = app._tr # Get color from user - col = QColorDialog.getColor(Qt.white, self, _("Select a Color"), + col = QColorDialog.getColor(self.bg_color_code, self, _("Select a Color"), QColorDialog.DontUseNativeDialog | QColorDialog.ShowAlphaChannel) # Update SVG colors if col.isValid(): self.btnBackgroundColor.setStyleSheet("background-color: %s" % col.name()) self.set_bg_style(col.name(), col.alphaF()) + self.bg_color_code = col # Something changed, so update temp SVG self.writeToFile(self.xmldoc) @@ -419,6 +421,7 @@ def update_font_color_button(self): # Convert the opacity into the alpha value alpha = int(opacity * 65535.0) self.btnFontColor.setStyleSheet("background-color: %s; opacity %s" % (color.name(), alpha)) + self.font_color_code = color def update_background_color_button(self): """Updates the color shown on the background color button""" @@ -464,6 +467,7 @@ def update_background_color_button(self): alpha = int(opacity * 65535.0) # Set the alpha value of the button self.btnBackgroundColor.setStyleSheet("background-color: %s; opacity %s" % (color.name(), alpha)) + self.bg_color_code = color def set_font_style(self): '''sets the font properties''' From c8381e68524fbc2d41d038afc6e323bfd13826d0 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Thu, 4 Oct 2018 12:13:05 -0400 Subject: [PATCH 2/6] Title Editor: Use update_bg_color_button() Previously when a new color was selected for the SVG font/background, the corresponding button's color was being updated ad hoc within the code. This change calls `update_background_color_button()` instead, to properly refresh the button style. --- src/windows/title_editor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/windows/title_editor.py b/src/windows/title_editor.py index 0055b685ea..ae899b383d 100644 --- a/src/windows/title_editor.py +++ b/src/windows/title_editor.py @@ -322,8 +322,8 @@ def btnFontColor_clicked(self): # Update SVG colors if col.isValid(): - self.btnFontColor.setStyleSheet("background-color: %s" % col.name()) self.set_font_color_elements(col.name(), col.alphaF()) + self.update_font_color_button() self.font_color_code = col # Something changed, so update temp SVG @@ -342,8 +342,8 @@ def btnBackgroundColor_clicked(self): # Update SVG colors if col.isValid(): - self.btnBackgroundColor.setStyleSheet("background-color: %s" % col.name()) self.set_bg_style(col.name(), col.alphaF()) + self.update_background_color_button() self.bg_color_code = col # Something changed, so update temp SVG From 2ed500e0512577b365d51ccfc3414f6b12f3e6b9 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Thu, 4 Oct 2018 12:15:51 -0400 Subject: [PATCH 3/6] Title Editor: Auto-contrast color buttons The text labels on the color-selection buttons will ensure contrast by using a luminance-based algorithm to switch between white and black text automatically, based on the button color. --- src/windows/title_editor.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/windows/title_editor.py b/src/windows/title_editor.py index ae899b383d..0208bb212d 100644 --- a/src/windows/title_editor.py +++ b/src/windows/title_editor.py @@ -418,9 +418,22 @@ def update_font_color_button(self): opacity = 1.0 color = QtGui.QColor(color) + + # Compute perceptive luminance of background color + colrgb = color.getRgbF() + lum = (0.299 * colrgb[0] + 0.587 * colrgb[1] + 0.114 * colrgb[2]) + if (lum < 0.5): + text_color = QtGui.QColor(Qt.white) + else: + text_color = QtGui.QColor(Qt.black) + # Convert the opacity into the alpha value alpha = int(opacity * 65535.0) - self.btnFontColor.setStyleSheet("background-color: %s; opacity %s" % (color.name(), alpha)) + + # Set the colors of the button + self.btnFontColor.setStyleSheet( + "background-color: %s; opacity: %s; color: %s;" + % (color.name(), alpha, text_color.name())) self.font_color_code = color def update_background_color_button(self): @@ -463,10 +476,22 @@ def update_background_color_button(self): opacity = 1.0 color = QtGui.QColor(color) + + # Compute perceptive luminance of background color + colrgb = color.getRgbF() + lum = (0.299 * colrgb[0] + 0.587 * colrgb[1] + 0.114 * colrgb[2]) + if (lum < 0.5): + text_color = QtGui.QColor(Qt.white) + else: + text_color = QtGui.QColor(Qt.black) + # Convert the opacity into the alpha value alpha = int(opacity * 65535.0) - # Set the alpha value of the button - self.btnBackgroundColor.setStyleSheet("background-color: %s; opacity %s" % (color.name(), alpha)) + + # Set the colors of the button + self.btnBackgroundColor.setStyleSheet( + "background-color: %s; opacity: %s; color: %s;" + % (color.name(), alpha, text_color.name())) self.bg_color_code = color def set_font_style(self): From 61dd92833410cc7c9d3bafe1f14e2d042dedb510 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Sun, 7 Oct 2018 05:33:57 -0400 Subject: [PATCH 4/6] Append correct extension to snapshot frames Reading the code for `actionSaveFrame_trigger()`, I happened to notice what looks like a minor copy-paste bug. If the save filename chosen by the user doesn't have a `.png` extension, instead of adding it, the code would've accidentally been appending an `.osp` extension (OpenShot project file) instead. Atom also caught a spurious space character following an `if ...:` statement, so I let it fix that as well. That's the other hunk in this PR. --- src/windows/main_window.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/windows/main_window.py b/src/windows/main_window.py index 77a43e8222..ae984ae34f 100644 --- a/src/windows/main_window.py +++ b/src/windows/main_window.py @@ -896,9 +896,9 @@ def actionSaveFrame_trigger(self, event): framePath, file_type = QFileDialog.getSaveFileName(self, _("Save Frame..."), framePath, _("Image files (*.png)")) if framePath: - # Append .osp if needed + # Append .png if needed if ".png" not in framePath: - framePath = "%s.osp" % framePath + framePath = "%s.png" % framePath else: # No path specified (save frame cancelled) self.statusBar.showMessage(_("Save Frame cancelled..."), 5000); @@ -932,7 +932,7 @@ def actionSaveFrame_trigger(self, event): #log.info("new framePathTime %s" % QFileInfo(framePath).lastModified().toString("yyMMdd hh:mm:ss.zzz") ) # Show message to user - if os.path.exists(framePath) and (QFileInfo(framePath).lastModified() > framePathTime): + if os.path.exists(framePath) and (QFileInfo(framePath).lastModified() > framePathTime): #QMessageBox.information(self, _("Save Frame Successful"), _("Saved image to %s" % framePath)) self.statusBar.showMessage(_("Saved Frame to %s" % framePath), 5000); else: From 608431a6586545e0f703d3c72f1d16b31a6d6d69 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Mon, 8 Oct 2018 09:47:33 -0400 Subject: [PATCH 5/6] Convert `language.py` line endings It's the only Python source I didn't convert a while back, because the new-translations PR was still open then. --- src/classes/language.py | 312 ++++++++++++++++++++-------------------- 1 file changed, 156 insertions(+), 156 deletions(-) diff --git a/src/classes/language.py b/src/classes/language.py index 1e0c39c463..cd6c223798 100644 --- a/src/classes/language.py +++ b/src/classes/language.py @@ -1,156 +1,156 @@ -""" - @file - @brief This file loads the current language based on the computer's locale settings - @author Noah Figg - @author Jonathan Thomas - - @section LICENSE - - Copyright (c) 2008-2018 OpenShot Studios, LLC - (http://www.openshotstudios.com). This file is part of - OpenShot Video Editor (http://www.openshot.org), an open-source project - dedicated to delivering high quality video editing and animation solutions - to the world. - - OpenShot Video Editor is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenShot Video Editor is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OpenShot Library. If not, see . - """ - -import os -import locale - -from PyQt5.QtCore import QLocale, QLibraryInfo, QTranslator, QCoreApplication - -from classes.logger import log -from classes import info -from classes import settings - - -try: - from language import openshot_lang - language_path=":/locale/" - log.debug("Using compiled translation resources") -except ImportError: - language_path=os.path.join(info.PATH, 'language') - log.debug("Loading translations from: {}".format(language_path)) - -def init_language(): - """ Find the current locale, and install the correct translators """ - - # Get app instance - app = QCoreApplication.instance() - - # Setup of our list of translators and paths - translator_types = ( - {"type": 'QT', - "prefix": 'qt_', # Older versions of Qt use this file (built-in translations) - "path": QLibraryInfo.location(QLibraryInfo.TranslationsPath)}, - {"type": 'QT', - "prefix": 'qtbase_', # Newer versions of Qt use this file (built-in translations) - "path": QLibraryInfo.location(QLibraryInfo.TranslationsPath)}, - {"type": 'QT', - "prefix": 'qt_', - "path": os.path.join(info.PATH, 'language')}, # Optional path where we package QT translations - {"type": 'QT', - "prefix": 'qtbase_', - "path": os.path.join(info.PATH, 'language')}, # Optional path where we package QT translations - {"type": 'OpenShot', - "prefix": 'OpenShot.', # Our custom translations - "path": language_path}, - ) - - # Determine the environment locale, or default to system locale name - locale_names = [os.environ.get('LANG', QLocale().system().name()), - os.environ.get('LOCALE', QLocale().system().name()) - ] - - # Get the user's configured language preference - preference_lang = settings.get_settings().get('default-language') - - # Output all languages detected from various sources - log.info("Qt Detected Languages: {}".format(QLocale().system().uiLanguages())) - log.info("LANG Environment Variable: {}".format(os.environ.get('LANG', ""))) - log.info("LOCALE Environment Variable: {}".format(os.environ.get('LOCALE', ""))) - log.info("OpenShot Preference Language: {}".format(preference_lang)) - - # Check if the language preference is something other than "Default" - if preference_lang == "en_US": - # Override language list with en_US, don't add to it - locale_names = [ "en_US" ] - elif preference_lang != "Default": - # Prepend preference setting to list - locale_names.insert(0, preference_lang) - - # If the user has used the --lang command line arg, override with that - # (We've already checked that it's in SUPPORTED_LANGUAGES) - if info.CMDLINE_LANGUAGE: - locale_names = [ info.CMDLINE_LANGUAGE ] - log.info("Language overridden on command line, using: {}".format(info.CMDLINE_LANGUAGE)) - - # Default the locale to C, for number formatting - locale.setlocale(locale.LC_ALL, 'C') - - # Loop through environment variables - found_language = False - for locale_name in locale_names: - - # Go through each translator and try to add for current locale - for type in translator_types: - trans = QTranslator(app) - if find_language_match(type["prefix"], type["path"], trans, locale_name): - # Install translation - app.installTranslator(trans) - found_language = True - - # Exit if found language for type: "OpenShot" - if found_language: - log.debug("Exiting translation system (since we successfully loaded: {})".format(locale_name)) - info.CURRENT_LANGUAGE = locale_name - break - - -# Try the full locale and base locale trying to find a valid path -# returns True when a match was found. -# pattern - a string expected to have one pipe to be filled by locale strings -# path - base path for file (pattern may contain more path) -# -def find_language_match(prefix, path, translator, locale_name): - """ Match all combinations of locale, language, and country """ - - filename = prefix + locale_name - log.debug('Attempting to load {} in \'{}\''.format(filename,path)) - success = translator.load(filename, path) - if success: - log.debug('Successfully loaded {} in \'{}\''.format(filename, path)) - return success - -def get_all_languages(): - """Get all language names and countries packaged with OpenShot""" - - # Loop through all supported language locale codes - all_languages = [] - for locale_name in info.SUPPORTED_LANGUAGES: - try: - native_lang_name = QLocale(locale_name).nativeLanguageName().title() - country_name = QLocale(locale_name).nativeCountryName().title() - all_languages.append((locale_name, native_lang_name, country_name)) - except: - # Ignore failed parsing of language - pass - - # Return list - return all_languages - -def get_current_locale(): - return info.CURRENT_LANGUAGE - +""" + @file + @brief This file loads the current language based on the computer's locale settings + @author Noah Figg + @author Jonathan Thomas + + @section LICENSE + + Copyright (c) 2008-2018 OpenShot Studios, LLC + (http://www.openshotstudios.com). This file is part of + OpenShot Video Editor (http://www.openshot.org), an open-source project + dedicated to delivering high quality video editing and animation solutions + to the world. + + OpenShot Video Editor is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenShot Video Editor is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OpenShot Library. If not, see . + """ + +import os +import locale + +from PyQt5.QtCore import QLocale, QLibraryInfo, QTranslator, QCoreApplication + +from classes.logger import log +from classes import info +from classes import settings + + +try: + from language import openshot_lang + language_path=":/locale/" + log.debug("Using compiled translation resources") +except ImportError: + language_path=os.path.join(info.PATH, 'language') + log.debug("Loading translations from: {}".format(language_path)) + +def init_language(): + """ Find the current locale, and install the correct translators """ + + # Get app instance + app = QCoreApplication.instance() + + # Setup of our list of translators and paths + translator_types = ( + {"type": 'QT', + "prefix": 'qt_', # Older versions of Qt use this file (built-in translations) + "path": QLibraryInfo.location(QLibraryInfo.TranslationsPath)}, + {"type": 'QT', + "prefix": 'qtbase_', # Newer versions of Qt use this file (built-in translations) + "path": QLibraryInfo.location(QLibraryInfo.TranslationsPath)}, + {"type": 'QT', + "prefix": 'qt_', + "path": os.path.join(info.PATH, 'language')}, # Optional path where we package QT translations + {"type": 'QT', + "prefix": 'qtbase_', + "path": os.path.join(info.PATH, 'language')}, # Optional path where we package QT translations + {"type": 'OpenShot', + "prefix": 'OpenShot.', # Our custom translations + "path": language_path}, + ) + + # Determine the environment locale, or default to system locale name + locale_names = [os.environ.get('LANG', QLocale().system().name()), + os.environ.get('LOCALE', QLocale().system().name()) + ] + + # Get the user's configured language preference + preference_lang = settings.get_settings().get('default-language') + + # Output all languages detected from various sources + log.info("Qt Detected Languages: {}".format(QLocale().system().uiLanguages())) + log.info("LANG Environment Variable: {}".format(os.environ.get('LANG', ""))) + log.info("LOCALE Environment Variable: {}".format(os.environ.get('LOCALE', ""))) + log.info("OpenShot Preference Language: {}".format(preference_lang)) + + # Check if the language preference is something other than "Default" + if preference_lang == "en_US": + # Override language list with en_US, don't add to it + locale_names = [ "en_US" ] + elif preference_lang != "Default": + # Prepend preference setting to list + locale_names.insert(0, preference_lang) + + # If the user has used the --lang command line arg, override with that + # (We've already checked that it's in SUPPORTED_LANGUAGES) + if info.CMDLINE_LANGUAGE: + locale_names = [ info.CMDLINE_LANGUAGE ] + log.info("Language overridden on command line, using: {}".format(info.CMDLINE_LANGUAGE)) + + # Default the locale to C, for number formatting + locale.setlocale(locale.LC_ALL, 'C') + + # Loop through environment variables + found_language = False + for locale_name in locale_names: + + # Go through each translator and try to add for current locale + for type in translator_types: + trans = QTranslator(app) + if find_language_match(type["prefix"], type["path"], trans, locale_name): + # Install translation + app.installTranslator(trans) + found_language = True + + # Exit if found language for type: "OpenShot" + if found_language: + log.debug("Exiting translation system (since we successfully loaded: {})".format(locale_name)) + info.CURRENT_LANGUAGE = locale_name + break + + +# Try the full locale and base locale trying to find a valid path +# returns True when a match was found. +# pattern - a string expected to have one pipe to be filled by locale strings +# path - base path for file (pattern may contain more path) +# +def find_language_match(prefix, path, translator, locale_name): + """ Match all combinations of locale, language, and country """ + + filename = prefix + locale_name + log.debug('Attempting to load {} in \'{}\''.format(filename,path)) + success = translator.load(filename, path) + if success: + log.debug('Successfully loaded {} in \'{}\''.format(filename, path)) + return success + +def get_all_languages(): + """Get all language names and countries packaged with OpenShot""" + + # Loop through all supported language locale codes + all_languages = [] + for locale_name in info.SUPPORTED_LANGUAGES: + try: + native_lang_name = QLocale(locale_name).nativeLanguageName().title() + country_name = QLocale(locale_name).nativeCountryName().title() + all_languages.append((locale_name, native_lang_name, country_name)) + except: + # Ignore failed parsing of language + pass + + # Return list + return all_languages + +def get_current_locale(): + return info.CURRENT_LANGUAGE + From ca2b674ed9716f88301daf1625f41c4d38b613e7 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Mon, 8 Oct 2018 09:49:58 -0400 Subject: [PATCH 6/6] Remove CRLF line endings from chromebook preset --- src/presets/chromebook.xml | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/presets/chromebook.xml b/src/presets/chromebook.xml index 799cdb676f..cfc9e8abca 100644 --- a/src/presets/chromebook.xml +++ b/src/presets/chromebook.xml @@ -1,20 +1,20 @@ - - - - Device - Chromebook - webm - libvpx - libvorbis - 2 - 3 - - - 48000 - + + + + Device + Chromebook + webm + libvpx + libvorbis + 2 + 3 + + + 48000 +