#!/usr/bin/env python
# -*- coding: latin-1 -*-
# Author: Mirko Pagliai
# Mail: mirko.pagliai@gmail.com
# Copyright: 2010 by Mirko Pagliai
# generated by wxGlade 0.6.3 on Mon Feb 8 14:59:59 2010
import wx, random, string
version = "1.0.1"
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.label_1 = wx.StaticText(self, -1, "Lunghezza password:")
self.label_2 = wx.StaticText(self, -1, "Tipo password:")
self.label_3 = wx.StaticText(self, -1, "Tipo lettere:")
self.pwdlength = wx.TextCtrl(self, -1, "8")
self.pwdtype = wx.ComboBox(self, -1, choices=["lettere e numeri", "solo lettere", "solo numeri", "lettere, numeri e simboli"], style=wx.CB_DROPDOWN)
self.letterstype = wx.ComboBox(self, -1, choices=["maiuscole e minuscole", "solo maiuscole", "solo minuscole"], style=wx.CB_DROPDOWN)
self.go = wx.Button(self, -1, "Genera password")
self.label_4 = wx.StaticText(self, -1, "Password generata:")
self.pwdbox = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY)
# Menu Bar
self.frame_menubar = wx.MenuBar()
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.NewId(), "Informazioni", "", wx.ITEM_NORMAL)
self.frame_menubar.Append(wxglade_tmp_menu, "Aiuto")
self.SetMenuBar(self.frame_menubar)
# Menu Bar end
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_BUTTON, self.generatespwd, self.go)
self.Bind(wx.EVT_MENU, self.showinfo, id=-1)
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("Generatore password")
self.pwdtype.SetMinSize((190, 27))
self.pwdtype.SetSelection(0)
self.letterstype.SetMinSize((195, 27))
self.letterstype.SetSelection(0)
self.pwdbox.SetMinSize((200, 27))
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer = wx.BoxSizer(wx.VERTICAL)
grid_sizer_2 = wx.FlexGridSizer(1, 3, 5, 15)
grid_sizer_1 = wx.FlexGridSizer(2, 3, 5, 15)
grid_sizer_1.Add(self.label_1, 0, wx.ADJUST_MINSIZE, 0)
grid_sizer_1.Add(self.label_2, 0, wx.ADJUST_MINSIZE, 0)
grid_sizer_1.Add(self.label_3, 0, wx.ADJUST_MINSIZE, 0)
grid_sizer_1.Add(self.pwdlength, 0, wx.ADJUST_MINSIZE, 0)
grid_sizer_1.Add(self.pwdtype, 0, wx.ADJUST_MINSIZE, 0)
grid_sizer_1.Add(self.letterstype, 0, wx.ADJUST_MINSIZE, 0)
sizer.Add(grid_sizer_1, 0, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, 10)
grid_sizer_2.Add(self.go, 0, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
grid_sizer_2.Add(self.label_4, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
grid_sizer_2.Add(self.pwdbox, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
sizer.Add(grid_sizer_2, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, 10)
self.SetSizer(sizer)
sizer.Fit(self)
self.Layout()
# end wxGlade
#Provoca un alert con errore
def alert(self, text, title="Errore", icon=wx.ICON_ERROR):
alert = wx.MessageDialog(self, text, title, wx.OK | icon)
alert.ShowModal()
alert.Destroy()
#Mostra le informazioni sull'applicazione
def showinfo(self, event): # wxGlade: MyFrame.<event_handler>
self.alert("pwdgenerator v. "+version+"\n\nCopyright © 2010\nby Mirko Pagliai\n(mirko.pagliai@gmail.com)", "Informazioni", wx.ICON_INFORMATION)
event.Skip()
#Genera la password
def generatespwd(self, event): # wxGlade: MyFrame.<event_handler>
#Se la password ha la lunghezza corretta
if int(self.pwdlength.GetValue()) >= 3 and int(self.pwdlength.GetValue()) <= 20:
#Inizializzazione variabili e liste
self.letters = []
self.pwd = ""
self.source = []
#Imposta le lettere da usare a seconda della scelta
if self.letterstype.GetValue() == "maiuscole e minuscole":
self.letters = string.letters
elif self.letterstype.GetValue() == "solo maiuscole":
self.letters = string.uppercase
elif self.letterstype.GetValue() == "solo minuscole":
self.letters = string.lowercase
#Imposta i caratteri sorgenti da usare a seconda della scelta
if self.pwdtype.GetValue() == "solo lettere":
self.source = self.letters
elif self.pwdtype.GetValue() == "solo numeri":
self.source = string.digits
elif self.pwdtype.GetValue() == "lettere e numeri":
self.source = self.letters + string.digits
elif self.pwdtype.GetValue() == "lettere, numeri e simboli":
self.source = self.letters + string.digits + string.punctuation
#Genera la password
for n in range(int(self.pwdlength.GetValue())):
self.pwd = self.pwd + random.choice(self.source)
#Imposta la password generata nel suo box
self.pwdbox.SetValue(self.pwd)
#In caso di password troppo lunga o troppo corta
else:
self.alert("La password deve avere una lunghezza tra i 3 e i 20 caratteri")
event.Skip()
# end of class MyFrame
if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame = MyFrame(None, -1, "")
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()