コード例 #1
0
 /**
  * Busca o texto do textview
  * 
  * @name get_text()
  * @return string $text Texto escrito no textview
  */
 public function get_text()
 {
     // Busca o buffer
     $buffer = parent::get_buffer();
     // Busca o inicio e fim do text
     $start = $buffer->get_start_iter();
     $end = $buffer->get_end_iter();
     // Retorna o texto
     return $buffer->get_text($start, $end);
 }
コード例 #2
0
 /**
  * Class Constructor
  * @param  $message    A string containint the question
  * @param  $action_yes Action taken for YES response
  * @param  $action_no  Action taken for NO  response
  */
 public function __construct($message, TAction $action_yes, TAction $action_no = NULL)
 {
     $buttons = array(Gtk::STOCK_YES, Gtk::RESPONSE_YES);
     if ($action_no instanceof TAction) {
         $buttons[] = Gtk::STOCK_NO;
         $buttons[] = Gtk::RESPONSE_NO;
     }
     $buttons[] = Gtk::STOCK_CANCEL;
     $buttons[] = Gtk::RESPONSE_CANCEL;
     parent::__construct('', NULL, Gtk::DIALOG_MODAL, $buttons);
     parent::set_position(Gtk::WIN_POS_CENTER);
     parent::set_size_request(500, 300);
     $textview = new GtkTextView();
     $textview->set_wrap_mode(Gtk::WRAP_WORD);
     $textview->set_border_width(12);
     $textbuffer = $textview->get_buffer();
     $tagtable = $textbuffer->get_tag_table();
     $customTag = new GtkTextTag();
     $tagtable->add($customTag);
     $customTag->set_property('foreground', '#525252');
     $tagBegin = $textbuffer->create_mark('tagBegin', $textbuffer->get_end_iter(), true);
     $textbuffer->insert_at_cursor("\n   " . $message);
     $tagEnd = $textbuffer->create_mark('tagEnd', $textbuffer->get_end_iter(), true);
     $start = $textbuffer->get_iter_at_mark($tagBegin);
     $end = $textbuffer->get_iter_at_mark($tagEnd);
     $textbuffer->apply_tag($customTag, $start, $end);
     $textview->set_editable(FALSE);
     $textview->set_cursor_visible(FALSE);
     $pango = new PangoFontDescription('Sans 14');
     $textview->modify_font($pango);
     $image = GtkImage::new_from_stock(Gtk::STOCK_DIALOG_QUESTION, Gtk::ICON_SIZE_DIALOG);
     $scroll = new GtkScrolledWindow();
     $scroll->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
     $scroll->add($textview);
     $hbox = new GtkHBox();
     $this->vbox->pack_start($hbox);
     $hbox->pack_start($image, FALSE, FALSE);
     $hbox->pack_start($scroll, TRUE, TRUE);
     $this->show_all();
     $result = parent::run();
     if ($result == Gtk::RESPONSE_YES) {
         parent::destroy();
         call_user_func_array($action_yes->getAction(), array($action_yes->getParameters()));
     } else {
         if ($result == Gtk::RESPONSE_NO) {
             parent::destroy();
             call_user_func_array($action_no->getAction(), array($action_no->getParameters()));
         } else {
             parent::destroy();
         }
     }
 }
コード例 #3
0
ファイル: TMessage.class.php プロジェクト: jhonleandres/crmbf
 /**
  * Class Constructor
  * @param $type    Type of the message (info, error)
  * @param $message Message to be shown
  * @param $action  Action to be processed when closing the dialog
  */
 public function __construct($type, $message, TAction $action = NULL)
 {
     parent::__construct('', NULL, Gtk::DIALOG_MODAL, array(Gtk::STOCK_OK, Gtk::RESPONSE_OK));
     parent::set_position(Gtk::WIN_POS_CENTER);
     parent::set_size_request(500, 300);
     $textview = new GtkTextView();
     $textview->set_wrap_mode(Gtk::WRAP_WORD);
     $textview->set_border_width(12);
     $textbuffer = $textview->get_buffer();
     $tagtable = $textbuffer->get_tag_table();
     $customTag = new GtkTextTag();
     $tagtable->add($customTag);
     $customTag->set_property('foreground', '#525252');
     $message = "\n   " . str_replace('<br>', "\n   ", $message);
     $tagBegin = $textbuffer->create_mark('tagBegin', $textbuffer->get_end_iter(), true);
     $textbuffer->insert_at_cursor(strip_tags($message));
     $tagEnd = $textbuffer->create_mark('tagEnd', $textbuffer->get_end_iter(), true);
     $start = $textbuffer->get_iter_at_mark($tagBegin);
     $end = $textbuffer->get_iter_at_mark($tagEnd);
     $textbuffer->apply_tag($customTag, $start, $end);
     $textview->set_editable(FALSE);
     $textview->set_cursor_visible(FALSE);
     $pango = new PangoFontDescription('Sans 14');
     $textview->modify_font($pango);
     $image = $type == 'info' ? GtkImage::new_from_stock(Gtk::STOCK_DIALOG_INFO, Gtk::ICON_SIZE_DIALOG) : GtkImage::new_from_stock(Gtk::STOCK_DIALOG_ERROR, Gtk::ICON_SIZE_DIALOG);
     $scroll = new GtkScrolledWindow();
     $scroll->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
     $scroll->add($textview);
     $hbox = new GtkHBox();
     $this->vbox->pack_start($hbox);
     $hbox->pack_start($image, FALSE, FALSE);
     $hbox->pack_start($scroll, TRUE, TRUE);
     $this->show_all();
     parent::connect('key_press_event', array($this, 'onClose'));
     $result = parent::run();
     if ($result == Gtk::RESPONSE_OK) {
         if ($action) {
             $parameters = $action->getParameters();
             call_user_func_array($action->getAction(), array($parameters));
         }
     }
     parent::destroy();
 }
