Re: beginner glade application
| From: | Steph Fox | Date: | Fri, 01 Sep 2006 14:01:46 +0000 |
| Subject: | Re: beginner glade application | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-7196@lists.php.net to get a copy of this message | ||
This is a pure PHP question. Go to the manual at www.php.net, look for simplexml.
----- Original Message ----- From: "suomaf" <suomaf@gmail.com>
To: <php-gtk-general@lists.php.net>
Sent: Friday, September 01, 2006 4:02 PM
Subject: [PHP-GTK] beginner glade application
Thanks to all the help i have been getting I was able to do a simple to do
list application. How would i read in a xml file to populate the tree view
in this case, and when I click add, how can i write to the xml file..
I am thinking it might be somthing like this
<done>false</done>
<toDo>This is something that needs to be done </toDo>
<priority>Normal</priority>
<date>8-22-2006</date>
... and repeat
Thanks
Suomaf
==== my php file
<?php
class loginClass extends GtkWindow
{
function __construct()
{
parent::__construct();
$this->glade = new GladeXML(dirname(__FILE__) . '/todo.glade');
$this->glade->signal_autoconnect_instance($this);
$this->glade->get_widget("priorityComboBox")->set_active(1);
//-----------------TEST CODE--------------------------
//the model
$store = new GtkListStore(Gtk::TYPE_BOOLEAN, Gtk::TYPE_STRING,
Gtk::TYPE_STRING, Gtk::TYPE_STRING);
$treeview=$this->glade->get_widget("treeview1");
$treeview->set_model($store);
//add some data to the data store
//$store->append(array(false , 'program the stupid
gms3','Normal','22-06-2006'));
//sort by year by default
$store->set_sort_column_id(2, Gtk::SORT_ASCENDING);
//the text renderer is used to display text
$cell_renderer = new GtkCellRendererText();
//Create the first column, make it resizable and sortable
$colTask= new GtkTreeViewColumn('Task', $cell_renderer, 'text', 1);
//make the column resizable in width
$colTask->set_resizable(true);
//make it sortable and let it sort after model column 1
$colTask->set_sort_column_id(1);
//add the column to the view
$treeview->append_column($colTask);
//second column, also sortable
$colPriority = new GtkTreeViewColumn('Priority', $cell_renderer,
'text', 2);
$colPriority->set_sort_column_id(2);
$treeview->append_column($colPriority);
//third column
$colDate = new GtkTreeViewColumn('Date', $cell_renderer, 'text',3);
$colDate->set_sort_column_id(3);
$treeview->append_column($colDate);
//we want to display a boolean value, so we can use a check box fordisplay
$bool_cell_renderer = new GtkCellRendererToggle();
$colUsed = new GtkTreeViewColumn('Done', $bool_cell_renderer,
'active', 0);
$colUsed->set_sort_column_id(0);
$treeview->append_column($colUsed);
//-----------------END CODE---------------------------} function on_addButton_clicked() { $date = $this->glade->get_widget("calendar1")->get_date(); $dateString = $date[1] . "-" . $date[2] . "-" . $date[0]; $errors = null; $toDo = $this->glade->get_widget('toDoEntry')->get_text(); $priority = $this->glade->get_widget('priorityComboBox')->get_active_text(); if (strlen($toDo)) { $errors .= "No task entered.\r\n"; } if ($errors == null)
{
$dialog = new GtkMessageDialog($wnd, Gtk::DIALOG_MODAL,
GTK::MESSAGE_ERROR, GTK::BUTTONS_OK, $errors);
$dialog->set_markup("Please enter a task:\r\n" . "<span
foreground='red'>" .$errors . "</span>");
$dialog->run();
$dialog->destroy();
}
else
{
//---------------------some code here
---------------------------------
echo $dateString;//$store = new GtkListStore(Gtk::TYPE_BOOLEAN, Gtk::TYPE_STRING, Gtk::TYPE_STRING, Gtk::TYPE_STRING);
$treeview=$this->glade->get_widget("treeview1");
$store = $treeview->get_model();
$store->append(array(false , $toDo,$priority,$dateString));
//-------------------------end code-----------------------------------
}} function on_clearButton_clicked() { $this->glade->get_widget('toDoEntry')->set_text(''); } } $myClassInstance = new loginClass(); //Start the main loop Gtk::main() ?> ==== my todo.glade file <?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> <glade-interface> <widget class="GtkWindow" id="toDoForm"> <property name="visible">True</property> <property name="title" translatable="yes">gms::to do list</property> <property name="type">GTK_WINDOW_TOPLEVEL</property> <property name="window_position">GTK_WIN_POS_CENTER</property> <property name="modal">False</property> <property name="default_width">800</property> <property name="default_height">600</property> <property name="resizable">True</property> <property name="destroy_with_parent">False</property> <property name="decorated">True</property> <property name="skip_taskbar_hint">False</property> <property name="skip_pager_hint">False</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="focus_on_map">True</property> <property name="urgency_hint">False</property> <signal name="destroy" handler="Gtk::main_quit" last_modification_time="Fri, 01 Sep 2006 13:45:16 GMT"/> <child> <widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">5</property>
<child><widget class="GtkLabel" id="label1"> <property name="visible">True</property> <property name="label" translatable="yes">To Do</property> <property name="use_underline">False</property> <property name="use_markup">False</property> <property name="justify">GTK_JUSTIFY_LEFT</property> <property name="wrap">False</property> <property name="selectable">False</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> <property name="width_chars">-1</property> <property name="single_line_mode">False</property> <property name="angle">0</property> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">False</property> </packing>
</child>
<child><widget class="GtkHBox" id="hbox1"> <property name="visible">True</property> <property name="homogeneous">False</property> <property name="spacing">5</property> <child> <widget class="GtkCalendar" id="calendar1">
<property name="visible">True</property>
<property
name="display_options">GTK_CALENDAR_SHOW_HEADING|GTK_CALENDAR_SHOW_DAY_NAMES</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkTreeView" id="treeview1">
<property name="visible">True</property>
<property name="headers_visible">True</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
<property name="fixed_height_mode">False</property>
<property name="hover_selection">False</property>
<property name="hover_expand">False</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">5</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child><widget class="GtkHBox" id="hbox2"> <property name="visible">True</property> <property name="homogeneous">False</property> <property name="spacing">5</property> <child> <widget class="GtkEntry" id="toDoEntry">
<property name="visible">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">•</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="padding">5</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkComboBoxEntry" id="priorityComboBox">
<property name="visible">True</property>
<property name="items" translatable="yes">KIV
Normal
Urgent
Top Urgent
ASAP</property>
<property name="add_tearoffs">False</property>
<property name="has_frame">True</property>
<property name="focus_on_click">True</property>
<child internal-child="entry"><widget class="GtkEntry" id="comboboxentry-entry1"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property> <property name="editable">True</property> <property name="visibility">True</property> <property name="max_length">0</property> <property name="text" translatable="yes"></property> <property name="has_frame">True</property> <property name="invisible_char">•</property> <property name="activates_default">False</property> </widget>
</child></widget> <packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox1">
<property name="border_width">1</property>
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_START</property>
<property name="spacing">4</property>
<child><widget class="GtkButton" id="addButton"> <property name="visible">True</property> <property name="label" translatable="yes">_Add</property> <property name="use_underline">True</property> <property name="relief">GTK_RELIEF_NORMAL</property> <property name="focus_on_click">True</property> <signal name="clicked" handler="on_addButton_clicked" last_modification_time="Fri, 01 Sep 2006 13:43:56 GMT"/> </widget>
</child>
<child><widget class="GtkButton" id="clearButton"> <property name="visible">True</property> <property name="label" translatable="yes">_Clear</property> <property name="use_underline">True</property> <property name="relief">GTK_RELIEF_NORMAL</property> <property name="focus_on_click">True</property> <signal name="clicked" handler="on_clearButton_clicked" last_modification_time="Fri, 01 Sep 2006 13:44:03 GMT"/> </widget>
</child></widget> <packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">5</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child><widget class="GtkStatusbar" id="statusbar1"> <property name="visible">True</property> <property name="has_resize_grip">True</property> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">False</property> </packing>
</child></widget> </child> </widget> </glade-interface> -- View this message in context: http://www.nabble.com/beginner-glade-application-tf2202747.html#a6099180 Sent from the Php - GTK - General forum at Nabble.com. -- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __________ NOD32 1.1380 (20060125) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com