Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

THE HOLY GRAIL: Cross Platform programming made easy

Options
  • 05-06-2002 7:41pm
    #1
    Closed Accounts Posts: 1,026 ✭✭✭


    I'm starting a project for Linux and came accross gtk-php. In case you don't know gtk is the widget set used by the Open Source desktop Gnome.

    There is a windows version of gtk and php is cross- platform, so what does php-gtk give you? the power and ease of php to give you a cross platform API.

    check out this basic program:
    <?php
        // Our 'callback' function for gkt+ events
        function quitApplication() {
            Gtk::main_quit();
        }
    
        // Ensure that php_gtk.so is loaded
        dl( 'php_gtk.' . (strstr(PHP_OS, 'WIN') ? 'dll' : 'so')) ||
            die("Can't load php_gtk module!\n");
    
        // Create a new window; this is going to be our new main window
        $window = &new GtkWindow;
    
        // Set the title of our window
        $window->set_title("PHP-GTK for world domination");
    
        // Set the default size of our window
        $window->set_default_size(320, 200);
    
        // Almost every window manager automatically provides
        // a way to close the window.
        // This triggers the gtk+ 'delete' event
        // We therefore connect a PHP function to the event
        // which gets executed as soon as the event is fired
        $window->connect('delete_event', 'quitApplication');
    
        // The next step will be to add additional widgets HERE
    
        // show the parent window and all its children
        $window->show_all();
    
        // nothing happens on the screen until Gtk::main() is called
        Gtk::main();
    ?>
    

    To me that just looks beautifully simple. I never bothered learning c and the same program in C or C++ would be about 4 times longer.

    Unfortunately it is not widespread yet so any programs have to carry the disclaimer "You must download and install php-gtk" etc....

    anyone used it yet?


Comments

  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Hehe, I wouldn't go calling it the holy grail of cross platform programming just yet. Perl's had Tk extensions for ages. Besides Java's a far better choice for cross platform GUI programming. And if you're not worried about any other platform than Win32 then by all means go for VB.

    Is there really a need to be able to write GUI programs in PHP? I mean the language was designed as a scripting language for websites, when did it become an applications language?

    I'm not saying it's not cool or anything, it is really cool. But it's never going to replace C, C++ or VB on the desktop is it?

    Sometimes I wish Open Source developers would stop and think before they go tacking something onto everything they do. I mean, look at Perl :)

    Oh and the C/C++ to do the above isn't really that hard or that long really, granted you do have to do a bit more work but to be honest I'd much rather work with C than PHP (Hey cool that ryhmes!)

    What's your project anyways? Have you considered using Java Swing for the GUI?


  • Closed Accounts Posts: 1,026 ✭✭✭sisob


    Is there really a need to be able to write GUI programs in PHP? I mean the language was designed as a scripting language for websites, when did it become an applications language?

    I'm not saying it's not cool or anything, it is really cool. But it's never going to replace C, C++ or VB on the desktop is it?

    Well imagine a website that uses gtk. is that not cool, try and do it in c++, php is easy to program in and v. powerful etc....
    Sometimes I wish Open Source developers would stop and think before they go tacking something onto everything they do. I mean, look at Perl :)
    what do you mean by "tacking something on" - OpenSource programmers have created some great languages and we like to push them to their limits.

    What's your project anyways? Have you considered using Java Swing for the GUI?
    I'm working on a set of small apps to supplement openoffice.org which is multi-platform and i dont want have to maintain 2 sets of code. I'm still not sure if I will use php-gtk, I'm trying to make the software completely idiot proof and "download and complie php-gtk" doesnt fall into that catagory.


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Hehe, I wouldn't go calling it the holy grail of cross platform programming just yet. Perl's had Tk extensions for ages.

    Very true. PHP-GTK is very cool, but it has a long way to go yet. And the widgets are Linux-GUI-Ugly. Ewww!

    Besides Java's a far better choice for cross platform GUI programming.

    It is, but to be fair, PHP isn't far off. It's been ported to pretty much everything at this stage. I don't know how that applies to the GTK widget sets though, tbh.

    Is there really a need to be able to write GUI programs in PHP?

    No. But I have to say it is handy for those of us who never got around to learning a "proper" language. (No disrepect intended, I'd love to learn a "proper" language, I just don't have the time.) For example, I wanted a wee HOSTS editor a while back, for ad blocking, and I couldn't find anything native for Win32. So I hacked together something in PHP-GTK. It was ugly as sin, but it worked.

    I mean the language was designed as a scripting language for websites, when did it become an applications language?

    It's not, but the above applies here too. I use PHP for shell scripts - particularly cron jobs - all the time. I never really got as far as modules in Perl, which means I never got as far as database connectivity. So when I want to clean out a MySQL database periodically or somesuch, I hack something together in PHP in about a minute and a half. It's bloody handy. And I wrote an rm replacement to handle Trash in about three, after many a `rm -fR`accident. Oops!

    I'm not saying it's not cool or anything, it is really cool. But it's never going to replace C, C++ or VB on the desktop is it?

    Nope. But it's not really intended too. It's pretty much for the bull-headed PHP hacker who wants to play. What's wrong with that? :)

    Sometimes I wish Open Source developers would stop and think before they go tacking something onto everything they do.

    I agree, but it doesn't really apply in this case. The PHP-GTK guys are pretty much separate from the core PHP developers, and if I know Rasmus, he'll keep it that way. (I recently asked on PHP-DEV if the developers were considering adding PerlSections-like functionality to PHP, and Rasmus came back sharpish with a snappy "no". I don't think Rasmus likes me very much! :)) Same goes for PEAR, none of that stuff hits the core until it's proved itself beyond doubt in PECL, and the developers tend to stay out of each others way most of the time.

    Imagine what PHP would be like today if the developers hadn't bothered with tacking on MySQL functionality!

    I mean, look at Perl

    I know. I wonder will they ever get to 6. Still though, CPAN rocks.

    adam


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    I'm trying to make the software completely idiot proof and "download and complie php-gtk" doesnt fall into that catagory.

    So bundle the binary? Last time I looked it wasn't all that big.

    adam


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by sisob
    I'm trying to make the software completely idiot proof and "download and complie php-gtk" doesnt fall into that catagory.

    Pretty much nothing falls into that category. Any native app is platform dependant. Any non-native app requires that the correct compiler/interpreter/widget be on the target machine. Look at Java - will the user have Java? The right version?

    Hell, even web-based applications arent idiot proof, given the differences between browsers, the non-standardness of feature support across the main players, and the lovely problems of firewalls etc.

    In short, there is no idiot-proof solution, until you start narrowing down which idiots you wish to proof against.

    The best solutions I have seen generally involve distributing an app inside a universal installer of some sort, or using similar web-based approaches (e.g. Suns Web-Start for Java). Even then, Ive seen the stuff fail.

    jc

    jc


  • Advertisement
  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by dahamsta
    I'm trying to make the software completely idiot proof and "download and complie php-gtk" doesnt fall into that catagory.

    So bundle the binary? Last time I looked it wasn't all that big.

    Err...adam....I dont think the binary would be cross-platform :)

    If it was, then surely whatever it was written in would be what youd write the app in, and just ship a binary of your compiled app.

    jc


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Err...adam....I dont think the binary would be cross-platform :)

    I never said it was, smart-arse. :)

    I meant bundle the binary for the appropriate platform. There's no holy grail, we all know that. :)

    adam


Advertisement