# for qtdragon:
# put/rename the file in YOUR CONFIG/qtvcp/screens/qtdragon/qtdragon_handler.py
# for qtdragon_hd:
# put/rename the file in YOUR CONFIG/qtvcp/screens/qtdragon_hd/qtdragon_hd_handler.py

import sys
import importlib
from qtvcp.core import Path, Qhal, Action, Status

PATH = Path()
QHAL = Qhal()
ACTION = Action()
STATUS = Status()

# get reference to original handler file so we can subclass it
sys.path.insert(0, PATH.SCREENDIR)
module = "{}.{}_handler".format(PATH.BASEPATH,PATH.BASEPATH)
#print(PATH.SCREENDIR,module)
#print('->',PATH.modnamefromFilename(__file__))
mod = importlib.import_module(module, PATH.SCREENDIR)
sys.path.remove(PATH.SCREENDIR)
HandlerClass = mod.HandlerClass

# return our subclassed handler object
def get_handlers(halcomp, widgets, paths):
    return [UserHandlerClass(halcomp, widgets, paths)]

class UserHandlerClass(HandlerClass):
    print('Custom (override limits with F5) subclassed handler loaded\n')

    def initialized__(self):
        super().initialized__()
        self.KEYBIND.add_call('Key_F5','on_keycall_F5')

    def on_keycall_F5(self,event,state,shift,cntrl):
        if state:
            temp = not self.w.chk_override_limits.isChecked()
            self.w.chk_override_limits.setChecked(temp)
