Tema: os.walk
Ver Mensaje Individual
  #6 (permalink)  
Antiguo 19/01/2012, 11:55
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: os.walk

Código Python:
Ver original
  1. import gtk
  2. import os
  3.  
  4. text = []
  5.  
  6. class PackBox1:
  7.        
  8.     def __init__(self):
  9.         self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  10.        
  11.         self.window.set_title("ejemplo")
  12.         self.window.set_border_width(10)
  13.         self.window.set_size_request(500, 100)
  14.         self.window.set_resizable(False)
  15.         self.window.connect('destroy', gtk.main_quit)
  16.        
  17.         box1 = gtk.VBox(gtk.FALSE, 0)
  18.        
  19.         caja = gtk.HBox(gtk.FALSE, 0)
  20.         caja.set_border_width(10)
  21.        
  22.        
  23.         self.combo = gtk.combo_box_new_text()
  24.         self.actualizar_combo()
  25.        
  26.         self.texto = gtk.Entry()
  27.         self.texto.set_text("nombre-de-la-carpta")
  28.         self.texto.connect("activate", self.crear_carpeta)
  29.        
  30.         boton = gtk.Button("Crear Carpeta")
  31.         boton.connect("clicked", self.crear_carpeta)
  32.        
  33.        
  34.         caja.pack_start(self.combo, False, False,5)
  35.         self.combo.show()
  36.         caja.pack_start(self.texto, False, False, 5)
  37.         self.texto.show()
  38.         caja.pack_start(boton, True, True, 5)
  39.         boton.show()
  40.        
  41.         box1.pack_start(caja, gtk.FALSE, gtk.FALSE, 0)
  42.         caja.show()
  43.              
  44.         box1.show()
  45.         self.window.add(box1)
  46.         self.window.show()
  47.        
  48.     def actualizar_combo(self):
  49.         model = self.combo.get_model()
  50.         self.combo.set_model(None)
  51.         self.ruta = os.path.expanduser("~")
  52.         text = next(os.walk(self.ruta))[1]
  53.         model.clear()
  54.         for t in text:
  55.             model.append([t])
  56.         self.combo.set_model(model)
  57.        
  58.    
  59.     def crear_carpeta(self, data=None):
  60.         self.ruta = os.path.expanduser("~")
  61.         self.ruta = os.path.join(self.ruta, self.combo.get_active_text())
  62.         self.ruta = os.path.join(self.ruta, self.texto.get_text())
  63.         systema = os.system('mkdir ' + self.ruta)
  64.        
  65.  
  66. if __name__ =="__main__":
  67.     packbox1 = PackBox1()
  68.     gtk.main()
Creo que mas o menos quiere algo así