コード例 #4
0
ファイル: GtkTextView1.php プロジェクト: amitjoy/php-gtk
$title->set_size_request(-1, 60);
$title->set_justify(Gtk::JUSTIFY_CENTER);
$alignment = new GtkAlignment(0.5, 0, 0, 0);
$alignment->add($title);
$vbox->pack_start($alignment, 0, 0);
$vbox->pack_start(new GtkLabel(), 0, 0);
$hbox = new GtkHBox();
$hbox->pack_start(new GtkLabel("Search string: "), 0);
$hbox->pack_start($entry = new GtkEntry(), 0);
$hbox->pack_start($button_search = new GtkButton('Search'), 0);
$vbox->pack_start($hbox, 0);
$button_search->connect('clicked', 'on_search_button', $entry);
// note 1
// Create a new buffer and a new view to show the buffer.
$buffer = new GtkTextBuffer();
$view = new GtkTextView();
$view->set_buffer($buffer);
$view->modify_font(new PangoFontDescription("Verdana italic 14"));
$view->set_wrap_mode(Gtk::WRAP_WORD);
$scrolled_win = new GtkScrolledWindow();
$scrolled_win->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
$vbox->pack_start($scrolled_win);
$scrolled_win->add($view);
$window->show_all();
Gtk::main();
function on_search_button($widget, $entry)
{
    global $view, $buffer;
    $search_str = $entry->get_text();
    $start_iter = $buffer->get_start_iter();
    // note 2
    // Get the mark that wasn't moved.
    if ($mark == $buffer->get_mark('insert')) {
        $mark2 = $buffer->get_mark('selection_bound');
    } else {
        $mark2 = $buffer->get_mark('insert');
    }
    // Get the iter at the other mark.
    $iter2 = $buffer->get_iter_at_offset(0);
    $buffer->get_iter_at_mark($iter2, $mark2);
    echo 'Iter1: ' . $iter->get_offset() . "\t";
    echo 'Iter2: ' . $iter2->get_offset() . "\t";
    // Print the text between the two iters.
    echo 'SELECTION: ' . $buffer->get_text($iter, $iter2) . "\n";
}
// Create a GtkTextView.
$text = new GtkTextView();
// Get the buffer from the view.
$buffer = $text->get_buffer();
// Add some text.
$buffer->set_text('Moving a mark is done with either move_mark or move_mark_by_name.');
// Connect the printSelected method.
$buffer->connect('mark-set', 'printSelected');
// How NOT to move the cursor to the beginning of the text.
echo "Move to start\n";
$buffer->move_mark_by_name('insert', $buffer->get_start_iter());
$buffer->move_mark_by_name('selection_bound', $buffer->get_start_iter());
// How NOT to select a range of text.
echo "Select range\n";
$buffer->move_mark_by_name('selection_bound', $buffer->get_iter_at_offset(7));
$buffer->move_mark_by_name('insert', $buffer->get_iter_at_offset(16));
// The better way to move the cursor to the beginning of the text.
コード例 #6
0
ファイル: GtkTextView2.php プロジェクト: amitjoy/php-gtk
<?php

$window = new GtkWindow();
$window->set_size_request(400, 240);
$window->connect_simple('destroy', array('Gtk', 'main_quit'));
$window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Change the Font of GtkTextView");
$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);
$vbox->pack_start(new GtkLabel(), 0, 0);
// Create a new buffer and a new view to show the buffer.
$buffer = new GtkTextBuffer();
$view = new GtkTextView();
$view->set_buffer($buffer);
$view->modify_font(new PangoFontDescription("Courier New 16"));
// note 1
$view->set_wrap_mode(Gtk::WRAP_WORD);
$scrolled_win = new GtkScrolledWindow();
$scrolled_win->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
$vbox->pack_start($scrolled_win);
$scrolled_win->add($view);
$window->show_all();
Gtk::main();
<?php

function varDumpTag($tag)
{
    var_dump($tag);
}
$view = new GtkTextView();
$buffer = $view->get_buffer();
$textTable = $buffer->get_tag_table();
$tag = new GtkTextTag('Bob');
$textTable->add($tag);
$textTable->lookup('Bob');
$textTable->foreach('varDumpTag');
コード例 #8
0
	/**
	 * Returns the text from a textview.
	 * @param GtkTextView $tv The textview where the text should be read from.
	*/
	function textview_gettext(GtkTextView $tv){
		return $tv->get_buffer()->get_text(
			$tv->get_buffer()->get_start_iter(),
			$tv->get_buffer()->get_end_iter()
		);
	}