Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
110 additions
and
97 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,77 @@ | ||
import sys | ||
sys.path.append("../../") | ||
from appJar import gui | ||
from sqlalchemy import create_engine, select, Column, Integer, Text, MetaData, Table, Boolean, String, Date, Numeric | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker | ||
from datetime import datetime | ||
|
||
data1 = [["Name", "Age", "Gender"], ["Fred", 45, "Male"], ["Tina", 37, "Female"], ["Clive", 28, "Male"], ["Betty", 51, "Female"]] | ||
data2 = [["NewName", "NewAge", "NewGender", "A.N.Other"], ["Fred", 45, "Male"], ["Tina", 37, "Female"], ["Clive", 28, "Male"], ["Betty", 51, "Female"]] | ||
app = gui("Test SQL Alch (ORM GUI)", "600x600") | ||
app.setBg("#FF9D40") | ||
|
||
def swapGrid(btn): | ||
engine = create_engine('sqlite:///:memory:') | ||
|
||
Base = declarative_base() | ||
Session = sessionmaker(bind=engine) | ||
|
||
class Money(Base): | ||
__tablename__ = 'money' | ||
md5hash = Column(String, primary_key=True) | ||
category = Column(String) | ||
verified = Column(Boolean) | ||
booked = Column(Date) | ||
valuta = Column(Date) | ||
issuer = Column(String) | ||
receiver = Column(String) | ||
account_nr = Column(String) | ||
iban = Column(String) | ||
blz = Column(String) | ||
bic = Column(String) | ||
reference = Column(String) | ||
comment = Column(String) | ||
currency = Column(String) | ||
amount = Column(String) | ||
type = Column(String) | ||
|
||
def __repr__(self): | ||
return "<Money(md5='%s', amount='%s', date='%s')>" % ( | ||
self.md5hash, self.amount, self.booked) | ||
|
||
session = Session() | ||
|
||
Base.metadata.create_all(engine) | ||
for n in range(25): | ||
session.add(Money(md5hash="test"+str(n), amount=n, comment="test", verified=False, | ||
receiver="rec"+str(n), reference="ref"+str(n), booked=datetime.now(), type="S")) | ||
session.commit() | ||
|
||
def press(row): | ||
print(all_money[row]) | ||
|
||
all_money = [] | ||
|
||
def runQuery(): | ||
data = [["booked", "receiver", "reference", "comment", "amnt", "type"]] | ||
query = session.query(Money).filter(Money.verified != None) | ||
if len(app.getEntry("receiver"))>0: | ||
query = query.filter(Money.receiver.like("%"+app.getEntry("receiver")+"%")) | ||
else: | ||
query = query.limit(25) | ||
all_money = query.all() | ||
for m in all_money: | ||
data.append([m.booked, m.receiver[:14], m.reference[:18], m.comment[:10], m.amount, m.type]) | ||
app.addGrid("g1", data, action=press, row=1) | ||
|
||
def submit(obj): | ||
app.removeGrid("g1") | ||
app.openTab("Tabs", "one") | ||
app.addGrid("g1", data2) | ||
app.stopTab() | ||
|
||
app = gui() | ||
app.startTabbedFrame("Tabs") | ||
app.startTab("one") | ||
app.addGrid("g1", data1) | ||
app.stopTab() | ||
app.startTab("two") | ||
app.addLabel("l2", "Tab Two") | ||
app.stopTab() | ||
app.startTab("three") | ||
app.addLabel("l3", "Tab Three") | ||
app.stopTab() | ||
app.stopTabbedFrame() | ||
app.addButton("SWAP", swapGrid) | ||
runQuery() | ||
|
||
app.setStretch("none") | ||
app.addLabelEntry("receiver") | ||
app.setEntrySubmitFunction("receiver", submit) | ||
app.setFocus("receiver") | ||
app.setStretch("both") | ||
runQuery() | ||
|
||
app.go() | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
sys.path.append("../../") | ||
from appJar import gui | ||
|
||
def press(btn): | ||
if btn == "SUB": | ||
app.hide() | ||
app.showSubWindow("Sub Window") | ||
elif btn == "MAIN": | ||
app.show() | ||
app.hideSubWindow("Sub Window") | ||
elif btn in ["EXIT", "e"]: | ||
app.stop() | ||
|
||
def mainStop(btn=None): | ||
print("Main stop") | ||
return True | ||
|
||
def subStop(btn=None): | ||
app.show() | ||
return True | ||
|
||
|
||
app=gui("Main Window") | ||
|
||
app.addLabel("title", "Main Window") | ||
app.addButton("SUB", press) | ||
app.addButton("EXIT", press) | ||
app.setStopFunction(mainStop) | ||
|
||
app.startSubWindow("Sub Window") | ||
app.addLabel("sub_title", "Sub Window") | ||
app.addButton("MAIN", press) | ||
app.addNamedButton("EXIT", "e", press) | ||
app.setStopFunction(subStop) | ||
app.stopSubWindow() | ||
|
||
|
||
|
||
app.go() |