Esempio n. 1
0
def create_printer(printer_name='PSPrinter'):
    printer_info_2 = {
        'pPrinterName': printer_name,
        'pDevMode': pywintypes.DEVMODEType(),        
        'pDriverName': 'MS Publisher Imagesetter',
        'pPortName': 'FILE:',
        'pPrintProcessor': 'WinPrint',
        'Attributes': 0,
        'AveragePPM': 0,
        'cJobs': 0,
        'DefaultPriority': 0,
        'Priority': 0,
        'StartTime': 0,
        'Status': 0,
        'UntilTime': 0,
        'pComment': '',
        'pLocation': '',
        'pDatatype': None,
        'pParameters': None,
        'pSecurityDescriptor': None,
        'pSepFile': None,
        'pServerName': None,
        'pShareName': None}

    h_printer = win32print.AddPrinter(None, 2, printer_info_2)
    return h_printer
Esempio n. 2
0
    def tgFullScreen(self, e=None):
        self.fs = not self.fs
        self.root.attributes("-fullscreen", self.fs)

        if PLATFORM == "darwin":
            if self.fs:  # For easier zoom
                px = (self.root.winfo_screenwidth() - self.W) // 2
                py = (self.root.winfo_screenheight() - self.H) // 2
                self.d.grid(padx=px, pady=py)
            else:
                self.d.grid(padx=0, pady=0)
                self.root.geometry("{}x{}+0+0".format(self.W, self.H))
                self.root.title("AXI Combat")

        if PLATFORM != "win32": return
        if not self.activeFS: return

        if self.fs:
            res = sorted(self.getResolutions())
            w = self.W
            h = self.H
            for x in res:
                if (x[0] >= w) and (x[1] >= h):
                    w, h = x
                    break
            dm = pywintypes.DEVMODEType()
            dm.PelsWidth = w
            dm.PelsHeight = h
            dm.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
            win32api.ChangeDisplaySettings(dm, 0)
        else:
            win32api.ChangeDisplaySettings(None, 0)
Esempio n. 3
0
def cfgPrt(selPrt):

    p = win32print.OpenPrinter(selPrt)
    printprocessor = win32print.GetPrinter(p, 2)['pPrintProcessor']
    dmsize = win32print.DocumentProperties(0, p, selPrt, None, None, 0)
    driverextra = dmsize - pywintypes.DEVMODEType().Size
    dm = pywintypes.DEVMODEType(driverextra)
    dm.Fields = dm.Fields | win32con.DM_ORIENTATION | win32con.DM_COPIES  #|win32con.DM_PAPERSIZE
    dm.Orientation = win32con.DMORIENT_LANDSCAPE
    dm.Copies = 1
    #dm.Papersize=win32con.DM_PAPERLENGTH(790)
    #dm.Paperwidth=530
    win32print.DocumentProperties(
        0, p, selPrt, dm, dm, win32con.DM_IN_BUFFER | win32con.DM_OUT_BUFFER)
    hDC = win32gui.CreateDC(printprocessor, selPrt, dm)
    printerwidth = win32ui.GetDeviceCaps(hDC, 110)
    printerheight = win32ui.GetDeviceCaps(hDC, 111)
Esempio n. 4
0
def set_resolution(gamestream_width, gamestream_height):
    print("Switching resolution to {0}x{1}".format(gamestream_width,
                                                   gamestream_height))
    devmode = pywintypes.DEVMODEType()
    devmode.PelsWidth = int(gamestream_width)
    devmode.PelsHeight = int(gamestream_height)
    devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
    win32api.ChangeDisplaySettings(devmode, 0)
Esempio n. 5
0
def setRes(x,y):
    
    devmode = pywintypes.DEVMODEType()

    devmode.PelsWidth = x
    devmode.PelsHeight = y
    devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
    if ChangeDisplaySettings(devmode, 0) != win32con.DISP_CHANGE_SUCCESSFUL:
        return False
    return True
