Re: GtkEntry and "special keys"

From: Date: Sun, 08 Oct 2006 16:26:44 +0000
Subject: Re: GtkEntry and "special keys"
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-7345@lists.php.net to get a copy of this message
Sven Siwek wrote: > > I want to bind a special key(function key) to some GtkEntry?s. > > In fact I do have a date field and I want to popup a gtkwindow with the > gtkcalendar in it, when the users presses the F7 key while he is in that > date field. > > So what is the "best" way of doing that? > Try this... <?php $window = new GtkWindow(); $window->set_size_request(400, 150); $window->set_position(Gtk::WIN_POS_CENTER_ALWAYS); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox()); // display title $title = new GtkLabel("Press F7 to choose a date"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 40); $vbox->pack_start($title, 0, 0); $hbox = new GtkHBox(); $vbox->pack_start($hbox, 0, 0); $hbox->pack_start(new GtkLabel("Select Date: "), 0, 0); $hbox->pack_start($entry = new GtkEntry(), 0, 0); $entry->connect('key-press-event', 'on_keypress', $entry); function on_keypress($widget, $event, $entry) { if ($event->keyval!=Gdk::KEY_F7) return false; // process only F7 $selected_date = get_date(); $entry->set_text($selected_date); $entry->grab_focus(); } function get_date() { $getdate_dialog = new GetDate(); $date = $getdate_dialog->calendar->get_date(); $selected_date = $date[1].'/'.$date[2].'/'.$date[0]; return $selected_date; } class GetDate{ var $calendar; function GetDate() { $dialog = new GtkDialog('Get Date', null, Gtk::DIALOG_MODAL); $dialog->set_position(Gtk::WIN_POS_CENTER_ALWAYS); $top_area = $dialog->vbox; $top_area->pack_start($hbox = new GtkHBox()); $stock = GtkImage::new_from_stock(Gtk::STOCK_DIALOG_QUESTION, Gtk::ICON_SIZE_DIALOG); $this->calendar = new GtkCalendar(); $top_area->pack_start($this->calendar, 0, 0); $dialog->add_button(Gtk::STOCK_OK, Gtk::RESPONSE_OK); $buttons = $dialog->action_area->get_children(); $button_ok = $buttons[0]; // get the ID of the OK button $dialog->set_has_separator(false); $dialog->show_all(); $dialog->run(); $dialog->destroy(); } } $window->show_all(); Gtk::main(); ?> Regards, /kksou -- View this message in context: http://www.nabble.com/GtkEntry-and-%22special-keys%22-tf2404486.html#a6705714 Sent from the Php - GTK - General mailing list archive at Nabble.com.

« previous php.gtk.general (#7345) next »