Coverage for pyilper/pilprinter.py: 91%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/python3
2# -*- coding: utf-8 -*-
3# pyILPER 1.2.1 for Linux
4#
5# An emulator for virtual HP-IL devices for the PIL-Box
6# derived from ILPER 1.4.5 for Windows
7# Copyright (c) 2008-2013 Jean-Francois Garnier
8# C++ version (c) 2013 Christoph Gießelink
9# Python Version (c) 2015 Joachim Siebold
10#
11# This program is free software; you can redistribute it and/or
12# modify it under the terms of the GNU General Public License
13# as published by the Free Software Foundation; either version 2
14# of the License, or (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24#
25from .pilconfig import PILCONFIG
26from .pilwidgets import cls_tabtermgeneric, T_STRING
27from .pildevbase import cls_pildevbase
28from .pilcharconv import CHARSET_HP71, charsets, icharconv
29#
30# Generic printer tab classes -------------------------------------------------
31#
32# Changelog
33# 01.08.2017 jsi
34# - refactoring: printer tab classes moved to this file
35# 03.09.2017 jsi
36# - register pildevice is now method of commobject
37# 04.01.2018 jsi
38# - flush log after a line feed was encountered
39# 16.01.2018 jsi
40# - adapted to cls_tabtermgeneric, implemented cascading config menu
41# 28.01.2018 jsi
42# - fixed charset configuration
43# 16.01.2018 jsi
44# - use int instead char for printer data
45#
46class cls_tabprinter(cls_tabtermgeneric):
48 def __init__(self,parent,name):
49 super().__init__(parent,name)
50#
51# init local configuration parameters
52#
53 self.charset=PILCONFIG.get(self.name,"charset",CHARSET_HP71)
54#
55# add logging
56#
57 self.add_logging()
58#
59# add printer config options to cascading menu
60#
61 self.cBut.add_option("Character set","charset",T_STRING,charsets)
62#
63# create HP-IL device and let the GUI object know it
64#
65 self.pildevice= cls_pilprinter(self,self.guiobject)
66 self.guiobject.set_pildevice(self.pildevice)
67 self.guiobject.set_charset(self.charset)
69 self.cBut.config_changed_signal.connect(self.do_tabconfig_changed)
70#
71# handle changes of the character set
72#
73 def do_tabconfig_changed(self):
74 param= self.cBut.get_changed_option_name()
75#
76# change local config parameters
77#
78 if param=="charset":
79 self.charset= PILCONFIG.get(self.name,"charset")
80 self.guiobject.set_charset(self.charset)
82 super().do_tabconfig_changed()
84 def enable(self):
85 super().enable()
86 self.parent.commthread.register(self.pildevice,self.name)
87 self.pildevice.setactive(PILCONFIG.get(self.name,"active"))
88#
89# output a character to the terminal and perform logging
90#
91 def out_printer(self,t):
92 self.guiobject.out_terminal(t)
93 if t !=8 and t != 13:
94 self.cbLogging.logWrite(icharconv(t,self.charset))
95 if t== 10:
96 self.cbLogging.logFlush()
97#
98# callback reset terminal
99#
100 def reset_printer(self):
101 self.guiobject.reset()
102#
103# Generic HPIL printer class -------------------------------------------------
104#
105# Initial release derived from ILPER 1.4.3 for Windows
106#
107# Changelog
108#
109# 09.02.2015 Improvements and changes of IPLER 1.5
110# - fixed __fprinter__ handling in do_cmd LAD/SAD
111# - not implemented: auto extended address support switch
112# - not implemeted: set/get AID, ID$
113# 30.05.2015 fixed error in handling AP, added getstatus
114# 06.10.2015 jsi:
115# - class statement syntax update
116# 23.11.2015 jsi:
117# - removed SSRQ/CSRQ approach
118# 29.11.2015 jsi:
119# - introduced device lock
120# 07.02.2016 jsi
121# - refactored and merged new Ildev base class of Christoph Giesselink
122# 09.02.2016 jsi
123# - clear device implemented
124# 09.07.2017 jsi
125# - register_callback_output and register_callback_clear implemented (from base
126# class)
127class cls_pilprinter(cls_pildevbase):
129 def __init__(self,parent,guiobject):
131 super().__init__()
132 self.__aid__ = 0x2E # accessory id = printer
133 self.__defaddr__ = 3 # default address alter AAU
134 self.__did__ = "PRINTER" # device id
135 self.__fesc__ = False # no escape sequence
136 self.__parent__= parent # parent object
137 self.__guiobject__= guiobject
138#
139#
140# private (overloaded) ----------
141#
142#
143# print and handle special characters
144#
145 def __indata__(self,frame):
147 t=frame & 0xFF
148#
149# no escape squence
150#
151 if not self.__fesc__:
152 if t == 27:
153 self.__fesc__ = True
154 if not self.__fesc__:
155 self.__access_lock__.acquire()
156 locked= self.__islocked__
157 self.__access_lock__.release()
158 if not locked:
159 self.__parent__.out_printer(t)
160#
161# ignore escape sequences
162#
163 else:
164 self.__fesc__= False
166#
167# clear device: reset terminal via callback
168#
169 def __clear_device__(self):
170 super().__clear_device__()
171 self.__guiobject__.reset_terminal()
172 return