Example #1
0
INSERT INTO Mood VALUES (2,"Sad");
INSERT INTO Mood VALUES (3,"Angry");
INSERT INTO Mood VALUES (4,"Emotional");
INSERT INTO Mood VALUES (5,"Content");
INSERT INTO Mood VALUES (6,"Curious");
"""

# -------------------------
# CREATE PYSIMPLEGUI LAYOUT
# -------------------------
# Define the columns for the table selector
headings=['id','Date:              ','Mood:      ','Title:                                 '] # The width of the headings defines column width!
visible=[0,1,1,1] # Hide the id column
layout=[
    ss.selector('sel_journal','Journal',sg.Table,num_rows=10,headings=headings,visible_column_map=visible),
    ss.actions('act_journal','Journal', edit_protect=False), # These are your database controls (Previous, Next, Save, Insert, etc!)
    ss.record('Journal.entry_date', label='Date:'),
    ss.record('Journal.mood_id', sg.Combo, label='My mood:', size=(30,10), auto_size_text=False),
    ss.record('Journal.title', size=(71,1)),
    ss.record('Journal.entry', sg.MLine, size=(71,20))
]

win=sg.Window('Journal example', layout, finalize=True)
db=ss.Database('journal.db', win, sql_commands=sql) #<=== ONE SIMPLE CHANGE!!!
# Now we just give the new databasase a name - "journal.db" in this case.  If journal.db is not present
# when this code is run, then a new one is created using the commands supplied to the sql_commands keyword argument.
# If journal.db does exist, then it is used and the sql_commands are not run at all.

# Reverse the default sort order so new journal entries appear at the top
db['Journal'].set_order_clause('ORDER BY entry_date DESC')
# Set the column order for search operations.  By default, only the column designated as the description column is searched
              size=(30, 10),
              auto_size_text=False)
]
sub_layout = [
    ss.selector('selector1', 'Item', size=(35, 10)) + [
        sg.Col([
            ss.record('Item.name'),
            ss.record(
                'Item.fkMenu', sg.Combo, size=(30, 10), auto_size_text=False),
            ss.record('Item.price'),
            ss.record('Item.description', sg.MLine, (30, 7))
        ])
    ],
    ss.actions('act_item',
               'Item',
               edit_protect=False,
               navigation=False,
               save=False,
               search=False)
]
layout += [[sg.Frame('Items', sub_layout)]]
layout += [ss.actions('act_restaurant', 'Restaurant')]

# Initialize our window and database, then bind them together
win = sg.Window('places to eat', layout, finalize=True)
db = ss.Database(':memory:', win, sql_script='example.sql'
                 )  # <=== load the database and bind it to the window
# NOTE: ":memory:" is a special database URL for in-memory databases

# Set our callbacks
# See documentation for a full list of callbacks supported
db.set_callback('edit_enable', enable)
Example #3
0
# CREATE PYSIMPLEGUI LAYOUT
# -------------------------
# Define the columns for the table selector
headings = [
    'id', 'Date:              ', 'Mood:      ',
    'Title:                                 '
]
visible = [0, 1, 1, 1]  # Hide the id column
layout = [
    ss.selector('sel_journal',
                'Journal',
                sg.Table,
                num_rows=10,
                headings=headings,
                visible_column_map=visible),
    ss.actions('act_journal', 'Journal'),
    ss.record('Journal.entry_date'),
    ss.record('Journal.mood_id', sg.Combo, size=(30, 10),
              auto_size_text=False),
    ss.record('Journal.title'),
    ss.record('Journal.entry', sg.MLine, size=(71, 20))
]
win = sg.Window('Journal example', layout, finalize=True)
db = ss.Database(':memory:', win, sql_commands=sql)  #<=== Here is the magic!
# Note:  sql_commands in only run if journal.db does not exist!  This has the effect of creating a new blank
# database as defined by the sql_commands if the database does not yet exist, otherwise it will use the database!

# Reverse the default sort order so new journal entries appear at the top
db['Journal'].set_order_clause('ORDER BY entry_date DESC')
# Set the column order for search operations.  By default, only the column designated as the description column is searched
db['Journal'].set_search_order(['entry_date', 'title', 'entry'])
Example #4
0
INSERT INTO "Person" ("name") VALUES ("Pat");

INSERT INTO "FavoriteColor" VALUES (1,1,1);
INSERT INTO "FavoriteColor" VALUES (2,1,2);
INSERT INTO "FavoriteColor" VALUES (3,1,4);
INSERT INTO "FavoriteColor" VALUES (4,2,3);
INSERT INTO "FavoriteColor" VALUES (5,2,5);
INSERT INTO "FavoriteColor" VALUES (6,2,6);
INSERT INTO "FavoriteColor" VALUES (7,3,7);
INSERT INTO "FavoriteColor" VALUES (8,3,6);
INSERT INTO "FavoriteColor" VALUES (9,3,4);
'''

person_layout = [
    ss.selector('sel_person', 'Person', size=(48, 10)),
    ss.actions('act_person', 'Person', edit_protect=False, search=False),
    ss.record('Person.name', label_above=True)
]
color_layout = [
    ss.selector('sel_color', 'Color', size=(48, 10)),
    ss.actions('act_color', 'Color', edit_protect=False, search=False),
    ss.record('Color.name', label_above=True)
]
headings = [
    'ID (this will be hidden)', 'Person            ', 'Favorite Color     '
]
vis = [0, 1, 1]
favorites_layout = [
    ss.selector('sel_favorite',
                'FavoriteColor',
                sg.Table,
Example #5
0
    ss.record("Addresses.fkGroupName",
              sg.Combo,
              auto_size_text=False,
              size=(30, 10)),
    ss.record("Addresses.firstName", label="First name:"),
    ss.record("Addresses.lastName", label="Last name:"),
    ss.record("Addresses.address1", label="Address 1:"),
    ss.record("Addresses.address2", label="Address 2:"),
    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)), [sg.Text("Zip:" + " " * 63)] +
    ss.record("Addresses.zip", no_label=True, size=(6, 1)),
    ss.actions("browser", "Addresses", edit_protect=False)
]
win = sg.Window('Journal example', layout, finalize=True)
db = ss.Database(':memory:', win, sql_commands=sql)  #<=== Here is the magic!
# Note:  sql_commands in only run if journal.db does not exist!  This has the effect of creating a new blank
# database as defined by the sql_commands if the database does not yet exist, otherwise it will use the database!

# Use a callback to validate the zip code
db['Addresses'].set_callback('before_save', validate_zip)

# ---------
# MAIN LOOP
# ---------
while True:
    event, values = win.read()
]  # Table column widths can be set by the spacing of the headings!
visible = [0, 1, 1, 1]  # Hide the primary key column in the table
record_columns = [
    ss.record('Colors.name', label='Color name:'),
    ss.record('Colors.example', label='Example usage: '),
    ss.record('Colors.primary_color', label='Primary Color?', element=sg.CBox),
]
selectors = [
    ss.selector('tableSelector',
                'Colors',
                element=sg.Table,
                headings=headings,
                visible_column_map=visible,
                num_rows=10) +
    ss.selector('selector1', 'Colors', size=(15, 10)),
    ss.actions('colorActions', 'Colors'),
    ss.selector('selector2', 'Colors', element=sg.Slider, size=(26, 18)) +
    ss.selector('selector3', 'Colors', element=sg.Combo, size=(30, 10)),
]
layout = [
    [sg.Text(description)],
    [
        sg.Frame('Test out all of these selectors and watch the magic!',
                 selectors)
    ],
    [sg.Col(record_columns, vertical_alignment='t')],
]

win = sg.Window('Record Selector Demo', layout, finalize=True)
db = ss.Database(':memory:', win, sql_commands=sql)  #<=== Here is the magic!
# note: Since win was passed as a parameter, binding is automatic (including event mapping!)
Example #7
0
# table where the key column is equal to 'first_name'.  This is basically the equivalent in SQL as the statement
# SELECT value FROM Settings WHERE key='first_name';
layout = [
    [sg.Text('APPLICATION SETTINGS')],
    [sg.HorizontalSeparator()],
    ss.record('Settings.value?key=company_name'),
    [sg.Text('')],
    ss.record('Settings.value?key=debug_mode', sg.CBox),
    [sg.Text('')],
    ss.record('Settings.value?key=antialiasing', sg.CBox),
    [sg.Text('')],
    ss.record('Settings.value?key=query_retries'),
    # For the actions, we don't want to offer users to insert or delete records from the settings table,
    # and there is no use for navigation buttons due to the key,value nature of the data.  Therefore, we will
    # disable all actions (default=False) except for the Save action (save=True)
    ss.actions('nav', 'Settings', default=False, save=True)
]

# Initialize our window and database, then bind them together
win = sg.Window('Preferences: Application Settings', layout, finalize=True)
db = ss.Database(
    'Settigs.db', win,
    sql_commands=sql)  # <=== load the database and bind it to the window

# Now that the database is loaded, lets set our tool tips using the description column.
# The Table.get_keyed_value can return the value column where the key column equals a specific value as well.
win['Settings.value?key=company_name'].set_tooltip(
    db['Settings'].get_keyed_value('description', 'key', 'company_name'))
win['Settings.value?key=debug_mode'].set_tooltip(
    db['Settings'].get_keyed_value('description', 'key', 'debug_mode'))
win['Settings.value?key=antialiasing'].set_tooltip(