How to use hidelist method in pyatom

Best Python code snippet using pyatom_python

menu_final.py

Source:menu_final.py Github

copy

Full Screen

1import tkinter as tk 2from tkinter import ttk #Se importa tkinter y ttk para la creación de todo lo que contine la interfaz gráfica3import carpetas 4import leer_imagen5import piedrapapelotijera #Se importan los archivos carpetas.py, leer_imagen.py y piedrapapelotijera.py para llamar las funciones dentro de estas cuando se requiera6intro="""7 BIENVENIDO A SU MULTITASKER8Para iniciar, tenga en cuenta que:9El MULTITASKER consta de 6 opciones para facilitar su trabajo, las cuales son:101. Escribir información para posteriormente guardarla en el archivo que desee112. Obtener la información que esta en el archivo que desee, para poder visualizarla desde BLOC DE NOTAS123. Ordenar sus archivos según lo requiera, agrupando por carpetas con cierto nombre archivos con el mismo nombre134. Usar una calculadora interactiva para hacer operaciones rápidas145. Extraer texto de una imagen que contenga cadenas de caracteres156. Jugar juegos adicionales como piedra, papel o tijera a modo de pasatiempo 16 ¡Ya puede iniciar! 17"""18def popup(mensaje): #Funcion para generar un "popup" que imprime el texto que se defina en forma de ventana temporal19 top= tk.Toplevel(ventana)20 top.title("Mensaje")21 tk.Label(top, text= mensaje, font=(fonta),justify="left").pack()22 ttk.Button(top,text="Aceptar",style="TButton",command=top.destroy).pack()23def hide(): #Función para ocultar los botones, labels o cajas de texto que ya no se usen y dar paso a otras segun se requiera24 for i in hidelist:25 i.pack_forget()26 hidelist.clear()27def menu(): #Función con el menú principal del programa y todas las acciones que puede realizar28 hide()29 label1=tk.Label(ventana,text="¡Bienvenido! Por favor, elija una opción:",font=fonta)30 label1.pack(pady=10)31 hidelist.append(label1)32 opcion1=ttk.Button(ventana,text="Crear una nueva carpeta",style="TButton",command=crear_carpeta)33 opcion1.pack(pady=2)34 hidelist.append(opcion1)35 opcion2 = ttk.Button(ventana, text="Entrar en una carpeta existente", style="TButton",command=entrar_carpeta)36 opcion2.pack(pady=2)37 hidelist.append(opcion2)38 opcion3 = ttk.Button(ventana, text="Ordenar archivos", style="TButton",command=ordenar_archivos)39 opcion3.pack(pady=2)40 hidelist.append(opcion3)41 opcion4 = ttk.Button(ventana, text="Calculadora", style="TButton", command=calculadora)42 opcion4.pack(pady=2)43 hidelist.append(opcion4)44 opcion5 = ttk.Button(ventana, text="Extraer texto de imagen", style="TButton", command=lista_imagenes)45 opcion5.pack(pady=2)46 hidelist.append(opcion5)47 opcion6 = ttk.Button(ventana, text="Piedra, papel o tijera", style="TButton", command=elegir)48 opcion6.pack(pady=2)49 hidelist.append(opcion6)50 opcion7 = ttk.Button(ventana, text="Salir del programa", style="TButton",command=ventana.destroy)51 opcion7.pack(pady=2)52 hidelist.append(opcion7)53#Opcion 1: Crear carpetas54def save_archivo(nombre,data,carpeta,actualoption): #Funcion para guardar el archivo .txt creado y preguntar si desea crear otro o salir de la opción55 if actualoption==1:56 end=menu57 elif actualoption==2:58 end=entrar_carpeta59 contenido=data.get()60 carpetas.escribir_texto(nombre,contenido,carpeta)61 hide()62 label1 = tk.Label(ventana, text="¿Desea crear otro archivo?", font=fonta)63 label1.pack(pady=10)64 hidelist.append(label1)65 opcion1 = ttk.Button(ventana, text="Si", style="TButton",command=lambda: crear_archivo(carpeta))66 opcion1.pack(pady=2)67 hidelist.append(opcion1)68 opcion2 = ttk.Button(ventana, text="No", style="TButton", command=end)69 opcion2.pack(pady=2)70 hidelist.append(opcion2)71def contenido_archivo(data,carpeta,actualoption): #Función que pide al usuario el contenido del archivo .txt72 nombre=data.get()73 hide()74 label1 = tk.Label(ventana, text="A continuacion, ingrese el contenido del archivo: ", font=fonta)75 label1.pack(pady=10)76 hidelist.append(label1)77 entry1 = tk.Entry(ventana)78 entry1.pack(pady=2)79 hidelist.append(entry1)80 confirm = ttk.Button(ventana, text="Confirmar", style="TButton", command=lambda: save_archivo(nombre,entry1,carpeta,actualoption))81 confirm.pack()82 hidelist.append(confirm)83 #Poner mensaje84def crear_archivo(carpeta,actualoption): #Función que pide al usuario el nombre del archivo .txt85 hide()86 label1 = tk.Label(ventana, text="Ingrese el nombre del archivo: ", font=fonta)87 label1.pack(pady=10)88 hidelist.append(label1)89 entry1 = tk.Entry(ventana)90 entry1.pack(pady=2)91 hidelist.append(entry1)92 confirm = ttk.Button(ventana, text="Confirmar", style="TButton", command=lambda: contenido_archivo(entry1,carpeta,actualoption))93 confirm.pack()94 hidelist.append(confirm)95def save_carpeta(data,actualoption): #Funcion que guarda la carpeta creada y pregunta si desea crear un archivo en la carpeta o salir de la misma96 carpeta=data.get()97 if carpetas.existe(carpeta) == False:98 popup(carpetas.crear_carpeta(carpeta))99 hide()100 label1 = tk.Label(ventana, text="¿Que desea hacer en esta carpeta?", font=fonta)101 label1.pack(pady=10)102 hidelist.append(label1)103 opcion1 = ttk.Button(ventana, text="Crear un nuevo archivo", style="TButton", command=lambda: crear_archivo(carpeta,actualoption))104 opcion1.pack(pady=2)105 hidelist.append(opcion1)106 opcion2 = ttk.Button(ventana, text="Salir de la carpeta", style="TButton", command=menu)107 opcion2.pack(pady=2)108 hidelist.append(opcion2)109 else:110 popup("Esta carpeta ya existe, ingrese otro nombre")111 crear_carpeta()112def crear_carpeta(): #Archivo que pregunta al usuario el nombre de la carpeta a crear113 actualoption=1114 hide()115 label1=tk.Label(ventana,text="Ingrese el nombre de la carpeta: ",font=fonta)116 label1.pack(pady=10)117 hidelist.append(label1)118 entry1 = tk.Entry(ventana)119 entry1.pack(pady=2)120 hidelist.append(entry1)121 confirm = ttk.Button(ventana, text="Confirmar", style="TButton",command= lambda:save_carpeta(entry1,actualoption))122 confirm.pack()123 hidelist.append(confirm)124#Opcion 2: Entrar en carpeta125def leer(data,carpeta): #Funcion que evalua si el archivo ingresado existe o no126 texto=data.get()127 ruta = str(carpeta) + str("/") + str(texto)128 exist = carpetas.existe(ruta)129 if exist==False: #Si no existe, notifica que el archivo no existe y pregunta si desea buscar otro o salir de la opción130 hide()131 label1 = tk.Label(ventana, text="El archivo no existe, ¿Desea buscar otro archivo?", font=fonta)132 label1.pack(pady=10)133 hidelist.append(label1)134 opcion1 = ttk.Button(ventana, text="Si", style="TButton",command=entrar_archivo(carpeta))135 opcion1.pack(pady=2)136 hidelist.append(opcion1)137 opcion2 = ttk.Button(ventana, text="No", style="TButton", command=menu)138 opcion2.pack(pady=2)139 hidelist.append(opcion2)140 elif exist==True: #Si existe, imprime el contenido del archivo y pregunta si desea buscar otro o salir de la opción141 hide()142 txt=texto+".txt:\n\n"+carpetas.leer(ruta)143 popup(txt)144 label1 = tk.Label(ventana, text="¿Desea buscar otro archivo?", font=fonta)145 label1.pack(pady=10)146 hidelist.append(label1)147 opcion1 = ttk.Button(ventana, text="Si", style="TButton", command=entrar_archivo)148 opcion1.pack(pady=2)149 hidelist.append(opcion1)150 opcion2 = ttk.Button(ventana, text="No", style="TButton", command=entrar_carpeta)151 opcion2.pack(pady=2)152 hidelist.append(opcion2)153def entrar_archivo(carpeta): #Función que pide al usuario ingresar el nombre del archivo que desea buscar154 hide()155 label1 = tk.Label(ventana, text="Ingrese el nombre del archivo a buscar: ", font=fonta)156 label1.pack(pady=10)157 hidelist.append(label1)158 entry1 = tk.Entry(ventana)159 entry1.pack(pady=2)160 hidelist.append(entry1)161 confirm = ttk.Button(ventana, text="Confirmar", style="TButton", command=lambda: leer(entry1, carpeta))162 confirm.pack()163 hidelist.append(confirm)164def save_entrada(data,actualoption): #Funcion que evalua si la carpeta ingresada existe o no165 carpeta=data.get()166 exist=carpetas.existe(carpeta)167 if exist==False: #Si no existe, notifica al usuario que no existe y pregunta si desea buscar otra o salir de la opción168 hide()169 label1 = tk.Label(ventana, text="La carpeta no existe, ¿Desea buscar otra carpeta?", font=fonta)170 label1.pack(pady=10)171 hidelist.append(label1)172 opcion1 = ttk.Button(ventana, text="Si", style="TButton",command=entrar_carpeta)173 opcion1.pack(pady=2)174 hidelist.append(opcion1)175 opcion2 = ttk.Button(ventana, text="No", style="TButton", command=menu)176 opcion2.pack(pady=2)177 hidelist.append(opcion2)178 elif exist==True: #Si existe, pregunta al usuario que desea hacer en esta carpeta, crear un archivo, leer un archivo o salir179 hide()180 label1 = tk.Label(ventana, text="¿Que desea hacer en esta carpeta?", font=fonta)181 label1.pack(pady=10)182 hidelist.append(label1)183 opcion1 = ttk.Button(ventana, text="Crear un nuevo archivo", style="TButton", command=lambda: crear_archivo(carpeta,actualoption))184 opcion1.pack(pady=2)185 hidelist.append(opcion1)186 opcion2 = ttk.Button(ventana, text="Leer un archivo", style="TButton", command=lambda: entrar_archivo(carpeta))187 opcion2.pack(pady=2)188 hidelist.append(opcion2)189 opcion3 = ttk.Button(ventana, text="Salir de la carpeta", style="TButton", command=menu)190 opcion3.pack(pady=2)191 hidelist.append(opcion3)192def entrar_carpeta(): #Funcion que pregunta al usuario el nombre de la carpeta a buscar193 actualoption=2194 hide()195 label1 = tk.Label(ventana, text="Ingrese el nombre de la carpeta a buscar: ", font=fonta)196 label1.pack(pady=10)197 hidelist.append(label1)198 entry1 = tk.Entry(ventana)199 entry1.pack(pady=2)200 hidelist.append(entry1)201 confirm = ttk.Button(ventana, text="Confirmar", style="TButton", command=lambda: save_entrada(entry1,actualoption))202 confirm.pack()203 hidelist.append(confirm)204#Opcion 3: Ordenar archivos205def continuar(): #Funcion que pregunta al usuario si desea ordenar mas archivos o salir de la opción206 hide()207 label1 = tk.Label(ventana, text="¿Desea ordenar mas archivos? ", font=fonta)208 label1.pack(pady=10)209 hidelist.append(label1)210 opcion1 = ttk.Button(ventana, text="Si", style="TButton", command=ordenar_archivos)211 opcion1.pack(pady=2)212 hidelist.append(opcion1)213 opcion2 = ttk.Button(ventana, text="No", style="TButton", command=menu)214 opcion2.pack(pady=2)215 hidelist.append(opcion2)216def nombre_carpeta(carpeta): #Funcion que notifica que los archivos fueron ordenados con exito217 hide()218 carpetas.ordenar_nombre(carpeta)219 popup("Los archivos fueron ordenados con éxito")220 continuar()221def palabra_carpeta(carpeta,data): #Funcion que notifica que los archivos fueron ordenados con exito222 hide()223 clave=data.get()224 carpetas.ordenar_palabra(carpeta,clave)225 popup("Los archivos fueron ordenados con éxito")226 continuar()227def palabra_clave(carpeta): #Funcion que pregunta al usuario la palabra clave para ordenar los archivos228 hide()229 label1 = tk.Label(ventana, text="Ingrese la palabra clave para ordenar los archivos", font=fonta)230 label1.pack(pady=10)231 hidelist.append(label1)232 entry1 = tk.Entry(ventana)233 entry1.pack(pady=2)234 hidelist.append(entry1)235 confirm = ttk.Button(ventana, text="Confirmar", style="TButton", command=lambda: palabra_carpeta(carpeta,entry1))236 confirm.pack()237 hidelist.append(confirm)238def tipo_carpeta(carpeta,data): #Funcion que notifica que los archivos fueron ordenados con exito239 hide()240 sufijo="."+data.get()241 carpetas.ordenar_tipo(carpeta,sufijo)242 popup("Los archivos fueron ordenados con éxito")243 continuar()244def tipo_sufijo(carpeta): #Funcion que pregunta al usuario el sufijo para ordenar los archivos245 hide()246 label1 = tk.Label(ventana, text="Ingrese la extensión para ordenar los archivos: ", font=fonta)247 label1.pack(pady=10)248 hidelist.append(label1)249 entry1 = tk.Entry(ventana)250 entry1.pack(pady=2)251 hidelist.append(entry1)252 confirm = ttk.Button(ventana, text="Confirmar", style="TButton", command=lambda: tipo_carpeta(carpeta,entry1))253 confirm.pack()254 hidelist.append(confirm)255def tipo_orden(data): #Funcion que evalua si la carpeta ingresada existe256 carpeta = data.get()257 exist = carpetas.existe(carpeta)258 if exist == False: #Si no existe, notifica al usuario que no existe y pregunta si desea buscar otra o salir de la opción259 hide()260 label1 = tk.Label(ventana, text="La carpeta no existe, ¿Desea buscar otra carpeta?", font=fonta)261 label1.pack(pady=10)262 hidelist.append(label1)263 opcion1 = ttk.Button(ventana, text="Si", style="TButton", command=ordenar_archivos)264 opcion1.pack(pady=2)265 hidelist.append(opcion1)266 opcion2 = ttk.Button(ventana, text="No", style="TButton", command=menu)267 opcion2.pack(pady=2)268 hidelist.append(opcion2)269 elif exist == True: #Si existe, pregunta al usuario si desea ordenar los archivos por nombre de la carpeta, palabra clave o sufijo270 hide()271 label1 = tk.Label(ventana, text="¿Como desea ordenar los archivos?", font=fonta)272 label1.pack(pady=10)273 hidelist.append(label1)274 opcion1 = ttk.Button(ventana, text="Archivos que contengan el nombre de esta carpeta", style="TButton",command=lambda: nombre_carpeta(carpeta))275 opcion1.pack(pady=2)276 hidelist.append(opcion1)277 opcion2 = ttk.Button(ventana, text="Archivos que contengan cierto nombre", style="TButton", command=lambda: palabra_clave(carpeta))278 opcion2.pack(pady=2)279 hidelist.append(opcion2)280 opcion3 = ttk.Button(ventana, text="Archivos de cierta extensión", style="TButton", command=lambda : tipo_sufijo(carpeta))281 opcion3.pack(pady=2)282 hidelist.append(opcion3)283def ordenar_archivos(): #Funcion que pregunta al usuario en que carpeta desea ordenar los archivos284 hide()285 label1 = tk.Label(ventana, text="¿En que carpeta desea ordenar los archivos?", font=fonta)286 label1.pack(pady=10)287 hidelist.append(label1)288 entry1 = tk.Entry(ventana)289 entry1.pack(pady=2)290 hidelist.append(entry1)291 confirm = ttk.Button(ventana, text="Confirmar", style="TButton", command=lambda : tipo_orden(entry1))292 confirm.pack()293 hidelist.append(confirm)294#Opcion 4: Calculadora295def calculadora(): #Funcion que abre la calculadora296 import calculadora297 widget_principal = calculadora.Tk()298 calculadora.Interfaz(widget_principal)299 widget_principal.mainloop()300#Opcion 5: Leer texto de imagen301def extraerTextoDeImagen(imagen,idioma): #Imprime el texto extraido de la imagen y pregunta si desea ingresar otra imagen o salir de la opción302 text=leer_imagen.extraerTextoDeImagen(imagen,idioma)303 hide()304 popup(text)305 label1 = tk.Label(ventana, text="¿Desea extraer texto de otra imagen?", font=fonta)306 label1.pack(pady=10)307 hidelist.append(label1)308 opcion1 = ttk.Button(ventana, text="Si", style="TButton", command=lista_imagenes)309 opcion1.pack(pady=2)310 hidelist.append(opcion1)311 opcion2 = ttk.Button(ventana, text="No", style="TButton", command=menu)312 opcion2.pack(pady=2)313 hidelist.append(opcion2)314def idioma_imagen(data): #Funcion pide al usuario la imagen para extraer el texto315 imagen=data.get()316 exist = carpetas.existe(imagen)317 if exist == False: #Si no existe, notifica al usuario que la imagen no existe y le pregunta si desea ingresar otra o salir de la opción318 hide()319 label1 = tk.Label(ventana, text="La imagen no existe, ¿Desea buscar otra imagen?", font=fonta)320 label1.pack(pady=10)321 hidelist.append(label1)322 opcion1 = ttk.Button(ventana, text="Si", style="TButton", command=lista_imagenes)323 opcion1.pack(pady=2)324 hidelist.append(opcion1)325 opcion2 = ttk.Button(ventana, text="No", style="TButton", command=menu)326 opcion2.pack(pady=2)327 hidelist.append(opcion2)328 if exist==True: #Si existe, pide el idioma en el que desee el programa, español o inglés329 hide()330 label1 = tk.Label(ventana, text="Seleccione el idioma de la imagen", font=fonta)331 label1.pack(pady=10)332 hidelist.append(label1)333 opcion1 = ttk.Button(ventana, text="Español", style="TButton", command=lambda : extraerTextoDeImagen(imagen,"spa"))334 opcion1.pack(pady=2)335 hidelist.append(opcion1)336 opcion2 = ttk.Button(ventana, text="Inglés", style="TButton", command=lambda: extraerTextoDeImagen(imagen,"eng"))337 opcion2.pack(pady=2)338 hidelist.append(opcion2)339def lista_imagenes(): #Función que pide al usuario la imagen que desee340 hide()341 lista = leer_imagen.listaImagen()342 if lista == None:343 texto = "No hay imágenes en la carpeta"344 else:345 texto = "Las imágenes en la carpeta son: \n {0} \n Escriba el nombre de la imagen que quiere usar \n(junto con su extención) ".format(lista)346 label1 = tk.Label(ventana, text= texto, font=fonta)347 label1.pack(pady=10)348 hidelist.append(label1)349 entry1 = tk.Entry(ventana)350 entry1.pack(pady=2)351 hidelist.append(entry1)352 confirm = ttk.Button(ventana, text="Confirmar", style="TButton", command=lambda : idioma_imagen(entry1))353 confirm.pack()354 hidelist.append(confirm)355#Opción 6: Piedra, papel o tijera356def resultado(objeto): #Muestra al usuario la opción que eligio, como terminó el juego y pregunta si quiere jugar otra vez357 hide()358 texto=piedrapapelotijera.jugar(objeto)359 popup(texto)360 label1 = tk.Label(ventana, text="¿Desea jugar de nuevo?", font=fonta)361 label1.pack(pady=10)362 hidelist.append(label1)363 opcion1 = ttk.Button(ventana, text="Si", style="TButton", command=elegir)364 opcion1.pack(pady=2)365 hidelist.append(opcion1)366 opcion2 = ttk.Button(ventana, text="No", style="TButton", command=menu)367 opcion2.pack(pady=2)368 hidelist.append(opcion2)369def elegir(): #Función que pregunta al usuario el elemento con el que desea jugar370 hide()371 label1 = tk.Label(ventana, text="¿Con que elemento desea jugar?", font=fonta)372 label1.pack(pady=10)373 hidelist.append(label1)374 opcion1 = ttk.Button(ventana, text="Piedra", style="TButton", command=lambda: resultado("piedra"))375 opcion1.pack(pady=2)376 hidelist.append(opcion1)377 opcion2 = ttk.Button(ventana, text="Papel", style="TButton", command=lambda: resultado("papel"))378 opcion2.pack(pady=2)379 hidelist.append(opcion2)380 opcion3 = ttk.Button(ventana, text="Tijera", style="TButton", command=lambda: resultado("tijera"))381 opcion3.pack(pady=2)382 hidelist.append(opcion3)383#Declaracion de variables384ventana=tk.Tk(className="Multitasker")385ventana.geometry("500x600") #Crea la ventana principal386fonta="Gadugi 18" #Fuente del texto del programa387ttk.Style(ventana).configure('TButton', font=(fonta))388actualoption=0 #Variable para saber que opción se encuentra en uso389hidelist=[] #Lista de los labels, botones y entradas a eliminar390menu() #Llama a la funcion menu para crearlo391popup(intro) #Llamado a la función popup para crear una ventana con un texto introductorio previamente declarado...

