2022-03-29 03:18:34 +00:00
#!/usr/bin/env python3
# requires: pywin32, pillow, qtpy, a module compatible with qtpy (try pyqt5)
import sys
import ctypes
import traceback
import win32clipboard
oldexcepthook = sys . excepthook
def newexcepthook ( type , value , tb ) :
excText = " " . join ( traceback . format_exception ( type , value , tb ) )
try :
for window in windows :
try :
window . close ( )
except :
pass
except :
pass
2023-08-23 23:43:29 +00:00
output = ctypes . windll . user32 . MessageBoxW ( None , u " " + excText + " \n The program must close. Copy exception to clipboard? " , u " Unhandled exception - " + prettyDistro , 0x00000114 )
2022-03-29 03:18:34 +00:00
if output == 6 :
copyString ( excText )
oldexcepthook ( type , value , tb )
sys . excepthook = newexcepthook
def copyString ( s ) :
win32clipboard . OpenClipboard ( )
win32clipboard . EmptyClipboard ( )
win32clipboard . SetClipboardText ( s , win32clipboard . CF_UNICODETEXT )
win32clipboard . CloseClipboard ( )
import os
p = os . path . join
pUp = os . path . dirname
s = False
if getattr ( sys , ' frozen ' , False ) and hasattr ( sys , ' _MEIPASS ' ) :
s = os . path . realpath ( sys . executable )
else :
s = os . path . realpath ( __file__ )
sp = pUp ( s )
import qtpy
import qtpy . QtGui as QtGui
from qtpy . QtGui import *
from qtpy . QtWidgets import *
from qtpy . QtCore import *
2023-08-23 23:43:29 +00:00
import winreg
import json
import win32ui
import PIL . Image
import PIL . ImageWin
import subprocess
2023-08-23 23:43:00 +00:00
# https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdevicecaps
HORZRES = 8
VERTRES = 10
2022-03-29 03:18:34 +00:00
PHYSICALWIDTH = 110
PHYSICALHEIGHT = 111
2023-08-23 23:43:00 +00:00
PHYSICALOFFSETX = 112
PHYSICALOFFSETY = 113
2022-03-29 03:18:34 +00:00
2023-08-23 23:43:29 +00:00
prettyDistro = " batchprint "
distro = " me.fier. " + prettyDistro
configDir = p ( os . environ [ " APPDATA " ] , distro )
defaultProfile = { }
defaultProfile [ " printer " ] = None
defaultProfile [ " amount " ] = 1
defaultProfile [ " stretch " ] = True
defaultProfile [ " rotate " ] = True
defaultProfile [ " offset-x " ] = 0
defaultProfile [ " offset-y " ] = 0
# Profiles
def saveProfile ( profile , profileName ) :
with open ( p ( configDir , " profiles " , profileName + " .json " ) , " w " , encoding = " utf-8 " ) as f :
f . write ( json . dumps ( profile , sort_keys = True , indent = 1 ) )
def loadProfile ( profileName ) :
with open ( p ( configDir , " profiles " , profileName + " .json " ) , " r " , encoding = " utf-8 " ) as f :
profile = json . loads ( f . read ( ) )
for i in defaultProfile :
if not i in profile : profile [ i ] = defaultProfile [ i ]
return profile
def deleteProfile ( profileName ) :
os . remove ( p ( configDir , " profiles " , profileName + " .json " ) )
def getProfiles ( ) :
profiles = [ ]
for root , dirs , files in os . walk ( p ( configDir , " profiles " ) ) :
for file in files :
if not file . lower ( ) . endswith ( " .json " ) : continue
ffile = p ( configDir , " profiles " , file )
lfile = ffile . replace ( p ( configDir , " profiles " ) + os . path . sep , " " , 1 )
profiles . append ( lfile . rsplit ( " . " , 1 ) [ 0 ] )
break
profiles . sort ( )
return profiles
def isProfileSame ( profile1 , profile2 ) :
for i in profile1 :
if not i in profile2 : return False
for i in profile2 :
if not i in profile1 : return False
for i in profile1 :
if profile1 [ i ] != profile2 [ i ] : return False
return True
# System
2022-03-29 03:18:34 +00:00
def getPrinters ( ) :
hive = winreg . ConnectRegistry ( None , winreg . HKEY_LOCAL_MACHINE )
key = winreg . OpenKey ( hive , r " SYSTEM \ CurrentControlSet \ Control \ Print \ Printers " )
printers = [ ]
index = 0
while True :
try :
printers . append ( winreg . EnumKey ( key , index ) )
index + = 1
except OSError :
break
winreg . CloseKey ( key )
hive . Close ( )
2023-08-23 23:43:29 +00:00
printers . sort ( )
2022-03-29 03:18:34 +00:00
return printers
2023-08-23 23:43:29 +00:00
# Config
def readConfigFile ( filePath ) :
with open ( p ( configDir , filePath ) , " r " , encoding = " utf-8 " ) as f :
return f . read ( )
def writeConfigFile ( filePath , data ) :
with open ( p ( configDir , filePath ) , " w " , encoding = " utf-8 " ) as f :
f . write ( data )
2022-03-29 03:18:34 +00:00
2023-08-23 23:43:29 +00:00
# Qt Widgets
def limitWidgetSize ( widget , small = False ) :
sizeHint = widget . sizeHint ( )
if small == False :
widget . setMaximumWidth ( sizeHint . width ( ) )
else :
widget . setMaximumWidth ( sizeHint . height ( ) )
widget . setMaximumHeight ( sizeHint . height ( ) )
2022-03-29 03:18:34 +00:00
2023-08-23 23:43:29 +00:00
def createLine ( style = " dotted " ) :
line = QLabel ( " " )
line . setStyleSheet ( " border-width: 1px; border-style: " + style )
line . setMaximumHeight ( 1 )
return line
class infoWindow ( QMainWindow ) :
def __init__ ( self , parent , title , message , * args , * * kwargs ) :
2022-03-29 03:18:34 +00:00
super ( ) . __init__ ( * args , * * kwargs )
2023-08-23 23:43:29 +00:00
self . cParent = parent
self . cTitle = title
self . cMessage = message
2022-03-29 03:18:34 +00:00
self . setWindowTitle ( self . cTitle )
self . cWidth = 320
2023-08-23 23:43:29 +00:00
self . cHeight = 80
2022-03-29 03:18:34 +00:00
self . resize ( self . cWidth , self . cHeight )
self . cCreateElements ( )
2023-08-23 23:43:29 +00:00
self . show ( )
2022-03-29 03:18:34 +00:00
def cCreateElements ( self ) :
self . cLabel = QLabel ( self )
self . cLabel . setAlignment ( Qt . AlignCenter )
2023-08-23 23:43:29 +00:00
self . cLabel . setText ( self . cMessage )
2022-03-29 03:18:34 +00:00
self . cButton = QPushButton ( self )
self . cButton . setText ( " OK " )
2023-08-23 23:43:29 +00:00
self . cButton . clicked . connect ( self . cClose )
2022-03-29 03:18:34 +00:00
self . cResizeElements ( )
def cResizeElements ( self ) :
2023-08-23 23:43:29 +00:00
sizeHint = self . cButton . sizeHint ( )
self . cButton . move ( ( self . cWidth * 0.5 ) - ( sizeHint . width ( ) * 0.5 ) , self . cHeight - sizeHint . height ( ) - 5 )
self . cButton . resize ( sizeHint . width ( ) , sizeHint . height ( ) )
self . cLabel . move ( 5 , 5 )
self . cLabel . resize ( self . cWidth - 10 , self . cHeight - sizeHint . height ( ) - 15 )
2022-03-29 03:18:34 +00:00
def resizeEvent ( self , event ) :
self . cWidth = self . width ( )
self . cHeight = self . height ( )
self . cResizeElements ( )
2023-08-23 23:43:29 +00:00
def cClose ( self ) :
self . close ( )
2022-03-29 03:18:34 +00:00
def closeEvent ( self , event ) :
windows . remove ( self )
2023-08-23 23:43:29 +00:00
self . cParent . setEnabled ( True )
class saveWindow ( QMainWindow ) :
def __init__ ( self , parent , profile , callback , * args , * * kwargs ) :
super ( ) . __init__ ( * args , * * kwargs )
self . cParent = parent
self . cProfile = profile
self . cCallback = callback
self . setWindowTitle ( " save " )
self . cWidth = 320
self . cHeight = 80
self . resize ( self . cWidth , self . cHeight )
self . cCreateElements ( )
self . show ( )
2022-03-29 03:18:34 +00:00
2023-08-23 23:43:29 +00:00
def cCreateElements ( self ) :
self . cInput = QLineEdit ( self )
self . cInput . setText ( self . cProfile )
self . cInput . selectAll ( )
self . cButtonCancel = QPushButton ( self )
self . cButtonCancel . setText ( " Cancel " )
self . cButtonCancel . clicked . connect ( self . cClose )
self . cButtonSave = QPushButton ( self )
self . cButtonSave . setText ( " Save " )
self . cButtonSave . clicked . connect ( self . cSave )
self . cResizeElements ( )
def cResizeElements ( self ) :
sizeHint = self . cButtonCancel . sizeHint ( )
self . cInput . move ( 5 , 5 + ( ( self . cHeight - sizeHint . height ( ) - 10 ) * 0.5 ) - ( self . cInput . sizeHint ( ) . height ( ) * 0.5 ) )
self . cInput . resize ( self . cWidth - 10 , self . cInput . sizeHint ( ) . height ( ) )
self . cButtonCancel . move ( 5 , self . cHeight - sizeHint . height ( ) - 5 )
self . cButtonCancel . resize ( sizeHint . width ( ) , sizeHint . height ( ) )
self . cButtonSave . move ( self . cWidth - sizeHint . width ( ) - 5 , self . cHeight - sizeHint . height ( ) - 5 )
self . cButtonSave . resize ( sizeHint . width ( ) , sizeHint . height ( ) )
def resizeEvent ( self , event ) :
self . cWidth = self . width ( )
self . cHeight = self . height ( )
self . cResizeElements ( )
def cSave ( self ) :
2022-03-29 03:18:34 +00:00
self . close ( )
2023-08-23 23:43:29 +00:00
self . cCallback ( self . cInput . text ( ) )
2023-08-23 11:56:31 +00:00
2023-08-23 23:43:29 +00:00
def cClose ( self ) :
self . close ( )
def closeEvent ( self , event ) :
windows . remove ( self )
self . cParent . setEnabled ( True )
2022-03-29 03:18:34 +00:00
2023-08-23 23:43:29 +00:00
class mainWindow ( QMainWindow ) :
def __init__ ( self , * args , * * kwargs ) :
2022-03-29 03:18:34 +00:00
super ( ) . __init__ ( * args , * * kwargs )
self . setAcceptDrops ( True )
2023-08-23 23:43:29 +00:00
self . cTitle = prettyDistro
self . setWindowTitle ( self . cTitle )
self . cWidth = 300
self . cHeight = 256
2022-03-29 03:18:34 +00:00
self . resize ( self . cWidth , self . cHeight )
2023-08-23 23:43:29 +00:00
self . cCreateElements ( )
2022-03-29 03:18:34 +00:00
2023-08-23 23:43:29 +00:00
self . cPrinters = getPrinters ( )
self . cPrinterDropdown . addItems ( self . cPrinters )
2022-03-29 03:18:34 +00:00
2023-08-23 23:43:29 +00:00
self . cProfiles = getProfiles ( )
self . cProfileDropdown . addItems ( self . cProfiles )
selectProfile = self . cProfiles [ 0 ]
try :
selectProfile = readConfigFile ( " lastProfile.txt " )
except :
pass
if not selectProfile in self . cProfiles : selectProfile = self . cProfiles [ 0 ]
self . cProfileDropdown . setCurrentIndex ( self . cProfiles . index ( selectProfile ) )
2022-03-29 03:18:34 +00:00
2023-08-23 23:43:29 +00:00
def cLoadCurrentProfile ( self ) :
profile = self . cProfileDropdown . currentText ( )
if profile == " " : return
#print("profile loaded")
self . cProfileOld = loadProfile ( profile )
self . cProfile = self . cProfileOld . copy ( )
2022-03-29 03:18:34 +00:00
2023-08-23 11:56:48 +00:00
try :
2023-08-23 23:43:29 +00:00
printerIndex = self . cPrinters . index ( self . cProfile [ " printer " ] )
2023-08-23 11:56:48 +00:00
except :
2023-08-23 23:43:29 +00:00
printerIndex = 0
self . cProfile [ " printer " ] = self . cPrinters [ printerIndex ]
self . cPrinterDropdown . setCurrentIndex ( printerIndex )
2023-08-23 11:56:48 +00:00
2023-08-23 23:43:29 +00:00
self . cAmountInput . setText ( str ( self . cProfile [ " amount " ] ) )
self . cRotateTick . setChecked ( self . cProfile [ " rotate " ] )
self . cStretchTick . setChecked ( self . cProfile [ " stretch " ] )
self . cOffsetHorzInput . setText ( str ( self . cProfile [ " offset-x " ] ) )
self . cOffsetVertInput . setText ( str ( self . cProfile [ " offset-y " ] ) )
def cSaveProfile ( self ) :
self . setEnabled ( False )
profile = self . cMenuToProfile ( )
if type ( profile ) == str :
windows . append ( infoWindow ( self , prettyDistro , " The profile can ' t be saved: ' " + profile + " ' is set to an invalid value. " ) )
return
windows . append ( saveWindow ( self , self . cProfileDropdown . currentText ( ) , self . cSaveProfileCallback ) )
def cSaveProfileCallback ( self , profileName ) :
profile = self . cMenuToProfile ( )
saveProfile ( profile , profileName )
if not profileName in self . cProfiles :
self . cProfiles . append ( profileName )
self . cProfiles . sort ( )
self . cProfileDropdown . clear ( )
self . cProfileDropdown . addItems ( self . cProfiles )
self . cProfileDropdown . setCurrentIndex ( self . cProfiles . index ( profileName ) )
def cDeleteProfile ( self ) :
if len ( self . cProfiles ) < 2 :
self . setEnabled ( False )
windows . append ( infoWindow ( self , prettyDistro , " You can ' t delete your last profile! " ) )
return
profile = self . cProfileDropdown . currentText ( )
profileIndex = self . cProfiles . index ( profile )
deleteProfile ( profile )
self . cProfiles . pop ( profileIndex )
self . cProfileDropdown . removeItem ( profileIndex )
def cPrinterSettings ( self ) :
self . hide ( )
subprocess . Popen ( [ " rundll32 " , " printui.dll,PrintUIEntry " , " /e " , " /n " + self . cPrinterDropdown . currentText ( ) ] ) . wait ( )
2022-03-29 03:18:34 +00:00
self . show ( )
2023-08-23 23:43:29 +00:00
def cMenuToProfile ( self ) :
profile = { }
try :
error = " Printer "
profile [ " printer " ] = self . cPrinterDropdown . currentText ( )
error = " Print amount "
profile [ " amount " ] = int ( self . cAmountInput . text ( ) )
error = " Stretch images "
profile [ " stretch " ] = self . cStretchTick . isChecked ( )
error = " Auto-rotate images "
profile [ " rotate " ] = self . cRotateTick . isChecked ( )
error = " Offset horizontal "
profile [ " offset-x " ] = int ( self . cOffsetHorzInput . text ( ) )
error = " Offset vertical "
profile [ " offset-y " ] = int ( self . cOffsetVertInput . text ( ) )
except :
return error
return profile
2022-03-29 03:18:34 +00:00
2023-08-23 23:43:29 +00:00
def cCreateLayout ( self , detached = False ) :
widget = QWidget ( self )
layout = QHBoxLayout ( widget )
layout . cWidget = widget
layout . setAlignment ( Qt . AlignTop )
layout . setSpacing ( 2 )
layout . setContentsMargins ( 0 , 0 , 0 , 0 )
if not detached : self . cLayout . addWidget ( widget )
return layout
2022-03-29 03:18:34 +00:00
def dragEnterEvent ( self , event ) :
2023-08-23 23:43:29 +00:00
if not event . mimeData ( ) . hasUrls ( ) : return
2022-03-29 03:18:34 +00:00
self . activateWindow ( )
2023-08-23 23:43:29 +00:00
self . cStatus . setStyleSheet ( " font-weight: bold " )
urls = event . mimeData ( ) . urls ( )
if len ( urls ) == 1 :
path = str ( urls [ 0 ] . toLocalFile ( ) ) . replace ( " / " , os . path . sep )
self . cStatus . showMessage ( " Print " + path )
else :
self . cStatus . showMessage ( " Print " + str ( len ( urls ) ) + " images " )
event . accept ( )
2022-03-29 03:18:34 +00:00
def dragLeaveEvent ( self , event ) :
2023-08-23 23:43:29 +00:00
self . cStatus . setStyleSheet ( " " )
self . cStatus . showMessage ( " Drag & Drop an image to start printing " )
2022-03-29 03:18:34 +00:00
def dropEvent ( self , event ) :
2023-08-23 23:43:29 +00:00
self . setEnabled ( False )
self . cStatus . setStyleSheet ( " " )
self . cStatus . showMessage ( " Drag & Drop an image to start printing " )
profile = self . cMenuToProfile ( )
if type ( profile ) == str :
windows . append ( infoWindow ( self , prettyDistro , " Cannot print: ' " + profile + " ' is set to an invalid value. " ) )
return
dc = win32ui . CreateDC ( )
dc . CreatePrinterDC ( profile [ " printer " ] )
printerPhysicalSize = [ dc . GetDeviceCaps ( PHYSICALWIDTH ) , dc . GetDeviceCaps ( PHYSICALHEIGHT ) ]
printerPrintSize = [ dc . GetDeviceCaps ( HORZRES ) , dc . GetDeviceCaps ( VERTRES ) ]
printerPrintOffset = [ dc . GetDeviceCaps ( PHYSICALOFFSETX ) , dc . GetDeviceCaps ( PHYSICALOFFSETY ) ]
2022-03-29 03:18:34 +00:00
for url in event . mimeData ( ) . urls ( ) :
path = str ( url . toLocalFile ( ) ) . replace ( " / " , os . path . sep )
2023-08-23 23:43:29 +00:00
self . cStatus . showMessage ( " Converting ... ( " + path + " ) " )
2022-03-29 03:18:34 +00:00
self . repaint ( )
bmp = PIL . Image . open ( path )
2023-08-23 11:56:48 +00:00
2023-08-23 23:43:29 +00:00
if profile [ " rotate " ] :
self . cStatus . showMessage ( " Rotating ... ( " + path + " ) " )
self . repaint ( )
2023-08-23 11:56:48 +00:00
if bmp . size [ 1 ] > bmp . size [ 0 ] :
2023-08-23 23:43:29 +00:00
if printerPrintSize [ 0 ] > printerPrintSize [ 1 ] :
2023-08-23 11:56:48 +00:00
bmp = bmp . transpose ( PIL . Image . ROTATE_90 )
elif bmp . size [ 0 ] > bmp . size [ 1 ] :
2023-08-23 23:43:29 +00:00
if printerPrintSize [ 1 ] > printerPrintSize [ 0 ] :
2023-08-23 11:56:48 +00:00
bmp = bmp . transpose ( PIL . Image . ROTATE_90 )
2023-08-23 23:43:29 +00:00
imStartX = printerPrintOffset [ 0 ]
imStartY = printerPrintOffset [ 1 ]
if profile [ " stretch " ] :
imEndX = imStartX + printerPrintSize [ 0 ]
imEndY = imStartY + printerPrintSize [ 1 ]
2023-08-23 11:56:48 +00:00
else :
2023-08-23 23:43:29 +00:00
imEndX = imStartX + bmp . size [ 0 ]
imEndY = imStartY + bmp . size [ 1 ]
imStartX + = profile [ " offset-x " ]
imEndX + = profile [ " offset-x " ]
imStartY + = profile [ " offset-y " ]
imEndY + = profile [ " offset-y " ]
2022-03-29 03:18:34 +00:00
2023-08-23 23:43:29 +00:00
copies = profile [ " amount " ]
2022-03-29 03:18:34 +00:00
dib = PIL . ImageWin . Dib ( bmp )
2023-08-23 23:43:29 +00:00
while copies > 0 :
self . cStatus . showMessage ( " Plotting ... ( " + path + " ) " )
dc . StartDoc ( path )
dc . StartPage ( )
self . repaint ( )
dib . draw ( dc . GetHandleOutput ( ) , (
imStartX , imStartY ,
imEndX , imEndY
) )
dc . EndPage ( )
dc . EndDoc ( )
copies - = 1
dc . DeleteDC ( )
self . cStatus . showMessage ( " Drag & Drop an image to start printing " )
self . setEnabled ( True )
2022-03-29 03:18:34 +00:00
2023-08-23 23:43:29 +00:00
def cCreateElements ( self ) :
mainWidget = QWidget ( self )
self . cLayout = QVBoxLayout ( mainWidget )
self . cLayout . setAlignment ( Qt . AlignTop )
self . cLayout . setSpacing ( 2 )
self . cLayout . setContentsMargins ( 5 , 5 , 5 , 5 )
self . cScroll = QScrollArea ( self )
self . cScroll . setWidget ( mainWidget )
self . cScroll . setWidgetResizable ( True )
self . cProfileLayout = self . cCreateLayout ( True )
self . cProfileLabel = QLabel ( " Profile: " )
self . cProfileLabel . setStyleSheet ( " font-weight: bold " )
self . cProfileLayout . addWidget ( self . cProfileLabel )
self . cProfileDropdown = QComboBox ( )
self . cProfileDropdown . currentIndexChanged . connect ( self . cLoadCurrentProfile )
self . cProfileLayout . addWidget ( self . cProfileDropdown )
self . cProfileCreateButton = QPushButton ( )
self . cProfileCreateButton . setText ( " + " )
self . cProfileCreateButton . clicked . connect ( self . cSaveProfile )
self . cProfileLayout . addWidget ( self . cProfileCreateButton )
self . cProfileDeleteButton = QPushButton ( )
self . cProfileDeleteButton . setText ( " - " )
self . cProfileDeleteButton . clicked . connect ( self . cDeleteProfile )
self . cProfileLayout . addWidget ( self . cProfileDeleteButton )
# Printer
layout = self . cCreateLayout ( )
self . cPrinterLabel = QLabel ( " Printer: " )
#self.cPrinterLabel.setStyleSheet("font-weight: bold")
layout . addWidget ( self . cPrinterLabel )
self . cPrinterDropdown = QComboBox ( )
layout . addWidget ( self . cPrinterDropdown )
self . cPrinterSettingsButton = QPushButton ( )
self . cPrinterSettingsButton . setText ( " Configure " )
self . cPrinterSettingsButton . clicked . connect ( self . cPrinterSettings )
layout . addWidget ( self . cPrinterSettingsButton )
# Print amount
layout = self . cCreateLayout ( )
self . cAmountLabel = QLabel ( " Print amount: " )
#self.cAmountLabel.setStyleSheet("font-weight: bold")
layout . addWidget ( self . cAmountLabel )
line = createLine ( )
layout . addWidget ( line )
self . cAmountInput = QLineEdit ( )
layout . addWidget ( self . cAmountInput )
2023-08-23 11:56:48 +00:00
2023-08-23 23:43:29 +00:00
line = createLine ( " solid " )
self . cLayout . addWidget ( line )
# Stretch image
layout = self . cCreateLayout ( )
self . cStretchLabel = QLabel ( " Stretch images: " )
#self.cStretchLabel.setStyleSheet("font-weight: bold")
layout . addWidget ( self . cStretchLabel )
line = createLine ( )
layout . addWidget ( line )
self . cStretchTick = QCheckBox ( )
layout . addWidget ( self . cStretchTick )
# Rotate image
layout = self . cCreateLayout ( )
self . cRotateLabel = QLabel ( " Auto-rotate images: " )
#self.cRotateLabel.setStyleSheet("font-weight: bold")
layout . addWidget ( self . cRotateLabel )
line = createLine ( )
layout . addWidget ( line )
self . cRotateTick = QCheckBox ( )
layout . addWidget ( self . cRotateTick )
# Offset horizontal
layout = self . cCreateLayout ( )
self . cOffsetHorzLabel = QLabel ( " Offset horizontal: " )
#self.cOffsetHorzLabel.setStyleSheet("font-weight: bold")
layout . addWidget ( self . cOffsetHorzLabel )
line = createLine ( )
layout . addWidget ( line )
self . cOffsetHorzInput = QLineEdit ( )
layout . addWidget ( self . cOffsetHorzInput )
# Offset vertical
layout = self . cCreateLayout ( )
self . cOffsetVertLabel = QLabel ( " Offset vertical: " )
#self.cOffsetVertLabel.setStyleSheet("font-weight: bold")
layout . addWidget ( self . cOffsetVertLabel )
line = createLine ( )
layout . addWidget ( line )
self . cOffsetVertInput = QLineEdit ( )
layout . addWidget ( self . cOffsetVertInput )
line = createLine ( " solid " )
self . cLayout . addWidget ( line )
# Information
layout = self . cCreateLayout ( )
self . cInfoResolutionLabel = QLabel ( " Paper resolution: " )
#self.cInfoResolutionLabel.setStyleSheet("font-weight: bold")
layout . addWidget ( self . cInfoResolutionLabel )
line = createLine ( )
layout . addWidget ( line )
self . cInfoResolutionValue = QLabel ( " 0*0 " )
layout . addWidget ( self . cInfoResolutionValue )
layout = self . cCreateLayout ( )
self . cInfoRealResolutionLabel = QLabel ( " Usable (real) resolution: " )
#self.cInfoRealResolutionLabel.setStyleSheet("font-weight: bold")
layout . addWidget ( self . cInfoRealResolutionLabel )
line = createLine ( )
layout . addWidget ( line )
self . cInfoRealResolutionValue = QLabel ( " 0*0 (100 % ) " )
layout . addWidget ( self . cInfoRealResolutionValue )
# Status bar
self . cStatus = QStatusBar ( self )
self . cStatus . showMessage ( " Drag & Drop an image to start printing " )
self . cResizeElements ( )
self . show ( )
def cResizeElements ( self ) :
statusSize = self . cStatus . sizeHint ( ) . height ( )
# Profile
limitWidgetSize ( self . cProfileLabel )
limitWidgetSize ( self . cProfileCreateButton , True )
limitWidgetSize ( self . cProfileDeleteButton , True )
profileSize = self . cProfileLayout . cWidget . sizeHint ( ) . height ( )
profilePadding = 2
self . cProfileLayout . cWidget . move ( 5 , profilePadding )
self . cProfileLayout . cWidget . resize ( self . cWidth - 10 , profileSize )
self . cScroll . move ( 0 , profileSize + ( profilePadding * 2 ) )
self . cScroll . resize ( self . cWidth , self . cHeight - statusSize - profileSize - ( profilePadding * 2 ) )
# Printer
limitWidgetSize ( self . cPrinterLabel )
limitWidgetSize ( self . cPrinterSettingsButton )
# Print amount
limitWidgetSize ( self . cAmountLabel )
self . cAmountInput . setMaximumWidth ( 64 )
# Stretch image
limitWidgetSize ( self . cStretchLabel )
limitWidgetSize ( self . cStretchTick )
# Rotate image
limitWidgetSize ( self . cRotateLabel )
limitWidgetSize ( self . cRotateTick )
# Offset horizontal
limitWidgetSize ( self . cOffsetHorzLabel )
self . cOffsetHorzInput . setMaximumWidth ( 64 )
# Offset vertical
limitWidgetSize ( self . cOffsetVertLabel )
self . cOffsetVertInput . setMaximumWidth ( 64 )
# Information
limitWidgetSize ( self . cInfoResolutionLabel )
limitWidgetSize ( self . cInfoResolutionValue )
limitWidgetSize ( self . cInfoRealResolutionLabel )
limitWidgetSize ( self . cInfoRealResolutionValue )
self . cStatus . move ( 0 , self . cHeight - statusSize )
self . cStatus . resize ( self . cWidth , statusSize )
def resizeEvent ( self , event ) :
self . cWidth = self . width ( )
self . cHeight = self . height ( )
self . cResizeElements ( )
def closeEvent ( self , event ) :
for window in windows :
if window != self :
window . close ( )
writeConfigFile ( " lastProfile.txt " , self . cProfileDropdown . currentText ( ) )
2022-03-29 03:18:34 +00:00
windows . remove ( self )
windows = [ ]
2023-08-23 23:43:29 +00:00
def main ( ) :
if not os . path . isdir ( p ( configDir , " profiles " ) ) :
os . makedirs ( p ( configDir , " profiles " ) )
if len ( getProfiles ( ) ) == 0 :
saveProfile ( defaultProfile , " default " )
app = QApplication ( sys . argv )
windows . append ( mainWindow ( ) )
app . exec_ ( )
main ( )