mirror of
https://github.com/iperov/DeepFaceLive
synced 2025-08-20 05:23:23 -07:00
qt refactoring
This commit is contained in:
parent
60cd65a97e
commit
225c234076
8 changed files with 48 additions and 47 deletions
|
@ -87,11 +87,8 @@ class QLiveSwap(qtx.QXWidget):
|
|||
(qtx.QXWidgetVBox([self.q_ds_merged_frame_viewer], fixed_width=256), qtx.AlignTop),
|
||||
], spacing=5, size_policy=('fixed', 'fixed') )
|
||||
|
||||
self.setLayout(qtx.QXVBoxLayout(
|
||||
[ (qtx.QXWidgetVBox([(q_nodes, qtx.AlignTop),
|
||||
(q_view_nodes, qtx.AlignHCenter), ], spacing=5), qtx.AlignCenter),
|
||||
]))
|
||||
|
||||
self.setLayout(qtx.QXVBoxLayout( [ (qtx.QXWidgetVBox([q_nodes, q_view_nodes], spacing=5), qtx.AlignCenter) ]))
|
||||
|
||||
self._timer = qtx.QXTimer(interval=5, timeout=self._on_timer_5ms, start=True)
|
||||
|
||||
def _process_messages(self):
|
||||
|
@ -139,7 +136,7 @@ class QDFLAppWindow(qtx.QXWindow):
|
|||
menu_language = menu_bar.addMenu( L('@QDFLAppWindow.language') )
|
||||
|
||||
menu_file_action_reinitialize = menu_file.addAction( L('@QDFLAppWindow.reinitialize') )
|
||||
menu_file_action_reinitialize.triggered.connect(lambda: qtx.QXMainApplication.get_singleton().reinitialize() )
|
||||
menu_file_action_reinitialize.triggered.connect(lambda: qtx.QXMainApplication.inst.reinitialize() )
|
||||
|
||||
menu_file_action_reset_settings = menu_file.addAction( L('@QDFLAppWindow.reset_modules_settings') )
|
||||
menu_file_action_reset_settings.triggered.connect(self._on_reset_modules_settings)
|
||||
|
@ -148,13 +145,13 @@ class QDFLAppWindow(qtx.QXWindow):
|
|||
menu_file_action_quit.triggered.connect(lambda: qtx.QXMainApplication.quit() )
|
||||
|
||||
menu_language_action_english = menu_language.addAction('English' )
|
||||
menu_language_action_english.triggered.connect(lambda: (qtx.QXMainApplication.get_singleton().set_language('en-US'), qtx.QXMainApplication.get_singleton().reinitialize()) )
|
||||
menu_language_action_english.triggered.connect(lambda: (qtx.QXMainApplication.inst.set_language('en-US'), qtx.QXMainApplication.inst.reinitialize()) )
|
||||
|
||||
menu_language_action_russian = menu_language.addAction('Русский')
|
||||
menu_language_action_russian.triggered.connect(lambda: (qtx.QXMainApplication.get_singleton().set_language('ru-RU'), qtx.QXMainApplication.get_singleton().reinitialize()) )
|
||||
menu_language_action_russian.triggered.connect(lambda: (qtx.QXMainApplication.inst.set_language('ru-RU'), qtx.QXMainApplication.inst.reinitialize()) )
|
||||
|
||||
menu_language_action_chinesse = menu_language.addAction('汉语')
|
||||
menu_language_action_chinesse.triggered.connect(lambda: (qtx.QXMainApplication.get_singleton().set_language('zh-CN'), qtx.QXMainApplication.get_singleton().reinitialize()) )
|
||||
menu_language_action_chinesse.triggered.connect(lambda: (qtx.QXMainApplication.inst.set_language('zh-CN'), qtx.QXMainApplication.inst.reinitialize()) )
|
||||
|
||||
menu_help = menu_bar.addMenu( L('@QDFLAppWindow.help') )
|
||||
menu_help_action_github = menu_help.addAction( L('@QDFLAppWindow.visit_github_page') )
|
||||
|
@ -188,13 +185,13 @@ class QDFLAppWindow(qtx.QXWindow):
|
|||
def _on_reset_modules_settings(self):
|
||||
if self.q_live_swap is not None:
|
||||
self.q_live_swap.clear_backend_db()
|
||||
qtx.QXMainApplication.get_singleton().reinitialize()
|
||||
qtx.QXMainApplication.inst.reinitialize()
|
||||
|
||||
def _on_cb_process_priority_choice(self, prio : lib_os.ProcessPriority, _):
|
||||
lib_os.set_process_priority(prio)
|
||||
|
||||
if self.q_live_swap is not None:
|
||||
qtx.QXMainApplication.get_singleton().reinitialize()
|
||||
qtx.QXMainApplication.inst.reinitialize()
|
||||
|
||||
def finalize(self):
|
||||
self.q_live_swap.finalize()
|
||||
|
@ -202,10 +199,6 @@ class QDFLAppWindow(qtx.QXWindow):
|
|||
def _on_closeEvent(self):
|
||||
self.finalize()
|
||||
|
||||
class QDeepFaceLiveSplashWindow(qtx.QXSplashWindow):
|
||||
def __init__(self):
|
||||
super().__init__(layout=qtx.QXVBoxLayout([ (qtx.QXLabel(image=QXImageDB.splash_deepfacelive()), qtx.AlignCenter)
|
||||
], contents_margins=20))
|
||||
|
||||
class DeepFaceLiveApp(qtx.QXMainApplication):
|
||||
def __init__(self, userdata_path):
|
||||
|
@ -218,13 +211,15 @@ class DeepFaceLiveApp(qtx.QXMainApplication):
|
|||
self.setFont( QXFontDB.get_default_font() )
|
||||
self.setWindowIcon( QXImageDB.app_icon().as_QIcon() )
|
||||
|
||||
splash_wnd = self.splash_wnd = QDeepFaceLiveSplashWindow()
|
||||
splash_wnd = self.splash_wnd =\
|
||||
qtx.QXSplashWindow(layout=qtx.QXVBoxLayout([ (qtx.QXLabel(image=QXImageDB.splash_deepfacelive()), qtx.AlignCenter)
|
||||
], contents_margins=20))
|
||||
splash_wnd.show()
|
||||
splash_wnd.center_on_screen()
|
||||
|
||||
self._dfl_wnd = None
|
||||
self.initialize()
|
||||
self._t = qtx.QXTimer(interval=1666, timeout=self._on_splash_wnd_expired, single_shot=True, start=True)
|
||||
self.initialize()
|
||||
|
||||
def on_reinitialize(self):
|
||||
self.finalize()
|
||||
|
|
|
@ -77,7 +77,7 @@ class QLabelPopupInfo(qtx.QXWidget):
|
|||
if label_widget.isHidden():
|
||||
label_widget = self._info_btn
|
||||
|
||||
screen_size = qtx.QXMainApplication.get_singleton().primaryScreen().size()
|
||||
screen_size = qtx.QXMainApplication.inst.primaryScreen().size()
|
||||
label_size = label_widget.size()
|
||||
global_pt = label_widget.mapToGlobal( qtx.QPoint(0, label_size.height()))
|
||||
popup_wnd_size = popup_wnd.size()
|
||||
|
|
|
@ -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