From: <dg...@us...> - 2010-11-06 09:49:52
|
Revision: 678 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=678&view=rev Author: dgranda Date: 2010-11-06 09:49:44 +0000 (Sat, 06 Nov 2010) Log Message: ----------- Basic equipment management - thx to ncjones Modified Paths: -------------- pytrainer/trunk/glade/newrecord.glade pytrainer/trunk/glade/profile.glade pytrainer/trunk/glade/pytrainer.glade pytrainer/trunk/pytrainer/gui/windowmain.py pytrainer/trunk/pytrainer/gui/windowprofile.py pytrainer/trunk/pytrainer/gui/windowrecord.py pytrainer/trunk/pytrainer/lib/ddbb.py pytrainer/trunk/pytrainer/main.py pytrainer/trunk/pytrainer/record.py Added Paths: ----------- pytrainer/trunk/glade/equipment.glade pytrainer/trunk/pytrainer/equipment.py pytrainer/trunk/pytrainer/gui/equipment.py pytrainer/trunk/test/ pytrainer/trunk/test/pytrainer/ pytrainer/trunk/test/pytrainer/equipment_test.py pytrainer/trunk/test/pytrainer/gui/ pytrainer/trunk/test/pytrainer/gui/equipment_test.py Added: pytrainer/trunk/glade/equipment.glade =================================================================== --- pytrainer/trunk/glade/equipment.glade (rev 0) +++ pytrainer/trunk/glade/equipment.glade 2010-11-06 09:49:44 UTC (rev 678) @@ -0,0 +1,642 @@ +<?xml version="1.0"?> +<interface> + <!-- interface-requires gtk 2.6 --> + <!-- interface-naming-policy project-wide --> + <object class="GtkNotebook" id="notebookEquipment"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="show_tabs">False</property> + <property name="show_border">False</property> + <child> + <object class="GtkFrame" id="frameEquipmentList"> + <property name="visible">True</property> + <property name="border_width">5</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <child> + <object class="GtkAlignment" id="alignmentEquipmentList"> + <property name="visible">True</property> + <property name="left_padding">12</property> + <child> + <object class="GtkVBox" id="vboxEquipmentList"> + <property name="visible">True</property> + <property name="border_width">5</property> + <child> + <object class="GtkScrolledWindow" id="scrolledwindowEquipmentList"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="shadow_type">in</property> + <child> + <object class="GtkTreeView" id="treeviewEquipmentList"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </object> + </child> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hboxEquipmentListButtons"> + <property name="visible">True</property> + <child> + <object class="GtkButton" id="buttonEquipmentDelete"> + <property name="label">gtk-delete</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="delete_equipment_clicked"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">end</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkButton" id="buttonEquipmentEdit"> + <property name="label">gtk-edit</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="edit_equipment_clicked"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">end</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButton" id="buttonEquipmentAdd"> + <property name="label">gtk-add</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="add_equipment_clicked"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> + </child> + <child type="label"> + <object class="GtkLabel" id="labelEquipmentList"> + <property name="visible">True</property> + <property name="label" translatable="yes"><b>Equipment List</b></property> + <property name="use_markup">True</property> + </object> + </child> + </object> + <packing> + <property name="tab_expand">True</property> + </packing> + </child> + <child type="tab"> + <placeholder/> + </child> + <child> + <object class="GtkFrame" id="frameEquipmentAdd"> + <property name="visible">True</property> + <property name="border_width">5</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <child> + <object class="GtkAlignment" id="alignmentEquipmentAdd"> + <property name="visible">True</property> + <property name="left_padding">12</property> + <child> + <object class="GtkVBox" id="vboxEquipmentAdd"> + <property name="visible">True</property> + <property name="border_width">5</property> + <child> + <object class="GtkHBox" id="hboxEquipmentAddDetails"> + <property name="visible">True</property> + <child> + <object class="GtkTable" id="tableEquipmentAddDetails"> + <property name="visible">True</property> + <property name="n_rows">4</property> + <property name="n_columns">2</property> + <property name="row_spacing">5</property> + <child> + <object class="GtkLabel" id="labelEquipmentAddDescription"> + <property name="visible">True</property> + <property name="xalign">1</property> + <property name="xpad">5</property> + <property name="label" translatable="yes">Description</property> + </object> + <packing> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkEntry" id="entryEquipmentAddDescription"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="invisible_char">●</property> + <property name="width_chars">35</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="x_options"></property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkLabel" id="labelEquipmentAddLifeExpectancy"> + <property name="visible">True</property> + <property name="xalign">1</property> + <property name="xpad">5</property> + <property name="label" translatable="yes">Life Expectancy</property> + </object> + <packing> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkAlignment" id="alignment3"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="xscale">0</property> + <child> + <object class="GtkEntry" id="entryEquipmentAddLifeExpectancy"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="invisible_char">●</property> + <property name="width_chars">8</property> + </object> + </child> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkCheckButton" id="checkbuttonEquipmentAddActive"> + <property name="label" translatable="yes">Active</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkAlignment" id="alignment6"> + <property name="visible">True</property> + <child> + <placeholder/> + </child> + </object> + <packing> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkLabel" id="labelEquipmentAddNotes"> + <property name="visible">True</property> + <property name="xalign">1</property> + <property name="yalign">0</property> + <property name="xpad">5</property> + <property name="ypad">5</property> + <property name="label" translatable="yes">Notes</property> + </object> + <packing> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkScrolledWindow" id="scrolledwindow1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hscrollbar_policy">automatic</property> + <property name="shadow_type">in</property> + <child> + <object class="GtkTextView" id="textviewEquipmentAddNotes"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </object> + </child> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hboxEquipmentAddButtons"> + <property name="visible">True</property> + <child> + <object class="GtkButton" id="buttonEquipmentAddCancel"> + <property name="label">gtk-cancel</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="cancel_add_equipment_clicked"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">end</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButton" id="buttonEquipmentAddConfirm"> + <property name="label">gtk-add</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="confirm_add_equipment_clicked"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> + </child> + <child type="label"> + <object class="GtkLabel" id="labelEquipmentAdd"> + <property name="visible">True</property> + <property name="label" translatable="yes"><b>Add New Equipment</b></property> + <property name="use_markup">True</property> + </object> + </child> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + <child type="tab"> + <placeholder/> + </child> + <child> + <object class="GtkFrame" id="frameEquipmentEdit"> + <property name="visible">True</property> + <property name="border_width">5</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <child> + <object class="GtkAlignment" id="alignmentEquipmentEdit"> + <property name="visible">True</property> + <property name="left_padding">12</property> + <child> + <object class="GtkVBox" id="vboxEquipmentEdit"> + <property name="visible">True</property> + <property name="border_width">5</property> + <child> + <object class="GtkHBox" id="hboxEquipmentEditDetails"> + <property name="visible">True</property> + <child> + <object class="GtkTable" id="tableEquipmentEditDetails"> + <property name="visible">True</property> + <property name="n_rows">4</property> + <property name="n_columns">2</property> + <property name="row_spacing">5</property> + <child> + <object class="GtkLabel" id="labelEquipmentEditDescription"> + <property name="visible">True</property> + <property name="xalign">1</property> + <property name="xpad">5</property> + <property name="label" translatable="yes">Description</property> + </object> + <packing> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkEntry" id="entryEquipmentEditDescription"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="invisible_char">●</property> + <property name="width_chars">35</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="x_options"></property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkLabel" id="labelEquipmentEditLifeExpectancy"> + <property name="visible">True</property> + <property name="xalign">1</property> + <property name="xpad">5</property> + <property name="label" translatable="yes">Life Expectancy</property> + </object> + <packing> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkAlignment" id="alignment1"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="xscale">0</property> + <child> + <object class="GtkEntry" id="entryEquipmentEditLifeExpectancy"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="invisible_char">●</property> + <property name="width_chars">8</property> + </object> + </child> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkCheckButton" id="checkbuttonEquipmentEditActive"> + <property name="label" translatable="yes">Active</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkAlignment" id="alignment8"> + <property name="visible">True</property> + <child> + <placeholder/> + </child> + </object> + <packing> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkLabel" id="labelEquipmentEditNotes"> + <property name="visible">True</property> + <property name="xalign">1</property> + <property name="yalign">0</property> + <property name="xpad">5</property> + <property name="ypad">5</property> + <property name="label" translatable="yes">Notes</property> + </object> + <packing> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkScrolledWindow" id="scrolledwindow2"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hscrollbar_policy">automatic</property> + <property name="shadow_type">in</property> + <child> + <object class="GtkTextView" id="textviewEquipmentEditNotes"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </object> + </child> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hboxEquipmentEditButtons"> + <property name="visible">True</property> + <child> + <object class="GtkButton" id="buttonEquipmentEditCancel"> + <property name="label">gtk-cancel</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="cancel_edit_equipment_clicked"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">end</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButton" id="buttonEquipmentEditConfirm"> + <property name="label">gtk-save</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="confirm_edit_equipment_clicked"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> + </child> + <child type="label"> + <object class="GtkLabel" id="labelEquipmentEdit"> + <property name="visible">True</property> + <property name="label" translatable="yes"><b>Edit Equipment</b></property> + <property name="use_markup">True</property> + </object> + </child> + </object> + <packing> + <property name="position">2</property> + </packing> + </child> + <child type="tab"> + <placeholder/> + </child> + <child> + <object class="GtkFrame" id="frameEquipmentDelete"> + <property name="visible">True</property> + <property name="border_width">5</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <child> + <object class="GtkAlignment" id="alignmentEquipmentDelete"> + <property name="visible">True</property> + <property name="left_padding">12</property> + <child> + <object class="GtkVBox" id="vboxEquipmentDelete"> + <property name="visible">True</property> + <property name="border_width">5</property> + <child> + <object class="GtkLabel" id="labelEquipmentDeleteConfirm"> + <property name="visible">True</property> + <property name="label" translatable="yes">Really delete the equipment item?</property> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkHButtonBox" id="hbuttonboxEquipmentDeleteButtons"> + <property name="visible">True</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="buttonEquipmentDeleteCancel"> + <property name="label">gtk-cancel</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="cancel_delete_equipment_clicked"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="buttonEquipmentDeleteConfirm"> + <property name="label">gtk-ok</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="confirm_delete_equipment_clicked"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> + </child> + <child type="label"> + <object class="GtkLabel" id="labelEquipmentDelete"> + <property name="visible">True</property> + <property name="label" translatable="yes"><b>Delete Equipment</b></property> + <property name="use_markup">True</property> + </object> + </child> + </object> + <packing> + <property name="position">3</property> + </packing> + </child> + <child type="tab"> + <placeholder/> + </child> + </object> +</interface> Modified: pytrainer/trunk/glade/newrecord.glade =================================================================== --- pytrainer/trunk/glade/newrecord.glade 2010-11-04 01:46:37 UTC (rev 677) +++ pytrainer/trunk/glade/newrecord.glade 2010-11-06 09:49:44 UTC (rev 678) @@ -1100,6 +1100,68 @@ <property name="type">tab</property> </packing> </child> + <child> + <widget class="GtkFrame" id="frameRecordEquipment"> + <property name="visible">True</property> + <property name="border_width">5</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <child> + <widget class="GtkAlignment" id="alignmentRecordEquipment"> + <property name="visible">True</property> + <property name="left_padding">12</property> + <child> + <widget class="GtkTable" id="table1"> + <property name="visible">True</property> + <property name="border_width">5</property> + <child> + <widget class="GtkScrolledWindow" id="scrolledwindow1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="border_width">5</property> + <property name="hscrollbar_policy">automatic</property> + <property name="vscrollbar_policy">automatic</property> + <property name="shadow_type">in</property> + <child> + <widget class="GtkTreeView" id="treeviewRecordEquipment"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="headers_visible">False</property> + <property name="headers_clickable">False</property> + </widget> + </child> + </widget> + </child> + </widget> + </child> + </widget> + </child> + <child> + <widget class="GtkLabel" id="label3"> + <property name="visible">True</property> + <property name="label" translatable="yes"><b>Associated Equipment</b></property> + <property name="use_markup">True</property> + </widget> + <packing> + <property name="type">label_item</property> + </packing> + </child> + </widget> + <packing> + <property name="position">3</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="record_equipment_label"> + <property name="visible">True</property> + <property name="label" translatable="yes">Equipment</property> + </widget> + <packing> + <property name="position">3</property> + <property name="tab_fill">False</property> + <property name="type">tab</property> + </packing> + </child> </widget> <packing> <property name="expand">False</property> Modified: pytrainer/trunk/glade/profile.glade =================================================================== --- pytrainer/trunk/glade/profile.glade 2010-11-04 01:46:37 UTC (rev 677) +++ pytrainer/trunk/glade/profile.glade 2010-11-06 09:49:44 UTC (rev 678) @@ -1420,6 +1420,28 @@ </packing> </child> <child> + <widget class="GtkAlignment" id="equipment_container"> + <property name="visible">True</property> + <child> + <placeholder/> + </child> + </widget> + <packing> + <property name="position">5</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="labelEquipment"> + <property name="visible">True</property> + <property name="label" translatable="yes">Equipment</property> + </widget> + <packing> + <property name="position">5</property> + <property name="tab_fill">False</property> + <property name="type">tab</property> + </packing> + </child> + <child> <widget class="GtkVBox" id="vbox25"> <property name="visible">True</property> <child> Modified: pytrainer/trunk/glade/pytrainer.glade =================================================================== --- pytrainer/trunk/glade/pytrainer.glade 2010-11-04 01:46:37 UTC (rev 677) +++ pytrainer/trunk/glade/pytrainer.glade 2010-11-06 09:49:44 UTC (rev 678) @@ -57,7 +57,7 @@ </child> <child> <widget class="GtkImageMenuItem" id="export_csv"> - <property name="label">_Export as Text Separated by Commas</property> + <property name="label" translatable="yes">_Export as Text Separated by Commas</property> <property name="visible">True</property> <property name="use_underline">True</property> <property name="use_stock">False</property> @@ -342,7 +342,7 @@ <child> <widget class="GtkTable" id="table13"> <property name="visible">True</property> - <property name="n_rows">10</property> + <property name="n_rows">11</property> <property name="n_columns">6</property> <property name="column_spacing">3</property> <property name="row_spacing">6</property> @@ -480,8 +480,8 @@ <property name="use_markup">True</property> </widget> <packing> - <property name="top_attach">6</property> - <property name="bottom_attach">7</property> + <property name="top_attach">7</property> + <property name="bottom_attach">8</property> <property name="x_options">GTK_FILL</property> <property name="y_options"></property> </packing> @@ -796,8 +796,8 @@ </widget> <packing> <property name="right_attach">6</property> - <property name="top_attach">7</property> - <property name="bottom_attach">8</property> + <property name="top_attach">8</property> + <property name="bottom_attach">9</property> </packing> </child> <child> @@ -831,6 +831,35 @@ </packing> </child> <child> + <widget class="GtkLabel" id="label26"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="yalign">0</property> + <property name="label" translatable="yes"><b>Equipment:</b></property> + <property name="use_markup">True</property> + </widget> + <packing> + <property name="top_attach">6</property> + <property name="bottom_attach">7</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label_record_equipment"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="yalign">0</property> + <property name="label" translatable="yes"></property> + <property name="use_markup">True</property> + <property name="wrap">True</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">6</property> + <property name="top_attach">6</property> + <property name="bottom_attach">7</property> + </packing> + </child> + <child> <placeholder/> </child> <child> @@ -5973,7 +6002,7 @@ <widget class="GtkMenu" id="popup"> <child> <widget class="GtkImageMenuItem" id="edit_record1"> - <property name="label">Edit Record</property> + <property name="label" translatable="yes">Edit Record</property> <property name="visible">True</property> <property name="use_stock">False</property> <signal name="activate" handler="on_editrecord_activate"/> Added: pytrainer/trunk/pytrainer/equipment.py =================================================================== --- pytrainer/trunk/pytrainer/equipment.py (rev 0) +++ pytrainer/trunk/pytrainer/equipment.py 2010-11-06 09:49:44 UTC (rev 678) @@ -0,0 +1,203 @@ +# -*- coding: iso-8859-1 -*- + +#Copyright (C) Nathan Jones nc...@us... + +#This program is free software; you can redistribute it and/or +#modify it under the terms of the GNU General Public License +#as published by the Free Software Foundation; either version 2 +#of the License, or (at your option) any later version. + +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with this program; if not, write to the Free Software +#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +import logging + +class Equipment(object): + + """An equipment item that can be used during an activity, such as a pair of running shoes.""" + + def __init__(self): + self._id = None + self.description = u"" + self.active = True + self.life_expectancy = 0 + self.notes = u"" + + def _get_id(self): + return self._id + + def _set_id(self, id): + self._id = int(id) + + id = property(_get_id, _set_id) + + def _get_description(self): + return self._description + + def _set_description(self, description): + if not isinstance(description, unicode): + raise TypeError("Description must be unicode string, not {0}.".format(type(description).__name__)) + self._description = description + + description = property(_get_description, _set_description) + + def _get_active(self): + return self._active + + def _set_active(self, active): + if not isinstance(active, bool): + raise TypeError("Active must be boolean, not {0}.".format(type(active).__name__)) + self._active = active + + active = property(_get_active, _set_active) + + def _get_life_expectancy(self): + return self._life_expectancy + + def _set_life_expectancy(self, life_expectancy): + self._life_expectancy = int(life_expectancy) + + life_expectancy = property(_get_life_expectancy, _set_life_expectancy) + + def _get_notes(self): + return self._notes + + def _set_notes(self, notes): + if not isinstance(notes, unicode): + raise TypeError("Notes must be unicode string, not {0}.".format(type(notes).__name__)) + self._notes = notes + + notes = property(_get_notes, _set_notes) + + def __eq__(self, o): + if isinstance(o, Equipment): + if self.id is not None and o.id is not None: + return self.id == o.id + return False + + def __hash__(self): + if self.id is not None: + return self.id + else: + return object.__hash__(self) + +_TABLE_NAME = "equipment" + +_UPDATE_COLUMNS = "description,active,life_expectancy,notes" + +_ALL_COLUMNS = "id," + _UPDATE_COLUMNS + +def _create_row(equipment): + return [equipment.description, + 1 if equipment.active else 0, + equipment.life_expectancy, + equipment.notes] + +class EquipmentServiceException(Exception): + + def __init__(self, value): + self.value = value + + def __str__(self): + return repr(self.value) + +class EquipmentService(object): + + """Provides access to stored equipment items.""" + + def __init__(self, ddbb): + self._ddbb = ddbb + + def get_all_equipment(self): + """Get all equipment items.""" + return self._get_equipment(None) + + def get_active_equipment(self): + """Get all the active equipment items.""" + return self._get_equipment("active = 1") + + def _get_equipment(self, condition): + logging.debug("Retrieving all equipment (condition: '{0}').".format(condition)) + resultSet = self._ddbb.select(_TABLE_NAME, _ALL_COLUMNS, condition) + equipmentList = [] + for result in resultSet: + equipmentList.append(self._create_equipment_item(result)) + return equipmentList + + def get_equipment_item(self, item_id): + """Get an individual equipment item by id. + + If no item with the given id exists then None is returned. + """ + resultSet = self._ddbb.select(_TABLE_NAME, _ALL_COLUMNS, "id = {0}".format(item_id)) + if len(resultSet) == 0: + return None + else: + return self._create_equipment_item(resultSet[0]) + + def _create_equipment_item(self, row): + equipment = Equipment() + (id, description, active, life_expectancy, notes) = row + equipment.id = id + equipment.description = description + equipment.active = bool(active) + equipment.life_expectancy = life_expectancy + equipment.notes = notes + return equipment + + def store_equipment(self, equipment): + """Store a new or update an existing equipment item. + + The stored object is returned.""" + logging.debug("Storing equipment item.") + item_id = None + if equipment.id != None: + item_id = self._update_equipment(equipment) + else: + item_id = self._store_new_equipment(equipment) + return self.get_equipment_item(item_id) + + def _update_equipment(self, equipment): + logging.debug("Updating existing equipment item.") + self._assert_exists(equipment) + self._ddbb.update(_TABLE_NAME, _UPDATE_COLUMNS, _create_row(equipment), "id = {0}".format(equipment.id)) + return equipment.id + + def _assert_exists(self, equipment): + if self.get_equipment_item(equipment.id) == None: + raise EquipmentServiceException("No equipment item exists with id '{0}'".format(equipment.id)) + logging.debug("Asserted item exists with id: '{0}'.".format(equipment.id)) + + def _store_new_equipment(self, equipment): + logging.debug("Storing new equipment item.") + self._assert_unique(equipment) + self._ddbb.insert(_TABLE_NAME, _UPDATE_COLUMNS, _create_row(equipment)) + return self._ddbb.select(_TABLE_NAME, "id", "description = \"{0}\"".format(equipment.description))[0][0] + + def _assert_unique(self, equipment): + result = self._ddbb.select(_TABLE_NAME, "id", "description = \"{0}\"".format(equipment.description)) + if len(result) > 0: + raise EquipmentServiceException("An equipment item already exists with description '{0}'".format(equipment.description)) + logging.debug("Asserted description is unique: '{0}'.".format(equipment.description)) + + def remove_equipment(self, equipment): + """Remove an existing equipment item.""" + logging.debug("Deleting equipment item with id: '{0}'".format(equipment.id)) + self._ddbb.delete("record_equipment", "equipment_id=\"{0}\"".format(equipment.id)) + self._ddbb.delete(_TABLE_NAME, "id=\"{0}\"".format(equipment.id)) + + def get_equipment_usage(self, equipment): + """Get the total use of the given equipment.""" + result = self._ddbb.select("records inner join record_equipment " + "on records.id_record = record_equipment.record_id", + "sum(distance)", + "record_equipment.equipment_id = {0}".format(equipment.id)) + usage = result[0][0] + return 0 if usage == None else usage + Added: pytrainer/trunk/pytrainer/gui/equipment.py =================================================================== --- pytrainer/trunk/pytrainer/gui/equipment.py (rev 0) +++ pytrainer/trunk/pytrainer/gui/equipment.py 2010-11-06 09:49:44 UTC (rev 678) @@ -0,0 +1,186 @@ +# -*- coding: iso-8859-1 -*- + +#Copyright (C) Nathan Jones nc...@us... + +#This program is free software; you can redistribute it and/or +#modify it under the terms of the GNU General Public License +#as published by the Free Software Foundation; either version 2 +#of the License, or (at your option) any later version. + +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with this program; if not, write to the Free Software +#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +import gtk +from pytrainer.equipment import Equipment + +class EquipmentStore(gtk.ListStore): + + def __init__(self, equipment_service): + super(EquipmentStore, self).__init__(int, str, float, str, bool) + self._equipment_service = equipment_service + for equipment in equipment_service.get_all_equipment(): + self._append_row(equipment) + + def _append_row(self, equipment): + self.append(self._create_tuple(equipment)) + + def _create_tuple(self, equipment): + usage = self._equipment_service.get_equipment_usage(equipment) + return (equipment.id, + equipment.description, + self._calculate_usage_percent(usage, equipment.life_expectancy), + str(int(round(usage))) + " / " + str(equipment.life_expectancy), + equipment.active) + + def _calculate_usage_percent(self, usage, life_expectancy): + if life_expectancy == 0: + return 0 + else: + return 100.0 * usage / life_expectancy + + def add_equipment(self, equipment): + added_equipment = self._equipment_service.store_equipment(equipment) + self._append_row(added_equipment) + + def get_equipment_item(self, item_path): + item_id = self.get_value(self.get_iter(item_path), 0) + return self._equipment_service.get_equipment_item(item_id) + + def edit_equipment(self, item_path, equipment): + updated_item = self._equipment_service.store_equipment(equipment) + for (column_index, value) in enumerate(self._create_tuple(updated_item)): + self.set(self.get_iter(item_path), column_index, value) + + def remove_equipment(self, item_path): + item = self.get_equipment_item(item_path) + self._equipment_service.remove_equipment(item) + self.remove(self.get_iter(item_path)) + +class EquipmentUi(gtk.HBox): + + def __init__(self, glade_conf_dir, equipment_service): + gtk.HBox.__init__(self) + self._equipment_store = EquipmentStore(equipment_service) + self._builder = gtk.Builder() + self._builder.add_from_file(glade_conf_dir + "/equipment.glade") + self._init_tree_view() + self._init_signals() + self.add(self._get_notebook()) + self.set_property('visible', True) + + def _get_notebook(self): + return self._builder.get_object("notebookEquipment") + + def _get_tree_view(self): + return self._builder.get_object("treeviewEquipmentList") + + def _init_tree_view(self): + tree_view = self._get_tree_view() + column = gtk.TreeViewColumn("Description", gtk.CellRendererText(), text=1) + column.set_resizable(True) + tree_view.append_column(column) + tree_view.append_column(gtk.TreeViewColumn("Usage", gtk.CellRendererProgress(), value=2, text=3)) + tree_view.append_column(gtk.TreeViewColumn("Active", gtk.CellRendererToggle(), active=4)) + # add filler column + tree_view.append_column(gtk.TreeViewColumn()) + tree_view.set_model(self._equipment_store) + + def _init_signals(self): + self._builder.connect_signals({ + "add_equipment_clicked": self._add_equipment_clicked, + "cancel_add_equipment_clicked": self._cancel_add_equipment_clicked, + "confirm_add_equipment_clicked": self._confirm_add_equipment_clicked, + "edit_equipment_clicked": self._edit_equipment_clicked, + "cancel_edit_equipment_clicked": self._cancel_edit_equipment_clicked, + "confirm_edit_equipment_clicked": self._confirm_edit_equipment_clicked, + "delete_equipment_clicked": self._delete_equipment_clicked, + "cancel_delete_equipment_clicked": self._cancel_delete_equipment_clicked, + "confirm_delete_equipment_clicked": self._confirm_delete_equipment_clicked}) + + def _get_selected_equipment_path(self): + (path, _) = self._get_tree_view().get_cursor() + return path + + def _get_selected_equipment_item(self): + return self._equipment_store.get_equipment_item(self._get_selected_equipment_path()) + + def clear_add_equipment_fields(self): + self._builder.get_object("entryEquipmentAddDescription").set_text("") + self._builder.get_object("entryEquipmentAddLifeExpectancy").set_text("0") + self._builder.get_object("checkbuttonEquipmentAddActive").set_active(True) + self._builder.get_object("textviewEquipmentAddNotes").get_buffer().set_text("") + + def show_page_equipment_list(self): + self._get_notebook().set_current_page(0) + + def show_page_equipment_add(self): + self._get_notebook().set_current_page(1) + self._builder.get_object("entryEquipmentAddDescription").grab_focus() + + def show_page_equipment_edit(self): + self._get_notebook().set_current_page(2) + + def show_page_equipment_delete(self): + self._get_notebook().set_current_page(3) + ... [truncated message content] |