Best Python code snippet using AutoItDriverServer_python
Select_file.py
Source:Select_file.py
1from tkinter import *2import asyncio3import shutil4import os 5from os import remove6from checkFiles import check_sd_files7from checkFiles import check_usb_files8from alert_windows import ask_delete9send_file = None10content_size_font = 1211sd_selected = True12usb_selected = False13def pack_list_box(lst_box_archivos,list_files):14 for i in list_files:15 print("Archivos disponibles : " + i)16 lst_box_archivos.insert(1,i) 17 lst_box_archivos.config(font = ("",content_size_font))18 lst_box_archivos.grid(padx=20, pady=10,row = 2, column = 0,columnspan = 4, sticky="nsew" )19def usb_list(lst_box_archivos,btn_sd, btn_USB):20 global sd_selected21 global usb_selected22 sd_selected = False23 usb_selected = True24 lst_box_archivos.delete(0,"end")25 btn_sd["state"] = ACTIVE26 btn_USB["state"] = DISABLED27 list_files = check_usb_files()28 pack_list_box(lst_box_archivos,list_files,)29def sd_list(lst_box_archivos,btn_sd, btn_USB):30 global sd_selected31 global usb_selected32 sd_selected = True33 usb_selected = False34 lst_box_archivos.delete(0,"end")35 btn_sd["state"] = DISABLED36 btn_USB["state"] = ACTIVE37 list_files = check_sd_files()38 pack_list_box(lst_box_archivos, list_files)39def select_file(lst_box_archivos, select_window):40 global send_file41 print("conectar")42 try:43 select = lst_box_archivos.curselection()44 select = lst_box_archivos.get(select)45 send_file = select46 select_window.destroy()47 except:48 pass49def move_file(lst_box_archivos, select_window,btn_sd, btn_USB):50 global sd_selected51 global usb_selected52 try:53 select = lst_box_archivos.curselection()54 select = lst_box_archivos.get(select)55 #mover de usb a sd56 if usb_selected:57 rute = os.listdir("/media/pi")58 copy_ruta = "/media/pi/" + rute[0] + "/"59 copy = copy_ruta + select60 #paste = "/home/rafael/gcodes/"+ select61 paste = "/home/pi/gcodes/"+ select62 shutil.copyfile(copy,paste)63 print("copiado")64 sd_list(lst_box_archivos,btn_sd, btn_USB)65 66 #mover de sd a usb67 else:68 copy = "/home/pi/gcodes/"+ select69 70 rute = os.listdir("/media/pi")71 paste_ruta = "/media/pi/" + rute[0] + "/"72 copy = paste_ruta + select73 paste = "/home/rafael/usb/"+ select74 shutil.copyfile(copy, paste)75 print("copiado")76 usb_list(lst_box_archivos,btn_sd, btn_USB)77 78 except:79 print("error")80def remove_file(lst_box_archivos, select_window,btn_sd, btn_USB):81 global sd_selected82 global send_file83 #try:84 file_name = lst_box_archivos.curselection()85 file_name = lst_box_archivos.get(file_name)86 ask_window = Toplevel(select_window)87 result = ask_delete(ask_window,select_window,file_name) 88 #borrar archivo de sd89 if result:90 if sd_selected:91 #delete_file = "/home/rafael/gcodes/" + file_name92 delete_file = "/home/pi/gcodes/" + file_name93 print("Borrado")94 remove(delete_file)95 sd_list(lst_box_archivos,btn_sd, btn_USB)96 #borrar archivo de usb97 else:98 #delete_file = "/home/rafael/usb/" + file_name99 #file_list = os.listdir("/media/pi/"+rute[0])100 rute = os.listdir("/media/pi")101 delete_ruta = "/media/pi/" + rute[0] + "/"102 delete_file = delete_ruta + file_name103 print("Borrado")104 remove(delete_file)105 usb_list(lst_box_archivos,btn_sd, btn_USB)106def cerrar_w(select_window):107 global send_file108 send_file = "cerrar"109 select_window.destroy()110 111def run_select_file(select_window, root):112 global send_file113 global file_list114 global sd_selected115 #variables de stylo116 title_size_font = 16117 content_size_font = 12118 color_theme = "snow"119 color_button = "deepskyblue3"120 color_text_button = "gray99"121 font = "Garuda"122 color_font_activate_button = "gray25"123 color_bg_activate_button = "deep sky Blue"124 #select_window.title("Colibrgyti 3D")125 select_window.minsize(800, 480 )126 select_window.attributes("-type","splash")127 select_window.attributes("-zoomed", True)128 select_window.fullScreenState = True129 select_window.attributes('-fullscreen')130 select_window.focus_force()131 select_window.resizable(0,0)132 133 #select_window.attributes("-type","splash")134 #select_window.attributes("-zoomed", True)135 select_window.config(bg = color_theme)136 select_window.protocol("WM_DELETE_WINDOW", lambda : cerrar_w(select_window)) #accion al cerrar la ventana 137 138 #Preparacion de los puertos 139 #print("Puerto :" + str(puerto))140 141 #preparacion de la listbox para seleccionar los puertos 142 titlep = Label(select_window, text = "Selecciona el archivo para imprimir", bg = color_theme, 143 font = (font, content_size_font))144 titlep.grid(padx=10, pady=10, row = 0, column = 0, columnspan = 2)145 146 lst_box_archivos = Listbox(select_window)147 btn_USB = Button(select_window,text =" USB ", command = lambda : usb_list(lst_box_archivos,btn_sd,btn_USB), )148 btn_USB.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))149 btn_USB.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button,150 font = (font,content_size_font))151 # 3 b btn_USB["state"] = DISABLED152 btn_USB.grid(padx=10, pady=10,row = 1, column = 0)153 154 155 btn_sd = Button(select_window,text ="IMPRESORA", command = lambda : sd_list(lst_box_archivos,btn_sd,btn_USB), )156 btn_sd.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))157 btn_sd.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button, 158 font = (font,content_size_font))159 #btn_sd.pack(padx = 15, pady = 10)160 btn_sd.grid( pady=10,row = 1, column = 1 )161 btn_sd["state"] = DISABLED 162 select_window.columnconfigure(3,weight=1)#configura la columna para que se estire163 #select_window.rowconfigure(2,weight=1) #configura la columna para que se estire164 #lst_box_archivos.grid(row=0, column=0)165 sd_list(lst_box_archivos,btn_sd,btn_USB)166 167 btn_select = Button(select_window,text ="Seleccionar", command = lambda : select_file(lst_box_archivos,select_window), )168 btn_select.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))169 btn_select.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button, 170 font = (font,content_size_font))171 #btn_sd.pack(padx = 15, pady = 10)172 btn_select.grid( pady=10,row = 3, column = 0 )173 #btn_select["state"] = DISABLED 174 175 btn_move = Button(select_window,text ="Mover", command = lambda : move_file(lst_box_archivos,select_window,btn_sd, btn_USB), )176 btn_move.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))177 btn_move.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button, 178 font = (font,content_size_font))179 #btn_sd.pack(padx = 15, pady = 10)180 btn_move.grid( pady=10,row = 3, column = 1 )181 #btn_select["state"] = DISABLED 182 btn_move = Button(select_window,text ="Borrar", command = lambda : remove_file(lst_box_archivos,select_window,btn_sd, btn_USB), )183 btn_move.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))184 btn_move.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button, 185 font = (font,content_size_font))186 #btn_sd.pack(padx = 15, pady = 10)187 btn_move.grid( pady=10,row = 3, column = 2 )188 #btn_select["state"] = DISABLED 189 """ 190 #interfaz grafica191 btn_connect = Button(select_window,text ="seleccionar", command = lambda : connect(lst_box_archivos, select_window), )192 btn_connect.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))193 btn_connect.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button, 194 font = (font,content_size_font))195 btn_connect.pack(padx = 15, pady = 10)196 btn_update = Button(select_window, text ="Actualizar", command = lambda : update(lst_box_archivos) )197 btn_update.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))198 btn_update.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button, font = (font,content_size_font))199 btn_update.pack(padx = 15, pady = 10)200 """201 root.wait_window(select_window)202 #send_file = "/home/rafael/gcodes/"+send_file203 if sd_selected:204 send_file = "/home/pi/gcodes/"+send_file205 else:206 rute = os.listdir("/media/pi")207 ruta = "/media/pi/" + rute[0] + "/"208 send_file = ruta + send_file 209 print("Archivo enviado: "+send_file)...
test_window_select_file.py
Source:test_window_select_file.py
1from tkinter import *2import asyncio3import shutil4from os import remove5from checkFiles import check_sd_files6from checkFiles import check_usb_files7from alert_windows import ask_delete8send_file = None9content_size_font = 1210sd_selected = True11usb_selected = False12def pack_list_box(lst_box_archivos,list_files):13 for i in list_files:14 print("Archivos disponibles : " + i)15 lst_box_archivos.insert(1,i) 16 lst_box_archivos.config(font = ("",content_size_font))17 lst_box_archivos.grid(padx=20, pady=10,row = 2, column = 0,columnspan = 4, sticky="nsew" )18def usb_list(lst_box_archivos,btn_sd, btn_USB):19 global sd_selected20 global usb_selected21 sd_selected = False22 usb_selected = True23 lst_box_archivos.delete(0,"end")24 btn_sd["state"] = ACTIVE25 btn_USB["state"] = DISABLED26 list_files = check_usb_files()27 pack_list_box(lst_box_archivos,list_files,)28def sd_list(lst_box_archivos,btn_sd, btn_USB):29 global sd_selected30 global usb_selected31 sd_selected = True32 usb_selected = False33 lst_box_archivos.delete(0,"end")34 btn_sd["state"] = DISABLED35 btn_USB["state"] = ACTIVE36 list_files = check_sd_files()37 pack_list_box(lst_box_archivos, list_files)38def select_file(lst_box_archivos, select_window):39 global send_file40 print("conectar")41 try:42 select = lst_box_archivos.curselection()43 select = lst_box_archivos.get(select)44 send_file = select45 select_window.destroy()46 except:47 pass48def move_file(lst_box_archivos, select_window,btn_sd, btn_USB):49 global sd_selected50 global usb_selected51 try:52 select = lst_box_archivos.curselection()53 select = lst_box_archivos.get(select)54 #mover de usb a sd55 if usb_selected:56 copy = "/home/rafael/usb/"+ select57 paste = "/home/rafael/gcodes/"+ select58 shutil.copyfile(copy,paste)59 print("copiado")60 sd_list(lst_box_archivos,btn_sd, btn_USB)61 62 #mover de sd a usb63 else:64 copy = "/home/rafael/gcodes/"+ select65 paste = "/home/rafael/usb/"+ select66 shutil.copyfile(copy, paste)67 print("copiado")68 usb_list(lst_box_archivos,btn_sd, btn_USB)69 70 except:71 print("error")72def remove_file(lst_box_archivos, select_window,btn_sd, btn_USB):73 global sd_selected74 global send_file75 #try:76 file_name = lst_box_archivos.curselection()77 file_name = lst_box_archivos.get(file_name)78 ask_window = Toplevel(select_window)79 result = ask_delete(ask_window,select_window,file_name) 80 #borrar archivo de sd81 if result:82 if sd_selected:83 delete_file = "/home/rafael/gcodes/" + file_name84 print("Borrado")85 remove(delete_file)86 sd_list(lst_box_archivos,btn_sd, btn_USB)87 #borrar archivo de usb88 else:89 delete_file = "/home/rafael/usb/" + file_name90 print("Borrado")91 remove(delete_file)92 usb_list(lst_box_archivos,btn_sd, btn_USB)93def cerrar_w(select_window):94 global send_file95 send_file = "cerrar"96 select_window.destroy()97 98def run_select_file(select_window, root):99 global send_file100 global file_list101 global sd_selected102 #variables de stylo103 title_size_font = 16104 content_size_font = 12105 color_theme = "snow"106 color_button = "deepskyblue3"107 color_text_button = "gray99"108 font = "Garuda"109 color_font_activate_button = "gray25"110 color_bg_activate_button = "deep sky Blue"111 #select_window.title("Colibrgyti 3D")112 select_window.minsize(800, 480 )113 #select_window.attributes("-type","splash")114 #select_window.attributes("-zoomed", True)115 select_window.config(bg = color_theme)116 select_window.protocol("WM_DELETE_WINDOW", lambda : cerrar_w(select_window)) #accion al cerrar la ventana 117 118 #Preparacion de los puertos 119 #print("Puerto :" + str(puerto))120 121 #preparacion de la listbox para seleccionar los puertos 122 titlep = Label(select_window, text = "Selecciona el archivo para imprimir", bg = color_theme, 123 font = (font, content_size_font))124 titlep.grid(padx=10, pady=10, row = 0, column = 0, columnspan = 2)125 126 lst_box_archivos = Listbox(select_window)127 btn_USB = Button(select_window,text =" USB ", command = lambda : usb_list(lst_box_archivos,btn_sd,btn_USB), )128 btn_USB.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))129 btn_USB.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button,130 font = (font,content_size_font))131 # 3 b btn_USB["state"] = DISABLED132 btn_USB.grid(padx=10, pady=10,row = 1, column = 0)133 134 135 btn_sd = Button(select_window,text ="IMPRESORA", command = lambda : sd_list(lst_box_archivos,btn_sd,btn_USB), )136 btn_sd.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))137 btn_sd.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button, 138 font = (font,content_size_font))139 #btn_sd.pack(padx = 15, pady = 10)140 btn_sd.grid( pady=10,row = 1, column = 1 )141 btn_sd["state"] = DISABLED 142 select_window.columnconfigure(3,weight=1)#configura la columna para que se estire143 #select_window.rowconfigure(2,weight=1) #configura la columna para que se estire144 #lst_box_archivos.grid(row=0, column=0)145 sd_list(lst_box_archivos,btn_sd,btn_USB)146 147 btn_select = Button(select_window,text ="Seleccionar", command = lambda : select_file(lst_box_archivos,select_window), )148 btn_select.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))149 btn_select.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button, 150 font = (font,content_size_font))151 #btn_sd.pack(padx = 15, pady = 10)152 btn_select.grid( pady=10,row = 3, column = 0 )153 #btn_select["state"] = DISABLED 154 155 btn_move = Button(select_window,text ="Mover", command = lambda : move_file(lst_box_archivos,select_window,btn_sd, btn_USB), )156 btn_move.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))157 btn_move.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button, 158 font = (font,content_size_font))159 #btn_sd.pack(padx = 15, pady = 10)160 btn_move.grid( pady=10,row = 3, column = 1 )161 #btn_select["state"] = DISABLED 162 btn_move = Button(select_window,text ="Borrar", command = lambda : remove_file(lst_box_archivos,select_window,btn_sd, btn_USB), )163 btn_move.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))164 btn_move.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button, 165 font = (font,content_size_font))166 #btn_sd.pack(padx = 15, pady = 10)167 btn_move.grid( pady=10,row = 3, column = 2 )168 #btn_select["state"] = DISABLED 169 """ 170 #interfaz grafica171 btn_connect = Button(select_window,text ="seleccionar", command = lambda : connect(lst_box_archivos, select_window), )172 btn_connect.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))173 btn_connect.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button, 174 font = (font,content_size_font))175 btn_connect.pack(padx = 15, pady = 10)176 btn_update = Button(select_window, text ="Actualizar", command = lambda : update(lst_box_archivos) )177 btn_update.config(bg = color_button, fg = color_text_button ,font =(font,content_size_font))178 btn_update.config( activebackground = color_bg_activate_button, activeforeground =color_font_activate_button, font = (font,content_size_font))179 btn_update.pack(padx = 15, pady = 10)180 """181 root.wait_window(select_window)182 send_file = "/home/rafael/gcodes/"+send_file183 print("Archivo enviado: "+send_file)184 return send_file185def run():186 root = Tk()187 select_window = Toplevel(root)188 run_select_file(select_window,root)189 root.mainloop()190if __name__ == "__main__":...
mainwindow.py
Source:mainwindow.py
1""" Main Window Class """2import sys3from PyQt5.QtCore import Qt4from PyQt5.QtGui import QIcon5from PyQt5.QtWidgets import QWidget, QApplication, QGridLayout, QPushButton, QTextEdit, QTabWidget6from car_file import CarFile7from constants import ICON_PATH8from ui.add_window import AddCarWindow9from ui.delete_window import DeleteCarWindow10from ui.select_window import SelectCarWindow, SelectCategoryWindow11from ui.update_window import UpdateCarWindow12from version import VERSION13APP = QApplication([])14class MainWindow(QWidget):15 """MainWindow class"""16 def __init__(self, parent=None, title=f"Car Rater {VERSION}"):17 super().__init__(parent)18 self.setWindowTitle(title)19 self.setWindowIcon(QIcon(ICON_PATH))20 self.car_file = CarFile()21 self.elements = self.build_ui()22 def build_ui(self):23 """24 Build the UI and return a dict mapping of elements25 """26 grid_main = QGridLayout()27 self.setLayout(grid_main)28 add = QPushButton("Add Car", self)29 add.clicked.connect(self._add_car)30 delete = QPushButton("Delete Car", self)31 delete.clicked.connect(self._delete_car)32 update = QPushButton("Update Car", self)33 update.clicked.connect(self._update_car)34 chevies = QTextEdit(self)35 fords = QTextEdit(self)36 mopars = QTextEdit(self)37 trucks = QTextEdit(self)38 other = QTextEdit(self)39 tabs = QTabWidget()40 tabs.addTab(chevies, "Chevies")41 tabs.addTab(fords, "Fords")42 tabs.addTab(mopars, "Mopars")43 tabs.addTab(trucks, "Trucks")44 tabs.addTab(other, "Other")45 for text_edit in [chevies, fords, mopars, trucks, other]:46 text_edit.setFontFamily("Courier")47 text_edit.setMinimumWidth(500)48 text_edit.setMinimumHeight(200)49 text_edit.setReadOnly(True)50 chevies.setText(str(self.car_file.chevy_list))51 fords.setText(str(self.car_file.ford_list))52 mopars.setText(str(self.car_file.mopar_list))53 trucks.setText(str(self.car_file.truck_list))54 other.setText(str(self.car_file.other_list))55 close = QPushButton("Close", self)56 close.clicked.connect(self.close)57 grid_main.addWidget(add, 0, 0)58 grid_main.addWidget(update, 1, 0)59 grid_main.addWidget(delete, 2, 0)60 grid_main.addWidget(close, 3, 0)61 grid_main.addWidget(tabs, 4, 0)62 return {63 "grids": {64 "main": grid_main,65 },66 "buttons": {67 "add": add,68 "delete": delete,69 "update": update,70 },71 "text_edits": {72 "Chevy": chevies,73 "Ford": fords,74 "Mopar": mopars,75 "Truck": trucks,76 "Other": other,77 },78 }79 def start(self):80 """81 Show and start the GUI82 """83 self.show()84 sys.exit(APP.exec_())85 def _add_car(self):86 """87 Show the Add Car Window88 """89 self.setEnabled(False)90 add_window = AddCarWindow(self.car_file, "Add a Car")91 add_window.exec_()92 add_window.show()93 car_list = add_window.selected_list94 if car_list is not None:95 self.elements["text_edits"][car_list.category].setText(str(car_list))96 self.setEnabled(True)97 def _delete_car(self):98 """99 Show the Delete Car Window100 """101 self.setEnabled(False)102 select_window = SelectCategoryWindow(self.car_file, "Select a Category")103 select_window.exec_()104 select_window.show()105 car_list = select_window.car_list106 select_window.close()107 if car_list is not None:108 delete_window = DeleteCarWindow(self.car_file, car_list, "Delete a Car")109 delete_window.exec_()110 delete_window.show()111 self.elements["text_edits"][car_list.category].setText(str(car_list))112 self.setEnabled(True)113 def _update_car(self):114 """115 Show the Update Car Window116 """117 self.setEnabled(False)118 select_window = SelectCategoryWindow(self.car_file, "Select a Category")119 select_window.exec_()120 select_window.show()121 car_list = select_window.car_list122 select_window.close()123 # Exit early if they hit cancel124 if car_list is None:125 self.setEnabled(True)126 return127 select_window = SelectCarWindow(self.car_file, car_list, "Select a Car")128 select_window.exec_()129 select_window.show()130 car = select_window.selected_car131 select_window.close()132 if car is not None:133 update_window = UpdateCarWindow(134 self.car_file, car_list, "Update a Car", car135 )136 update_window.exec_()137 update_window.show()138 self.elements["text_edits"][car_list.category].setText(str(car_list))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!