Esempio n. 6
0
def set_resolution(gamestream_width, gamestream_height, refresh_rate=None):
    if refresh_rate is None:
        print("Switching resolution to {0}x{1}".format(gamestream_width,
                                                       gamestream_height))
    else:
        print("Switching resolution to {0}x{1} at {2}Hz".format(
            gamestream_width, gamestream_height, refresh_rate))
    devmode = pywintypes.DEVMODEType()
    devmode.PelsWidth = int(gamestream_width)
    devmode.PelsHeight = int(gamestream_height)
    devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
    if refresh_rate is not None:
        devmode.DisplayFrequency = refresh_rate
        devmode.Fields |= win32con.DM_DISPLAYFREQUENCY
    win32api.ChangeDisplaySettings(devmode, 0)
Esempio n. 7
0
import win32print, pywintypes, win32con, win32gui, win32api

pname = win32print.GetDefaultPrinter()
print(pname)
p = win32print.OpenPrinter(pname)
print('Printer handle: ', p)
print_processor = win32print.GetPrinter(p, 2)['pPrintProcessor']
## call with last parm set to 0 to get total size needed for printer's DEVMODE
dmsize = win32print.DocumentProperties(0, p, pname, None, None, 0)
## dmDriverExtra should be total size - fixed size
driverextra = dmsize - pywintypes.DEVMODEType(
).Size  ## need a better way to get DEVMODE.dmSize
dm = pywintypes.DEVMODEType(driverextra)
dm.Fields = dm.Fields | win32con.DM_ORIENTATION | win32con.DM_COPIES
dm.Orientation = win32con.DMORIENT_LANDSCAPE
dm.Copies = 2
win32print.DocumentProperties(0, p, pname, dm, dm,
                              win32con.DM_IN_BUFFER | win32con.DM_OUT_BUFFER)

pDC = win32gui.CreateDC(print_processor, pname, dm)
printerwidth = win32print.GetDeviceCaps(pDC, win32con.PHYSICALWIDTH)
printerheight = win32print.GetDeviceCaps(pDC, win32con.PHYSICALHEIGHT)

hwnd = win32gui.GetDesktopWindow()
l, t, r, b = win32gui.GetWindowRect(hwnd)
desktopheight = b - t
desktopwidth = r - l
dDC = win32gui.GetWindowDC(hwnd)

