コード例 #1
0
# Here are our callback functions
def en(db, win):
    res = sg.popup_get_text(
        'Enter password for edit mode.\n(Hint: it is 1234)')
    return True if res == '1234' else False


def dis(db, win):
    res = sg.popup_yes_no('Are you sure you want to disabled edit mode?')
    return True if res == 'Yes' else False


# Define our layout. We will use the ss.record convenience function to create the controls
layout = [
    ss.record('Restaurant', 'name'),
    ss.record('Restaurant', 'location'),
    ss.record('Restaurant', 'fkType', sg.Combo)
]
sub_layout = [[
    sg.Listbox(values=(),
               size=(35, 10),
               key="SELECTOR.Item",
               select_mode=sg.LISTBOX_SELECT_MODE_SINGLE,
               enable_events=True),
    sg.Col([
        ss.record('Item', 'name'),
        ss.record('Item', 'fkMenu', sg.Combo),
        ss.record('Item', 'price'),
        ss.record('Item', 'description', sg.MLine, (30, 7))
    ])
コード例 #2
0
ファイル: journal.py プロジェクト: PySimpleSQL/pysimplesql
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
db['Journal'].set_search_order(['entry_date','title','entry'])
コード例 #3
0
# Here are our callback functions
def enable(db, win):
    res = sg.popup_get_text(
        'Enter password for edit mode.\n(Hint: it is 1234)')
    return True if res == '1234' else False


def disable(db, win):
    res = sg.popup_yes_no('Are you sure you want to disabled edit mode?')
    return True if res == 'Yes' else False


# Define our layout. We will use the ss.record convenience function to create the controls
layout = [
    ss.record('Restaurant.name'),
    ss.record('Restaurant.location'),
    ss.record('Restaurant.fkType',
              sg.Combo,
              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))
        ])
コード例 #4
0
# -------------------------
# 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'])
コード例 #5
0
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,
                num_rows=10,
コード例 #6
0
# Define the columns for the table selector
columns = ['pkAddresses', 'firstName', 'lastName', 'city', 'fkState']
headings = [
    'pk', 'First name:    ', 'Last name:     ', 'City:        ', 'State'
]
visible = [0, 1, 1, 1, 1]  # Hide the primary key column
layout = [
    ss.selector("sel",
                "Addresses",
                sg.Table,
                headings=headings,
                visible_column_map=visible,
                columns=columns,
                num_rows=10),
    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)
コード例 #7
0
description = """
Many different types of PySimpleGUI elements can be used as Selector controls to select database records.
Navigation buttons, the Search box, ListBoxes, ComboBoxes, Sliders and tables can all be set to control
record navigation. Multiple selectors can be used simultaneously and they will all work together in harmony. Try each selector
on this form and watch it all just work!
"""

# PySimpleGUI™ layout code
headings = [
    'id', 'Name     ', 'Example                                          ',
    'Primary Color?'
]  # 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)),
]
コード例 #8
0
-- There is nothing special about the key and value column names, they can literally be anything.
INSERT INTO SETTINGS VALUES (1,'company_name','My company','Enter your company name here.');
INSERT INTO SETTINGS VALUES (2,'debug_mode',True,'Check if you would like debug mode enabled.');
INSERT INTO SETTINGS VALUES (3,'antialiasing', True,'Would you like to render with antialiasing?');
INSERT INTO SETTINGS VALUES (4, 'query_retries', 3,'Retry queries this many times before aborting.');
"""

# When using ss.record() to create entries based on key/value pairs, it just uses an extended syntax.
# Where ss.record('Settings.value') would return the value column from the Settings table FOR THE CURRENT RECORD,
# the extended syntax of ss.record('Settings.value?key=first_name will return the value column from the Settings
# 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(