Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #passwdGen
- import random
- import string
- import gi
- gi.require_version('Gtk', '3.0')
- from gi.repository import Gtk
- class Fce():
- def generuj(self,znakygeneruj,delkageneruj):
- return "".join(random.choice(znakygeneruj) for x in range (int(delkageneruj)))
- def zobrazheslo (self,button):
- znakyobsah = win.znaky.get_text()
- delkaobsah = win.delka.get_text()
- heslo = self.generuj(znakyobsah,delkaobsah)
- win.heslo.set_text(heslo)
- def hlidejcislo (self,Entry):
- text = win.delka.get_text().strip()
- win.delka.set_text(''.join([i for i in text if i in '0123456789']))
- def vypisznaky (self,button):
- win.znaky.set_text(string.ascii_letters+string.digits+string.punctuation)
- class Okno(Gtk.Window):
- def __init__(self):
- fce = Fce()
- Gtk.Window.__init__(self, title="Password generator by JachyHm")
- #vytvoří okno s titulkem "Password generator by JachyHm"
- self.set_size_request(650, 100)
- #definuej jeho velikost na 300*100px
- cbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=3)
- #definuje tabulku, která rozdělí obrazovku vertikálně na 3 části (generované heslo, použité znaky, délka hesla a tlačítka)
- hbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=1)
- #definuje tabulku, která rozdělí obrazovku horizontálně na 1 část
- pbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=3)
- #definuje tabulku, která rozdělí obrazovku horizontálně na 3 části
- dbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=1)
- #definuje tabulku, která rozdělí obrazovku horizontálně na 1 část
- cbox.pack_start(hbox, True, True, 0)
- cbox.pack_start(pbox, True, True, 0)
- cbox.pack_start(dbox, True, True, 0)
- self.heslo = Gtk.Entry()
- self.heslo.set_text("Zde se zobrazí vygenerované heslo podle vašich parametrů")
- self.heslo.progress_pulse()
- self.heslo.set_editable(False)
- self.heslo.set_alignment(xalign = 0.5)
- hbox.pack_start(self.heslo, True, False, 0)
- self.generuj = Gtk.Button.new_with_label("Generuj heslo")
- self.generuj.connect("clicked", fce.zobrazheslo)
- pbox.pack_start(self.generuj, True, True, 0)
- adjustment = Gtk.Adjustment(0, 0, 100, 1, 10, 0)
- self.delka = Gtk.SpinButton()
- self.delka.set_text("10")
- self.delka.set_adjustment(adjustment)
- self.delka.connect("changed", fce.hlidejcislo)
- pbox.pack_start(self.delka, True, True, 1)
- self.vypisznaky = Gtk.Button.new_with_label("Vypiš všechny znaky")
- self.vypisznaky.connect("clicked", fce.vypisznaky)
- pbox.pack_start(self.vypisznaky, True, True, 0)
- self.znaky = Gtk.Entry()
- self.znaky.set_text(string.ascii_letters+string.digits+string.punctuation)
- self.znaky.progress_pulse()
- dbox.pack_start(self.znaky, True, True, 1)
- self.add(cbox)
- #vytvoří definované tabulky
- win = Okno()
- win.connect("delete-event", Gtk.main_quit)
- win.show_all()
- Gtk.main()
Add Comment
Please, Sign In to add comment