mirror of
https://github.com/iperov/DeepFaceLive
synced 2025-08-14 18:57:24 -07:00
qt refactoring
This commit is contained in:
parent
9afde06f50
commit
9ef7be4f3a
59 changed files with 632 additions and 890 deletions
|
@ -1,3 +1,22 @@
|
|||
from PyQt6.QtCore import *
|
||||
from PyQt6.QtGui import *
|
||||
from PyQt6.QtWidgets import *
|
||||
|
||||
AlignLeft = Qt.AlignmentFlag.AlignLeft
|
||||
AlignLeading = Qt.AlignmentFlag.AlignLeading
|
||||
AlignRight = Qt.AlignmentFlag.AlignRight
|
||||
AlignTrailing = Qt.AlignmentFlag.AlignTrailing
|
||||
AlignHCenter = Qt.AlignmentFlag.AlignHCenter
|
||||
AlignJustify = Qt.AlignmentFlag.AlignJustify
|
||||
AlignAbsolute = Qt.AlignmentFlag.AlignAbsolute
|
||||
AlignHorizontal_Mask = Qt.AlignmentFlag.AlignHorizontal_Mask
|
||||
AlignTop = Qt.AlignmentFlag.AlignTop
|
||||
AlignBottom = Qt.AlignmentFlag.AlignBottom
|
||||
AlignVCenter = Qt.AlignmentFlag.AlignVCenter
|
||||
AlignVertical_Mask = Qt.AlignmentFlag.AlignVertical_Mask
|
||||
AlignCenter = Qt.AlignmentFlag.AlignCenter
|
||||
AlignBaseline = Qt.AlignmentFlag.AlignBaseline
|
||||
|
||||
from .core.QXTimeLine import QXTimeLine
|
||||
from .core.QXTimer import QXTimer
|
||||
from .core.widget import (BlockSignals, disable, enable, hide,
|
||||
|
@ -16,6 +35,8 @@ from .widgets.QXDoubleSpinBox import QXDoubleSpinBox
|
|||
from .widgets.QXFileDialog import QXFileDialog
|
||||
from .widgets.QXFixedLayeredImages import QXFixedLayeredImages
|
||||
from .widgets.QXFrame import QXFrame
|
||||
from .widgets.QXFrameHBox import QXFrameHBox
|
||||
from .widgets.QXFrameVBox import QXFrameVBox
|
||||
from .widgets.QXGridLayout import QXGridLayout
|
||||
from .widgets.QXHBoxLayout import QXHBoxLayout
|
||||
from .widgets.QXHorizontalLine import QXHorizontalLine
|
||||
|
@ -24,6 +45,7 @@ from .widgets.QXLineEdit import QXLineEdit
|
|||
from .widgets.QXMainApplication import QXMainApplication
|
||||
from .widgets.QXMenuBar import QXMenuBar
|
||||
from .widgets.QXOpenGLWidget import QXOpenGLWidget
|
||||
from .widgets.QXPopupWindow import QXPopupWindow
|
||||
from .widgets.QXProgressBar import QXProgressBar
|
||||
from .widgets.QXPushButton import QXPushButton
|
||||
from .widgets.QXRadioButton import QXRadioButton
|
||||
|
@ -31,9 +53,12 @@ from .widgets.QXSaveableComboBox import QXSaveableComboBox
|
|||
from .widgets.QXScrollArea import QXScrollArea
|
||||
from .widgets.QXSlider import QXSlider
|
||||
from .widgets.QXSpinBox import QXSpinBox
|
||||
from .widgets.QXSplashWindow import QXSplashWindow
|
||||
from .widgets.QXTextEdit import QXTextEdit
|
||||
from .widgets.QXToolButton import QXToolButton
|
||||
from .widgets.QXVBoxLayout import QXVBoxLayout
|
||||
from .widgets.QXVerticalLine import QXVerticalLine
|
||||
from .widgets.QXWidget import QXWidget
|
||||
from .widgets.QXWidgetHBox import QXWidgetHBox
|
||||
from .widgets.QXWidgetVBox import QXWidgetVBox
|
||||
from .widgets.QXWindow import QXWindow
|
||||
|
|
|
@ -6,17 +6,15 @@ from ._part_QXWidget import _part_QXWidget
|
|||
|
||||
|
||||
class QXCheckBox(QCheckBox, _part_QXWidget):
|
||||
def __init__(self, text=None, color=None, clicked=None, toggled=None, font=None, size_policy=None, hided=False, enabled=True):
|
||||
def __init__(self, text=None, color=None, clicked=None, toggled=None, **kwargs):
|
||||
super().__init__()
|
||||
if text is not None:
|
||||
self.setText(text)
|
||||
|
||||
if color is not None:
|
||||
self.setStyleSheet(f'QCheckBox {{ color: {color};}}')
|
||||
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
_part_QXWidget.connect_signal(clicked, self.clicked)
|
||||
_part_QXWidget.connect_signal(toggled, self.toggled)
|
||||
_part_QXWidget.__init__(self, font=font, size_policy=size_policy, hided=hided, enabled=enabled )
|
||||
if text is not None:
|
||||
self.setText(text)
|
||||
if color is not None:
|
||||
self.setStyleSheet(f'QCheckBox {{ color: {color};}}')
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
|
|
|
@ -7,7 +7,8 @@ from .QXHBoxLayout import QXHBoxLayout
|
|||
from .QXLabel import QXLabel
|
||||
from .QXToolButton import QXToolButton
|
||||
from .QXVBoxLayout import QXVBoxLayout
|
||||
|
||||
from .QXFrameVBox import QXFrameVBox
|
||||
from .QXFrameHBox import QXFrameHBox
|
||||
|
||||
class QXCollapsibleSection(QXFrame):
|
||||
"""
|
||||
|
@ -15,10 +16,8 @@ class QXCollapsibleSection(QXFrame):
|
|||
|
||||
Open/close state is saved to app db.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, title, content_layout, vertical=False, is_opened=True, allow_open_close=True):
|
||||
super().__init__()
|
||||
|
||||
self._is_opened = is_opened
|
||||
self._vertical = vertical
|
||||
|
||||
|
@ -27,10 +26,9 @@ class QXCollapsibleSection(QXFrame):
|
|||
|
||||
label_title = self.label_title = QXLabel(text=title)
|
||||
|
||||
btn = self.btn = QXToolButton(checkable=True)
|
||||
btn = self.btn = QXToolButton(checkable=True, checked=False)
|
||||
btn.setStyleSheet('border: none;')
|
||||
btn.setArrowType(Qt.ArrowType.RightArrow)
|
||||
btn.setChecked(False)
|
||||
|
||||
if allow_open_close:
|
||||
btn.toggled.connect(self.on_btn_toggled)
|
||||
|
@ -38,23 +36,16 @@ class QXCollapsibleSection(QXFrame):
|
|||
frame = self.frame = QXFrame(layout=content_layout, size_policy=(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding), hided=True)
|
||||
|
||||
if vertical:
|
||||
main_l = QXHBoxLayout([ ( QXFrame(layout=
|
||||
QXVBoxLayout([ (btn, Qt.AlignmentFlag.AlignTop),
|
||||
(label_title, Qt.AlignmentFlag.AlignCenter)
|
||||
]),
|
||||
size_policy=(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) ), Qt.AlignmentFlag.AlignTop),
|
||||
|
||||
frame ])
|
||||
main_l = QXHBoxLayout([ ( QXFrameVBox([ (btn, Qt.AlignmentFlag.AlignTop),
|
||||
(label_title, Qt.AlignmentFlag.AlignCenter)
|
||||
], size_policy=('fixed', 'fixed') ), Qt.AlignmentFlag.AlignTop),
|
||||
frame])
|
||||
else:
|
||||
main_l = QXVBoxLayout( [ ( QXFrame(layout=
|
||||
QXHBoxLayout([ (btn, Qt.AlignmentFlag.AlignTop),
|
||||
(label_title, Qt.AlignmentFlag.AlignCenter)
|
||||
]),
|
||||
size_policy=(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) ) , Qt.AlignmentFlag.AlignTop),
|
||||
|
||||
frame])
|
||||
|
||||
self.setLayout(main_l)
|
||||
main_l = QXVBoxLayout( [ ( QXFrameHBox([ (btn, Qt.AlignmentFlag.AlignTop),
|
||||
(label_title, Qt.AlignmentFlag.AlignCenter)
|
||||
], size_policy=('fixed', 'fixed')) , Qt.AlignmentFlag.AlignTop),
|
||||
frame])
|
||||
super().__init__(layout=main_l)
|
||||
|
||||
if self._is_opened:
|
||||
self.open()
|
||||
|
|
|
@ -6,23 +6,11 @@ from ._part_QXWidget import _part_QXWidget
|
|||
from typing import List
|
||||
|
||||
class QXComboBox(QComboBox, _part_QXWidget):
|
||||
def __init__(self, choices : List[str] = None,
|
||||
on_index_changed=None,
|
||||
font=None, tooltip_text=None,
|
||||
minimum_width=None, maximum_width=None, fixed_width=None, minimum_height=None, maximum_height=None, fixed_height=None, size_policy=None, hided=False, enabled=True):
|
||||
def __init__(self, choices : List[str] = None, on_index_changed=None, **kwargs):
|
||||
super().__init__()
|
||||
|
||||
if choices is not None:
|
||||
for choice in choices:
|
||||
self.addItem(choice)
|
||||
|
||||
[ self.addItem(choice) for choice in choices ] if choices is not None else []
|
||||
_part_QXWidget.connect_signal(on_index_changed, self.currentIndexChanged)
|
||||
_part_QXWidget.__init__(self, font=font, tooltip_text=tooltip_text,
|
||||
size_policy=size_policy,
|
||||
minimum_width=minimum_width, maximum_width=maximum_width,
|
||||
minimum_height=minimum_height, maximum_height=maximum_height,
|
||||
fixed_width=fixed_width, fixed_height=fixed_height,
|
||||
hided=hided, enabled=enabled )
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
|
|
|
@ -6,8 +6,11 @@ from ._part_QXWidget import _part_QXWidget
|
|||
|
||||
|
||||
class QXDoubleSpinBox(QDoubleSpinBox, _part_QXWidget):
|
||||
def __init__(self, min=None, max=None, step=None, decimals=None, readonly=False, special_value_text=None, color=None, alignment=None, editingFinished=None, valueChanged=None, font=None, size_policy=None, hided=False, enabled=True):
|
||||
def __init__(self, min=None, max=None, step=None, decimals=None, readonly=False, special_value_text=None, color=None, alignment=None, editingFinished=None, valueChanged=None, **kwargs):
|
||||
super().__init__()
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
_part_QXWidget.connect_signal(editingFinished, self.editingFinished)
|
||||
_part_QXWidget.connect_signal(valueChanged, self.valueChanged)
|
||||
|
||||
if min is not None:
|
||||
self.setMinimum(min)
|
||||
|
@ -27,11 +30,6 @@ class QXDoubleSpinBox(QDoubleSpinBox, _part_QXWidget):
|
|||
if color is not None:
|
||||
self.setStyleSheet(f'QDoubleSpinBox {{ color: {color};}}\n QDoubleSpinBox::disabled {{ color: dark-gray;}}')
|
||||
|
||||
_part_QXWidget.connect_signal(editingFinished, self.editingFinished)
|
||||
_part_QXWidget.connect_signal(valueChanged, self.valueChanged)
|
||||
|
||||
_part_QXWidget.__init__(self, font=font, size_policy=size_policy, hided=hided, enabled=enabled )
|
||||
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
|
|
|
@ -14,10 +14,10 @@ class QXFixedLayeredImages(QXWidget):
|
|||
|
||||
all images must have the same aspect ratio
|
||||
"""
|
||||
def __init__(self, fixed_width, fixed_height):
|
||||
def __init__(self, fwidth, height):
|
||||
super().__init__()
|
||||
self._fixed_width = fixed_width
|
||||
self._fixed_height = fixed_height
|
||||
self._fwidth = fwidth
|
||||
self._height = height
|
||||
self._qp = QPainter()
|
||||
self._images : List = []
|
||||
|
||||
|
@ -44,7 +44,7 @@ class QXFixedLayeredImages(QXWidget):
|
|||
self.update()
|
||||
|
||||
def sizeHint(self):
|
||||
return QSize(self._fixed_width, self._fixed_height)
|
||||
return QSize(self._fwidth, self._height)
|
||||
|
||||
def paintEvent(self, event):
|
||||
super().paintEvent(event)
|
||||
|
@ -53,8 +53,8 @@ class QXFixedLayeredImages(QXWidget):
|
|||
qp.begin(self)
|
||||
qp.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform)
|
||||
|
||||
w = self._fixed_width
|
||||
h = self._fixed_height
|
||||
w = self._fwidth
|
||||
h = self._height
|
||||
|
||||
w_half = w /2
|
||||
h_half = h /2
|
||||
|
|
|
@ -3,18 +3,11 @@ from PyQt6.QtWidgets import *
|
|||
|
||||
from ._part_QXWidget import _part_QXWidget
|
||||
from .QXMainApplication import QXMainApplication
|
||||
from .QXWidget import QXWidget
|
||||
|
||||
|
||||
class QXFrame(QFrame, _part_QXWidget):
|
||||
def __init__(self, bg_color=None, layout=None, minimum_width=None, maximum_width=None, fixed_width=None, minimum_height=None, maximum_height=None, fixed_height=None, size_policy=None, hided=False, enabled=True):
|
||||
QFrame.__init__(self)
|
||||
|
||||
_part_QXWidget.__init__(self, layout=layout,
|
||||
size_policy=size_policy,
|
||||
minimum_width=minimum_width, maximum_width=maximum_width,
|
||||
minimum_height=minimum_height, maximum_height=maximum_height,
|
||||
fixed_width=fixed_width, fixed_height=fixed_height,
|
||||
hided=hided, enabled=enabled )
|
||||
class QXFrame(QXWidget):
|
||||
def __init__(self, bg_color=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
pal = QXMainApplication.get_singleton().palette()
|
||||
|
||||
|
@ -37,10 +30,7 @@ class QXFrame(QFrame, _part_QXWidget):
|
|||
_part_QXWidget.resizeEvent(self, ev)
|
||||
|
||||
def paintEvent(self, ev : QPaintEvent):
|
||||
rect = self.rect()
|
||||
qp = self._qp
|
||||
qp.begin(self)
|
||||
|
||||
qp.fillRect(rect, self._bg_color )
|
||||
|
||||
qp.fillRect(self.rect(), self._bg_color )
|
||||
qp.end()
|
||||
|
|
9
xlib/qt/widgets/QXFrameHBox.py
Normal file
9
xlib/qt/widgets/QXFrameHBox.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from PyQt6.QtGui import *
|
||||
from PyQt6.QtWidgets import *
|
||||
|
||||
from .QXFrame import QXFrame
|
||||
from .QXHBoxLayout import QXHBoxLayout
|
||||
|
||||
class QXFrameHBox(QXFrame):
|
||||
def __init__(self, widgets=None, contents_margins=0, spacing=0, **kwargs):
|
||||
super().__init__(layout=QXHBoxLayout(widgets=widgets, contents_margins=contents_margins, spacing=spacing), **kwargs)
|
9
xlib/qt/widgets/QXFrameVBox.py
Normal file
9
xlib/qt/widgets/QXFrameVBox.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from PyQt6.QtGui import *
|
||||
from PyQt6.QtWidgets import *
|
||||
|
||||
from .QXFrame import QXFrame
|
||||
from .QXVBoxLayout import QXVBoxLayout
|
||||
|
||||
class QXFrameVBox(QXFrame):
|
||||
def __init__(self, widgets=None, contents_margins=0, spacing=0, **kwargs):
|
||||
super().__init__(layout=QXVBoxLayout(widgets=widgets, contents_margins=contents_margins, spacing=spacing), **kwargs)
|
|
@ -8,6 +8,6 @@ class QXHorizontalLine(QXLabel):
|
|||
color=None):
|
||||
|
||||
super().__init__(size_policy=(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed),
|
||||
fixed_height=thickness )
|
||||
fixed_size=(None,thickness) )
|
||||
if color is not None:
|
||||
self.setStyleSheet(f'background: {color};')
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Union, Any
|
||||
from typing import Any, Union
|
||||
|
||||
from PyQt6.QtCore import *
|
||||
from PyQt6.QtGui import *
|
||||
|
@ -9,22 +9,14 @@ from ._part_QXWidget import _part_QXWidget
|
|||
|
||||
|
||||
class QXLabel(QLabel, _part_QXWidget):
|
||||
def __init__(self, text = None,
|
||||
color = None,
|
||||
image : QXImage = None,
|
||||
movie = None,
|
||||
word_wrap = False, scaled_contents = False,
|
||||
|
||||
font=None, tooltip_text=None,
|
||||
size_policy=None,
|
||||
minimum_size=None, minimum_width=None, minimum_height=None,
|
||||
maximum_size=None, maximum_width=None, maximum_height=None,
|
||||
fixed_size=None, fixed_width=None, fixed_height=None,
|
||||
hided=False, enabled=True
|
||||
):
|
||||
|
||||
def __init__(self, text = None,
|
||||
color = None,
|
||||
image : QXImage = None,
|
||||
movie = None,
|
||||
word_wrap = False, scaled_contents = False,
|
||||
**kwargs):
|
||||
super().__init__()
|
||||
self._default_pal = QPalette( self.palette() )
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
|
||||
if text is not None:
|
||||
self.setText(text)
|
||||
|
@ -36,15 +28,10 @@ class QXLabel(QLabel, _part_QXWidget):
|
|||
self.setWordWrap(True)
|
||||
|
||||
self.setScaledContents(scaled_contents)
|
||||
|
||||
self._default_pal = QPalette( self.palette() )
|
||||
self.set_color(color)
|
||||
|
||||
_part_QXWidget.__init__(self, font=font, tooltip_text=tooltip_text,
|
||||
size_policy=size_policy,
|
||||
minimum_size=minimum_size, minimum_width=minimum_width, minimum_height=minimum_height,
|
||||
maximum_size=maximum_size, maximum_width=maximum_width, maximum_height=maximum_height,
|
||||
fixed_size=fixed_size, fixed_width=fixed_width, fixed_height=fixed_height,
|
||||
hided=hided, enabled=enabled )
|
||||
|
||||
def _update_color(self):
|
||||
if self._color is not None:
|
||||
pal = QPalette(self._default_pal)
|
||||
|
@ -53,18 +40,15 @@ class QXLabel(QLabel, _part_QXWidget):
|
|||
else:
|
||||
self.setPalette(self._default_pal)
|
||||
|
||||
|
||||
def set_color(self, color : Union[Any,None] ):
|
||||
self._color = QColor(color) if color is not None else None
|
||||
self._update_color()
|
||||
|
||||
def changeEvent(self, ev : QEvent):
|
||||
super().changeEvent(ev)
|
||||
|
||||
if ev.type() == QEvent.Type.EnabledChange:
|
||||
self._update_color()
|
||||
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
_part_QXWidget.focusInEvent(self, ev)
|
||||
|
|
|
@ -10,20 +10,18 @@ class QXLineEdit(QLineEdit, _part_QXWidget):
|
|||
style_sheet=None,
|
||||
read_only=False,
|
||||
editingFinished=None,
|
||||
font=None, size_policy=None, hided=False, enabled=True):
|
||||
|
||||
**kwargs):
|
||||
super().__init__()
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
_part_QXWidget.connect_signal(editingFinished, self.editingFinished)
|
||||
|
||||
if placeholder_text is not None:
|
||||
self.setPlaceholderText(placeholder_text)
|
||||
|
||||
if style_sheet is not None:
|
||||
self.setStyleSheet(style_sheet)
|
||||
if read_only:
|
||||
self.setReadOnly(True)
|
||||
|
||||
_part_QXWidget.connect_signal(editingFinished, self.editingFinished)
|
||||
_part_QXWidget.__init__(self, font=font, size_policy=size_policy, hided=hided, enabled=enabled )
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
_part_QXWidget.focusInEvent(self, ev)
|
||||
|
|
|
@ -5,17 +5,9 @@ from ._part_QXWidget import _part_QXWidget
|
|||
|
||||
|
||||
class QXMenuBar(QMenuBar, _part_QXWidget):
|
||||
def __init__(self,
|
||||
font=None, size_policy=None, minimum_width=None, maximum_width=None, fixed_width=None, minimum_height=None, maximum_height=None, fixed_height=None, hided=False, enabled=True):
|
||||
def __init__(self, **kwargs):
|
||||
QMenuBar.__init__(self)
|
||||
|
||||
_part_QXWidget.__init__(self, font=font,
|
||||
size_policy=size_policy,
|
||||
minimum_width=minimum_width, maximum_width=maximum_width,
|
||||
minimum_height=minimum_height, maximum_height=maximum_height,
|
||||
fixed_width=fixed_width, fixed_height=fixed_height,
|
||||
hided=hided, enabled=enabled )
|
||||
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
self.setStyleSheet(f"""
|
||||
QMenuBar {{
|
||||
border: 0px;
|
||||
|
|
|
@ -5,43 +5,13 @@ from PyQt6.QtWidgets import *
|
|||
|
||||
from ._part_QXWidget import _part_QXWidget
|
||||
|
||||
_size_policy_from_str = {
|
||||
'fixed' : QSizePolicy.Policy.Fixed,
|
||||
'minimum' : QSizePolicy.Policy.Minimum,
|
||||
'maximum' : QSizePolicy.Policy.Maximum,
|
||||
'preferred' : QSizePolicy.Policy.Preferred,
|
||||
'minimumexpanding' : QSizePolicy.Policy.MinimumExpanding,
|
||||
'expanding' : QSizePolicy.Policy.Expanding,
|
||||
'ignored' : QSizePolicy.Policy.Ignored,
|
||||
}
|
||||
|
||||
class QXOpenGLWidget(QOpenGLWidget, _part_QXWidget):
|
||||
def __init__(self,
|
||||
font=None, tooltip_text=None,
|
||||
size_policy=None,
|
||||
minimum_size=None, minimum_width=None, minimum_height=None,
|
||||
maximum_size=None, maximum_width=None, maximum_height=None,
|
||||
fixed_size=None, fixed_width=None, fixed_height=None,
|
||||
hided=False, enabled=True
|
||||
):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__()
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
self._default_pal = QPalette( self.palette() )
|
||||
|
||||
if size_policy is not None:
|
||||
x1, x2 = size_policy
|
||||
if isinstance(x1, str):
|
||||
x1 = _size_policy_from_str[x1.lower()]
|
||||
if isinstance(x2, str):
|
||||
x2 = _size_policy_from_str[x2.lower()]
|
||||
size_policy = (x1, x2)
|
||||
|
||||
_part_QXWidget.__init__(self, font=font, tooltip_text=tooltip_text,
|
||||
size_policy=size_policy,
|
||||
minimum_size=minimum_size, minimum_width=minimum_width, minimum_height=minimum_height,
|
||||
maximum_size=maximum_size, maximum_width=maximum_width, maximum_height=maximum_height,
|
||||
fixed_size=fixed_size, fixed_width=fixed_width, fixed_height=fixed_height,
|
||||
hided=hided, enabled=enabled )
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
_part_QXWidget.focusInEvent(self, ev)
|
||||
|
|
13
xlib/qt/widgets/QXPopupWindow.py
Normal file
13
xlib/qt/widgets/QXPopupWindow.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from PyQt6.QtCore import *
|
||||
from PyQt6.QtGui import *
|
||||
from PyQt6.QtWidgets import *
|
||||
from .QXWindow import QXWindow
|
||||
|
||||
class QXPopupWindow(QXWindow):
|
||||
def __init__(self, **kwargs):
|
||||
"""
|
||||
represents top widget which has no parent
|
||||
"""
|
||||
super().__init__(**kwargs)
|
||||
self.setWindowFlags(Qt.WindowType.Popup)
|
||||
|
|
@ -6,18 +6,14 @@ from ._part_QXWidget import _part_QXWidget
|
|||
|
||||
|
||||
class QXProgressBar(QProgressBar, _part_QXWidget):
|
||||
def __init__(self, min=None,
|
||||
max=None,
|
||||
valueChanged=None,
|
||||
font=None, size_policy=None, hided=False, enabled=True, ):
|
||||
|
||||
def __init__(self, min=None, max=None, valueChanged=None, **kwargs):
|
||||
super().__init__()
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
_part_QXWidget.connect_signal(valueChanged, self.valueChanged)
|
||||
if min is not None:
|
||||
self.setMinimum(min)
|
||||
if max is not None:
|
||||
self.setMaximum(max)
|
||||
_part_QXWidget.connect_signal(valueChanged, self.valueChanged)
|
||||
_part_QXWidget.__init__(self, font=font, size_policy=size_policy, hided=hided, enabled=enabled )
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
|
|
|
@ -11,18 +11,16 @@ class QXPushButton(QPushButton, _part_QXWidget):
|
|||
def __init__(self, image : QXImage = None, flat=False,
|
||||
text=None, padding=4, checkable=False,
|
||||
toggled=None, released=None,
|
||||
font=None, tooltip_text=None, size_policy=None,
|
||||
minimum_size=None, minimum_width=None, minimum_height=None,
|
||||
fixed_size=None, fixed_width=None, fixed_height=None, hided=False, enabled=True
|
||||
):
|
||||
**kwargs):
|
||||
super().__init__()
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
_part_QXWidget.connect_signal(released, self.released)
|
||||
_part_QXWidget.connect_signal(toggled, self.toggled)
|
||||
|
||||
self._image = None
|
||||
self._image_sequence = None
|
||||
self._tl = None
|
||||
|
||||
if size_policy is None:
|
||||
size_policy = (QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum)
|
||||
|
||||
if text is not None:
|
||||
self.setText(text)
|
||||
|
||||
|
@ -39,7 +37,6 @@ QPushButton {{
|
|||
padding: {padding}px;
|
||||
}}
|
||||
|
||||
|
||||
QPushButton:hover {{
|
||||
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #434343, stop: 0.3 #515151, stop: 0.6 #515151, stop: 1.0 #434343);
|
||||
|
||||
|
@ -49,16 +46,8 @@ QPushButton:pressed {{
|
|||
}}
|
||||
""")
|
||||
|
||||
|
||||
_part_QXWidget.connect_signal(released, self.released)
|
||||
_part_QXWidget.connect_signal(toggled, self.toggled)
|
||||
_part_QXWidget.__init__(self, font=font, tooltip_text=tooltip_text,
|
||||
size_policy=size_policy, minimum_size=minimum_size, minimum_width=minimum_width, minimum_height=minimum_height,
|
||||
fixed_size=fixed_size, fixed_width=fixed_width, fixed_height=fixed_height,
|
||||
hided=hided, enabled=enabled )
|
||||
|
||||
def sizeHint(self) -> QSize:
|
||||
return QSize(0,0)
|
||||
#def sizeHint(self) -> QSize:
|
||||
# return QSize(0,0)
|
||||
|
||||
def setText(self, text):
|
||||
QPushButton.setText(self, text)
|
||||
|
@ -73,27 +62,30 @@ QPushButton:pressed {{
|
|||
if self._image is not None:
|
||||
rect = self.rect()
|
||||
image = self._image
|
||||
|
||||
w, h = rect.width(), rect.height()
|
||||
rect_aspect = w / h
|
||||
|
||||
size = image.size()
|
||||
pixmap_aspect = size.width() / size.height()
|
||||
if h != 0:
|
||||
rect_aspect = w / h
|
||||
|
||||
if pixmap_aspect != rect_aspect:
|
||||
if pixmap_aspect > rect_aspect:
|
||||
pw, ph = w, int(h * (rect_aspect / pixmap_aspect))
|
||||
px, py = 0, h/2-ph/2
|
||||
elif pixmap_aspect < rect_aspect:
|
||||
pw, ph = int( w * (pixmap_aspect / rect_aspect) ), h
|
||||
px, py = w/2-pw/2, 0
|
||||
else:
|
||||
px, py, pw, ph = 0, 0, w, h
|
||||
self.setIconSize( QSize(pw-4,ph-4) )
|
||||
size = image.size()
|
||||
pixmap_aspect = size.width() / size.height()
|
||||
|
||||
if pixmap_aspect != rect_aspect:
|
||||
if pixmap_aspect > rect_aspect:
|
||||
pw, ph = w, int(h * (rect_aspect / pixmap_aspect))
|
||||
px, py = 0, h/2-ph/2
|
||||
elif pixmap_aspect < rect_aspect:
|
||||
pw, ph = int( w * (pixmap_aspect / rect_aspect) ), h
|
||||
px, py = w/2-pw/2, 0
|
||||
else:
|
||||
px, py, pw, ph = 0, 0, w, h
|
||||
|
||||
self.setIconSize( QSize(pw-4,ph-4) )
|
||||
|
||||
def _set_image(self, image : QXImage ):
|
||||
self._image = image
|
||||
self.setIcon( image.as_QIcon() )
|
||||
self._update_icon_size()
|
||||
|
||||
def set_image(self, image : QXImage ):
|
||||
self.stop_image_sequence()
|
||||
|
@ -128,5 +120,4 @@ QPushButton:pressed {{
|
|||
def resizeEvent(self, ev : QResizeEvent):
|
||||
super().resizeEvent(ev)
|
||||
_part_QXWidget.resizeEvent(self, ev)
|
||||
|
||||
self._update_icon_size()
|
||||
|
|
|
@ -10,8 +10,12 @@ class QXRadioButton(QRadioButton, _part_QXWidget):
|
|||
disabled_color=None,
|
||||
auto_exclusive=False,
|
||||
clicked=None, toggled=None,
|
||||
font=None, size_policy=None, hided=False, enabled=True):
|
||||
**kwargs):
|
||||
super().__init__()
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
_part_QXWidget.connect_signal(clicked, self.clicked)
|
||||
_part_QXWidget.connect_signal(toggled, self.toggled)
|
||||
|
||||
if text is not None:
|
||||
self.setText(text)
|
||||
self.setAutoExclusive(auto_exclusive)
|
||||
|
@ -23,10 +27,6 @@ class QXRadioButton(QRadioButton, _part_QXWidget):
|
|||
if len(style_sheet) != 0:
|
||||
self.setStyleSheet(style_sheet)
|
||||
|
||||
_part_QXWidget.connect_signal(clicked, self.clicked)
|
||||
_part_QXWidget.connect_signal(toggled, self.toggled)
|
||||
_part_QXWidget.__init__(self, font=font, size_policy=size_policy, hided=hided, enabled=enabled )
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
_part_QXWidget.focusInEvent(self, ev)
|
||||
|
|
|
@ -6,14 +6,9 @@ from ._part_QXWidget import _part_QXWidget
|
|||
|
||||
|
||||
class QXScrollArea(QScrollArea, _part_QXWidget):
|
||||
|
||||
def __init__(self,
|
||||
size_policy=None, hided=False, enabled=True):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__()
|
||||
|
||||
|
||||
_part_QXWidget.__init__(self, size_policy=size_policy, hided=hided, enabled=enabled )
|
||||
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
|
|
|
@ -15,11 +15,16 @@ class QXSlider(QSlider, _part_QXWidget):
|
|||
sliderMoved=None,
|
||||
sliderPressed=None,
|
||||
sliderReleased=None,
|
||||
size_policy=None, hided=False, enabled=True):
|
||||
**kwargs):
|
||||
if orientation is not None:
|
||||
super().__init__(orientation)
|
||||
else:
|
||||
super().__init__()
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
_part_QXWidget.connect_signal(valueChanged, self.valueChanged)
|
||||
_part_QXWidget.connect_signal(sliderMoved, self.sliderMoved)
|
||||
_part_QXWidget.connect_signal(sliderPressed, self.sliderPressed)
|
||||
_part_QXWidget.connect_signal(sliderReleased, self.sliderReleased)
|
||||
|
||||
if min is not None:
|
||||
self.setMinimum(min)
|
||||
|
@ -30,13 +35,6 @@ class QXSlider(QSlider, _part_QXWidget):
|
|||
if tick_interval is not None:
|
||||
self.setTickInterval(tick_interval)
|
||||
|
||||
_part_QXWidget.connect_signal(valueChanged, self.valueChanged)
|
||||
_part_QXWidget.connect_signal(sliderMoved, self.sliderMoved)
|
||||
_part_QXWidget.connect_signal(sliderPressed, self.sliderPressed)
|
||||
_part_QXWidget.connect_signal(sliderReleased, self.sliderReleased)
|
||||
_part_QXWidget.__init__(self, size_policy=size_policy, hided=hided, enabled=enabled )
|
||||
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
_part_QXWidget.focusInEvent(self, ev)
|
||||
|
|
|
@ -14,8 +14,13 @@ class QXSpinBox(QSpinBox, _part_QXWidget):
|
|||
alignment=None,
|
||||
button_symbols=None, readonly=False,
|
||||
editingFinished=None, textChanged=None, valueChanged=None,
|
||||
font=None, size_policy=None, hided=False, enabled=True):
|
||||
**kwargs):
|
||||
super().__init__()
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
_part_QXWidget.connect_signal(editingFinished, self.editingFinished)
|
||||
_part_QXWidget.connect_signal(textChanged, self.textChanged)
|
||||
_part_QXWidget.connect_signal(valueChanged, self.valueChanged)
|
||||
|
||||
if min is not None:
|
||||
self.setMinimum(min)
|
||||
if max is not None:
|
||||
|
@ -33,12 +38,6 @@ class QXSpinBox(QSpinBox, _part_QXWidget):
|
|||
if color is not None:
|
||||
self.setStyleSheet(f'QSpinBox {{ color: {color};}}')
|
||||
|
||||
_part_QXWidget.connect_signal(editingFinished, self.editingFinished)
|
||||
_part_QXWidget.connect_signal(textChanged, self.textChanged)
|
||||
_part_QXWidget.connect_signal(valueChanged, self.valueChanged)
|
||||
_part_QXWidget.__init__(self, font=font, size_policy=size_policy, hided=hided, enabled=enabled )
|
||||
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
_part_QXWidget.focusInEvent(self, ev)
|
||||
|
|
13
xlib/qt/widgets/QXSplashWindow.py
Normal file
13
xlib/qt/widgets/QXSplashWindow.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from PyQt6.QtCore import *
|
||||
from PyQt6.QtGui import *
|
||||
from PyQt6.QtWidgets import *
|
||||
from .QXWindow import QXWindow
|
||||
|
||||
class QXSplashWindow(QXWindow):
|
||||
def __init__(self, **kwargs):
|
||||
"""
|
||||
represents top widget which has no parent
|
||||
"""
|
||||
super().__init__(**kwargs)
|
||||
self.setWindowFlags(Qt.WindowType.SplashScreen)
|
||||
|
|
@ -9,31 +9,17 @@ class QXTextEdit(QTextEdit, _part_QXWidget):
|
|||
def __init__(self, placeholder_text=None,
|
||||
style_sheet=None,
|
||||
read_only=False,
|
||||
|
||||
font=None, tooltip_text=None,
|
||||
size_policy=None,
|
||||
minimum_size=None, minimum_width=None, minimum_height=None,
|
||||
maximum_size=None, maximum_width=None, maximum_height=None,
|
||||
fixed_size=None, fixed_width=None, fixed_height=None,
|
||||
hided=False, enabled=True
|
||||
):
|
||||
|
||||
**kwargs):
|
||||
super().__init__()
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
#_part_QXWidget.connect_signal(editingFinished, self.editingFinished)
|
||||
|
||||
if placeholder_text is not None:
|
||||
self.setPlaceholderText(placeholder_text)
|
||||
|
||||
if style_sheet is not None:
|
||||
self.setStyleSheet(style_sheet)
|
||||
if read_only:
|
||||
self.setReadOnly(True)
|
||||
self.setWordWrapMode
|
||||
#_part_QXWidget.connect_signal(editingFinished, self.editingFinished)
|
||||
_part_QXWidget.__init__(self, font=font, tooltip_text=tooltip_text,
|
||||
size_policy=size_policy,
|
||||
minimum_size=minimum_size, minimum_width=minimum_width, minimum_height=minimum_height,
|
||||
maximum_size=maximum_size, maximum_width=maximum_width, maximum_height=maximum_height,
|
||||
fixed_size=fixed_size, fixed_width=fixed_width, fixed_height=fixed_height,
|
||||
hided=hided, enabled=enabled )
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
|
|
|
@ -6,22 +6,22 @@ from ._part_QXWidget import _part_QXWidget
|
|||
|
||||
|
||||
class QXToolButton(QToolButton, _part_QXWidget):
|
||||
|
||||
def __init__(self, text=None,
|
||||
checkable=False,
|
||||
checked=None,
|
||||
toggled=None, released=None,
|
||||
font=None, size_policy=None, hided=False, enabled=True):
|
||||
**kwargs):
|
||||
super().__init__()
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
_part_QXWidget.connect_signal(released, self.released)
|
||||
_part_QXWidget.connect_signal(toggled, self.toggled)
|
||||
|
||||
if text is not None:
|
||||
self.setText(text)
|
||||
|
||||
self.setCheckable(checkable)
|
||||
|
||||
_part_QXWidget.connect_signal(released, self.released)
|
||||
_part_QXWidget.connect_signal(toggled, self.toggled)
|
||||
_part_QXWidget.__init__(self, font=font, size_policy=size_policy, hided=hided, enabled=enabled )
|
||||
|
||||
if checked is not None:
|
||||
self.setChecked(checked)
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
|
|
|
@ -6,6 +6,6 @@ from .QXLabel import QXLabel
|
|||
class QXVerticalLine(QXLabel):
|
||||
def __init__(self, thickness=1, color=None):
|
||||
super().__init__(size_policy=(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Expanding),
|
||||
fixed_width=thickness)
|
||||
fixed_size=(thickness,None) )
|
||||
if color is not None:
|
||||
self.setStyleSheet(f'background: {color.name()};')
|
||||
|
|
|
@ -6,20 +6,11 @@ from ._part_QXWidget import _part_QXWidget
|
|||
|
||||
|
||||
class QXWidget(QWidget, _part_QXWidget):
|
||||
"""
|
||||
|
||||
"""
|
||||
def __init__(self, layout=None, font=None, tooltip_text=None,
|
||||
minimum_width=None, maximum_width=None, fixed_width=None, minimum_height=None, maximum_height=None, fixed_height=None, size_policy=None, hided=False, enabled=True):
|
||||
def __init__(self, **kwargs):
|
||||
"""
|
||||
"""
|
||||
super().__init__()
|
||||
|
||||
|
||||
_part_QXWidget.__init__(self, layout=layout, font=font, tooltip_text=tooltip_text,
|
||||
size_policy=size_policy,
|
||||
minimum_width=minimum_width, maximum_width=maximum_width,
|
||||
minimum_height=minimum_height, maximum_height=maximum_height,
|
||||
fixed_width=fixed_width, fixed_height=fixed_height,
|
||||
hided=hided, enabled=enabled )
|
||||
_part_QXWidget.__init__(self, **kwargs)
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
super().focusInEvent(ev)
|
||||
|
|
9
xlib/qt/widgets/QXWidgetHBox.py
Normal file
9
xlib/qt/widgets/QXWidgetHBox.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from PyQt6.QtGui import *
|
||||
from PyQt6.QtWidgets import *
|
||||
|
||||
from .QXWidget import QXWidget
|
||||
from .QXHBoxLayout import QXHBoxLayout
|
||||
|
||||
class QXWidgetHBox(QXWidget):
|
||||
def __init__(self, widgets=None, contents_margins=0, spacing=0, **kwargs):
|
||||
super().__init__(layout=QXHBoxLayout(widgets=widgets, contents_margins=contents_margins, spacing=spacing), **kwargs)
|
9
xlib/qt/widgets/QXWidgetVBox.py
Normal file
9
xlib/qt/widgets/QXWidgetVBox.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from PyQt6.QtGui import *
|
||||
from PyQt6.QtWidgets import *
|
||||
|
||||
from .QXWidget import QXWidget
|
||||
from .QXVBoxLayout import QXVBoxLayout
|
||||
|
||||
class QXWidgetVBox(QXWidget):
|
||||
def __init__(self, widgets=None, contents_margins=0, spacing=0, **kwargs):
|
||||
super().__init__(layout=QXVBoxLayout(widgets=widgets, contents_margins=contents_margins, spacing=spacing), **kwargs)
|
|
@ -9,15 +9,11 @@ from .QXWidget import QXWidget
|
|||
|
||||
|
||||
class QXWindow(QXWidget):
|
||||
"""
|
||||
represents top widget which has no parent
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, save_load_state=False,
|
||||
size_policy=None):
|
||||
|
||||
super().__init__(size_policy=size_policy)
|
||||
def __init__(self, save_load_state=False, **kwargs):
|
||||
"""
|
||||
represents top widget which has no parent
|
||||
"""
|
||||
super().__init__(**kwargs)
|
||||
self._save_load_state = save_load_state
|
||||
|
||||
#QXMainApplication.get_singleton().register_QXWindow(self)
|
||||
|
|
|
@ -1,18 +1,28 @@
|
|||
from PyQt6.QtCore import *
|
||||
from PyQt6.QtGui import *
|
||||
from PyQt6.QtWidgets import *
|
||||
|
||||
from ..core.widget import BlockSignals
|
||||
from .QXMainApplication import QXMainApplication
|
||||
|
||||
_size_policy_from_str = {
|
||||
'fixed' : QSizePolicy.Policy.Fixed,
|
||||
'minimum' : QSizePolicy.Policy.Minimum,
|
||||
'maximum' : QSizePolicy.Policy.Maximum,
|
||||
'preferred' : QSizePolicy.Policy.Preferred,
|
||||
'minimumexpanding' : QSizePolicy.Policy.MinimumExpanding,
|
||||
'expanding' : QSizePolicy.Policy.Expanding,
|
||||
'ignored' : QSizePolicy.Policy.Ignored,
|
||||
}
|
||||
|
||||
class _part_QXWidget:
|
||||
def __init__(self, layout=None,
|
||||
font=None,
|
||||
tooltip_text=None,
|
||||
size_policy=None,
|
||||
minimum_size=None, minimum_width=None, minimum_height=None,
|
||||
maximum_size=None, maximum_width=None, maximum_height=None,
|
||||
fixed_size=None, fixed_width=None, fixed_height=None,
|
||||
minimum_width=None, maximum_width=None, fixed_width=None,
|
||||
minimum_height=None, maximum_height=None, fixed_height=None,
|
||||
minimum_size=None, maximum_size=None, fixed_size=None,
|
||||
hided=False, enabled=True):
|
||||
|
||||
self._registered = False
|
||||
|
@ -23,8 +33,16 @@ class _part_QXWidget:
|
|||
self.setFont(font)
|
||||
if tooltip_text is not None:
|
||||
self.setToolTip(tooltip_text)
|
||||
|
||||
if size_policy is not None:
|
||||
x1, x2 = size_policy
|
||||
if isinstance(x1, str):
|
||||
x1 = _size_policy_from_str[x1.lower()]
|
||||
if isinstance(x2, str):
|
||||
x2 = _size_policy_from_str[x2.lower()]
|
||||
size_policy = (x1, x2)
|
||||
self.setSizePolicy(*size_policy)
|
||||
|
||||
if layout is not None:
|
||||
self.setLayout(layout)
|
||||
|
||||
|
@ -41,7 +59,7 @@ class _part_QXWidget:
|
|||
self.setMaximumWidth(maximum_width)
|
||||
if maximum_height is not None:
|
||||
self.setMaximumHeight(maximum_height)
|
||||
|
||||
|
||||
if fixed_size is not None:
|
||||
fixed_width, fixed_height = fixed_size
|
||||
if fixed_width is not None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue