Skip to content

Commit

Permalink
Testing subs #278
Browse files Browse the repository at this point in the history
Also moved issue #232 testing
  • Loading branch information
jarvisteach committed Oct 20, 2017
1 parent aadf044 commit 20ba771
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 97 deletions.
77 changes: 0 additions & 77 deletions examples/issue232.py

This file was deleted.

90 changes: 70 additions & 20 deletions examples/issues/issue232.py
@@ -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()

40 changes: 40 additions & 0 deletions examples/issues/issue278.py
@@ -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()

0 comments on commit 20ba771

Please sign in to comment.