mirror of
https://github.com/iperov/DeepFaceLive
synced 2025-08-21 22:13:21 -07:00
qt refactoring
This commit is contained in:
parent
60cd65a97e
commit
225c234076
8 changed files with 48 additions and 47 deletions
|
@ -6,18 +6,17 @@ from ..io import FormattedFileIO
|
|||
|
||||
|
||||
class KeyValueDB:
|
||||
"""
|
||||
Simple key/value database.
|
||||
|
||||
each key/value pickled/unpickled separately,
|
||||
thus unpickling error will not corrupt whole db
|
||||
|
||||
filepath(None) if None, DB will not be saved on disk
|
||||
"""
|
||||
|
||||
_KeyValueDB_VERSION = 1
|
||||
|
||||
def __init__(self, filepath = None):
|
||||
"""
|
||||
Simple key/value database.
|
||||
|
||||
each key/value pickled/unpickled separately,
|
||||
thus unpickling error will not corrupt whole db
|
||||
|
||||
filepath(None) if None, DB will not be saved on disk
|
||||
"""
|
||||
self._filepath = Path(filepath) if filepath is not None else None
|
||||
self._save_timestamp = None
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class QXFrame(QXWidget):
|
|||
def __init__(self, bg_color=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
pal = QXMainApplication.get_singleton().palette()
|
||||
pal = QXMainApplication.inst.palette()
|
||||
|
||||
if bg_color is not None:
|
||||
bg_color = QColor(bg_color)
|
||||
|
|
|
@ -10,14 +10,6 @@ from .forward_declarations import forward_declarations
|
|||
|
||||
|
||||
class QXMainApplication(QApplication):
|
||||
"""
|
||||
base class for MainApplication
|
||||
|
||||
QXMainApplication.inst - singleton instance
|
||||
|
||||
settings_dirpath(None) where the data will be saved
|
||||
"""
|
||||
|
||||
inst : 'QXMainApplication' = None
|
||||
|
||||
@staticmethod
|
||||
|
@ -27,6 +19,13 @@ class QXMainApplication(QApplication):
|
|||
return QXMainApplication.inst
|
||||
|
||||
def __init__(self, app_name=None, settings_dirpath : Path = None):
|
||||
"""
|
||||
base class for MainApplication
|
||||
|
||||
QXMainApplication.inst - singleton instance
|
||||
|
||||
settings_dirpath(None) where the data will be saved
|
||||
"""
|
||||
super().__init__([])
|
||||
|
||||
if QXMainApplication.inst is not None:
|
||||
|
@ -152,6 +151,9 @@ QRadioButton::disabled {{
|
|||
self._app_db.finish_pending_jobs()
|
||||
|
||||
def reinitialize(self):
|
||||
"""
|
||||
start reinitialization of app.
|
||||
"""
|
||||
self._reinitialize = True
|
||||
|
||||
def on_reinitialize(self):
|
||||
|
@ -161,4 +163,8 @@ QRadioButton::disabled {{
|
|||
return self.get_app_data('__app_language', 'en-US')
|
||||
|
||||
def set_language(self, lang : str) -> str:
|
||||
"""
|
||||
lang xx-YY
|
||||
example: en-US ru-RU
|
||||
"""
|
||||
return self.set_app_data('__app_language', lang)
|
|
@ -8,10 +8,11 @@ from .QXMainApplication import QXMainApplication
|
|||
from ..core.widget import BlockSignals
|
||||
|
||||
class QXSaveableComboBox(QXComboBox):
|
||||
"""
|
||||
a saveable QXComboBox
|
||||
"""
|
||||
|
||||
def __init__(self, db_key, choices : Iterable, default_choice, choices_names=None, on_choice_selected = None):
|
||||
"""
|
||||
a saveable QXComboBox
|
||||
"""
|
||||
self._choices = [x for x in choices]
|
||||
self._default_choice = default_choice
|
||||
|
||||
|
@ -27,13 +28,13 @@ class QXSaveableComboBox(QXComboBox):
|
|||
|
||||
super().__init__(choices=choices_names, on_index_changed=self._index_changed)
|
||||
|
||||
self.set_choice( QXMainApplication.get_singleton().get_app_data (db_key) )
|
||||
self.set_choice( QXMainApplication.inst.get_app_data (db_key) )
|
||||
|
||||
def set_choice(self, choice):
|
||||
if choice not in self._choices:
|
||||
choice = self._default_choice
|
||||
|
||||
QXMainApplication.get_singleton().set_app_data(self._db_key, choice)
|
||||
QXMainApplication.inst.set_app_data(self._db_key, choice)
|
||||
|
||||
idx = self._choices.index(choice)
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class QXWindow(QXWidget):
|
|||
super().__init__(**kwargs)
|
||||
self._save_load_state = save_load_state
|
||||
|
||||
#QXMainApplication.get_singleton().register_QXWindow(self)
|
||||
#QXMainApplication.inst.register_QXWindow(self)
|
||||
|
||||
#self.keyPressEvent_listeners = []
|
||||
#self.keyReleaseEvent_listeners = []
|
||||
|
@ -27,7 +27,7 @@ class QXWindow(QXWidget):
|
|||
self.setFocusPolicy(Qt.FocusPolicy.WheelFocus)
|
||||
self._qp = QPainter()
|
||||
|
||||
pal = QXMainApplication.get_singleton().palette()
|
||||
pal = QXMainApplication.inst.palette()
|
||||
self._bg_color = pal.color(QPalette.ColorRole.Window)
|
||||
|
||||
def call_on_closeEvent(self, func_or_list):
|
||||
|
@ -44,7 +44,7 @@ class QXWindow(QXWidget):
|
|||
|
||||
def center_on_screen(self):
|
||||
widget_width, widget_height = self.size().width(), self.size().height()
|
||||
screen_size = QXMainApplication.get_singleton().primaryScreen().size()
|
||||
screen_size = QXMainApplication.inst.primaryScreen().size()
|
||||
|
||||
self.move( (screen_size.width() - widget_width) // 2, (screen_size.height() - widget_height) // 2 )
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ class _part_QXWidget:
|
|||
if not self._registered:
|
||||
return default_value
|
||||
|
||||
return QXMainApplication.get_singleton().get_app_data ( (self._name_id, key), default_value=default_value )
|
||||
return QXMainApplication.inst.get_app_data ( (self._name_id, key), default_value=default_value )
|
||||
|
||||
def set_widget_data(self, key, data):
|
||||
"""
|
||||
|
@ -109,7 +109,7 @@ class _part_QXWidget:
|
|||
|
||||
if widget is not registered, nothing will be happened
|
||||
"""
|
||||
QXMainApplication.get_singleton().set_app_data ( (self._name_id, key), data )
|
||||
QXMainApplication.inst.set_app_data ( (self._name_id, key), data )
|
||||
|
||||
def focusInEvent(self, ev : QFocusEvent):
|
||||
if ev.reason() == Qt.FocusReason.TabFocusReason:
|
||||
|
@ -119,7 +119,7 @@ class _part_QXWidget:
|
|||
def resizeEvent(self, ev : QResizeEvent):
|
||||
if not self._registered:
|
||||
self._registered = True
|
||||
self._name_id = QXMainApplication.get_singleton().register_QXWidget(self)
|
||||
self._name_id = QXMainApplication.inst.register_QXWidget(self)
|
||||
self._on_registered()
|
||||
|
||||
def _on_registered(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue