Skip to content

Commit

Permalink
update example apps
Browse files Browse the repository at this point in the history
  • Loading branch information
samschott committed Jun 7, 2022
1 parent 708ae75 commit 6690292
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
11 changes: 5 additions & 6 deletions examples/table/table/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ def startup(self):
table_data = bee_movies * 1000

self.table1 = toga.Table(
headings=headings,
columns=headings,
data=table_data,
accessors=["title", "year", "rating", "genre"],
style=Pack(
flex=1,
padding_right=5,
Expand All @@ -121,7 +122,7 @@ def startup(self):
)

self.table2 = toga.Table(
headings=headings,
columns=headings,
data=self.table1.data,
multiple_select=True,
style=Pack(flex=1, padding_left=5),
Expand Down Expand Up @@ -171,14 +172,12 @@ def startup(self):
def reduce_fontsize(self, widget):
font_size = int(self.lbl_fontsize.text) - 1
self.lbl_fontsize.text = str(font_size)
font = toga.Font("monospace", font_size, "italic")
self.table1._impl.set_font(font)
self.table1.style.font_size = font_size

def increase_fontsize(self, widget):
font_size = int(self.lbl_fontsize.text) + 1
self.lbl_fontsize.text = str(font_size)
font = toga.Font("monospace", font_size, "italic")
self.table1._impl.set_font(font)
self.table1.style.font_size = font_size


def main():
Expand Down
14 changes: 7 additions & 7 deletions examples/table_source/table_source/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ def __getitem__(self, index):
def index(self, entry):
return self._filtered().index(entry)

# A listener that passes on all notifications, but only if the apply
# A listener that passes on all notifications, but only if they apply
# to the filtered data source
def insert(self, index, item):
# If the item exists in the filtered list, propegate the notification
# If the item exists in the filtered list, propagate the notification
for i, filtered_item in enumerate(self._filtered()):
if filtered_item == item:
# Propegate the insertion, with the position in the
# Propagate the insertion, with the position in the
# *filtered* list.
self._notify('insert', index=i, item=item)

def pre_remove(self, index, item):
# If the item exists in the filtered list, track that it is being
# removed; but don't propegate the removal notification until it has
# removed; but don't propagate the removal notification until it has
# been removed from the base data source
for i, filtered_item in enumerate(self._filtered()):
if filtered_item == item:
Expand All @@ -108,7 +108,7 @@ def pre_remove(self, index, item):

def remove(self, index, item):
# If the removed item previously existed in the filtered data source,
# propegate the removal notification.
# propagate the removal notification.
try:
i = self._removals.pop(item)
self._notify('remove', index=i, item=item)
Expand Down Expand Up @@ -150,14 +150,14 @@ def startup(self):
# of the second reads from the first.
# The headings are also in a different order.
self.table1 = toga.Table(
headings=['Year', 'Title', 'Rating', 'Genre'],
columns=['Year', 'Title', 'Rating', 'Genre'],
data=MovieSource(),
style=Pack(flex=1),
on_select=self.on_select_handler
)

self.table2 = toga.Table(
headings=['Rating', 'Title', 'Year', 'Genre'],
columns=['Rating', 'Title', 'Year', 'Genre'],
data=GoodMovieSource(self.table1.data),
style=Pack(flex=1)
)
Expand Down
2 changes: 1 addition & 1 deletion examples/tree/tree/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def startup(self):
self.label = toga.Label('Ready.', style=Pack(padding=10))

self.tree = toga.Tree(
headings=['Year', 'Title', 'Rating', 'Genre'],
columns=['Year', 'Title', 'Rating', 'Genre'],
on_select=self.on_select_handler,
style=Pack(flex=1)
)
Expand Down
21 changes: 19 additions & 2 deletions examples/tree_source/tree_source/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,16 @@ def can_have_children(self):
# this will trigger loading of children, if not yet done
return len(self.children) > 0

# Property that returns the first column value as (icon, label)
# Property that returns the item name
@property
def name(self):
return self.path.name

# Property that returns the item name
@property
def icon(self):
return self._icon

# Property that returns modified date as str
@property
def date_modified(self):
Expand Down Expand Up @@ -147,8 +152,20 @@ def startup(self):

self.fs_source = FileSystemSource(Path.cwd())

columns = [
toga.Tree.Column(
title="Name",
text_accessor="name",
icon_accessor="icon",
),
toga.Tree.Column(
title="Date Modified",
text_accessor="date_modified",
),
]

self.tree = toga.Tree(
headings=['Name', 'Date Modified'],
columns,
data=self.fs_source,
style=Pack(flex=1),
multiple_select=True,
Expand Down

0 comments on commit 6690292

Please sign in to comment.