# Path: pyilper/pilqterm.py
# class QScrolledTerminalWidget(QtWidgets.QWidget):
# 
#     def __init__(self,parent,name):
#         super().__init__(parent)
#         self.pildevice= None
#         self.name= name
#         self.tabwidget=parent
# #
# #       create terminal window and scrollbar
# #
#         self.hbox= QtWidgets.QHBoxLayout()
#         self.hbox.addStretch(1)
#         self.terminalwidget= QTerminalWidget(self,self.name,self.tabwidget)
#         self.hbox.addWidget(self.terminalwidget)
#         self.scrollbar= QtWidgets.QScrollBar()
#         self.hbox.addWidget(self.scrollbar)
#         self.hbox.addStretch(1)
#         self.setLayout(self.hbox)
#         self.HPTerminal= HPTerminal(self,self.name)
#         self.terminalwidget.setHPTerminal(self.HPTerminal)
# #
# #       initialize scrollbar
# #
#         self.scrollbar.valueChanged.connect(self.do_scrollbar)
#         self.scrollbar.setEnabled(False)
# #
# #       enable/disable
# #
#     def enable(self):
#         self.scrollbar.setEnabled(True)
#         self.HPTerminal.enable()
#         return
# 
#     def disable(self):
#         self.scrollbar.setEnabled(False)
#         self.HPTerminal.disable()
#         return
# #
# #      enable/disable keyboard input
# #
#     def enable_keyboard(self):
#         self.terminalwidget.set_kbdfunc(self.pildevice.putDataToHPIL)
# 
#     def disable_keyboard(self):
#         self.terminalwidget.set_kbdfunc(None)
#   
# #
# #   scrollbar value changed action
# #
#     def do_scrollbar(self):
#        self.HPTerminal.scroll_to(self.scrollbar.value())
#        self.scrollbar.setEnabled(True)
# #
# #   setting function pass through to backend
# #
#     def set_charset(self,charset):
#         self.HPTerminal.set_charset(charset)
# 
# #
# #   set keyboard type
# #
#     def set_keyboardtype(self,t):
#        self.terminalwidget.set_keyboardtype(t)
# #
# #   tab becomes visible, call appropriate methods to:
# #   - stop cursor blink
# #   - disable update of the graphics scene (the buffer gets still updated)
# # 
#     def becomes_visible(self):
#         self.terminalwidget.becomes_visible()
#         self.HPTerminal.becomes_visible()
# #
# #   tab becomes invisible, call appropriate methods to:
# #   - restart cursor blink
# #   - enable update of the graphics scene
# #   - redraw graphics scene
# #
#     def becomes_invisible(self):
#         self.terminalwidget.becomes_invisible()
#         self.HPTerminal.becomes_invisible()
# #
# #   output character to terminal
# #
#     def out_terminal(self,t):
#         self.HPTerminal.out_terminal(t)
# #
# #   reset terminal
# #
#     def reset_terminal(self):
#         self.HPTerminal.reset_terminal()
# #
# #   redraw do nothing
# #
#     def redraw(self):
#        return
# #
# #   set pildevice
# #
#     def set_pildevice(self,device):
#         self.pildevice= device
# #
# #   reconfigure
# #
#     def reconfigure(self):
#       self.terminalwidget.reconfigure()
#       self.HPTerminal.reconfigure()
# #
# #   get actual number of columns
# #
#     def get_cols(self):
#       return self.terminalwidget.get_cols()
# #
# #   get actual number of rows
# #
#     def get_rows(self):
#       return self.terminalwidget.get_rows()
# 
# Path: pyilper/pilcharconv.py
# CHARSET_HP71=0
# CHARSET_HP41=1
# CHARSET_HP75=2
# CHARSET_ROMAN8=3
# CHARSET_HP2225=4
# def charconv(s, charset):
# def icharconv(i, charset):
# def barrconv(barr, charset):
# def stringconv(string, charset):
# 
# Path: pyilper/pilconfig.py
# PILCONFIG=  cls_pilconfig()


import os
import glob
import datetime
import re
import sys
import functools
import pyilper
   import winreg
from PyQt5 import QtCore, QtGui, QtWidgets
   from PyQt5 import QtWebKitWidgets
   from PyQt5 import QtWebEngineWidgets
from .pilqterm import QScrolledTerminalWidget
from .pilcharconv import CHARSET_HP71, charsets
from .pilconfig import PILCONFIG
from .pilcore import *
#
   def do_cbLogging(self):
      self.cbLogging.setEnabled(False)
      self.logging= self.cbLogging.isChecked()
      self.pildevice.setlocked(True)
      if self.logging:
         self.cbLogging.logOpen()
      else:
         self.cbLogging.logClose()
      PILCONFIG.put(self.name,"logging",self.logging)
      self.pildevice.setlocked(False)
      self.cbLogging.setEnabled(True)
#
# generic terminal tab widget ------------------------------------------------
#
class cls_tabtermgeneric(cls_tabgeneric):

   def __init__(self,parent,name):
      super().__init__(parent,name)
      self.kbd_delay=False
#
#     init local configuration parameters
#
      self.terminalwidth= PILCONFIG.get(self.name,"terminalwidth",80)
      self.colorscheme= PILCONFIG.get(self.name,"colorscheme",COLOR_SCHEME_WHITE)
      self.scrollupbuffersize=PILCONFIG.get(self.name,"scrollupbuffersize",1000)
      self.termcharsize=PILCONFIG.get(self.name,"terminalcharsize",-1)
#
#     Build GUI 
#