Full Screen

Full Screen

datechooser.py

Source:datechooser.py Github

copy

Full Screen

1from tkinter import *2from tkinter.ttk import *3import calendar4import time5import collections6class Datechooser(Frame):7 def __init__(self, parent, data=[], default="", command=None, label_text=""):8 Frame.__init__(self, parent)9 self.command = command10 11 self.variable=StringVar()12 13 self.label = Label(self, text=label_text)14 self.label.pack(side="left")15 self.entry=Entry(self, textvariable=self.variable)16 self.entry.pack(side="left", fill="x", expand="yes")17 self.entry.bind("<ButtonRelease-1>", self.hideList)18 self.entry.bind("<Return>", self.invoke)19 20 21 self.button=Button(self, command=self.buttonCommand)22 self.button.pack(side="left")23 self.createButtonImage()24 25 self.popup=Toplevel(self)26 self.popup.interior=Frame(self.popup)27 self.popup.interior.pack(fill="both", expand="yes")28 self.popup.withdraw()29 self.popup.overrideredirect(1)30 self.popup.hideList = self.hideList31 self.popup.setentry = self.setentry32 33 self.listbox=DateSelector(self.popup)34 self.listbox.pack(fill="both", expand="yes")35 self.listbox.visible = 036 parent.winfo_toplevel().bind("<Configure>", self.reconfigure)37 38 def createButtonImage(self):39 width=self.entry.winfo_reqheight()-440 height=width41 self.image=PhotoImage(width=width, height=height)42 for row in range(3, height-3, 1):43 for col in range(int(row/1.75), width-int(row/1.75), 1):44 self.image.put("black", (col, row))45 self.button["image"]=self.image46 47 def get(self):48 return self.variable.get()49 50 def getentry(self):51 return self.variable.get()52 53 def setentry(self, value):54 self.variable.set(value)55 56 def buttonCommand(self):57 if self.listbox.visible:58 self.hideList(None)59 else:60 self.showList()61 62 def invoke(self, *event):63 if isinstance(self.command, collections.Callable):64 self.command(self.getentry())65 66 67 68 def reconfigure(self, event):69 if self.listbox.visible:70 self.hideList(event)71 self.showList()72 73 def hideList(self, *event):74 self.listbox.visible = 075 self.popup.withdraw()76 77 def showList(self):78 self.listbox.visible = 179 self.update()80 x = self.entry.winfo_rootx()81 y = self.entry.winfo_rooty() + self.entry.winfo_height()82 w = self.entry.winfo_width() + self.button.winfo_width()83 h = self.listbox.winfo_height()84 sh = self.winfo_screenheight()85 if y + h > sh and y > sh / 2:86 y = self.entry.winfo_rooty() - h87 self.popup.interior.configure(width=w)88 self.popup.update()89 self.popup.geometry('+%d+%d' % (x, y))90 self.popup.deiconify()91 self.popup.tkraise()92 self.listbox.focus_set()93 94 95class DateSelector(Frame):96 def __init__(self, parent):97 Frame.__init__(self, parent)98 self.parent = parent99 today = time.localtime(time.time())100 self.year = today[0]101 self.month = today[1]102 self.thisYear = today[0]103 self.thisMonth = today[1]104 self.day = today[2]105 106 107 self.monthYear = MonthYearSelector(self, year=self.year, 108 month=self.month, command=self.gridMonth)109 self.monthYear.grid(row=0, columnspan=7)110 self.gridMonth("%s - %d" %(self.year, self.month))111 112 113 114 def gridMonth(self, stuff):115 116 year, month = self.monthYear.get()117 self.year = year118 self.month = month119 120 row = 1121 col = 0122 cal = calendar.monthcalendar(year, month)123 124 for dname in "MTWTFSS":125 l=Label(self, text=dname, width=2)126 l.grid(row=row, column=col)127 col=col+1128 129 row = 2130 col = 0131 132 133 for w in cal:134 for d in w:135 if d:136 b=Button(self, text=d, width=2,137 command=lambda self=self, day=d: self.returnDay(day))138 b.grid(row=row, column=col)139 if col>4:140 b.config()141 if d==self.day and self.year==self.thisYear and self.month==self.thisMonth:142 b.config()143 144 145 col=col+1146 row=row+1147 col=0148 149 150 def returnDay(self, day):151 self.parent.setentry("%d/%s/%d" %(day, calendar.month_name[self.month], self.year))152 self.parent.hideList()153 154 155 156class MonthYearSelector(Frame):157 def __init__(self, parent, year=1973, month=5, command=None):158 Frame.__init__(self, parent)159 self.parent = parent160 self.year = year161 self.month = month162 163 l = []164 for year in range(1970, 2030, 1):165 for month in calendar.month_name:166 if month:167 l.append("%d - %s" %(year, month))168 169 self.counter = StringVar()170 counter = Combobox(self, values=l, textvariable = self.counter)171 counter.bind('<<ComboboxSelected>>', command)172 173 counter.pack(fill="x")174 self.set(self.year, self.month)175 176 177 def set(self, year, month):178 self.counter.set("%d - %s" %(year, calendar.month_name[month]))179 180 181 def get(self):182 year, month = self.counter.get().split(" - ")183 month = list(calendar.month_name).index(month)184 year = int(year)185 186 return year, month187 188 189if __name__=="__main__":190 root=Tk()191 def printit(thing):192 print(thing)193 194 cb=Datechooser(root)195 cb.pack(fill="x")...

