JachyHm

PasswdGen

Mar 23rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.17 KB | None | 0 0
  1. #passwdGen
  2. import random
  3. import string
  4. import gi
  5. gi.require_version('Gtk', '3.0')
  6. from gi.repository import Gtk
  7.  
  8.  
  9. class Fce():
  10.     def generuj(self,znakygeneruj,delkageneruj):
  11.         return "".join(random.choice(znakygeneruj) for x in range (int(delkageneruj)))
  12.     def zobrazheslo (self,button):
  13.         znakyobsah = win.znaky.get_text()
  14.         delkaobsah = win.delka.get_text()
  15.         heslo = self.generuj(znakyobsah,delkaobsah)
  16.         win.heslo.set_text(heslo)
  17.     def hlidejcislo (self,Entry):
  18.         text = win.delka.get_text().strip()
  19.         win.delka.set_text(''.join([i for i in text if i in '0123456789']))
  20.     def vypisznaky (self,button):
  21.         win.znaky.set_text(string.ascii_letters+string.digits+string.punctuation)
  22. class Okno(Gtk.Window):
  23.     def __init__(self):
  24.         fce = Fce()
  25.         Gtk.Window.__init__(self, title="Password generator by JachyHm")
  26.         #vytvoří okno s titulkem "Password generator by JachyHm"
  27.         self.set_size_request(650, 100)
  28.         #definuej jeho velikost na 300*100px
  29.         cbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=3)
  30.         #definuje tabulku, která rozdělí obrazovku vertikálně na 3 části (generované heslo, použité znaky, délka hesla a tlačítka)
  31.         hbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=1)
  32.         #definuje tabulku, která rozdělí obrazovku horizontálně na 1 část
  33.         pbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=3)
  34.         #definuje tabulku, která rozdělí obrazovku horizontálně na 3 části
  35.         dbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=1)
  36.         #definuje tabulku, která rozdělí obrazovku horizontálně na 1 část
  37.         cbox.pack_start(hbox, True, True, 0)
  38.         cbox.pack_start(pbox, True, True, 0)
  39.         cbox.pack_start(dbox, True, True, 0)
  40.        
  41.         self.heslo = Gtk.Entry()
  42.         self.heslo.set_text("Zde se zobrazí vygenerované heslo podle vašich parametrů")
  43.         self.heslo.progress_pulse()
  44.         self.heslo.set_editable(False)
  45.         self.heslo.set_alignment(xalign = 0.5)
  46.         hbox.pack_start(self.heslo, True, False, 0)
  47.  
  48.         self.generuj = Gtk.Button.new_with_label("Generuj heslo")
  49.         self.generuj.connect("clicked", fce.zobrazheslo)
  50.         pbox.pack_start(self.generuj, True, True, 0)
  51.  
  52.         adjustment = Gtk.Adjustment(0, 0, 100, 1, 10, 0)
  53.         self.delka = Gtk.SpinButton()
  54.         self.delka.set_text("10")
  55.         self.delka.set_adjustment(adjustment)
  56.         self.delka.connect("changed", fce.hlidejcislo)
  57.         pbox.pack_start(self.delka, True, True, 1)
  58.  
  59.         self.vypisznaky = Gtk.Button.new_with_label("Vypiš všechny znaky")
  60.         self.vypisznaky.connect("clicked", fce.vypisznaky)
  61.         pbox.pack_start(self.vypisznaky, True, True, 0)
  62.  
  63.         self.znaky = Gtk.Entry()
  64.         self.znaky.set_text(string.ascii_letters+string.digits+string.punctuation)
  65.         self.znaky.progress_pulse()
  66.         dbox.pack_start(self.znaky, True, True, 1)
  67.        
  68.         self.add(cbox)
  69.         #vytvoří definované tabulky
  70.        
  71. win = Okno()
  72. win.connect("delete-event", Gtk.main_quit)
  73. win.show_all()
  74. Gtk.main()
Add Comment
Please, Sign In to add comment