DWI File for the Bicycle Ride Calorie Calculator
Below follows the example DWI source code for the calculator.
It assumes that you are already familiar with the basic
DWI markup, which
can be found here.
<?xml version="1.0"?>
<!--
- FILE: biker.dui
-
- FUNCTION:
- Provide an example of using DWI to attach a glade dialog to GObjects.
- This demo assumes you already understand the basics of dwi/gobject
- interaction; if not, you may want to look at the "active-object.dui"
- example in the "basic-gobj" directory. It also assumes you understand
- the DWI XML in general: if not, you will want to look at the
- 'testbasic.dui' example.
-
- This code performs four basic functions:
- 1) Show the 'about' dialog when use picks the Help->About menu item.
- 2) Copy data from GUI widgets to the 'ibiker' GObject inputs.
- 3) Copy output data from the 'ibiker' GObject to the GUI.
- 4) Change the GUI labels from English to Metric Units when
- the user picks the English/Metric menu item.
-
- To actually run this demo, run the "biker" binary.
-->
<dwi name="biker">
<!-- about dialog pops up when user clicks on Help->about -->
<window provider="glade" name="about"
filename = "bike-calc.glade" root_widget="about dialog">
<report name="about window">
<entry widget="about dialog" value="some bogus value"/>
</report>
</window>
<!-- Main Window copies data to bike object when 'calculate' button
- is clicked. -->
<window provider="glade" name="main window" main="yes"
filename = "bike-calc.glade" root_widget="main biker window">
<!-- run about dialog if used picks menu about -->
<form report="about window">
<submit widget="about item" signal="activate"/>
</form>
<!-- initialize widget values, in particular, initialize
- the radio button mapping. -->
<form report="clear page">
<submit widget="main biker window" signal="show"/>
</form>
<report name = "clear page">
<entry widget="point choice" value="false" />
<entry widget="loop choice" value="true" />
<entry widget="aero choice" value="true" />
<entry widget="non-aero choice" value="false" />
</report>
<!-- Run the calculations when user clicks 'calculate' -->
<form report="show results">
<wtoobj widget="distance entry" object="ibiker" property="distance"/>
<wtoobj widget="drafting entry" object="ibiker" property="draft"/>
<wtoobj widget="climbing entry" object="ibiker" property="climb"/>
<wtoobj widget="elevation entry" object="ibiker" property="elevation"/>
<wtoobj widget="loop choice" object="ibiker" property="loop"/>
<wtoobj widget="aero choice" object="ibiker" property="aero"/>
<wtoobj widget="wind menu" object="ibiker" property="wind_direction"/>
<wtoobj widget="wind speed entry" object="ibiker" property="wind_speed"/>
<wtoobj widget="weight entry" object="ibiker" property="weight"/>
<!-- push the hour/minute/second widgets into the time converter -->
<wtoobj widget="hours entry" object="time-conv" property="hours"/>
<wtoobj widget="minutes entry" object="time-conv" property="minutes"/>
<wtoobj widget="seconds entry" object="time-conv" property="seconds"/>
<!-- get the total number of seconds out of converter,
- and into the bike computer -->
<pipe>
<src type="gobject" object="time-conv" property="total_seconds"/>
<tgt type="gobject" object="ibiker" property="time interval"/>
</pipe>
<submit widget="calculate button" signal="clicked"/>
</form>
<!-- This report will run when the above form has been 'submitted'.
- Computed values are displayed.
-->
<report name="show results">
<pipe>
<src type="gobject" object="ibiker" property="avg speed"/>
<tgt type="widget" widget="speed entry" />
</pipe>
<pipe>
<src type="gobject" object="ibiker" property="total calories"/>
<tgt type="widget" widget="calories entry" />
</pipe>
<pipe>
<src type="gobject" object="ibiker" property="ride calories"/>
<tgt type="widget" widget="riding entry" />
</pipe>
<!-- But we also want to echo back from the object, just in case
- the object somehow mangled the user's input (e.g. if the
- user had typed in asci where numbers were expected. -->
<pipe>
<src type="gobject" object="ibiker" property="distance"/>
<tgt type="widget" widget="distance entry" />
</pipe>
<pipe>
<src type="gobject" object="ibiker" property="draft"/>
<tgt type="widget" widget="drafting entry" />
</pipe>
<pipe>
<src type="gobject" object="ibiker" property="climb"/>
<tgt type="widget" widget="climbing entry" />
</pipe>
<pipe>
<src type="gobject" object="ibiker" property="elevation"/>
<tgt type="widget" widget="elevation entry" />
</pipe>
<pipe>
<src type="gobject" object="ibiker" property="wind_direction"/>
<tgt type="widget" widget="wind menu" />
</pipe>
<pipe>
<src type="gobject" object="ibiker" property="wind_speed"/>
<tgt type="widget" widget="wind speed entry" />
</pipe>
<pipe>
<src type="gobject" object="ibiker" property="weight"/>
<tgt type="widget" widget="weight entry" />
</pipe>
<!-- get the rebalanced time values as well. -->
<pipe>
<src type="gobject" object="time-conv" property="hours"/>
<tgt type="widget" widget="hours entry" />
</pipe>
<pipe>
<src type="gobject" object="time-conv" property="minutes"/>
<tgt type="widget" widget="minutes entry" />
</pipe>
<pipe>
<src type="gobject" object="time-conv" property="seconds"/>
<tgt type="widget" widget="seconds entry" />
</pipe>
</report>
<!-- Change units from english to metric, and back.
- This requires relabelling both the GUI, and telling
- the object -->
<form report="switch to metric">
<submit widget="metric menu" signal="activate"/>
</form>
<form report="switch to english">
<submit widget="english menu" signal="activate"/>
</form>
<!-- now redraw -->
<form report="show results">
<submit widget="metric menu" signal="activate"/>
<submit widget="english menu" signal="activate"/>
</form>
<!-- redraw the labels as well, to show english or metric -->
<report name="switch to metric">
<entry widget="dist label" value="km"/>
<entry widget="weight label" value="kg"/>
<entry widget="elevation label" value="m"/>
<entry widget="speed label" value="km/hr"/>
<entry widget="wind speed label" value="km/hr"/>
<pipe>
<src type="const" value="true"/>
<tgt type="gobject" object="ibiker" property="metric_units"/>
</pipe>
</report>
<report name="switch to english">
<entry widget="dist label" value="mi"/>
<entry widget="weight label" value="lbs"/>
<entry widget="elevation label" value="ft"/>
<entry widget="speed label" value="mi/hr"/>
<entry widget="wind speed label" value="mi/hr"/>
<pipe>
<src type="const" value="false"/>
<tgt type="gobject" object="ibiker" property="metric_units"/>
</pipe>
</report>
</window>
</dwi>
<!-- ===================== END OF FILE ========================== -->