Full Screen

Full Screen

FontAnchors.py

Source:FontAnchors.py Github

copy

Full Screen

1from mojo.extensions import getExtensionDefault2from extensionID import extensionID3class FontAnchors(object):4 anchorNames = []5 anchorGlyphs = {}6 anchorPositions = {}7 invisibleAnchors = []8 invisibleGlyphs = []9 invisibleMarks = []10 hideLists = {11 "anchor": invisibleAnchors,12 "glyph": invisibleGlyphs,13 "mark": invisibleMarks,14 }15 def __init__(self, font):16 self.font = font17 self._readFromFont(self.font)18 self.hideLists = getExtensionDefault(19 "%s.%s" % (extensionID, "hide"), self.hideLists20 )21 def _readFromFont(self, font):22 self.anchorNames = []23 self.anchorGlyphs = {}24 self.anchorPositions = {}25 if font is not None:26 for g in font:27 if len(g.anchors) > 0:28 for a in g.anchors:29 self.addAnchor(g, a.name, (a.x, a.y))30 # for a in sorted(self.anchorBaseMap.keys()):31 # self.anchorNames.append({"Show": True, "Name": a})32 # print("\nanchorGlyphs:", self.anchorGlyphs)33 # print("\nanchorPositions:", self.anchorPositions)34 # print()35 def getVisibility(self, kind, name, includeMatching=True):36 hideList = self.hideLists[kind]37 if not (38 name in hideList39 or (40 includeMatching41 and self.getMatchingAnchorName(name) in hideList42 )43 ):44 return True45 return False46 def setVisibility(self, kind, name, isVisible=True, includeMatching=True):47 hideList = self.hideLists[kind]48 if isVisible:49 if name in hideList:50 hideList.remove(name)51 if includeMatching:52 hideList.remove(self.getMatchingAnchorName(name))53 else:54 if not (name in hideList):55 hideList.append(name)56 if includeMatching:57 hideList.append(self.getMatchingAnchorName(name))58 def addAnchor(self, glyph, name, position, addToGlyph=False):59 if len(name) == 0:60 print(61 "WARNING: anchor with empty name at (%i, %i) in glyph '%s', ignored."62 % (position[0], position[1], glyph.name)63 )64 else:65 if (glyph.name, name) in self.anchorPositions.keys():66 print(67 "WARNING: Duplicate anchor name '%s' requested in glyph '%s' when trying to add anchor. Ignored."68 % (name, glyph.name)69 )70 else:71 self.anchorPositions[(glyph.name, name)] = position72 if name in self.anchorGlyphs.keys():73 self.anchorGlyphs[name] += [glyph.name]74 else:75 self.anchorGlyphs[name] = [glyph.name]76 if addToGlyph:77 glyph.appendAnchor(name, position)78 def moveAnchor(self, name, newPosition):79 # happens automatically - why?80 # probably only for current glyph, not "inverted" view81 pass82 def renameAnchor(self, name):83 pass84 def deleteAnchor(self, name):85 pass86 def getMatchingAnchorName(self, name):87 # returns "inverted" anchor name, i.e. with leading underscore added or88 # removed89 if name[0] == "_":90 return name[1:]91 else:92 return "_" + name93 def getAnchorNames(self):94 # TODO: anchorNames should not be constructed each time this method is95 # called.96 # Better to build it once and modify it together with other anchor97 # modifications98 anchorNames = []99 for a in sorted(self.anchorGlyphs.keys()):100 if len(a) > 0:101 if a[0] != "_":102 anchorNames.append(103 {104 "Show": self.getVisibility("anchor", a, False),105 "Name": a,106 }107 )108 return anchorNames109 def getAnchoredGlyphNames(self, anchorName):110 # print("Looking up anchored glyphs for", anchorName)111 targetAnchorName = self.getMatchingAnchorName(anchorName)112 if targetAnchorName in self.anchorGlyphs.keys():113 return self.anchorGlyphs[targetAnchorName]114 return []115 def getAnchoredGlyphNamesForList(self, anchorNames, marks=False):116 anchoredGlyphs = []117 for an in anchorNames:118 if marks:119 an = self.getMatchingAnchorName(an)120 if an in self.anchorGlyphs.keys():121 anchoredGlyphs += self.anchorGlyphs[an]122 result = []123 # print("anchoredGlyphs:", anchoredGlyphs)124 for g in sorted(set(anchoredGlyphs)):125 if marks:126 result.append(127 {"Show": self.getVisibility("mark", g, False), "Name": g}128 )129 else:130 result.append(131 {"Show": self.getVisibility("glyph", g, False), "Name": g}132 )133 return result134 def selectGlyphsWithAnchorName(self, anchorName):135 self.font.selection = self.getAnchoredGlyphNames(136 self.getMatchingAnchorName(anchorName)137 )...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful