TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Python to PHP Translation (http://www.talkphp.com/python-php-translation/)
-   -   Python to PHP Translation Needed (http://www.talkphp.com/python-php-translation/4683-python-php-translation-needed.html)

ETbyrne 07-04-2009 04:08 PM

Python to PHP Translation Needed
 
Ok I have this python code and I need it translated to PHP super fast before my mother in law dies... :-D

Code:

#!/usr/bin/env python

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *

class Application(QObject):

        def __init__(self):
                QObject.__init__(self)
                self.setObjectName('Application')

        class Console(QObject):
               
                def __init__(self):
                        QObject.__init__(self)
                        self.setObjectName('Console')
               
                @pyqtSignature('QString')
                def display(self,text):
                        print text
               
                @pyqtSignature("")
                def fortune(self):
                        print "fortune called"
                        return 23 # XXX: does not work

       
if __name__ == '__main__':
       
        app = QApplication(sys.argv)
       
        web = QWebView()
        web.setWindowTitle('My Application')
        web.resize(800,600)
        web.setHtml(QString("<a href=\"#\" onclick=\"Console.display('wow!')\">Hello, World!</a>"))
       
        frame = web.page().mainFrame()
        frame.addToJavaScriptWindowObject('Applicaiton',Application())
        frame.addToJavaScriptWindowObject('Console',Application.Console())
       
        web.show()
       
        sys.exit(app.exec_())

Now get going this is a life and death situation!!!

Village Idiot 07-04-2009 04:14 PM

Oh goto: "/dev/null"

adamdecaf 07-04-2009 05:12 PM

Code:

<a href="http://example.com" onclick="alert('wow');">Hello World</a>
If I had an idea as to what it's doing I would help. Sorry...

rguy84 07-05-2009 01:13 AM

I agree with adam, it just displays a link, in a window that's 800x600 in the users default browser.

ETbyrne 07-05-2009 01:56 PM

No no, you are all wrong! It displays a link in a custom browser window that is 800x600 that when you click on it a message is displayed in command prompt.

Quote:

In that case are you sure you want it translated? :-)
I'll get back to you on that.

FSX 07-05-2009 02:37 PM

It uses QT for it's GUI. PHP doesn't have this,but maybe you can use PHP-GTK.

ETbyrne 07-05-2009 04:45 PM

You're getting warmer!

adamdecaf 07-05-2009 05:39 PM

Quote:

Originally Posted by ETbyrne (Post 26646)
You're getting warmer!

So, if you know what this program does, why did you not port it to PHP for yourself?

Village Idiot 07-05-2009 06:39 PM

Quote:

Originally Posted by adamdecaf (Post 26647)
So, if you know what this program does, why did you not port it to PHP for yourself?

And do all that work?

adamdecaf 07-05-2009 08:05 PM

Quote:

Originally Posted by Village Idiot (Post 26648)
And do all that work?

Well, work is how some countries are formed... That and some businesses.

@VI congrats on 1000 posts.

Salathe 07-05-2009 08:36 PM

Quote:

Originally Posted by adamdecaf (Post 26647)
So, if you know what this program does, why did you not port it to PHP for yourself?

Presumably because this forum (just this Python to PHP Translation Needed forum) is a joke? 8-)

Village Idiot 07-05-2009 11:31 PM

Quote:

Originally Posted by adamdecaf (Post 26652)
Well, work is how some countries are formed... That and some businesses.

Work is also how some people die, ever hear of "work related" deaths?

Quote:

Originally Posted by adamdecaf (Post 26652)
@VI congrats on 1000 posts.

Thanks.

adamdecaf 07-06-2009 12:51 AM

Quote:

Originally Posted by Village Idiot (Post 26659)
Work is also how some people die, ever hear of "work related" deaths?


Thanks.

Yes, I think I read about them somewhere... (sarcastic and yet not sarcastic)

SneakyWhoami 09-30-2009 08:55 PM

Quote:

Originally Posted by FSX (Post 26643)
It uses QT for it's GUI. PHP doesn't have this,but maybe you can use PHP-GTK.


http://www.php-qt.org/

Not only should it be possible to reproduce the exact look and feel, it may even be fun to do it.

I didn't look at the python too closely though. I've been working on copying some things from python to php over the past couple of days (xmlrpc logins over https, generating and validating checksum files) so I know that all the basics can be copied over...


You've gotta feel tempted.

ETbyrne 10-01-2009 06:22 PM

Gotta say, I wasn't actually expecting to see an answer to this one... Looks interesting, but the lack of documentation basically makes it unusable.

I'll probably just stick to C++ for my desktop dev needs :-)

SneakyWhoami 10-03-2009 08:50 PM

Well... I first tried QT using the php extension and I could not really get my head around it.

After I did it in C++, the php extension was easy. BUT it's not really that useful, because nobody ships it. Debian, for instance, had a proposition to package it but then threw it out because at the time it was only available under the GPL, which according to FSF is incompatible with the PHP license due to a an "obnoxious advertising clause" or something (The PHP license forbids the use of the name "PHP" in derivative works).

Now QT is available under the LGPL and I don't think that restriction applies under the new license, but we've gone around in a full circle. Regardless of its legal status, no distribution that I know of ships a package for PHP-QT. I don't think it's in PECL either.

It's really a fantastic extension - one that you can't use in redistributable code unless you box the extension up with your code, but still fantastic... And then in that case, as you say, these sorts of obstacles start making look C++ look much more attractive.


....
Having said all that, bigger picture, time for threadjacking. There's no reason to not use PHP in desktop apps at least privately. The "It's only for the web" argument doesn't really work, and neither does "but it's not a compiled language".

GMail is a popular email client written in javascript, which was designed exclusively for the web.
Frozen-bubble, gstreamer, cowsay and gnome-system-tools all want to use PERL for something or other.
Eclipse, Mercury Messenger, Azureus and a number of other programs are written in humble Java. Java was first made public in 1995 targeting web applications (although they had originally intended it for embedded systems, say in appliances).
Quote:

The team originally considered using C++, but it was rejected for several reasons. Because they were developing an embedded system with limited resources, they decided that C++ demanded too large a footprint and that its complexity led to developer errors. The language's lack of garbage collection meant that programmers had to manually manage system memory, a challenging and error-prone task. The team was also troubled by the language's lack of portable facilities for security, distributed programming, and threading. Finally, they wanted a platform that could be easily ported to all types of devices.
I used to use an instant messaging client called imvu (before it became a chat client and game), which is a Windows program written in Python.

PHP, has a purpose-built desktop executable (php-cli).
Also, PHP applications can be compiled and can even ship as standalone executables.



PHP has its roots as a scripting language for the web, and there's a reason it's so popular there, but it is in good company on the desktop.


Nothing beats the satisfaction of doing it in C++ (although I've only ever completed one GUI project in C++), but scripting languages are a valid choice too.



I sound like I disagree, and I know I wrote a long post... It's really not silly to do it in PHP! But... Yeah, C++ is usually "the tool for the job". Especially when you're working with QT.

ETbyrne 10-03-2009 10:01 PM

Mostly very valid points, but compiling PHP does add quite a bit of bloat, does it not? I know a simple C++ Qt application can be only a few hundred kilobytes.

Also:

Quote:

GMail is a popular email client written in javascript, which was designed exclusively for the web.
Gmail does use javascript, but not for the back-end.

Btw don't you absolutely love the Qt Webkit module? It makes it so easy to make a GUI!


All times are GMT. The time now is 09:52 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0