PHP
  Home arrow PHP arrow Page 2 - Building Your Own Desktop Notepad Application Using PHP-GTK
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building Your Own Desktop Notepad Application Using PHP-GTK
By: K.K.Sou
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2008-09-23


    Table of Contents:
  • Building Your Own Desktop Notepad Application Using PHP-GTK
  • Assumptions
  • Calling each respective function
  • Edit Operations
  • About the modified flag

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building Your Own Desktop Notepad Application Using PHP-GTK - Assumptions
    ( Page 2 of 5 )

    The article assumes that you have successfully installed PHP-GTK v2.0 or v2.0.1, with the glade library properly set up.

    It is also recommended that you have Glade 3 installed, so that you can load the glade file and explore the widgets and their respective settings.

    And lastly, it is assumed that you already have some basic knowledge of PHP-GTK. This means that I will focus on how the various GTK widgets are being used, as opposed to explaining what they are.

    Having said that, if you're totally new to PHP-GTK and just want to have a feel of what PHP-GTK is, this application will serve as a good showcase. You will see what a typical PHP-GTK application looks like, what it can do, and how easy things can be done in PHP-GTK.

    Okay. Enough said. Let's get started right away!

    Step 1: Lay out the widgets with Glade

    The first step in developing a PHP-GTK application is to lay out the widgets using Glade.

    For the Notepad application, we start with a GtkWindow that contains a GtkVBox. In the GtkVBox, we first pack a GtkMenu, followed by a GtkTextView. To cater to long text, we also want to stuff the GtkTextView inside a GtkScrolledWindow so that a scroll bar is automatically displayed for long text. So the widget tree for our Notepad application is as follows:


    I assume that you are familiar with Glade. So I will stop the Glade portion for now. Please download the .glade file available at the end of this article, open it in the Glade application, and you will be able to explore the layout of the widgets, the settings, and the signals set up for each of the widgets.

    Step 2: Let's get the base up and running

    The very first thing I always do after designing the layout using Glade is write a base application that loads the glade file.

    So here's the base program that I've written (assuming you have named the glade file you've created in Step 1 "notepad.glade").


    <?php

    $app = new NotePad();

    Gtk::main();


    class NotePad {

    function __construct() {

    $glade = new GladeXML(dirname(__FILE__).'/notepad.glade');

    $glade->signal_autoconnect_instance($this);

    }


    public function on_menu_select($menu_item) {

    $item = $menu_item->child->get_label();

    echo "menu selected: $itemn";

    }


    public function on_search_entry_activate() {

    echo "on_search_entry_activaten";

    }


    public function on_search_button_clicked($button=null) {

    echo "on_search_button_clickedn";

    }


    public function on_wordwrap_toggled($menuitem) {

    $active = $menuitem->get_active();

    echo "on_wordwrap_toggled ($active)n";

    }

    }

    Copy the above program and save it in a file, say "notepad.php." Place this program together with the glade file in the same directory. Suppose your PHP-GTK2 is installed in the c:php-gtk2 directory. To run the program, open a command prompt, change the directory where you have stored notepad.php and notepad.glade, and type:

    c:php-gtk2 notepad.php

    You should see the following window appear:

    Try typing some text and selecting some of the menu items. You will be able to see the menu item selected being echoed in the command window.

    The constructor loads the Glade file, while the rest of the functions are empty stubs for the signal handlers. The signal handlers are here so that you do not get any warning messages for the missing signal handlers.

    This base program is the simplest completely runnable version of the notepad application. It allows you to test your .glade file to see if the layout of the widgets is the same as what you have designed in the Glade application. You can also test to see if all of the menu items respond to selection. If you see no echo in the command window when you select a menu item, you will know that you did not set up the signal handler correctly for that menu item in the glade file.

    Once your glade file has tested properly, you can start adding each functionality incrementally to this base program. At each step, your PHP-GTK will always be a fully runnable piece of code.

    Step 3: Adding each functionality incrementally

    Below I will step through each function of the Notepad application one by one.



     
     
    >>> More PHP Articles          >>> More By K.K.Sou
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT