Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import gtk, pango, random, string
- class PyApp(gtk.Window):
- def __init__(self):
- self.passes = []
- self.pos = -1
- super(PyApp, self).__init__()
- self.set_title("Random Names")
- self.set_size_request(280, 137)
- self.set_position(gtk.WIN_POS_CENTER)
- self.connect("destroy", self.on_destroy)
- fixed = gtk.Fixed()
- self.onepass = password()
- self.onepass.renew()
- self.passes.append(str(self.onepass))
- self.namez = gtk.Label(self.onepass)
- fontdesc = pango.FontDescription("Monospace 40")
- self.namez.modify_font(fontdesc)
- fixed.put(self.namez, 0, 0)
- prev = gtk.Button("Previous")
- prev.connect("clicked", self.prev)
- prev.set_size_request(80, 35)
- fixed.put(prev, 0, 100)
- check = gtk.Button("Check")
- check.connect("clicked", self.check)
- check.set_size_request(80, 35)
- fixed.put(check, 100, 100)
- next = gtk.Button("Next")
- next.connect("clicked", self.next)
- next.set_size_request(80, 35)
- fixed.put(next, 200, 100)
- self.add(fixed)
- self.show_all()
- def on_destroy(self, widget):
- gtk.main_quit()
- def next(self, widget):
- if self.pos < 0:
- self.pos += 1
- self.namez.set_text(str(self.passes[self.pos]))
- else:
- self.onepass.renew()
- self.passes.append(str(self.onepass))
- self.namez.set_text(str(self.onepass))
- def check(self, widget):
- gtk.main_quit()
- def prev(self, widget):
- self.pos -= 1
- self.namez.set_text(str(self.passes[self.pos]))
- class password(object):
- data = open("/usr/share/dict/words").read().lower()
- def renew(self, maxmem=3):
- n = random.randrange(6,9)
- self.chars = []
- for i in range(n):
- randspot = random.randrange(len(self.data))
- self.data = self.data[randspot:] + self.data[:randspot]
- where = -1
- locate = ''.join(self.chars[-maxmem:])
- while where < 0 and locate:
- where = self.data.find(locate)
- locate = locate[1:]
- c = self.data[where+len(locate)+1]
- if not c.islower(): c = random.choice(string.lowercase)
- self.chars.append(c)
- def __str__(self):
- return ''.join(self.chars)
- PyApp()
- gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement