Skip to content

Commit 6f5f5d2

Browse files
committed
Merge branch 'development'
# Conflicts: # README.md # VERSIONS.md # examples/address_book.py # examples/journal_external.py # examples/journal_internal.py # examples/journal_with_data_manipulation.py # examples/many_to_many.py # examples/password_callback.py # examples/restaurants.py # examples/selectors_demo.py # examples/settings.py # examples/tutorial_files/Journal/tutorial.md # examples/tutorial_files/Journal/v1/journal.py # examples/tutorial_files/Journal/v2/journal.py # examples/tutorial_files/Journal/v3/journal.py # examples/tutorial_files/Journal/v4/journal.py # pysimplesql/pysimplesql.py
2 parents 632da25 + f6b4599 commit 6f5f5d2

18 files changed

+1273
-846
lines changed

README.md

Lines changed: 158 additions & 116 deletions
Large diffs are not rendered by default.

VERSIONS.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# **pysimplesql** Version Information
2+
3+
## <develop>
4+
### Released <release_date>
5+
- Big change, moving from a Database/Table topology to a Form/Query topology. Aliases for Database/Table will be available to avoid breaking code as much as possible.
6+
I had to kick this around quite a bit, and in the end the new topology makes more sense, especially when you get into using multiple Forms and Queries against the same tables.
7+
- The above being said, the way records are created is chaging slightly, as well as how the Form is bound to the Window.
8+
- By default, auto-generated queries have the same name as the underlying table
9+
- Tons of documentation improvements
10+
- Prompt saves when dirty records are present. This will also be an option for Query object so that the feature can be turned on and off.
11+
- Forms and Queries now track created instances. They can be accessed with Form.instances and Query.instances
12+
- pysimplesql.update_elements() master function will update elements for all forms. Form.update_elements() still remains, and only updates elements for that specific Form instance.
13+
- pysimplesql.process_events() master function will process events for all forms. Form.process_events() still remains, and only processes events for that specific Form instance.
14+
- Examples and tutorials updated to work with new changes

examples/address_book.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,34 +60,35 @@ def validate_zip():
6060
headings=['pk','First name: ','Last name: ','City: ','State']
6161
visible=[0,1,1,1,1] # Hide the primary key column
6262
layout=[
63-
ss.selector("sel","Addresses",sg.Table, headings=headings,visible_column_map=visible, columns=columns,num_rows=10),
64-
ss.record("Addresses.fkGroupName",sg.Combo,auto_size_text=False, size=(30,10)),
65-
ss.record("Addresses.firstName", label="First name:"),
66-
ss.record("Addresses.lastName", label="Last name:"),
67-
ss.record("Addresses.address1", label="Address 1:"),
68-
ss.record("Addresses.address2", label="Address 2:"),
69-
ss.record("Addresses.city", label="City/State:", size=(23,1)) + ss.record("Addresses.fkState",element=sg.Combo, no_label=True, quick_editor=False, size=(3,10)),
70-
[sg.Text("Zip:"+" "*63)] + ss.record("Addresses.zip", no_label=True,size=(6,1)),
71-
ss.actions("browser","Addresses",edit_protect=False)
63+
[ss.selector("sel","Addresses",sg.Table, headings=headings,visible_column_map=visible, columns=columns,num_rows=10)],
64+
[ss.record("Addresses.fkGroupName",sg.Combo,auto_size_text=False, size=(30,10))],
65+
[ss.record("Addresses.firstName", label="First name:")],
66+
[ss.record("Addresses.lastName", label="Last name:")],
67+
[ss.record("Addresses.address1", label="Address 1:")],
68+
[ss.record("Addresses.address2", label="Address 2:")],
69+
[ss.record("Addresses.city", label="City/State:", size=(23,1)) ,ss.record("Addresses.fkState",element=sg.Combo, no_label=True, quick_editor=False, size=(3,10))],
70+
[sg.Text("Zip:"+" "*63), ss.record("Addresses.zip", no_label=True,size=(6,1))],
71+
[ss.actions("browser","Addresses",edit_protect=False)]
7272
]
73+
7374
win=sg.Window('Journal example', layout, finalize=True)
74-
db=ss.Database(':memory:', win, sql_commands=sql) #<=== Here is the magic!
75-
# Note: sql_commands in only run if journal.db does not exist! This has the effect of creating a new blank
76-
# database as defined by the sql_commands if the database does not yet exist, otherwise it will use the database!
75+
# Create our frm
76+
frm=ss.Form(':memory:', sql_commands=sql, bind=win)
77+
7778

7879
# Use a callback to validate the zip code
79-
db['Addresses'].set_callback('before_save',validate_zip)
80+
frm['Addresses'].set_callback('before_save',validate_zip)
8081

8182
# ---------
8283
# MAIN LOOP
8384
# ---------
8485
while True:
8586
event, values = win.read()
8687

87-
if db.process_events(event, values): # <=== let PySimpleSQL process its own events! Simple!
88+
if ss.process_events(event, values): # <=== let PySimpleSQL process its own events! Simple!
8889
logger.info(f'PySimpleDB event handler handled the event {event}!')
8990
elif event == sg.WIN_CLOSED or event == 'Exit':
90-
db=None # <= ensures proper closing of the sqlite database and runs a database optimization
91+
frm=None # <= ensures proper closing of the sqlite database and runs a database optimization
9192
break
9293
else:
9394
logger.info(f'This event ({event}) is not yet handled.')
@@ -100,11 +101,11 @@ def validate_zip():
100101
usable program! The combination of PySimpleSQL and PySimpleGUI is very fun, fast and powerful!
101102
102103
Learnings from this example:
103-
- Using Table.set_search_order() to set the search order of the table for search operations.
104+
- Using Query.set_search_order() to set the search order of the table for search operations.
104105
- embedding sql commands in code for table creation
105-
- creating a default/empty database with sql commands with the sql_commands keyword argument to ss.Database()
106+
- creating a default/empty database with sql commands with the sql_commands keyword argument to ss.Form()
106107
- using ss.record() and ss.selector() functions for easy GUI element creation
107108
- using the label keyword argument to ss.record() to define a custom label
108109
- using Tables as ss.selector() element types
109-
- changing the sort order of database tables
110+
- changing the sort order of database queries
110111
"""

examples/journal_external.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,41 @@
44
logger=logging.getLogger(__name__)
55
logging.basicConfig(level=logging.INFO) # <=== You can set the logging level here (NOTSET,DEBUG,INFO,WARNING,ERROR,CRITICAL)
66

7+
78
# -------------------------
89
# CREATE PYSIMPLEGUI LAYOUT
910
# -------------------------
1011
# Define the columns for the table selector
1112
headings=['id','Date: ','Mood: ','Title: ']
1213
visible=[0,1,1,1] # Hide the id column
1314
layout=[
14-
ss.selector('sel_journal','Journal',sg.Table,num_rows=10,headings=headings,visible_column_map=visible),
15-
ss.actions('act_journal','Journal'),
16-
ss.record('Journal.entry_date'),
17-
ss.record('Journal.mood_id', sg.Combo, label='My mood:', size=(30,10), auto_size_text=False),
18-
ss.record('Journal.title'),
19-
ss.record('Journal.entry', sg.MLine, size=(71,20))
15+
[ss.selector('sel_journal','Journal',sg.Table,num_rows=10,headings=headings,visible_column_map=visible)],
16+
[ss.actions('act_journal','Journal')],
17+
[ss.record('Journal.entry_date')],
18+
[ss.record('Journal.mood_id', sg.Combo, label='My mood:', size=(30,10), auto_size_text=False)],
19+
[ss.record('Journal.title')],
20+
[ss.record('Journal.entry', sg.MLine, size=(71,20))]
2021
]
21-
win=sg.Window('Journal example', layout, finalize=True)
22-
db=ss.Database('journal.db', win, sql_script='journal.sql') #<=== Here is the magic!
23-
# Note: sql_script is only run if journal.db does not exist! This has the effect of creating a new blank
22+
win=sg.Window('Journal (external) example', layout, finalize=True)
23+
frm=ss.Form('journal.db', sql_script='journal.sql', bind=win) #<=== Here is the magic!
24+
# Note: sql_script is only run if journal.frm does not exist! This has the effect of creating a new blank
2425
# database as defined by the sql_script file if the database does not yet exist, otherwise it will use the database!
2526

2627
# Reverse the default sort order so new journal entries appear at the top
27-
db['Journal'].set_order_clause('ORDER BY entry_date DESC')
28+
frm['Journal'].set_order_clause('ORDER BY entry_date DESC')
2829
# Set the column order for search operations. By default, only the column designated as the description column is searched
29-
db['Journal'].set_search_order(['entry_date','title','entry'])
30+
frm['Journal'].set_search_order(['entry_date','title','entry'])
3031

3132
# ---------
3233
# MAIN LOOP
3334
# ---------
3435
while True:
3536
event, values = win.read()
3637

37-
if db.process_events(event, values): # <=== let PySimpleSQL process its own events! Simple!
38+
if ss.process_events(event, values): # <=== let PySimpleSQL process its own events! Simple!
3839
logger.info(f'PySimpleDB event handler handled the event {event}!')
3940
elif event == sg.WIN_CLOSED or event == 'Exit':
40-
db=None # <= ensures proper closing of the sqlite database and runs a database optimization
41+
frm=None # <= ensures proper closing of the sqlite database and runs a database optimization
4142
break
4243
else:
4344
logger.info(f'This event ({event}) is not yet handled.')
@@ -48,10 +49,10 @@
4849
usable program! The combination of PySimpleSQL and PySimpleGUI is very fun, fast and powerful!
4950
5051
Learnings from this example:
51-
- Using Table.set_search_order() to set the search order of the table for search operations.
52-
- creating a default/empty database with an external sql script with the sql_script keyword argument to ss.Database()
53-
- using ss.record() and ss.selector() functions for easy GUI element creation
54-
- using the label keyword argument to ss.record() to define a custom label
55-
- using Tables as ss.selector() element types
56-
- changing the sort order of database tables
52+
- Using Query.set_search_order() to set the search order of the query for search operations.
53+
- creating a default/empty database with an external sql script with the sql_script keyword argument to ss.Form()
54+
- using Form.record() and Form.selector() functions for easy GUI element creation
55+
- using the label keyword argument to Form.record() to define a custom label
56+
- using Tables as Form.selector() element type
57+
- changing the sort order of Queries
5758
"""

examples/journal_internal.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,33 @@
3434
headings=['id','Date: ','Mood: ','Title: ']
3535
visible=[0,1,1,1] # Hide the id column
3636
layout=[
37-
ss.selector('sel_journal','Journal',sg.Table,num_rows=10,headings=headings,visible_column_map=visible),
38-
ss.actions('act_journal','Journal'),
39-
ss.record('Journal.entry_date'),
40-
ss.record('Journal.mood_id', sg.Combo, label='My mood:', size=(30,10), auto_size_text=False),
41-
ss.record('Journal.title'),
42-
ss.record('Journal.entry', sg.MLine, size=(71,20))
37+
[ss.selector('sel_journal','Journal',sg.Table,num_rows=10,headings=headings,visible_column_map=visible)],
38+
[ss.actions('act_journal','Journal')],
39+
[ss.record('Journal.entry_date')],
40+
[ss.record('Journal.mood_id', sg.Combo, label='My mood:', size=(30,10), auto_size_text=False)],
41+
[ss.record('Journal.title')],
42+
[ss.record('Journal.entry', sg.MLine, size=(71,20))]
4343
]
44-
win=sg.Window('Journal example', layout, finalize=True)
45-
db=ss.Database('journal.db', win, sql_commands=sql) #<=== Here is the magic!
46-
# Note: sql_commands in only run if journal.db does not exist! This has the effect of creating a new blank
44+
win=sg.Window('Journal (internal) example', layout, finalize=True)
45+
frm=ss.Form('::memory::', sql_commands=sql, bind=win) #<=== Here is the magic!
46+
# Note: sql_commands in only run if journal.frm does not exist! This has the effect of creating a new blank
4747
# database as defined by the sql_commands if the database does not yet exist, otherwise it will use the database!
4848

4949
# Reverse the default sort order so new journal entries appear at the top
50-
db['Journal'].set_order_clause('ORDER BY entry_date DESC')
50+
frm['Journal'].set_order_clause('ORDER BY entry_date DESC')
5151
# Set the column order for search operations. By default, only the column designated as the description column is searched
52-
db['Journal'].set_search_order(['entry_date','title','entry'])
52+
frm['Journal'].set_search_order(['entry_date','title','entry'])
5353

5454
# ---------
5555
# MAIN LOOP
5656
# ---------
5757
while True:
5858
event, values = win.read()
5959

60-
if db.process_events(event, values): # <=== let PySimpleSQL process its own events! Simple!
60+
if ss.process_events(event, values): # <=== let PySimpleSQL process its own events! Simple!
6161
logger.info(f'PySimpleDB event handler handled the event {event}!')
6262
elif event == sg.WIN_CLOSED or event == 'Exit':
63-
db=None # <= ensures proper closing of the sqlite database and runs a database optimization
63+
frm=None # <= ensures proper closing of the sqlite database and runs a database optimization
6464
break
6565
else:
6666
logger.info(f'This event ({event}) is not yet handled.')
@@ -71,11 +71,11 @@
7171
usable program! The combination of PySimpleSQL and PySimpleGUI is very fun, fast and powerful!
7272
7373
Learnings from this example:
74-
- Using Table.set_search_order() to set the search order of the table for search operations.
74+
- Using Query.set_search_order() to set the search order of the query for search operations.
7575
- embedding sql commands in code for table creation
76-
- creating a default/empty database with sql commands with the sql_commands keyword argument to ss.Database()
77-
- using ss.record() and ss.selector() functions for easy GUI element creation
78-
- using the label keyword argument to ss.record() to define a custom label
79-
- using Tables as ss.selector() element types
80-
- changing the sort order of database tables
76+
- creating a default/empty database with sql commands with the sql_commands keyword argument to ss.Form()
77+
- using Form.record() and Form.selector() functions for easy GUI element creation
78+
- using the label keyword argument to Form.record() to define a custom label
79+
- using Tables as Form.selector() element types
80+
- changing the sort order of database queries
8181
"""

0 commit comments

Comments
 (0)