A bunch of stuff

This commit is contained in:
Fierelier 2023-08-24 01:43:00 +02:00
parent 8e889715d1
commit 8216ee6b90

34
batchprint.pyw Normal file → Executable file
View File

@ -52,8 +52,13 @@ from qtpy.QtGui import *
from qtpy.QtWidgets import * from qtpy.QtWidgets import *
from qtpy.QtCore import * from qtpy.QtCore import *
# https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdevicecaps
HORZRES = 8
VERTRES = 10
PHYSICALWIDTH = 110 PHYSICALWIDTH = 110
PHYSICALHEIGHT = 111 PHYSICALHEIGHT = 111
PHYSICALOFFSETX = 112
PHYSICALOFFSETY = 113
def getPrinters(): def getPrinters():
hive = winreg.ConnectRegistry(None,winreg.HKEY_LOCAL_MACHINE) hive = winreg.ConnectRegistry(None,winreg.HKEY_LOCAL_MACHINE)
@ -140,18 +145,18 @@ class printerWindow(QMainWindow):
except: except:
pass pass
self.close() self.close()
printerOpenQueue(printer) #printerOpenQueue(printer)
windows.append(queueWindow(printer)) windows.append(queueWindow(printer))
def cOpenSettings(self): def cOpenSettings(self):
printer = self.cDropdown.currentText() printer = self.cDropdown.currentText()
self.hide()
printerOpenProperties(printer) printerOpenProperties(printer)
self.cOpenList()
class queueWindow(QMainWindow): class queueWindow(QMainWindow):
def __init__(self,printer,*args,**kwargs): def __init__(self,printer,*args,**kwargs):
super().__init__(*args,**kwargs) super().__init__(*args,**kwargs)
self.cTitle = printer+ " - batchprint"
self.setWindowTitle(self.cTitle)
self.setAcceptDrops(True) self.setAcceptDrops(True)
self.cWidth = 240 self.cWidth = 240
@ -161,7 +166,11 @@ class queueWindow(QMainWindow):
self.cPrinter = printer self.cPrinter = printer
self.cDC = win32ui.CreateDC() self.cDC = win32ui.CreateDC()
self.cDC.CreatePrinterDC(printer) self.cDC.CreatePrinterDC(printer)
self.cPrinterSize = self.cDC.GetDeviceCaps(PHYSICALWIDTH),self.cDC.GetDeviceCaps(PHYSICALHEIGHT) self.cPrinterPhysicalSize = [self.cDC.GetDeviceCaps(PHYSICALWIDTH),self.cDC.GetDeviceCaps(PHYSICALHEIGHT)]
self.cPrinterPrintSize = [self.cDC.GetDeviceCaps(HORZRES),self.cDC.GetDeviceCaps(VERTRES)]
self.cPrinterPrintOffset = [self.cDC.GetDeviceCaps(PHYSICALOFFSETX),self.cDC.GetDeviceCaps(PHYSICALOFFSETY)]
self.cTitle = printer+ " (" +str(self.cPrinterPrintSize[0])+ "x" +str(self.cPrinterPrintSize[1])+ ") - batchprint"
self.setWindowTitle(self.cTitle)
self.cCreateElements() self.cCreateElements()
@ -172,7 +181,7 @@ class queueWindow(QMainWindow):
self.cLabel.setWordWrap(True) self.cLabel.setWordWrap(True)
self.cTick = QCheckBox(self) self.cTick = QCheckBox(self)
self.cTick.setText("Raw print") self.cTick.setText("Do not scale/rotate")
self.cTick.setChecked(False) self.cTick.setChecked(False)
try: try:
with open(p(sp,"rawprint.txt"),encoding="utf-8") as f: with open(p(sp,"rawprint.txt"),encoding="utf-8") as f:
@ -187,6 +196,8 @@ class queueWindow(QMainWindow):
def cResizeElements(self): def cResizeElements(self):
self.cLabel.move(0,0) self.cLabel.move(0,0)
self.cLabel.resize(self.cWidth,self.cHeight) self.cLabel.resize(self.cWidth,self.cHeight)
self.cTick.move(5,0)
self.cTick.resize(self.cWidth - 10,22)
def resizeEvent(self,event): def resizeEvent(self,event):
self.cWidth = self.width() self.cWidth = self.width()
@ -213,13 +224,13 @@ class queueWindow(QMainWindow):
if not rawprint: if not rawprint:
if bmp.size[1] > bmp.size[0]: if bmp.size[1] > bmp.size[0]:
if self.cPrinterSize[0] > self.cPrinterSize[1]: if self.cPrinterPrintSize[0] > self.cPrinterPrintSize[1]:
bmp = bmp.transpose(PIL.Image.ROTATE_90) bmp = bmp.transpose(PIL.Image.ROTATE_90)
elif bmp.size[0] > bmp.size[1]: elif bmp.size[0] > bmp.size[1]:
if self.cPrinterSize[1] > self.cPrinterSize[0]: if self.cPrinterPrintSize[1] > self.cPrinterPrintSize[0]:
bmp = bmp.transpose(PIL.Image.ROTATE_90) bmp = bmp.transpose(PIL.Image.ROTATE_90)
imWidth = self.cPrinterSize[0] imWidth = self.cPrinterPrintSize[0]
imHeight = self.cPrinterSize[1] imHeight = self.cPrinterPrintSize[1]
else: else:
imWidth = bmp.size[0] imWidth = bmp.size[0]
imHeight = bmp.size[1] imHeight = bmp.size[1]
@ -227,7 +238,10 @@ class queueWindow(QMainWindow):
self.cDC.StartDoc(path) self.cDC.StartDoc(path)
self.cDC.StartPage() self.cDC.StartPage()
dib = PIL.ImageWin.Dib(bmp) dib = PIL.ImageWin.Dib(bmp)
dib.draw(self.cDC.GetHandleOutput(),(0,0,imWidth,imHeight)) dib.draw(self.cDC.GetHandleOutput(),(
self.cPrinterPrintOffset[0],self.cPrinterPrintOffset[1],
imWidth,imHeight
))
self.cDC.EndPage() self.cDC.EndPage()
self.cDC.EndDoc() self.cDC.EndDoc()
self.cLabel.setText("Drag & Drop images here") self.cLabel.setText("Drag & Drop images here")