dcDC = win32gui.CreateCompatibleDC(dDC)
dcBM = win32gui.CreateCompatibleBitmap(dDC, desktopwidth, desktopheight)
Esempio n. 8
0
    def printOut(self, file_name):

        # List available printers
        #print("Available printers")
        #print(win32print.EnumPrinters(0,"None",1))
        #print(win32print.EnumPrinters(1,"None",2))
        #print(win32print.EnumPrinters(3,"None",1)[4])
        #print(win32print.EnumPrinters(3,"None",5))

        # Use Default Printer
        #printer_name = win32print.GetDefaultPrinter ()
        printer_name = "MITSUBISHI CP70D Series(USB)"
        print("Printer: " + printer_name)

        hprinter = win32print.OpenPrinter(printer_name, {"DesiredAccess": win32print.PRINTER_ALL_ACCESS})
        devmode = win32print.GetPrinter(hprinter, 2)["pDevMode"]

        # DEVMODE
        devmodeSize=win32print.DocumentProperties(0, hprinter, printer_name, None, None, 0)
        devmode = pywintypes.DEVMODEType(devmodeSize - pywintypes.DEVMODEType().Size)
        #devmode.Fields = devmode.Fields|win32con.DM_ORIENTATION|win32con.DM_COPIES

        win32print.DocumentProperties(0, hprinter, printer_name, devmode, devmode, 0)

        '''
        try:
            win32print.SetPrinter(hprinter, 2, properties, 0)
        except pywintypes.error, err:
            print(err[2])
            #sys.exit()
        '''

        gDC = win32gui.CreateDC("WINSPOOL", printer_name, devmode)

        hDC = win32ui.CreateDCFromHandle(gDC)

        self.printable_area = hDC.GetDeviceCaps (self.HORZRES), hDC.GetDeviceCaps (self.VERTRES)
        print "printable_area",self.printable_area

        printer_size = hDC.GetDeviceCaps (self.PHYSICALWIDTH), hDC.GetDeviceCaps (self.PHYSICALHEIGHT)
        print "printer_size",printer_size

        printer_margins = hDC.GetDeviceCaps (self.PHYSICALOFFSETX), hDC.GetDeviceCaps (self.PHYSICALOFFSETY)
        print "printer_margins",printer_margins
        
        bmp = Image.open (file_name)

        print "bmp.size[0]",bmp.size[0]," bmp.size[1]",bmp.size[1]

        #if bmp.size[0] > bmp.size[1]:
          #bmp = bmp.rotate (90)

        ratios = [1.0 * self.printable_area[0] / bmp.size[0], 1.0 * self.printable_area[1] / bmp.size[1]]
        print "ratios",ratios

        scale = min (ratios)
        print "scale",scale
        
        hDC.StartDoc (file_name)
        hDC.StartPage () 

        dib = ImageWin.Dib (bmp)
        scaled_width, scaled_height = [int (scale * i) for i in bmp.size]

        print "scaled width",scaled_width," scaled height",scaled_height


        x1 = int ((printer_size[0] - scaled_width) / 2)
        y1 = int ((printer_size[1] - scaled_height) / 2)
        x2 = x1 + scaled_width
        y2 = y1 + scaled_height

        print "x1, y1, x2, y2",x1, y1, x2, y2

        #dib.draw (hDC.GetHandleOutput (), (x1-5, y1+38, x2-25, y2-24))
        #dib.draw (hDC.GetHandleOutput (), (x1-5, y1+38, x2, y2))
        dib.draw (hDC.GetHandleOutput (), (0, 0, scaled_width, scaled_height))

        hDC.EndPage ()
        hDC.EndDoc ()
        hDC.DeleteDC ()
Esempio n. 9
0
# pywin32: how do I get a pyDEVMODE object?
>>> import pywintypes
>>> pywintypes.DEVMODEType()
<PyDEVMODE object at 0x00F38E90>
Esempio n. 10
0
import pywintypes
import win32api
import win32con
import win32gui
import win32print

pname = win32print.GetDefaultPrinter()
print(pname)
p = win32print.OpenPrinter(pname)
print('Printer handle: ', p)
print_processor = win32print.GetPrinter(p, 2)['pPrintProcessor']
# call with last parm set to 0 to get total size needed for printer's DEVMODE
dmsize = win32print.DocumentProperties(0, p, pname, None, None, 0)
# dmDriverExtra should be total size - fixed size
# need a better way to get DEVMODE.dmSize
driverextra = dmsize - pywintypes.DEVMODEType().Size
dm = pywintypes.DEVMODEType(driverextra)
dm.Fields = dm.Fields | win32con.DM_ORIENTATION | win32con.DM_COPIES
dm.Orientation = win32con.DMORIENT_LANDSCAPE
dm.Copies = 2
win32print.DocumentProperties(
    0,
    p,
    pname,
    dm,
    dm,
    win32con.DM_IN_BUFFER | win32con.DM_OUT_BUFFER)

pDC = win32gui.CreateDC(print_processor, pname, dm)
printerwidth = win32print.GetDeviceCaps(pDC, win32con.PHYSICALWIDTH)
printerheight = win32print.GetDeviceCaps(pDC, win32con.PHYSICALHEIGHT)
import win32api
import win32con
import pywintypes
devmode = pywintypes.DEVMODEType()
devmode.PelsWidth = 640
devmode.PelsHeight = 480
devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
win32api.ChangeDisplaySettings(devmode, 0)