# 3/1/2024
# Credits to cmorley, many thanks!
# Personal touch and Tested by PoolCNC
# this module creates the necesarry HAL pins 
# - for overriding the sliders with analog values
# - for overriding the SLOW/FAST button for linear and angular movent
# - for jogging axis X, Y, Z, A, B, C with digital inputs
# in QtDragon(_hd)
# put/rename the file in YOUR CONFIG/qtvcp/screens/qtdragon/qtdragon_handler.py
# 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
from qtvcp.widgets.dialog_widget import ToolDialog as TD 

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

class CustomToolDialog(TD):
     def __init__(self, parent=None):
        super(CustomToolDialog, self).__init__(parent)
        self._title ='Custom Tool Dialog'

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

class UserHandlerClass(HandlerClass):
    print('Custom tool dialog subclassed handler loaded\n')

    def pre_hal_init__(self):
        self.w.screen_options.add_tool_dialog = False
        self.w.toolDialog_ = CustomToolDialog(self.w)
        self.w.toolDialog_.setObjectName('toolDialog_')
        self.w.toolDialog_.setProperty('useDesktopNotify', False)
        self.w.toolDialog_.setProperty('frameless', False)

