mirror of https://gitlab.com/openlp/openlp.git
Comment out a whole lot of code to make OpenLP start. Also figured out that OpenLP now requires OpenGL
This commit is contained in:
parent
b758bb2f52
commit
a1b8b431fb
|
@ -27,6 +27,8 @@ import faulthandler
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from OpenGL import GL
|
||||||
|
|
||||||
from openlp.core.app import main
|
from openlp.core.app import main
|
||||||
from openlp.core.common import is_win, is_macosx
|
from openlp.core.common import is_win, is_macosx
|
||||||
from openlp.core.common.applocation import AppLocation
|
from openlp.core.common.applocation import AppLocation
|
||||||
|
|
|
@ -33,7 +33,7 @@ import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from traceback import format_exception
|
from traceback import format_exception
|
||||||
|
|
||||||
from PyQt5 import QtCore, QtWidgets
|
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets # noqa
|
||||||
|
|
||||||
from openlp.core.common import is_macosx, is_win
|
from openlp.core.common import is_macosx, is_win
|
||||||
from openlp.core.common.applocation import AppLocation
|
from openlp.core.common.applocation import AppLocation
|
||||||
|
|
|
@ -143,6 +143,7 @@ class Registry(object):
|
||||||
if event in self.functions_list:
|
if event in self.functions_list:
|
||||||
for function in self.functions_list[event]:
|
for function in self.functions_list[event]:
|
||||||
try:
|
try:
|
||||||
|
log.debug('Running function {} for {}'.format(function, event))
|
||||||
result = function(*args, **kwargs)
|
result = function(*args, **kwargs)
|
||||||
if result:
|
if result:
|
||||||
results.append(result)
|
results.append(result)
|
||||||
|
|
|
@ -206,11 +206,11 @@ class ScreenList(object):
|
||||||
}
|
}
|
||||||
Settings.extend_default_settings(screen_settings)
|
Settings.extend_default_settings(screen_settings)
|
||||||
monitors = Settings().value('core/monitors')
|
monitors = Settings().value('core/monitors')
|
||||||
for number, monitor in monitors.items():
|
# for number, monitor in monitors.items():
|
||||||
if self.has_screen(number):
|
# if self.has_screen(number):
|
||||||
self[number].update(monitor)
|
# self[number].update(monitor)
|
||||||
else:
|
# else:
|
||||||
self.screens.append(Screen.from_dict(monitor))
|
# self.screens.append(Screen.from_dict(monitor))
|
||||||
|
|
||||||
def save_screen_settings(self):
|
def save_screen_settings(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -49,7 +49,7 @@ class GeneralTab(SettingsTab):
|
||||||
"""
|
"""
|
||||||
self.logo_file = ':/graphics/openlp-splash-screen.png'
|
self.logo_file = ':/graphics/openlp-splash-screen.png'
|
||||||
self.logo_background_color = '#ffffff'
|
self.logo_background_color = '#ffffff'
|
||||||
self.screen_list = ScreenList()
|
self.screens = ScreenList()
|
||||||
self.icon_path = ':/icon/openlp-logo.svg'
|
self.icon_path = ':/icon/openlp-logo.svg'
|
||||||
general_translated = translate('OpenLP.GeneralTab', 'General')
|
general_translated = translate('OpenLP.GeneralTab', 'General')
|
||||||
super(GeneralTab, self).__init__(parent, 'Core', general_translated)
|
super(GeneralTab, self).__init__(parent, 'Core', general_translated)
|
||||||
|
@ -283,16 +283,21 @@ class GeneralTab(SettingsTab):
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
settings.beginGroup(self.settings_section)
|
settings.beginGroup(self.settings_section)
|
||||||
self.monitor_combo_box.clear()
|
self.monitor_combo_box.clear()
|
||||||
self.monitor_combo_box.addItems([str(screen) for screen in self.screen_list])
|
self.monitor_combo_box.addItems([str(screen) for screen in self.screens])
|
||||||
monitor_number = settings.value('monitor')
|
monitors = settings.value('monitors')
|
||||||
self.monitor_combo_box.setCurrentIndex(monitor_number)
|
for number, monitor in monitors.items():
|
||||||
|
if monitor['is_display']:
|
||||||
|
self.monitor_combo_box.setCurrentIndex(int(number))
|
||||||
|
else:
|
||||||
|
self.monitor_combo_box.setCurrentIndex(0)
|
||||||
self.number_edit.setText(settings.value('ccli number'))
|
self.number_edit.setText(settings.value('ccli number'))
|
||||||
self.username_edit.setText(settings.value('songselect username'))
|
self.username_edit.setText(settings.value('songselect username'))
|
||||||
self.password_edit.setText(settings.value('songselect password'))
|
self.password_edit.setText(settings.value('songselect password'))
|
||||||
self.save_check_service_check_box.setChecked(settings.value('save prompt'))
|
self.save_check_service_check_box.setChecked(settings.value('save prompt'))
|
||||||
self.auto_unblank_check_box.setChecked(settings.value('auto unblank'))
|
self.auto_unblank_check_box.setChecked(settings.value('auto unblank'))
|
||||||
self.click_live_slide_to_unblank_check_box.setChecked(settings.value('click live slide to unblank'))
|
self.click_live_slide_to_unblank_check_box.setChecked(settings.value('click live slide to unblank'))
|
||||||
self.display_on_monitor_check.setChecked(self.screens.display)
|
# TODO: This is going to be a more complicated setup
|
||||||
|
# self.display_on_monitor_check.setChecked(self.screens.display)
|
||||||
self.warning_check_box.setChecked(settings.value('blank warning'))
|
self.warning_check_box.setChecked(settings.value('blank warning'))
|
||||||
self.auto_open_check_box.setChecked(settings.value('auto open'))
|
self.auto_open_check_box.setChecked(settings.value('auto open'))
|
||||||
self.show_splash_check_box.setChecked(settings.value('show splash'))
|
self.show_splash_check_box.setChecked(settings.value('show splash'))
|
||||||
|
@ -305,10 +310,10 @@ class GeneralTab(SettingsTab):
|
||||||
self.timeout_spin_box.setValue(settings.value('loop delay'))
|
self.timeout_spin_box.setValue(settings.value('loop delay'))
|
||||||
self.monitor_radio_button.setChecked(not settings.value('override position',))
|
self.monitor_radio_button.setChecked(not settings.value('override position',))
|
||||||
self.override_radio_button.setChecked(settings.value('override position'))
|
self.override_radio_button.setChecked(settings.value('override position'))
|
||||||
self.custom_X_value_edit.setValue(settings.value('x position'))
|
# self.custom_X_value_edit.setValue(settings.value('x position'))
|
||||||
self.custom_Y_value_edit.setValue(settings.value('y position'))
|
# self.custom_Y_value_edit.setValue(settings.value('y position'))
|
||||||
self.custom_height_value_edit.setValue(settings.value('height'))
|
# self.custom_height_value_edit.setValue(settings.value('height'))
|
||||||
self.custom_width_value_edit.setValue(settings.value('width'))
|
# self.custom_width_value_edit.setValue(settings.value('width'))
|
||||||
self.start_paused_check_box.setChecked(settings.value('audio start paused'))
|
self.start_paused_check_box.setChecked(settings.value('audio start paused'))
|
||||||
self.repeat_list_check_box.setChecked(settings.value('audio repeat list'))
|
self.repeat_list_check_box.setChecked(settings.value('audio repeat list'))
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
|
|
@ -584,8 +584,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, RegistryProperties):
|
||||||
"""
|
"""
|
||||||
process the bootstrap post setup request
|
process the bootstrap post setup request
|
||||||
"""
|
"""
|
||||||
self.preview_controller.panel.setVisible(Settings().value('user interface/preview panel'))
|
# self.preview_controller.panel.setVisible(Settings().value('user interface/preview panel'))
|
||||||
self.live_controller.panel.setVisible(Settings().value('user interface/live panel'))
|
# self.live_controller.panel.setVisible(Settings().value('user interface/live panel'))
|
||||||
self.load_settings()
|
self.load_settings()
|
||||||
self.restore_current_media_manager_item()
|
self.restore_current_media_manager_item()
|
||||||
Registry().execute('theme_update_global')
|
Registry().execute('theme_update_global')
|
||||||
|
@ -637,8 +637,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, RegistryProperties):
|
||||||
Show the main form, as well as the display form
|
Show the main form, as well as the display form
|
||||||
"""
|
"""
|
||||||
QtWidgets.QWidget.show(self)
|
QtWidgets.QWidget.show(self)
|
||||||
if self.live_controller.display.isVisible():
|
# if self.live_controller.display.isVisible():
|
||||||
self.live_controller.display.setFocus()
|
# self.live_controller.display.setFocus()
|
||||||
self.activateWindow()
|
self.activateWindow()
|
||||||
if self.arguments:
|
if self.arguments:
|
||||||
self.open_cmd_line_files(self.arguments)
|
self.open_cmd_line_files(self.arguments)
|
||||||
|
@ -829,13 +829,6 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, RegistryProperties):
|
||||||
"""
|
"""
|
||||||
self.settings_form.exec()
|
self.settings_form.exec()
|
||||||
|
|
||||||
def paintEvent(self, event):
|
|
||||||
"""
|
|
||||||
We need to make sure, that the SlidePreview's size is correct.
|
|
||||||
"""
|
|
||||||
self.preview_controller.preview_size_changed()
|
|
||||||
self.live_controller.preview_size_changed()
|
|
||||||
|
|
||||||
def on_settings_shortcuts_item_clicked(self):
|
def on_settings_shortcuts_item_clicked(self):
|
||||||
"""
|
"""
|
||||||
Show the shortcuts dialog
|
Show the shortcuts dialog
|
||||||
|
|
|
@ -1272,7 +1272,9 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
|
||||||
"""
|
"""
|
||||||
The theme may have changed in the settings dialog so make sure the theme combo box is in the correct state.
|
The theme may have changed in the settings dialog so make sure the theme combo box is in the correct state.
|
||||||
"""
|
"""
|
||||||
visible = self.renderer.theme_level != ThemeLevel.Global
|
# TODO: Gotta fix this too
|
||||||
|
# visible = self.renderer.theme_level != ThemeLevel.Global
|
||||||
|
visible = True
|
||||||
self.toolbar.actions['theme_combo_box'].setVisible(visible)
|
self.toolbar.actions['theme_combo_box'].setVisible(visible)
|
||||||
self.toolbar.actions['theme_label'].setVisible(visible)
|
self.toolbar.actions['theme_label'].setVisible(visible)
|
||||||
self.regenerate_service_items()
|
self.regenerate_service_items()
|
||||||
|
|
|
@ -40,6 +40,7 @@ from openlp.core.lib import ItemCapabilities, ImageSource, ServiceItemAction, bu
|
||||||
from openlp.core.lib.ui import create_action
|
from openlp.core.lib.ui import create_action
|
||||||
from openlp.core.ui import HideMode, DisplayControllerType
|
from openlp.core.ui import HideMode, DisplayControllerType
|
||||||
from openlp.core.display.window import DisplayWindow
|
from openlp.core.display.window import DisplayWindow
|
||||||
|
from openlp.core.widgets.layouts import AspectRatioLayout
|
||||||
from openlp.core.widgets.toolbar import OpenLPToolbar
|
from openlp.core.widgets.toolbar import OpenLPToolbar
|
||||||
from openlp.core.widgets.views import ListPreviewWidget
|
from openlp.core.widgets.views import ListPreviewWidget
|
||||||
|
|
||||||
|
@ -118,6 +119,7 @@ class SlideController(QtWidgets.QWidget, LogMixin, RegistryProperties):
|
||||||
self.is_live = False
|
self.is_live = False
|
||||||
self.controller_type = None
|
self.controller_type = None
|
||||||
self.displays = []
|
self.displays = []
|
||||||
|
self.screens = ScreenList()
|
||||||
Registry().set_flag('has doubleclick added item to service', True)
|
Registry().set_flag('has doubleclick added item to service', True)
|
||||||
Registry().set_flag('replace service manager item', False)
|
Registry().set_flag('replace service manager item', False)
|
||||||
|
|
||||||
|
@ -141,13 +143,16 @@ class SlideController(QtWidgets.QWidget, LogMixin, RegistryProperties):
|
||||||
self.displays.append(display)
|
self.displays.append(display)
|
||||||
# display.media_watcher.progress.connect(self.on_audio_time_remaining)
|
# display.media_watcher.progress.connect(self.on_audio_time_remaining)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def display(self):
|
||||||
|
return self.displays[0] if self.displays else None
|
||||||
|
|
||||||
def initialise(self):
|
def initialise(self):
|
||||||
"""
|
"""
|
||||||
Initialise the UI elements of the controller
|
Initialise the UI elements of the controller
|
||||||
"""
|
"""
|
||||||
self.screens = ScreenList()
|
|
||||||
try:
|
try:
|
||||||
self.ratio = self.screens.current['size'].width() / self.screens.current['size'].height()
|
self.ratio = self.screens.current.geometry.width() / self.screens.current.geometry.height()
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
self.ratio = 1
|
self.ratio = 1
|
||||||
self.process_queue_lock = Lock()
|
self.process_queue_lock = Lock()
|
||||||
|
@ -359,31 +364,14 @@ class SlideController(QtWidgets.QWidget, LogMixin, RegistryProperties):
|
||||||
self.preview_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
|
self.preview_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
|
||||||
self.preview_frame.setFrameShadow(QtWidgets.QFrame.Sunken)
|
self.preview_frame.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||||
self.preview_frame.setObjectName('preview_frame')
|
self.preview_frame.setObjectName('preview_frame')
|
||||||
self.grid = QtWidgets.QGridLayout(self.preview_frame)
|
self.slide_layout = AspectRatioLayout(self.preview_frame, self.ratio)
|
||||||
self.grid.setContentsMargins(8, 8, 8, 8)
|
self.slide_layout.margin = 8
|
||||||
self.grid.setObjectName('grid')
|
|
||||||
self.slide_layout = QtWidgets.QVBoxLayout()
|
|
||||||
self.slide_layout.setSpacing(0)
|
self.slide_layout.setSpacing(0)
|
||||||
self.slide_layout.setContentsMargins(0, 0, 0, 0)
|
|
||||||
self.slide_layout.setObjectName('SlideLayout')
|
self.slide_layout.setObjectName('SlideLayout')
|
||||||
# Set up the preview display
|
# Set up the preview display
|
||||||
# self.preview_display = DisplayWindow(self)
|
self.preview_display = DisplayWindow(self)
|
||||||
# self.slide_layout.insertWidget(0, self.preview_display)
|
self.slide_layout.addWidget(self.preview_display)
|
||||||
# self.preview_display.hide()
|
|
||||||
# Actual preview screen
|
# Actual preview screen
|
||||||
self.slide_preview = QtWidgets.QLabel(self)
|
|
||||||
size_policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
|
|
||||||
size_policy.setHorizontalStretch(0)
|
|
||||||
size_policy.setVerticalStretch(0)
|
|
||||||
size_policy.setHeightForWidth(self.slide_preview.sizePolicy().hasHeightForWidth())
|
|
||||||
self.slide_preview.setSizePolicy(size_policy)
|
|
||||||
self.slide_preview.setFrameShape(QtWidgets.QFrame.Box)
|
|
||||||
self.slide_preview.setFrameShadow(QtWidgets.QFrame.Plain)
|
|
||||||
self.slide_preview.setLineWidth(1)
|
|
||||||
self.slide_preview.setScaledContents(True)
|
|
||||||
self.slide_preview.setObjectName('slide_preview')
|
|
||||||
self.slide_layout.insertWidget(0, self.slide_preview)
|
|
||||||
self.grid.addLayout(self.slide_layout, 0, 0, 1, 1)
|
|
||||||
if self.is_live:
|
if self.is_live:
|
||||||
self.current_shortcut = ''
|
self.current_shortcut = ''
|
||||||
self.shortcut_timer = QtCore.QTimer()
|
self.shortcut_timer = QtCore.QTimer()
|
||||||
|
@ -589,8 +577,8 @@ class SlideController(QtWidgets.QWidget, LogMixin, RegistryProperties):
|
||||||
if self.displays:
|
if self.displays:
|
||||||
for display in self.displays:
|
for display in self.displays:
|
||||||
display.resize(self.screens.current['size'])
|
display.resize(self.screens.current['size'])
|
||||||
if self.is_live:
|
# if self.is_live:
|
||||||
self.__add_actions_to_widget(self.display)
|
# self.__add_actions_to_widget(self.display)
|
||||||
# The SlidePreview's ratio.
|
# The SlidePreview's ratio.
|
||||||
# TODO: Need to basically update everything
|
# TODO: Need to basically update everything
|
||||||
|
|
||||||
|
@ -613,28 +601,6 @@ class SlideController(QtWidgets.QWidget, LogMixin, RegistryProperties):
|
||||||
self.theme_screen,
|
self.theme_screen,
|
||||||
self.blank_screen])
|
self.blank_screen])
|
||||||
|
|
||||||
def preview_size_changed(self):
|
|
||||||
"""
|
|
||||||
Takes care of the SlidePreview's size. Is called when one of the the splitters is moved or when the screen
|
|
||||||
size is changed. Note, that this method is (also) called frequently from the mainwindow *paintEvent*.
|
|
||||||
"""
|
|
||||||
if self.ratio < self.preview_frame.width() / self.preview_frame.height():
|
|
||||||
# We have to take the height as limit.
|
|
||||||
max_height = self.preview_frame.height() - self.grid.contentsMargins().top() * 2
|
|
||||||
self.slide_preview.setFixedSize(QtCore.QSize(max_height * self.ratio, max_height))
|
|
||||||
self.preview_display.setFixedSize(QtCore.QSize(max_height * self.ratio, max_height))
|
|
||||||
self.preview_display.screen = {'size': self.preview_display.geometry()}
|
|
||||||
else:
|
|
||||||
# We have to take the width as limit.
|
|
||||||
max_width = self.preview_frame.width() - self.grid.contentsMargins().top() * 2
|
|
||||||
self.slide_preview.setFixedSize(QtCore.QSize(max_width, max_width / self.ratio))
|
|
||||||
self.preview_display.setFixedSize(QtCore.QSize(max_width, max_width / self.ratio))
|
|
||||||
self.preview_display.screen = {'size': self.preview_display.geometry()}
|
|
||||||
# Only update controller layout if width has actually changed
|
|
||||||
if self.controller_width != self.controller.width():
|
|
||||||
self.controller_width = self.controller.width()
|
|
||||||
self.on_controller_size_changed(self.controller_width)
|
|
||||||
|
|
||||||
def on_controller_size_changed(self, width):
|
def on_controller_size_changed(self, width):
|
||||||
"""
|
"""
|
||||||
Change layout of display control buttons on controller size change
|
Change layout of display control buttons on controller size change
|
||||||
|
@ -943,18 +909,18 @@ class SlideController(QtWidgets.QWidget, LogMixin, RegistryProperties):
|
||||||
Allow the main display to blank the main display at startup time
|
Allow the main display to blank the main display at startup time
|
||||||
"""
|
"""
|
||||||
display_type = Settings().value(self.main_window.general_settings_section + '/screen blank')
|
display_type = Settings().value(self.main_window.general_settings_section + '/screen blank')
|
||||||
if self.screens.which_screen(self.window()) != self.screens.which_screen(self.display):
|
# if self.screens.which_screen(self.window()) != self.screens.which_screen(self.display):
|
||||||
# Order done to handle initial conversion
|
# # Order done to handle initial conversion
|
||||||
if display_type == 'themed':
|
# if display_type == 'themed':
|
||||||
self.on_theme_display(True)
|
# self.on_theme_display(True)
|
||||||
elif display_type == 'hidden':
|
# elif display_type == 'hidden':
|
||||||
self.on_hide_display(True)
|
# self.on_hide_display(True)
|
||||||
elif display_type == 'blanked':
|
# elif display_type == 'blanked':
|
||||||
self.on_blank_display(True)
|
# self.on_blank_display(True)
|
||||||
else:
|
# else:
|
||||||
Registry().execute('live_display_show')
|
# Registry().execute('live_display_show')
|
||||||
else:
|
# else:
|
||||||
self.on_hide_display_enable()
|
# self.on_hide_display_enable()
|
||||||
|
|
||||||
def on_slide_blank(self):
|
def on_slide_blank(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1515,7 +1481,7 @@ class PreviewController(RegistryBase, SlideController):
|
||||||
"""
|
"""
|
||||||
Set up the base Controller as a preview.
|
Set up the base Controller as a preview.
|
||||||
"""
|
"""
|
||||||
self.__registry_name = 'preview_slidecontroller'
|
self.__registry_name = 'preview_controller'
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.split = 0
|
self.split = 0
|
||||||
self.type_prefix = 'preview'
|
self.type_prefix = 'preview'
|
||||||
|
|
|
@ -203,8 +203,8 @@ class ThemesTab(SettingsTab):
|
||||||
self.default_combo_box.clear()
|
self.default_combo_box.clear()
|
||||||
self.default_combo_box.addItems(theme_list)
|
self.default_combo_box.addItems(theme_list)
|
||||||
find_and_set_in_combo_box(self.default_combo_box, self.global_theme)
|
find_and_set_in_combo_box(self.default_combo_box, self.global_theme)
|
||||||
self.renderer.set_global_theme()
|
# self.renderer.set_global_theme()
|
||||||
self.renderer.set_theme_level(self.theme_level)
|
# self.renderer.set_theme_level(self.theme_level)
|
||||||
if self.global_theme is not '':
|
if self.global_theme is not '':
|
||||||
self._preview_global_theme()
|
self._preview_global_theme()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,182 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# OpenLP - Open Source Lyrics Projection #
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# Copyright (c) 2008-2018 OpenLP Developers #
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# This program 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; version 2 of the License. #
|
||||||
|
# #
|
||||||
|
# This program 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 this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
|
###############################################################################
|
||||||
|
"""
|
||||||
|
The :mod:`~openlp.core.widgets.layouts` module contains customised layout classes
|
||||||
|
"""
|
||||||
|
from PyQt5 import QtCore, QtWidgets
|
||||||
|
|
||||||
|
|
||||||
|
class AspectRatioLayout(QtWidgets.QLayout):
|
||||||
|
"""
|
||||||
|
A layout that contains a single widget and maintains the aspect ratio of the widget
|
||||||
|
|
||||||
|
This is based on the C++ example here: https://gist.github.com/pavel-perina/1324ff064aedede0e01311aab315f83d
|
||||||
|
"""
|
||||||
|
def __init__(self, parent=None, aspect_ratio=None):
|
||||||
|
"""
|
||||||
|
Create a layout.
|
||||||
|
|
||||||
|
:param PyQt5.QtWidgets.QWidget parent: The parent widget, can be None.
|
||||||
|
:param float aspect_ratio: The aspect ratio as a float (e.g. 16.0/9.0)
|
||||||
|
"""
|
||||||
|
super().__init__(parent)
|
||||||
|
self._aspect_ratio = aspect_ratio
|
||||||
|
self._item = None
|
||||||
|
self._margin = 0
|
||||||
|
self.setContentsMargins(0, 0, 0, 0)
|
||||||
|
|
||||||
|
def get_aspect_ratio(self):
|
||||||
|
"""
|
||||||
|
Return the aspect ratio
|
||||||
|
|
||||||
|
:return: The aspect ration
|
||||||
|
:rtype: float
|
||||||
|
"""
|
||||||
|
return self._aspect_ratio
|
||||||
|
|
||||||
|
def set_aspect_ratio(self, aspect_ratio):
|
||||||
|
"""
|
||||||
|
Set the aspect ratio
|
||||||
|
|
||||||
|
:param float aspect_ratio: The aspect ratio to set
|
||||||
|
"""
|
||||||
|
# TODO: Update the layout/widget if this changes
|
||||||
|
self._aspect_ratio = aspect_ratio
|
||||||
|
|
||||||
|
aspect_ratio = property(get_aspect_ratio, set_aspect_ratio)
|
||||||
|
|
||||||
|
def get_margin(self):
|
||||||
|
"""
|
||||||
|
Return the margin
|
||||||
|
|
||||||
|
:return: The margin
|
||||||
|
:rtype: int
|
||||||
|
"""
|
||||||
|
return self._margin
|
||||||
|
|
||||||
|
def set_margin(self, value):
|
||||||
|
"""
|
||||||
|
Set the margin
|
||||||
|
|
||||||
|
:param int value: The margin
|
||||||
|
"""
|
||||||
|
self._margin = int(value)
|
||||||
|
|
||||||
|
margin = property(get_margin, set_margin)
|
||||||
|
|
||||||
|
def count(self):
|
||||||
|
"""
|
||||||
|
Overridden Qt method
|
||||||
|
"""
|
||||||
|
return 1 if self._item else 0
|
||||||
|
|
||||||
|
def addItem(self, item):
|
||||||
|
"""
|
||||||
|
Overridden Qt method
|
||||||
|
"""
|
||||||
|
if self._item is not None:
|
||||||
|
raise ValueError('AspectRatioLayout can contain only 1 widget')
|
||||||
|
self._item = item
|
||||||
|
# self._item.setAlignment(0)
|
||||||
|
|
||||||
|
def itemAt(self, index):
|
||||||
|
"""
|
||||||
|
Overridden Qt method
|
||||||
|
"""
|
||||||
|
if index != 0:
|
||||||
|
return None
|
||||||
|
return self._item
|
||||||
|
|
||||||
|
def takeAt(self, index):
|
||||||
|
"""
|
||||||
|
Overridden Qt method
|
||||||
|
"""
|
||||||
|
if index != 0:
|
||||||
|
return None
|
||||||
|
result = self._item
|
||||||
|
self._item = None
|
||||||
|
return result
|
||||||
|
|
||||||
|
def expandingDirections(self):
|
||||||
|
"""
|
||||||
|
Overridden Qt method
|
||||||
|
"""
|
||||||
|
return QtCore.Qt.Horizontal | QtCore.Qt.Vertical
|
||||||
|
|
||||||
|
def hasHeightForWidth(self):
|
||||||
|
"""
|
||||||
|
Overridden Qt method
|
||||||
|
"""
|
||||||
|
return False
|
||||||
|
|
||||||
|
def heightForWidth(self, width):
|
||||||
|
"""
|
||||||
|
Overridden Qt method
|
||||||
|
"""
|
||||||
|
height = (width - 2 * self.margin) / (self._aspect_ratio + 2 * self.margin)
|
||||||
|
return height
|
||||||
|
|
||||||
|
def setGeometry(self, rect):
|
||||||
|
"""
|
||||||
|
Overridden Qt method
|
||||||
|
"""
|
||||||
|
super().setGeometry(rect)
|
||||||
|
if self._item:
|
||||||
|
widget = self._item.widget()
|
||||||
|
available_width = rect.width() - 2 * self.margin
|
||||||
|
available_height = rect.height() - 2 * self.margin
|
||||||
|
height = available_height
|
||||||
|
width = height * self._aspect_ratio
|
||||||
|
if width > available_width:
|
||||||
|
width = available_width
|
||||||
|
height = width / self._aspect_ratio
|
||||||
|
if self._item.alignment() & QtCore.Qt.AlignTop:
|
||||||
|
y = self.margin
|
||||||
|
elif self._item.alignment() & QtCore.Qt.AlignBottom:
|
||||||
|
y = rect.height() - self.margin - height
|
||||||
|
else:
|
||||||
|
y = self.margin + (available_height - height) / 2
|
||||||
|
widget.setGeometry(rect.x() + self.margin, rect.y() + y, width, height)
|
||||||
|
else:
|
||||||
|
if self._item.alignment() & QtCore.Qt.AlignLeft:
|
||||||
|
x = self.margin
|
||||||
|
elif self._item.alignment() & QtCore.Qt.AlignRight:
|
||||||
|
x = rect.width() - self.margin - width
|
||||||
|
else:
|
||||||
|
x = self.margin + (available_width - width) / 2
|
||||||
|
widget.setGeometry(rect.x() + x, rect.y() + self.margin, width, height)
|
||||||
|
|
||||||
|
def sizeHint(self):
|
||||||
|
"""
|
||||||
|
Overridden Qt method
|
||||||
|
"""
|
||||||
|
margins = 2 * self.margin
|
||||||
|
return self._item.sizeHint() + QtCore.QSize(margins, margins) \
|
||||||
|
if self._item else QtCore.QSize(margins, margins)
|
||||||
|
|
||||||
|
def minimumSize(self):
|
||||||
|
"""
|
||||||
|
Overridden Qt method
|
||||||
|
"""
|
||||||
|
margins = 2 * self.margin
|
||||||
|
return self._item.minimumSize() + QtCore.QSize(margins, margins) \
|
||||||
|
if self._item else QtCore.QSize(margins, margins)
|
Loading…
Reference in New Issue