Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/mainloop.cpython-34.pyc
Binary file not shown.
Binary file added __pycache__/screens.cpython-34.pyc
Binary file not shown.
Binary file modified __pycache__/screens.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/window.cpython-34.pyc
Binary file not shown.
Binary file modified __pycache__/window.cpython-35.pyc
Binary file not shown.
11 changes: 0 additions & 11 deletions appinst/exe.md

This file was deleted.

13 changes: 0 additions & 13 deletions appinst/setup.py

This file was deleted.

Binary file added dist/LearnPythonWithPython.exe
Binary file not shown.
60 changes: 60 additions & 0 deletions handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import sqlite3
import smtplib

class UserError(Exception):
pass

class SqlHandler:
def __init__(self):
self.connection = sqlite3.connect("comments.db")
self.cursor = self.connection

cmd = """
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
username TEXT
email TEXT
password TEXT);"""

self.cursor.execute(cmd)

cmd = """
CREATE TABLE IF NOT EXISTS comments (
id INTEGER PRIMARY KEY,
senderId INTEGER
comment TEXT);"""

self.cursor.execute(cmd)

def login(self, username, password):
cmd = "SELECT 1 FROM users WHERE ((username = {0} OR email = {0}) AND password = {1});".format(username, password)
self.cursor.execute(cmd)
user = self.cursor.fetchone()
try:
assert user != None
except AssertionError:
raise UserError("While logging in: Username or password not correct.")
return user

def signup(self, username, email, password):
cmd = "SELECT 1 FROM users WHERE (username = \"{0}\" OR email = \"{1}\");".format(username, email)
self.cursor.execute(cmd)
try:
assert user == None
except AssertionError:
raise UserError("While signing up: User with username or email already exists")
return False
cmd = "INSERT INTO users VALUES(NULL, {0}, {1}, {2});\n SELECT 1 FROM users WHERE (username = {0});".format(username, email, password)
self.cursor.execute(cmd)
return self.cursor.fetchone()

def sendComment(self, senderId, comment):
cmd = "INSERT INTO comments VALUES(NULL, {0}, {1});".format(senderId, comment)
self.cursor.execute(cmd)

def showComments(self):
cmd = "SELECT * FROM comments"
self.cursor.execute(cmd)
return self.fetchall


216 changes: 197 additions & 19 deletions screens.py

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions setup_exe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from distutils.core import setup
import py2exe
import window, screens

setup(
console = [{
"script": "mainloop.py",
"icon_resources": [(1, "pycon-icon.ico")],
"dest_base": "LearnPythonWithPython"
}]
)
14 changes: 7 additions & 7 deletions window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Window(Frame):
def __init__(self, master=None):
super(Window, self).__init__()
self.s_init()
self.s_init(1)

def close_app(self):
self.master.destroy()
Expand All @@ -21,8 +21,8 @@ def choBtn(self, txt, func, x, y):
def btnQuit(self):
return self.choBtn("Quit", self.close_app, 0, 0)

def btnBack(self):
return self.choBtn("Back", self.s_init, 0, 0)
def btnBack(self, unit):
return self.choBtn("Back", lambda: self.s_init(unit), 0, 0)

def btnNext(self, nextScreen):
return Button(self, text="Next", command=nextScreen).place(relx=1.0, rely=1.0, anchor=SE)
Expand All @@ -39,12 +39,12 @@ def cenLbl(self, txt):
return Label(self, text=txt).pack()

def multiLbl(self, txt):
return Label(self, text=txt, anchor=W, wraplength=425).pack()
return Label(self, text=txt, wraplength=750).pack(anchor=W)

def new(self, home=False):
def new(self, unit):
for widget in self.winfo_children():
widget.destroy()
if home == True:
if unit == 0:
self.btnQuit()
else:
self.btnBack()
self.btnBack(unit)