Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def get_information(self,info):
username = self.usernameEdit.text()
password = self.passwordEdit.text()
website = self.websiteEdit.text()
if username == '' or password == '' or website == '':
return None
else:
info[website] = [username,password]
return username,password,website
def add_label(self,user_info):
self.usernameLabel = QtWidgets.QLabel('Username: %s ' % (user_info[0]))
self.passwordLabel = QtWidgets.QLabel('Password: %s' % (user_info[1]))
self.websiteLabel = QtWidgets.QLabel('Website: %s' % (user_info[2]))
font = QtGui.QFont()
font.setPointSize(12)
self.usernameLabel.setFont(font)
self.passwordLabel.setFont(font)
self.websiteLabel.setFont(font)
h_box = QtWidgets.QHBoxLayout()
def btn_click(self,vertical_box,info):
try:
h_box=self.add_label(self.get_information(info))
vertical_box.addLayout(h_box)
self.save_passwords(info,'passwords.json')
except TypeError:
pass
self.usernameEdit.setText('')
self.passwordEdit.setText('')
self.websiteEdit.setText('')
def read_passwords(self,filename):
if os.path.exists(filename):
with open(filename) as file:
return json.load(file)
else:
data = {}
with open(filename,'w') as outfile:
json.dump(data,outfile)
return data
def convert_to_labels(self,info,vertical_box):
try:
for k,v in info.items():
user_data = (v[0],v[1],k)
h_box = self.add_label(user_data)
vertical_box.addLayout(h_box)
except:
pass
class PassGUI(QtWidgets.QWidget):
def __init__(self):
super().__init__() #call the constructor of QtWidgets
self.init_ui() #constructor for our UI
def init_ui(self): #everything inside the window
self.setGeometry(50,50,600,150)
def binary_search(list,item):
low = 0
high = len(list)-1
while low <= high:
mid = (low + high)//2
guess = list[mid]
if guess == item:
return mid
if guess > item:
from django.db import models
# Create your models here.
class ProjectInfo(models.Model):
name = models.CharField(max_length=30)
description = models.TextField(max_length=200)
github = models.URLField()
demo = models.URLField(blank=True)
image = models.FileField(upload_to="photos/",blank=True)
from rest_framework import serializers
from backend.models import ProjectInfo
# project serializer
class ProjectInfoSerializer(serializers.ModelSerializer):
class Meta:
model = ProjectInfo
fields = ['name','description','github','demo','image']