Advertisement
Azelphur

Untitled

Jul 21st, 2011
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.39 KB | None | 0 0
  1. #!/usr/bin/python
  2. import gtk, pango, random, string
  3.  
  4. class PyApp(gtk.Window):
  5.     def __init__(self):
  6.     self.passes = []
  7.     self.pos = -1
  8.         super(PyApp, self).__init__()
  9.        
  10.         self.set_title("Random Names")
  11.         self.set_size_request(280, 137)
  12.         self.set_position(gtk.WIN_POS_CENTER)
  13.         self.connect("destroy", self.on_destroy)
  14.        
  15.         fixed = gtk.Fixed()
  16.  
  17.     self.onepass = password()
  18.     self.onepass.renew()
  19.     self.passes.append(str(self.onepass))
  20.     self.namez = gtk.Label(self.onepass)
  21.         fontdesc = pango.FontDescription("Monospace 40")
  22.         self.namez.modify_font(fontdesc)
  23.         fixed.put(self.namez, 0, 0)
  24.  
  25.         prev = gtk.Button("Previous")
  26.         prev.connect("clicked", self.prev)
  27.         prev.set_size_request(80, 35)
  28.  
  29.         fixed.put(prev, 0, 100)
  30.  
  31.         check = gtk.Button("Check")
  32.         check.connect("clicked", self.check)
  33.         check.set_size_request(80, 35)
  34.  
  35.         fixed.put(check, 100, 100)
  36.  
  37.         next = gtk.Button("Next")
  38.         next.connect("clicked", self.next)
  39.         next.set_size_request(80, 35)
  40.  
  41.         fixed.put(next, 200, 100)
  42.  
  43.         self.add(fixed)
  44.         self.show_all()
  45.        
  46.     def on_destroy(self, widget):
  47.         gtk.main_quit()
  48.        
  49.     def next(self, widget):
  50.     if self.pos < 0:
  51.         self.pos += 1
  52.             self.namez.set_text(str(self.passes[self.pos]))
  53.     else:
  54.         self.onepass.renew()
  55.         self.passes.append(str(self.onepass))
  56.         self.namez.set_text(str(self.onepass))
  57.  
  58.     def check(self, widget):
  59.         gtk.main_quit()
  60.  
  61.     def prev(self, widget):
  62.     self.pos -= 1
  63.         self.namez.set_text(str(self.passes[self.pos]))
  64.  
  65. class password(object):
  66.     data = open("/usr/share/dict/words").read().lower()
  67.     def renew(self, maxmem=3):
  68.     n = random.randrange(6,9)
  69.         self.chars = []
  70.         for i in range(n):
  71.             randspot = random.randrange(len(self.data))
  72.             self.data = self.data[randspot:] + self.data[:randspot]
  73.             where = -1
  74.             locate = ''.join(self.chars[-maxmem:])
  75.             while where < 0 and locate:
  76.                 where = self.data.find(locate)
  77.                 locate = locate[1:]
  78.             c = self.data[where+len(locate)+1]
  79.             if not c.islower(): c = random.choice(string.lowercase)
  80.             self.chars.append(c)
  81.     def __str__(self):
  82.         return ''.join(self.chars)
  83.  
  84. PyApp()
  85. gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement