Last active
August 29, 2015 14:25
-
-
Save gnilchee/cfb07234cb31b7ac2e0d to your computer and use it in GitHub Desktop.
Python 3 Password Generator GUI for Gnome Shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Desktop Entry] | |
Name=Password Generator | |
Comment=Create a password and copy to clipboard | |
Icon=/path/to/icon/icon.png | |
Exec=/path/to/exec/passwordgengui.py | |
Type=Application | |
Terminal=false | |
Categories=System; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import string | |
import random | |
import sys | |
from gi.repository import Gtk, Gdk | |
class PasswordGenWindow(Gtk.Window): | |
def __init__(self): | |
Gtk.Window.__init__(self, title="Password Generator") | |
self.set_border_width(10) | |
hbox = Gtk.Box(spacing=6) | |
self.add(hbox) | |
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) | |
button = Gtk.Button("8") | |
button.connect("clicked", self.pass_gen_8_clicked) | |
hbox.pack_start(button, True, True, 0) | |
button = Gtk.Button("14") | |
button.connect("clicked", self.pass_gen_14_clicked) | |
hbox.pack_start(button, True, True, 0) | |
button = Gtk.Button("20") | |
button.connect("clicked", self.pass_gen_20_clicked) | |
hbox.pack_start(button, True, True, 0) | |
button = Gtk.Button("32") | |
button.connect("clicked", self.pass_gen_32_clicked) | |
hbox.pack_start(button, True, True, 0) | |
button = Gtk.Button("Reset") | |
button.connect("clicked", self.clear_all_clipboard) | |
hbox.pack_start(button, True, True, 0) | |
button = Gtk.Button("_Close", use_underline=True) | |
button.connect("clicked", self.on_close_clicked) | |
hbox.pack_start(button, True, True, 0) | |
def pass_gen_8_clicked(self, button): | |
self.clipboard.set_text(''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.punctuation) for _ in range(8)), -1) | |
def pass_gen_14_clicked(self, button): | |
self.clipboard.set_text(''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.punctuation) for _ in range(14)), -1) | |
def pass_gen_20_clicked(self, button): | |
self.clipboard.set_text(''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.punctuation) for _ in range(20)), -1) | |
def pass_gen_32_clicked(self, button): | |
self.clipboard.set_text(''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.punctuation) for _ in range(32)), -1) | |
def clear_all_clipboard(self, button): | |
self.clipboard.clear() | |
def on_close_clicked(self, button): | |
Gtk.main_quit() | |
pass_win = PasswordGenWindow() | |
pass_win.connect("delete-event", Gtk.main_quit) | |
pass_win.show_all() | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Place .desktop file in /usr/share/applications/ directory. It will now show up in your application drawer in Gnome Shell. Happy Password Generating!