Skip to content

Commit fc9676e

Browse files
committed
added resources updated demo, table, and menu
1 parent 4092b9f commit fc9676e

File tree

15 files changed

+189
-44
lines changed

15 files changed

+189
-44
lines changed

demo.py

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from icedpygui import IPG, IpgTextParams, IpgRadioDirection, IpgRadioParams
22
from icedpygui import IpgButtonParams, IpgProgressBarParams
33
from icedpygui import IpgColumnAlignment
4+
from icedpygui import TableWidget, TableRowHighLight
45
import random
56

67
"""
@@ -375,14 +376,13 @@ def text_on_input(self, _input_id, data):
375376

376377
def construct_window_2(self):
377378
self.ipg.add_window(self.wnd_2, "Demo Window 2 - Iced Wrapped in Python",
378-
width=500, height=500,
379+
width=600, height=500,
379380
pos_x=650, pos_y=25)
380381

381382
self.ipg.add_column(window_id=self.wnd_2, container_id=self.l_col_2,
382383
width_fill=True, align_items=IpgColumnAlignment.Center)
383384

384-
# A date picker is defined and the results are put in a text widget.
385-
385+
# A date picker is defined and the results are put in a text widget.
386386
def construct_date_picker(self):
387387
self.ipg.add_date_picker(self.l_col_2, on_submit=self.date_selected)
388388

@@ -392,35 +392,85 @@ def construct_date_picker(self):
392392
def date_selected(self, _date_id, date):
393393
self.ipg.update_item(self.date_text_id, IpgTextParams.Content, f"You selected: {date}")
394394

395-
# A table is defined with 4 columns of random items.
395+
# A table is defined with 6 columns of widgets and random items.
396396
# Rust does not allow types to be mixed in a list.
397397
# Therefore, if a mixed list is needed, convert it to a list[str].
398398
# The gui converts the list to strings anyway.
399-
# Width and height are required for the table.
399+
# Width and height are required for the table.
400400
def construct_table(self):
401-
col1: list[float] = []
402-
col2: list[str] = []
403-
col3: list[int] = []
404-
col4: list[bool] = []
405-
406-
for i in range(0, 25):
401+
# Initialize the lists.
402+
col0 = []
403+
col1 = []
404+
col2 = []
405+
col3 = []
406+
col4 = []
407+
col5 = []
408+
col6 = []
409+
410+
# Add some random data of different types
411+
for i in range(0, 20):
412+
# labels for the button widget
413+
col0.append("Button")
414+
# labels for the checkboxes
415+
col1.append("")
416+
# make a selectable text
417+
col2.append("Select Me")
407418
# make a float random number
408-
col1.append(random.randrange(10, 99) + random.randrange(10, 99) / 100)
409-
col2.append(random.choice(["one", "two", "3", "four", "5", "six", "seven"]))
410-
col3.append(random.randrange(10, 99))
411-
col4.append(random.choice([True, False]))
412-
413-
# Note this is a list of dictionaries not a single dictionary
414-
data = [
415-
{"Floats": col1},
416-
{"Strings": col2},
417-
{"Integers": col3},
418-
{"Booleans": col4}
419-
]
420-
421-
table_id = self.ipg.add_table(parent_id=self.l_col_2,
422-
title="My Table", data=data,
423-
width=450.0, height=300.0)
419+
col3.append(random.randrange(10, 99) + random.randrange(10, 99) / 100)
420+
col4.append(random.choice(["one", "two", "three", "four", "five", "six", "seven"]))
421+
col5.append(random.randrange(10, 99))
422+
col6.append(random.choice([True, False]))
423+
424+
# Create the table, the requirement is a list of dictionaries.
425+
# Rust does not have dictionaries but a similar type is called a HashMap.
426+
# The reason for the list of dictionaries is that you cannot extract a
427+
# mixed dictionary into a Rust HashMap. The HashMap has to have predefined
428+
# types. In this case they are <>String, Vec<Widgets>, <String, Vec<f64>>, <String, Vec<String>>,
429+
# <String, Vec<i64>>, and <String, Vec<bool>>. As one iterates through the list,
430+
# each type is tested to see if it can be extracted in one of the types above. If found,
431+
# the extraction occurs and life is wonderful. If no existing type is found, then an error occurs.
432+
# Currently, not every variation is covered but that can be improved in future versions.
433+
# This probably covers the vast majority of needs. If you need that mixed column, convert
434+
# the list to a string. When the final version is displayed, it's converted to a string anyway.
435+
data = [{"Button": col0},
436+
{"ChkBox": col1},
437+
{"Selectable": col2},
438+
{"Col3": col3},
439+
{"Col4": col4},
440+
{"Col5": col5},
441+
{"Col6": col6}]
442+
443+
444+
# The column widgets are prepared
445+
btn_widgets = []
446+
chkbox_widgets = []
447+
selectable = []
448+
449+
for _ in range(0, len(col0)):
450+
btn_widgets.append(TableWidget.Button)
451+
chkbox_widgets.append(TableWidget.Checkbox)
452+
selectable.append(TableWidget.Text)
453+
454+
# The table is added.
455+
self.ipg.add_table(self.l_col_2, "My Table", data,
456+
width=600.0, height=300.0,
457+
row_highlight=TableRowHighLight.Lighter,
458+
table_length=len(col1),
459+
widgets_using_columns= {0: btn_widgets, 1: chkbox_widgets, 2: selectable},
460+
on_press_button=self.widget_button,
461+
on_toggle_checkbox=self.widget_checkbox,
462+
on_enter=self.on_text_enter,
463+
)
464+
465+
def widget_button(self, tbl_id: int, wid_index: tuple[int, int]):
466+
print(tbl_id, wid_index)
467+
468+
def widget_checkbox(self, tbl_id: int, wid_index: tuple[int, int], is_checked: bool):
469+
print(tbl_id, wid_index, is_checked)
470+
471+
def on_text_enter(self, tbl_id, text_index: tuple[int, int]):
472+
print(tbl_id, text_index)
473+
424474

425475

426476
demo = Demo()

py_button_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def update_button(_btn_id: int):
4848

4949

5050
# A window widget needs to be added first.
51-
ipg.add_window("main", "Button Update", width=500, height=600,
51+
ipg.add_window("main", "Button Update", width=500, height=650,
5252
pos_x=100, pos_y=25)
5353

5454
# Adding a container helps in aligning widgets since it has an x and y centering.

py_date_picker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def date_resize(_dp_id: int):
2727

2828

2929
# Add a window first
30-
ipg.add_window("main", "Date Picker Demo", 800, 600,
30+
ipg.add_window("main", "Date Picker Demo", 800, 700,
3131
pos_x=100, pos_y=25)
3232

3333
# Add the container to center both x and y. Holds only one widget.

py_menu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def menu_pressed(_menu_id, data, user_data):
2020
# are used in the testing of the code to make sure it behaves as expected.
2121

2222
# Update the menu by adding a new dictionary.
23-
# This may not be a common scenario but for completion, it's included.
23+
# This update may not be a common scenario but for completion, it's included.
2424
# Since the dictionary needs to maintain its order, user OrderedDict.
2525
# Once the dictionary is made, update the menu using the update command.
2626
# This action will remove all separators, so these will need to be added

py_table.py

Lines changed: 104 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,64 @@
1-
from icedpygui import IPG
2-
import random
1+
from icedpygui import IPG, IpgColumnAlignment, TableRowHighLight, TableWidget
2+
import random, os
3+
34

45
ipg = IPG()
56

7+
8+
9+
def widget_button(tbl_id: int, wid_index: tuple[int, int]):
10+
print(tbl_id, wid_index)
11+
12+
13+
def widget_checkbox(tbl_id: int, wid_index: tuple[int, int], is_checked: bool):
14+
print(tbl_id, wid_index, is_checked)
15+
16+
17+
def image_on_something(tbl_id: int, wid_index: tuple[int, int], ):
18+
print(tbl_id, wid_index)
19+
20+
21+
def image_move(tbl_id: int, point: tuple[float, float]):
22+
print(tbl_id, point)
23+
24+
25+
def on_text_enter(tbl_id, text_index: tuple[int, int]):
26+
print(tbl_id, text_index)
27+
28+
629
# Add the window
7-
ipg.add_window(window_id="main", title="Table Demo", width=500, height=600,
8-
pos_x=100, pos_y=25)
30+
ipg.add_window(window_id="main", title="Table Demo", width=700, height=800,
31+
pos_x=100, pos_y=25, debug=False)
932

1033
# Add the container, since the table requires a width and height,
1134
# the container can shrink(default) to fit.
12-
ipg.add_container(window_id="main", container_id="cont")
35+
ipg.add_column(window_id="main", container_id="col",
36+
width_fill=True, height_fill=True,
37+
align_items=IpgColumnAlignment.Center,
38+
spacing=75)
1339

1440
# Initialize the lists.
41+
col0 = []
1542
col1 = []
1643
col2 = []
1744
col3 = []
1845
col4 = []
46+
col5 = []
47+
col6 = []
1948

2049
# Add some random data of different types
21-
for i in range(0, 50):
50+
for i in range(0, 20):
51+
# labels for the button widget
52+
col0.append("Button")
53+
# labels for the checkboxes
54+
col1.append("")
55+
# make a selectable text
56+
col2.append("Select Me")
2257
# make a float random number
23-
col1.append(random.randrange(10, 99) + random.randrange(10, 99) / 100)
24-
col2.append(random.choice(["one", "two", "three", "four", "five", "six", "seven"]))
25-
col3.append(random.randrange(10, 99))
26-
col4.append(random.choice([True, False]))
58+
col3.append(random.randrange(10, 99) + random.randrange(10, 99) / 100)
59+
col4.append(random.choice(["one", "two", "three", "four", "five", "six", "seven"]))
60+
col5.append(random.randrange(10, 99))
61+
col6.append(random.choice([True, False]))
2762

2863
# Create the table, the requirement is a list of dictionaries.
2964
# Rust does not have dictionaries but a similar type is called a HashMap.
@@ -36,14 +71,69 @@
3671
# Currently, not every variation is covered but that can be improved in future versions.
3772
# This probably covers the vast majorities needs. If you need that mixed column, convert
3873
# the list to a string. When the final version is displayed, it's converted to a string anyway.
39-
data = [{"Col1": col1},
40-
{"Col2": col2},
74+
data = [{"Button": col0},
75+
{"ChkBox": col1},
76+
{"Selectable": col2},
4177
{"Col3": col3},
42-
{"Col4": col4}]
78+
{"Col4": col4},
79+
{"Col5": col5},
80+
{"Col6": col6}]
81+
82+
83+
# The column widgets are prepared
84+
btn_widgets = []
85+
chkbox_widgets = []
86+
selectable = []
87+
88+
for _ in range(0, len(col0)):
89+
btn_widgets.append(TableWidget.Button)
90+
chkbox_widgets.append(TableWidget.Checkbox)
91+
selectable.append(TableWidget.Text)
4392

4493
# The table is added.
45-
ipg.add_table("cont", "My Table", data, width=700.0, height=600.0)
94+
ipg.add_table("col", "My Table", data,
95+
width=600.0, height=300.0,
96+
row_highlight=TableRowHighLight.Lighter,
97+
table_length=len(col1),
98+
widgets_using_columns= {0: btn_widgets, 1: chkbox_widgets, 2: selectable},
99+
on_press_button=widget_button,
100+
on_toggle_checkbox=widget_checkbox,
101+
on_enter=on_text_enter,
102+
)
103+
104+
105+
106+
# Setting up the image path
107+
cwd = os.getcwd()
108+
ferris_root_path = cwd + "/resources/ferris"
109+
tiger_root_path = cwd + "/resources/tiger"
110+
ferris = []
111+
tiger = []
112+
ferris_type = []
113+
tiger_type = []
114+
data = []
115+
116+
for i in range(0, 5):
117+
ferris.append(f"{ferris_root_path}_{i}.png")
118+
tiger.append(f"{tiger_root_path}_{i}.svg")
119+
ferris_type.append(TableWidget.Image)
120+
tiger_type.append(TableWidget.Image)
121+
122+
data_img = [
123+
{"Ferris": ferris},
124+
{"Tiger": tiger}
125+
]
46126

127+
# The table is added for svg and png images.
128+
ipg.add_table("col", "My Images", data_img,
129+
width=500.0, height=300.0,
130+
# row_highlight=TableRowHighLight.Lighter,
131+
table_length=len(ferris),
132+
widgets_using_columns= {0: ferris_type, 1: tiger_type},
133+
image_width=[100.0, 75.0], image_height=[100.0, 75.0],
134+
on_enter=image_on_something,
135+
on_move=image_move,
136+
)
47137

48138
# Required to be the last widget sent to Iced, If you start the program
49139
# and nothing happens, it might mean you forgot to add this command.

resources/ferris_0.png

32.3 KB
Loading

resources/ferris_1.png

32.3 KB
Loading

resources/ferris_2.png

32.3 KB
Loading

resources/ferris_3.png

32.3 KB
Loading

resources/ferris_4.png

32.3 KB
Loading

0 commit comments

Comments
 (0)