1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| from platform import system as system_name # Returns the system/OS name
import subprocess # Execute a shell command
from tkinter import *
Tk, StringVar, Label, Entry, Button, Frame
from functools import partial
import os
import os.path
import tkinter.font as tkFont
import sys
from tkinter import tix
from tkinter.constants import *
from tkinter import ttk
from tkinter.filedialog import askdirectory
import wmi
import win32print
import time
"""import pywin32"""
fontgras = "{courier new} 10 bold"
def ping(host):
"""
Returns True if host (str) responds to a ping request.
Remember that some hosts may not respond to a ping request even if the host name is valid.
"""
return subprocess.call(["ping", host], shell=True, stdout=open(os.devnull, 'wb'), stderr=open(os.devnull, 'wb'))
# Appelé quand l'utilisateur a choisi une imprimante
def onPrinterSelect(event):
pingResult = ping(e_imp.get())
if pingResult == 0:
e_imp['bg'] ='chartreuse2'
else:
e_imp['bg'] ='IndianRed1'
# Appelé quand l'utilisateur a choisi un ordinateur
def onComputerSelect(event):
host = e_ordi.get()
pingResult = ping(host)
if pingResult != 0:
e_ordi['bg'] ='IndianRed1'
return
e_ordi['bg'] ='chartreuse2'
c = wmi.WMI(host)
# Si t'as un seul repertoire en particulier dont tu veux le contenu, tu peux aussi
# le passer en parametre ici, pour rendre la fonction "getDirContent" plus generique
# Genre "getDirContent(c, dirPath)" que tu appelles comme ca : "getDirContent(c, 'C:/Mes Documents')"
contenu = getDirContent(c)
combomarque.entry.config(state='readonly') ## met la zone de texte en lecture seule
for x in range(len(contenu)):
combomarque.insert(x, contenu[x])
for printer in c.Win32_Printer():
txt.insert(END, '%s\n'%(printer.Caption))
print(printer.Caption)
txt.config(state=DISABLED)
combomarque.place(x=40, y=150)
def getDirContent(c):
#typeos=StringVar()
for winos in c.Win32_OperatingSystem(): #retourne le type d'os
labelos=Label(fenetre, text= winos.osarchitecture, font=fontgras).place(x=290,y=70)
typeos=winos.osarchitecture
print(typeos)
if typeos=="64 bits":
contenu=os.listdir("./drivers/X64") #liste le contenu du dossier
else :
contenu=os.listdir("./drivers/X86")
print(contenu)
return contenu
def onComboboxSelected(event):#function called when '<<ComboboxSelected>>' event is triggered
print (varcombo.get())#how to access to combobox selected item
def installimp():
connexip=win32print.AddPrinterConnection(e_imp.get()) #ajoute le port ip
#chemin du dossier des drivers
#copie des drivers en local sur le poste vise
#installation des pilotes en indiquant en plus le port ip"""
fenetre = Tk()
fenetre.geometry("600x400+350+100")
fenetre.title("Installateur d'imprimante")
"""text = StringVar (fenetre)"""
champ_label = Label(fenetre, text="IMPRIMANTE", font=fontgras).place(x=40,y=50)
champ_label2 = Label(fenetre, text="ORDINATEUR", font=fontgras).place(x=290,y=50)
""" grande fenetre reprenant toutes les imprimantes installees sur le poste cible"""
txt = Text(fenetre, height=10, width=40, wrap=WORD)
txt.place(x=200, y=150)
"""txt.insert(END, contenu)"""
imp = StringVar()
ordi = StringVar ()
e_imp = Entry(fenetre, textvariable=imp)
e_imp.place(x=130,y=50)
e_ordi = Entry(fenetre, textvariable=ordi)
e_ordi.place(x=390,y=50)
e_imp.bind("<FocusOut>", onPrinterSelect)
e_ordi.bind("<FocusOut>", onComputerSelect)
buttoninst = Button(fenetre, text='Installer', height=1, width=15, command=installimp)
buttoninst.place(x=150,y=345)
buttonquitter = Button(fenetre, text='Quitter', height=1, width=15, command=fenetre.destroy)
buttonquitter.place(x=300,y=345)
fenetre.tk.eval('package require Tix')
varcombo = tix.StringVar()
combomarque = tix.ComboBox(fenetre, editable=1, dropdown=1, variable=varcombo)
combomarque.bind('<<ComboboxSelected>>', onComboboxSelected)
fenetre.mainloop()
exit() |