from qtpy import QtCore, QtGui
from ..backend import franktonjunction


class SignalObject(QtCore.QObject):
    def __init__(self, func):
        super().__init__()
        self.signal.connect(func)

    def emit(self, *args):
        self.signal.emit(*args)


class NoTypeSignal(SignalObject):
    signal = QtCore.pyqtSignal()

    def __init__(self, func):
        super().__init__(func)


class IntSignal(SignalObject):
    signal = QtCore.pyqtSignal(int)

    def __init__(self, func):
        super().__init__(func)


class StrSignal(SignalObject):
    signal = QtCore.pyqtSignal(str)

    def __init__(self, func):
        super().__init__(func)


class FontSignal(SignalObject):
    signal = QtCore.pyqtSignal(QtGui.QFont)

    def __init__(self, func):
        super().__init__(func)

class KeyPressEventSignal(SignalObject):
    signal = QtCore.pyqtSignal(QtGui.QKeyEvent)

    def __init__(self, func):
        super().__init__(func)

# Need to add
# Signals from threads.
# Editor (lots of them)

QuitSignal = NoTypeSignal(franktonjunction.handle_quit)
TabCloseSignal = IntSignal(franktonjunction.tabclose)
NewCurrentIdSignal = IntSignal(franktonjunction.newcurrentid)
OpenPathSignal = StrSignal(franktonjunction.open)
SetFontSignal = FontSignal(franktonjunction.set_font)
SetThemeSignal = StrSignal(franktonjunction.set_theme)
NewEditorSignal = NoTypeSignal(franktonjunction.want_new_editor)
BlockFormatSignal = StrSignal(franktonjunction.block_state)
EditorKeyPressSignal = KeyPressEventSignal(franktonjunction.editor_key_pressed)
