TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-04-2009, 04:08 PM   #1 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Arrow 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...

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!!!
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 07-04-2009, 04:14 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Oh goto: "/dev/null"
__________________

Village Idiot is offline  
Reply With Quote
Old 07-04-2009, 05:12 PM   #3 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

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...
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 07-05-2009, 01:13 AM   #4 (permalink)
The Contributor
 
Join Date: Jun 2009
Location: Seattle, WA
Posts: 76
Thanks: 1
rguy84 is on a distinguished road
Default

I agree with adam, it just displays a link, in a window that's 800x600 in the users default browser.
__________________
Ryan | Blog | Twitter
Send a message via AIM to rguy84 Send a message via MSN to rguy84 Send a message via Yahoo to rguy84 Send a message via Skype™ to rguy84
rguy84 is offline  
Reply With Quote
Old 07-05-2009, 01:56 PM   #5 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

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.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 07-05-2009, 02:37 PM   #6 (permalink)
FSX
The Wanderer
 
FSX's Avatar
 
Join Date: Oct 2008
Posts: 15
Thanks: 0
FSX is on a distinguished road
Default

It uses QT for it's GUI. PHP doesn't have this,but maybe you can use PHP-GTK.
__________________
61924
FSX is offline  
Reply With Quote
Old 07-05-2009, 04:45 PM   #7 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

You're getting warmer!
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 07-05-2009, 05:39 PM   #8 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by ETbyrne View Post
You're getting warmer!
So, if you know what this program does, why did you not port it to PHP for yourself?
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 07-05-2009, 06:39 PM   #9 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by adamdecaf View Post
So, if you know what this program does, why did you not port it to PHP for yourself?
And do all that work?
__________________

Village Idiot is offline  
Reply With Quote
Old 07-05-2009, 08:05 PM   #10 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
And do all that work?
Well, work is how some countries are formed... That and some businesses.

@VI congrats on 1000 posts.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 07-05-2009, 08:36 PM   #11 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by adamdecaf View Post
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?
Salathe is offline  
Reply With Quote
Old 07-05-2009, 11:31 PM   #12 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by adamdecaf View Post
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 View Post
@VI congrats on 1000 posts.
Thanks.
__________________

Village Idiot is offline  
Reply With Quote
Old 07-06-2009, 12:51 AM   #13 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
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)
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 09-30-2009, 08:55 PM   #14 (permalink)
The Visitor
 
Join Date: Sep 2009
Posts: 3
Thanks: 0
SneakyWhoami is on a distinguished road
Default

Quote:
Originally Posted by FSX View Post
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.
SneakyWhoami is offline  
Reply With Quote
Old 10-01-2009, 06:22 PM   #15 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

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
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 10-03-2009, 08:50 PM   #16 (permalink)
The Visitor
 
Join Date: Sep 2009
Posts: 3
Thanks: 0
SneakyWhoami is on a distinguished road
Default

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.
SneakyWhoami is offline  
Reply With Quote
Old 10-03-2009, 10:01 PM   #17 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

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!
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need delphi to PHP translation Village Idiot Python to PHP Translation 10 06-25-2012 12:34 PM
PHP socket based communication with a python server tripy Advanced PHP Programming 7 07-15-2009 08:20 PM
need a built in function in php which work same as isinstance function of python tech Absolute Beginners 1 06-25-2009 01:22 PM
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM


All times are GMT. The time now is 10:29 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design