# Path: pyilper/pilcharconv.py
# def icharconv(i, charset):
#    return convert_to_unicode[charset][i]
# 
# CHARSET_HP71=0
# 
# CHARSET_HP75=2
# 
# CHARSET_HP41=1
# 
# Path: pyilper/pilcore.py
# UPDATE_TIMER=25                 # Poll timer (ms) for terminal output queue
# 
# CURSOR_BLINK=500                # 500 ms cursor blink rate
# 
# TERMINAL_MINIMUM_ROWS=24        # can't get beyond that
# 
# FONT="Monospace"
# 
# AUTOSCROLL_RATE=100             # 500 ms cursor blink rate
# 
# def isMACOS():
#    return platform.system()=="Darwin"
# 
# KEYBOARD_DELAY=500              # autorepeat delay to prevent too fast kbd input
# 
# Path: pyilper/shortcutconfig.py
# SHORTCUTCONFIG=  cls_shortcutconfig()
# 
# SHORTCUT_EXEC=1
# 
# SHORTCUT_EDIT=2
# 
# SHORTCUT_INSERT=3
# 
# Path: pyilper/pilconfig.py
# PILCONFIG=  cls_pilconfig()


import array
import queue
import threading
import time
from PyQt5 import QtCore, QtGui, QtWidgets
from .pilcharconv import icharconv, CHARSET_HP71, CHARSET_HP75, CHARSET_HP41
from .pilcore import UPDATE_TIMER, CURSOR_BLINK, TERMINAL_MINIMUM_ROWS,FONT, AUTOSCROLL_RATE, isMACOS, KEYBOARD_DELAY
from .shortcutconfig import SHORTCUTCONFIG, SHORTCUT_EXEC, SHORTCUT_EDIT, SHORTCUT_INSERT
from .pilconfig import PILCONFIG
from .pilkeymap import *
#                      print("keyboard alt value: ",self._alt_seq_value)
                       self._kbdfunc(self._alt_seq_value)
                    self._alt_sequence= False
              else:
                 self._alt_sequence= False
           else:
#
#          check if a new alt sequence begins
#
              if key== QtCore.Qt.Key_1 or key == QtCore.Qt.Key_0 :
                 self._alt_sequence=True
                 self._alt_seq_length=1
                 self._alt_seq_value=key - QtCore.Qt.Key_0
#
#          no alt sequence, do key lookup (macOS only)
#
              else:
                 alt_mode_lookup=[]
                 if isMACOS():
#                   print("keyboard ALT mode lookup for ",key)
                    alt_mode_lookup= keyboard_lookup(key | self._modifier_flags, self._keyboard_type)
#                   print("lookup result",alt_mode_lookup)
                    for i in alt_mode_lookup:
                       self._kbdfunc(i)
#
#                proces shortcuts
#
                 if not alt_mode_lookup :
                    if key >= QtCore.Qt.Key_A and key <= QtCore.Qt.Key_Z:
                       shortcut_index= key- QtCore.Qt.Key_A

# Path: pyilper/pilcharconv.py
# def icharconv(i, charset):
#    return convert_to_unicode[charset][i]
# 
# CHARSET_HP71=0
# 
# CHARSET_HP75=2
# 
# CHARSET_HP41=1
# 
# Path: pyilper/pilcore.py
# UPDATE_TIMER=25                 # Poll timer (ms) for terminal output queue
# 
# CURSOR_BLINK=500                # 500 ms cursor blink rate
# 
# TERMINAL_MINIMUM_ROWS=24        # can't get beyond that
# 
# FONT="Monospace"
# 
# AUTOSCROLL_RATE=100             # 500 ms cursor blink rate
# 
# def isMACOS():
#    return platform.system()=="Darwin"
# 
# KEYBOARD_DELAY=500              # autorepeat delay to prevent too fast kbd input
# 
# Path: pyilper/shortcutconfig.py
# SHORTCUTCONFIG=  cls_shortcutconfig()
# 
# SHORTCUT_EXEC=1
# 
# SHORTCUT_EDIT=2
# 
# SHORTCUT_INSERT=3
# 
# Path: pyilper/pilconfig.py
# PILCONFIG=  cls_pilconfig()


# Path: pyilper/pilqterm.py
import array
import queue
import threading
import time
from PyQt5 import QtCore, QtGui, QtWidgets
from .pilcharconv import icharconv, CHARSET_HP71, CHARSET_HP75, CHARSET_HP41
from .pilcore import UPDATE_TIMER, CURSOR_BLINK, TERMINAL_MINIMUM_ROWS,FONT, AUTOSCROLL_RATE, isMACOS, KEYBOARD_DELAY
from .shortcutconfig import SHORTCUTCONFIG, SHORTCUT_EXEC, SHORTCUT_EDIT, SHORTCUT_INSERT
from .pilconfig import PILCONFIG
from .pilkeymap import *

#                      print("keyboard alt value: ",self._alt_seq_value)
                       self._kbdfunc(self._alt_seq_value)
                    self._alt_sequence= False
              else:
                 self._alt_sequence= False
           else:
#
#          check if a new alt sequence begins
#
              if key== QtCore.Qt.Key_1 or key == QtCore.Qt.Key_0 :
                 self._alt_sequence=True
                 self._alt_seq_length=1
                 self._alt_seq_value=key - QtCore.Qt.Key_0
#
#          no alt sequence, do key lookup (macOS only)
#
              else:
                 alt_mode_lookup=[]
                 if isMACOS():
#                   print("keyboard ALT mode lookup for ",key)
                    alt_mode_lookup= keyboard_lookup(key | self._modifier_flags, self._keyboard_type)
#                   print("lookup result",alt_mode_lookup)
                    for i in alt_mode_lookup:
                       self._kbdfunc(i)
#
#                proces shortcuts
#
                 if not alt_mode_lookup :
                    if key >= QtCore.Qt.Key_A and key <= QtCore.Qt.Key_Z:
                       shortcut_index= key- QtCore.Qt.Key_A

                       shortcut_text,shortcut_flag= SHORTCUTCONFIG.get_shortcut(shortcut_index)