Skip to content

Instantly share code, notes, and snippets.

@javascripto
Created July 11, 2018 05:37
Show Gist options
  • Select an option

  • Save javascripto/86423dec13eb47d1216f2a21e7a681ff to your computer and use it in GitHub Desktop.

Select an option

Save javascripto/86423dec13eb47d1216f2a21e7a681ff to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'gerador-senhas.ui'
#
# Created by: PyQt4 UI code generator 4.12.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
from random import randint
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def __init__(self):
pass
def gerar(self):
self.lst_pass.clear()
self.btn_copy.setVisible(False)
chars = 'abcdefghijklmnopqrstuvwxyz'
if self.chk_upper.checkState():
chars += chars.upper()
if self.chkNum.checkState():
chars += '1234567890'
if self.chkSym.checkState():
chars += '!@#$%*-=_+'
qtd_chars = self.spin_chars.value()
for i in range(0,13):
passwd = ''
for x in range(qtd_chars):
index = randint(0, len(chars)-1)
passwd += chars[index]
self.lst_pass.addItem(str(passwd))
def copiar(self):
clipboard = QtGui.QApplication.clipboard()
clipboard.setText(self.selecionado)
msg = QtGui.QMessageBox()
msg.setText(self.selecionado)
msg.setWindowTitle("Copiado!")
msg.setStandardButtons(QtGui.QMessageBox.Ok)
msg.exec_()
def selecionar(self):
self.btn_copy.setVisible(True)
self.selecionado = self.lst_pass.selectedItems()[0].text()
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(400, 300)
MainWindow.setMinimumSize(QtCore.QSize(400, 300))
MainWindow.setMaximumSize(QtCore.QSize(400, 300))
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(230, 20, 54, 17))
self.label.setObjectName(_fromUtf8("label"))
self.spin_chars = QtGui.QSpinBox(self.centralwidget)
self.spin_chars.setGeometry(QtCore.QRect(230, 40, 61, 26))
self.spin_chars.setMaximum(20)
self.spin_chars.setProperty("value", 15)
self.spin_chars.setObjectName(_fromUtf8("spin_chars"))
self.chk_upper = QtGui.QCheckBox(self.centralwidget)
self.chk_upper.setGeometry(QtCore.QRect(230, 90, 141, 23))
self.chk_upper.setObjectName(_fromUtf8("chk_upper"))
self.chkSym = QtGui.QCheckBox(self.centralwidget)
self.chkSym.setGeometry(QtCore.QRect(230, 150, 121, 23))
self.chkSym.setObjectName(_fromUtf8("chkSym"))
self.chkNum = QtGui.QCheckBox(self.centralwidget)
self.chkNum.setGeometry(QtCore.QRect(230, 120, 121, 23))
self.chkNum.setObjectName(_fromUtf8("chkNum"))
self.btn_gerar = QtGui.QPushButton(self.centralwidget)
self.btn_gerar.setGeometry(QtCore.QRect(230, 230, 141, 51))
self.btn_gerar.setObjectName(_fromUtf8("btn_gerar"))
self.btn_copy = QtGui.QPushButton(self.centralwidget)
self.btn_copy.setVisible(False)
self.btn_copy.setGeometry(QtCore.QRect(230, 180, 80, 25))
self.btn_copy.setObjectName(_fromUtf8("btn_copy"))
self.lst_pass = QtGui.QListWidget(self.centralwidget)
self.lst_pass.setGeometry(QtCore.QRect(20, 20, 181, 261))
self.lst_pass.setObjectName(_fromUtf8("lst_pass"))
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
QtCore.QObject.connect(self.btn_gerar, QtCore.SIGNAL(_fromUtf8("clicked()")), self.gerar)
QtCore.QObject.connect(self.btn_copy, QtCore.SIGNAL(_fromUtf8("clicked()")), self.copiar)
self.lst_pass.itemClicked.connect(self.selecionar)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "Gerador de Senhas", None))
self.label.setText(_translate("MainWindow", "Nº Chars", None))
self.chk_upper.setText(_translate("MainWindow", "Utilizar MAIÚSCULAS", None))
self.chkSym.setText(_translate("MainWindow", "Utilizar S!mbo!os", None))
self.chkNum.setText(_translate("MainWindow", "Utilizar Núm3r0s", None))
self.btn_gerar.setText(_translate("MainWindow", "GERAR SENHAS", None))
self.btn_copy.setText(_translate("MainWindow", "Copiar", None))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment