Esempio n. 1
0
    def printFile(self, file):
        if (not os.path.exists(file)):
            sys.stderr.write('文件(%s)不存在\n' % file)
            return

        if win32print.GetDefaultPrinterW() == None:
            sys.stderr.write('找不到打印机')
            return

        win32api.ShellExecute(0,\
         'print',\
         file,\
         win32print.GetDefaultPrinterW(),\
         ".",
         0)
Esempio n. 2
0
File: edlp.py Progetto: vhsja/EDLP
 def print2Printer(self):
     ret = True
     try:
         rfile = string.join(random.sample('abcdefghijklmnopqistuvwxyz', 3))
         dfile = "C:\Users\Administrator\Desktop\\" + rfile.replace(
             ' ', '') + ".xps"
         pfile = 'file\\ftp.txt'
         if os.path.exists(pfile):
             win32api.ShellExecute(0, 'print', pfile,
                                   win32print.GetDefaultPrinterW(), ".", 0)
             x = os.system('autoit\\dialogconform.exe')
             if x == 0:
                 print "print file OK"
                 return True
             else:
                 print "print file False"
                 return False
         else:
             print "打印文件不存在"
             print "print file False"
             return False
     except Exception, e:
         print e
         print "print file False"
         return False
def printer_run(file_name):
    #for fn in ['1.txt', '2.txt', '3.txt', '4.docx']:
    win32api.ShellExecute(0,\
                          'print',\
                          file_name,\
                          win32print.GetDefaultPrinterW(),\
                          ".",0)
Esempio n. 4
0
 def SetPrinter(self, cPrinter=''):
     try:
         win32print.SetDefaultPrinterW(cPrinter)
     except Exception as e:
         # printer = QPrinter()
         #
         # dialog = QPrintDialog(printer)
         # dialog.exec_()
         _ventana = Ui_FormPrinter()
         _ventana.exec_()
         if _ventana.cPrinterSelected != '':
             win32print.SetDefaultPrinterW(_ventana.cPrinterSelected)
         else:
             Ventanas.showAlert(
                 "Sistema",
                 "No se encontro la impresora {} en la maquina y se imprimira en {}"
                 .format(cPrinter, win32print.GetDefaultPrinterW()))
             win32print.SetDefaultPrinterW(win32print.GetDefaultPrinterW())
Esempio n. 5
0
def callprint(img):
    '''
    调用打印机打印图片
    :param img_path:
    :return:
    '''
    try:
        fn = img
        win32api.ShellExecute(0,\
                              'print',\
                              fn,\
                              win32print.GetDefaultPrinterW(),\
                              ".",
                              0)
    except Exception as e:
        print(e)
Esempio n. 6
0
def printdoc(filename):
    handle = win32print.OpenPrinter(win32print.GetDefaultPrinter())
    status1 = 1024  # 初始化为1024表示忙 0是空闲状态
    status2 = 2  # 打印机队列数
    while (status1 == 1024) and (status2 >= 2):
        statusqueue = (win32print.GetPrinter(handle))
        status1 = statusqueue[-3]
        status2 = statusqueue[-2]
        print("    等待中,打印队列" + str(status2) + "文档")
        time.sleep(1)
        continue
    print("开始打印" + filename)
    win32api.ShellExecute(0, 'print', filename, win32print.GetDefaultPrinterW(), ".", 0)
    while ((win32print.GetPrinter(handle)[-2]) != (status2 +1)):
        time.sleep(1)
        print("等待打印机反馈")
    os.remove(filename)
Esempio n. 7
0
 def __print_in_windows(self):
     try:
         import win32api
         # import win32ui
         # import win32con
         import win32print
         print_files = self.__get_files()
         if print_files:
             for f in print_files:
                 temp = path.join(self.__config["dir_path"], f)
                 win32api.ShellExecute(0, 'print', temp,
                                       win32print.GetDefaultPrinterW(), ".",
                                       0)
         pass
     except (ImportError, Exception) as e:
         raise e
     pass
Esempio n. 8
0
 def GetDefaultPrinter(self):
     return win32print.GetDefaultPrinterW()
Esempio n. 9
0
 def __init__(self):
     self.cDefault = win32print.GetDefaultPrinterW()
Esempio n. 10
0
 def get_default_printer_name(cls):
     return win32print.GetDefaultPrinterW()