-
Notifications
You must be signed in to change notification settings - Fork 0
Tabwidget
The branch includes changes to the tabwidget code made by squiddy, and changes to the xml interface by me. It is tracked in [#2012] (https://github.com/unknown-horizons/unknown-horizons/pull/2012).
- Unified tab preparation interface (
init_widget
) -
widget
,helptext
andicon_path
defined in tab class (not__init__
)
class AccountTab(MainSquareTab):
# old:
def __init__(self, instance):
self.helptext = _("Account")
super(AccountTab, self).__init__(instance=instance, widget='tab_account.xml',
icon_path='icons/tabwidget/warehouse/account')
# new:
widget = 'tab_account.xml'
icon_path = 'icons/tabwidget/warehouse/account'
helptext = _lazy("Account")
Tabs no longer define a <Container>
with own size, background images, headline positioning code, etc.
Instead, they use <TabContainer>
which shares those features and tries to reduce layout/markup code.
Example commit illustrating this: [9ccd4f7
] (https://github.com/unknown-horizons/unknown-horizons/commit/9ccd4f7).
The idea is that xml files for tabs now only define a box of tab content, and the actual tab around it is handled by a template (also in xml).
Headlines are defined using the headline=
attribute of <TabContainer>
, for more on this see [below] (#headline-magic).
The background images are calculated from tab content.
Of course some layout flaws will happen, I can only test so much of it.
In general however if you need empty space in the tab (avoids ugly resizing when opened later), define a Container or Box with min_size=
attributes from xml.
Those will still be used in the calculations just as before, so hopefully not too much changed.
Code for determining background image size/amount:
self.tab_bg.amount = (self.content.parent.size[1] + 25) // 50
Some minor changes:
- warehouses and storages lost their almost-empty overview tab, functionality was added to Account tab
- new properties settlement.name and tier.inhabitant_name for use with headline magic
Some examples of what is possible:
<TabContainer headline="Hello"> <!-- Plain text is still possible -->
<TabContainer headline="{instance.name}"> <!-- This is the default (so no need to write it out) -->
<TabContainer headline="{instance.owner.name}">
<TabContainer headline="{helptext}"> <!-- Use helptext of this tab's button -->
<TabContainer headline="{tab_headline}"> <!-- Define custom property in the tab (see below)! -->
The code behind the templating is rather simple:
attrgetter(template[1:-1])(self.current_tab)
There is no error checking, so double-check those templates!
To define custom variables used as headlines, use code similar to this:
@property
def tab_headline(self):
return _('Build {building}').format(building=building)
# Use: <TabContainer headline="{tab_headline}">
Home > Developers >
Who is who?
Tests
FIFE: epydoc, doxygen
What to do: Segfaults
Usability
Translations