# Path: pyilper/pilqterm.py
# class QScrolledTerminalWidget(QtWidgets.QWidget):
# 
#     def __init__(self,parent,name):
#         super().__init__(parent)
#         self.pildevice= None
#         self.name= name
#         self.tabwidget=parent
# #
# #       create terminal window and scrollbar
# #
#         self.hbox= QtWidgets.QHBoxLayout()
#         self.hbox.addStretch(1)
#         self.terminalwidget= QTerminalWidget(self,self.name,self.tabwidget)
#         self.hbox.addWidget(self.terminalwidget)
#         self.scrollbar= QtWidgets.QScrollBar()
#         self.hbox.addWidget(self.scrollbar)
#         self.hbox.addStretch(1)
#         self.setLayout(self.hbox)
#         self.HPTerminal= HPTerminal(self,self.name)
#         self.terminalwidget.setHPTerminal(self.HPTerminal)
# #
# #       initialize scrollbar
# #
#         self.scrollbar.valueChanged.connect(self.do_scrollbar)
#         self.scrollbar.setEnabled(False)
# #
# #       enable/disable
# #
#     def enable(self):
#         self.scrollbar.setEnabled(True)
#         self.HPTerminal.enable()
#         return
# 
#     def disable(self):
#         self.scrollbar.setEnabled(False)
#         self.HPTerminal.disable()
#         return
# #
# #      enable/disable keyboard input
# #
#     def enable_keyboard(self):
#         self.terminalwidget.set_kbdfunc(self.pildevice.putDataToHPIL)
# 
#     def disable_keyboard(self):
#         self.terminalwidget.set_kbdfunc(None)
#   
# #
# #   scrollbar value changed action
# #
#     def do_scrollbar(self):
#        self.HPTerminal.scroll_to(self.scrollbar.value())
#        self.scrollbar.setEnabled(True)
# #
# #   setting function pass through to backend
# #
#     def set_charset(self,charset):
#         self.HPTerminal.set_charset(charset)
# 
# #
# #   set keyboard type
# #
#     def set_keyboardtype(self,t):
#        self.terminalwidget.set_keyboardtype(t)
# #
# #   tab becomes visible, call appropriate methods to:
# #   - stop cursor blink
# #   - disable update of the graphics scene (the buffer gets still updated)
# # 
#     def becomes_visible(self):
#         self.terminalwidget.becomes_visible()
#         self.HPTerminal.becomes_visible()
# #
# #   tab becomes invisible, call appropriate methods to:
# #   - restart cursor blink
# #   - enable update of the graphics scene
# #   - redraw graphics scene
# #
#     def becomes_invisible(self):
#         self.terminalwidget.becomes_invisible()
#         self.HPTerminal.becomes_invisible()
# #
# #   output character to terminal
# #
#     def out_terminal(self,t):
#         self.HPTerminal.out_terminal(t)
# #
# #   reset terminal
# #
#     def reset_terminal(self):
#         self.HPTerminal.reset_terminal()
# #
# #   redraw do nothing
# #
#     def redraw(self):
#        return
# #
# #   set pildevice
# #
#     def set_pildevice(self,device):
#         self.pildevice= device
# #
# #   reconfigure
# #
#     def reconfigure(self):
#       self.terminalwidget.reconfigure()
#       self.HPTerminal.reconfigure()
# #
# #   get actual number of columns
# #
#     def get_cols(self):
#       return self.terminalwidget.get_cols()
# #
# #   get actual number of rows
# #
#     def get_rows(self):
#       return self.terminalwidget.get_rows()
# 
# Path: pyilper/pilcharconv.py
# CHARSET_HP71=0
# CHARSET_HP41=1
# CHARSET_HP75=2
# CHARSET_ROMAN8=3
# CHARSET_HP2225=4
# def charconv(s, charset):
# def icharconv(i, charset):
# def barrconv(barr, charset):
# def stringconv(string, charset):
# 
# Path: pyilper/pilconfig.py
# PILCONFIG=  cls_pilconfig()


# Path: pyilper/pilwidgets.py
import os
import glob
import datetime
import re
import sys
import functools
import pyilper
   import winreg
from PyQt5 import QtCore, QtGui, QtWidgets
   from PyQt5 import QtWebKitWidgets
   from PyQt5 import QtWebEngineWidgets
from .pilqterm import QScrolledTerminalWidget
from .pilcharconv import CHARSET_HP71, charsets
from .pilconfig import PILCONFIG
from .pilcore import *

#
   def do_cbLogging(self):
      self.cbLogging.setEnabled(False)
      self.logging= self.cbLogging.isChecked()
      self.pildevice.setlocked(True)
      if self.logging:
         self.cbLogging.logOpen()
      else:
         self.cbLogging.logClose()
      PILCONFIG.put(self.name,"logging",self.logging)
      self.pildevice.setlocked(False)
      self.cbLogging.setEnabled(True)
#
# generic terminal tab widget ------------------------------------------------
#
class cls_tabtermgeneric(cls_tabgeneric):

   def __init__(self,parent,name):
      super().__init__(parent,name)
      self.kbd_delay=False
#
#     init local configuration parameters
#
      self.terminalwidth= PILCONFIG.get(self.name,"terminalwidth",80)
      self.colorscheme= PILCONFIG.get(self.name,"colorscheme",COLOR_SCHEME_WHITE)
      self.scrollupbuffersize=PILCONFIG.get(self.name,"scrollupbuffersize",1000)
      self.termcharsize=PILCONFIG.get(self.name,"terminalcharsize",-1)
#
#     Build GUI 
#

      self.guiobject=QScrolledTerminalWidget(self,self.name)