1
0
Fork 0
mirror of synced 2024-06-22 04:20:25 +12:00

IndicatorLineEdit: Wrap edit_func inside the QRunnable

This commit is contained in:
Stelios Tsampas 2023-03-15 18:25:32 +02:00
parent 07c64b8b9b
commit dc20293abb
2 changed files with 15 additions and 10 deletions

View file

@ -86,6 +86,8 @@ class MoveGamePopUp(QWidget):
def path_edit_callback(self, path: str) -> Tuple[bool, str, int]:
self.button.setEnabled(True)
self.warn_label.setHidden(False)
self.req_space.setText("...")
self.avail_space.setText("...")
def helper_func(reason: int) -> Tuple[bool, str, int]:
self.button.setEnabled(False)

View file

@ -98,7 +98,7 @@ class EditFuncRunnable(QRunnable):
super(EditFuncRunnable, self).__init__()
self.setAutoDelete(True)
self.signals = EditFuncRunnable.Signals()
self.func = func
self.func = self.__wrap_edit_function(func)
self.args = args
def run(self):
@ -106,6 +106,13 @@ class EditFuncRunnable(QRunnable):
self.signals.result.emit(o0, o1, o2)
self.signals.deleteLater()
@staticmethod
def __wrap_edit_function(func: Callable[[str], Tuple[bool, str, int]]):
if func:
return lambda text: func(os.path.expanduser(text) if text.startswith("~") else text)
else:
return func
class IndicatorLineEdit(QWidget):
textChanged = pyqtSignal(str)
@ -171,6 +178,11 @@ class IndicatorLineEdit(QWidget):
if text:
self.line_edit.setText(text)
def deleteLater(self) -> None:
if self.__thread is not None:
self.__thread.signals.result.disconnect()
super(IndicatorLineEdit, self).deleteLater()
def text(self) -> str:
return self.line_edit.text()
@ -279,8 +291,6 @@ class PathEdit(IndicatorLineEdit):
self.compl_model.setRootPath(path)
self.completer.setModel(self.compl_model)
edit_func = self.__wrap_edit_function(edit_func)
super(PathEdit, self).__init__(
text=path,
placeholder=placeholder,
@ -319,10 +329,3 @@ class PathEdit(IndicatorLineEdit):
names = dlg.selectedFiles()
self.line_edit.setText(names[0])
self.compl_model.setRootPath(names[0])
@staticmethod
def __wrap_edit_function(func: Callable[[str], Tuple[bool, str, int]]):
if func:
return lambda text: func(os.path.expanduser(text) if text.startswith("~") else text)
else:
return func