Advertisement
ranisalt

Pyssword GTK

Aug 10th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.29 KB | None | 0 0
  1. #!coding:utf-8
  2. from random import randint
  3. import pygtk, gtk
  4. pygtk.require("2.0")
  5.  
  6. def gerarSenha(comp, mi, ma, nu, si):
  7.     ch = mi * "abcdefghijklmnopqrstuvwxyz"\
  8.         + ma * "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\
  9.         + nu * "1234567890"\
  10.         + si * "!@#$%*(){}[]"
  11.     pw = ""        
  12.     for _ in xrange(1, comp): pw += ch[randint(0, len(ch) - 1)]
  13.     return pw
  14.  
  15. class MainWindow:
  16.     def __init__(self):
  17.         self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  18.         self.window.connect("destroy", self.destroy)
  19.         self.window.connect("delete_event", self.delete_event)
  20.         self.window.set_title("Pyssword")
  21.        
  22.         self.vbx_grid = gtk.VBox()
  23.         self.hbx_tambox = gtk.HBox()
  24.         self.hbx_chkbox = gtk.HBox()
  25.         self.hbx_senha = gtk.HBox()
  26.        
  27.         self.lbl_tamanho = gtk.Label("Tamanho: ")
  28.         self.hsc_comprimento = gtk.HScale()
  29.         self.hsc_comprimento.set_range(6, 32)
  30.         self.hsc_comprimento.set_value(16)
  31.         self.hsc_comprimento.set_value_pos(gtk.POS_RIGHT)
  32.         self.hsc_comprimento.set_digits(0)
  33.         self.chk_minusculo = gtk.CheckButton("Minúsculas")
  34.         self.chk_maiusculo = gtk.CheckButton("Maiúsculas")
  35.         self.chk_numeros = gtk.CheckButton("Números")
  36.         self.chk_simbolos = gtk.CheckButton("Símbolos")
  37.         self.ent_senha = gtk.Entry(max=32)
  38.         self.ent_senha.set_editable(False)
  39.         self.btn_gerar = gtk.Button("Gerar")
  40.         self.btn_gerar.connect("clicked", self.btn_gerar_click)
  41.        
  42.         self.hbx_tambox.pack_start(self.lbl_tamanho, False, False, 2)
  43.         self.lbl_tamanho.show()
  44.         self.hbx_tambox.pack_start(self.hsc_comprimento, True, True, 2)
  45.         self.hsc_comprimento.show()
  46.  
  47.         self.hbx_chkbox.pack_start(self.chk_minusculo, True, True, 2)
  48.         self.chk_minusculo.show()
  49.         self.hbx_chkbox.pack_start(self.chk_maiusculo, True, True, 2)
  50.         self.chk_maiusculo.show()
  51.         self.hbx_chkbox.pack_start(self.chk_numeros, True, True, 2)
  52.         self.chk_numeros.show()
  53.         self.hbx_chkbox.pack_start(self.chk_simbolos, True, True, 2)
  54.         self.chk_simbolos.show()
  55.        
  56.         self.hbx_senha.pack_start(self.ent_senha, True, True, 2)
  57.         self.ent_senha.show()
  58.         self.hbx_senha.pack_start(self.btn_gerar, False, False, 2)
  59.         self.btn_gerar.show()
  60.        
  61.         self.vbx_grid.pack_start(self.hbx_tambox, True, True, 2)
  62.         self.hbx_tambox.show()
  63.         self.vbx_grid.pack_start(self.hbx_chkbox, True, True, 2)
  64.         self.hbx_chkbox.show()
  65.         self.vbx_grid.pack_start(self.hbx_senha, True, True, 2)
  66.         self.hbx_senha.show()
  67.        
  68.         self.window.add(self.vbx_grid)
  69.         self.vbx_grid.show()
  70.         self.window.show()
  71.        
  72.     def main(self):
  73.         gtk.main()
  74.        
  75.     def destroy(self, widget, data=None):
  76.         gtk.main_quit()
  77.    
  78.     def delete_event(self, widget, event, data=None):
  79.         return False
  80.    
  81.     def btn_gerar_click(self, widget):
  82.         self.ent_senha.set_text(gerarSenha(\
  83.            int(self.hsc_comprimento.get_value()),\
  84.            self.chk_minusculo.get_active(),\
  85.            self.chk_maiusculo.get_active(),\
  86.            self.chk_numeros.get_active(),\
  87.            self.chk_simbolos.get_active()))
  88.    
  89. _w = MainWindow()
  90. _w.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement