Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 18th, 2005, 1:51 AM   #11
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by coldDeath
Nice I didn't realise it would be GPLed on Windows, that was Qts only bad point (IMHO).
That's the main reason why I was looking into GTK, which has no such restriction. Roll on PyQt 4
Arevos is offline   Reply With Quote
Old Nov 19th, 2005, 1:57 PM   #12
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
I tried out your WHOIS in glade/GTK, coldDeath, and here's what I came up with. I'll write a tutorial to mirror your rather excellent one, if I have time.

Comparing GTK to Qt was interesting, too. GTK's main advantage is that Glade produces its output as an XML file, so there's no need to run pyuic, nor to write your Python in an ugly C wrapper.

The disadvantage to using GTK, is that Glade simply isn't quite as good as Qt Designer. The layout system in Glade revolves around vboxes, hboxes and tables, so you really have to know what you're designing before you design it. Qt also appears to have more sensible default behavior than GTK; for instance, you didn't have to write a 'close' method for your Qt program. Glade also has a clunkier way of accessing widgets; 'self.glade.get_widget("textbox")', rather than Qt's "self.textbox" (something I tried to address with my small glade-wrapper).

The other advantage to Qt is that it integrates seamlessly with the native Windows toolkit, whilst GTK isn't quite so transparent (though GTK-WIMP addresses a lot of these problems). Alas, Qt3 is not available in GPL form for Windows, so until PyQt4 comes out, cross-platform development is rather limited.

Also, as an aside, you could improve your code by cutting out the temporary file and using the "popen2" module, instead. popen2 executes an external command, and opens up a file object for reading the output of the command, and a file object for writing input to the command.

e.g:
import popen2
read_file, write_file = popen2.popen2("whois " + address)
output_of_whois = read_file.read()
Arevos is offline   Reply With Quote
Old Nov 19th, 2005, 3:41 PM   #13
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Interesting comparison.

I've never really fully tried GTK but i've had a go at Glade and I didn't like it too much. Qt4 will be great and it will just make Qt perfect. But as you said, its horrible writing your code in a C function.
I didn't know about the popen2 module, it certainly looks good, thanks for showing me it

NOTE to everyone using Qt-Designer with Python:
You should do this:
Edit>Preferences>C++ Editor>Untick Auto Indent box
Otherwise coding in the built in editor is _hell_.
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Nov 19th, 2005, 6:01 PM   #14
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by coldDeath
But as you said, its horrible writing your code in a C function.
In theory you could leave that part blank, and use inheritance instead. In your tutorial you can stop after creating the connections, and then save and generate the python file using pyuic. Then you can inherit this generated file and override your custom functions.

e.g.
from qt import *
from form1 import *
from popen2 import *
import sys

class MyForm(Form1):
   def whois(self):
      whois, _ = popen2("whois " + self.lineEdit1.text().ascii())
      self.textEdit1.setText(whois.read())

if __name__ == "__main__":
    app = QApplication(sys.argv)
    f = MyForm()
    f.show()
    app.setMainWidget(f)
    app.exec_loop()
This way, you don't have to lay eyes on any C syntax, nor use the built-in editor.
Arevos is offline   Reply With Quote
Old Nov 20th, 2005, 7:19 AM   #15
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
I didn't see that you were writing it all inline. Didn't know you could even do that actually. Qt4 doesn't do let you do the whole .ui.h thing, making QtDesigner purely a GUI designer and not a mini-IDE. Cool thing is that QtDesigner4 is a lot easier to embed into other IDEs, so KDevelop will have it integrated.

Quote:
Also, as an aside, you could improve your code by cutting out the temporary file and using the "popen2" module
Or if you don't need seperate file objects for reading/writing, just use os.popen -
output = os.popen("whois " + address).read()
Cerulean is offline   Reply With Quote
Old Nov 20th, 2005, 7:26 AM   #16
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by Cerulean
Or if you don't need seperate file objects for reading/writing, just use os.popen -
output = os.popen("whois " + address).read()
You're right. Curiously, I was under the impression that os.popen didn't take shell commands, which is why I was using popen2.
Arevos is offline   Reply With Quote
Old Nov 20th, 2005, 2:59 PM   #17
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Oh, one more thing
Quote:
Originally Posted by Arevos
GTK's main advantage is that Glade produces its output as an XML file
Not sure what you mean - Qt designer produces .ui files which are XML files.
Cerulean is offline   Reply With Quote
Old Nov 20th, 2005, 4:49 PM   #18
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by Cerulean
Oh, one more thing

Not sure what you mean - Qt designer produces .ui files which are XML files.
Well, what I meant was that, at least in Qt3, you have to compile the ui and ui.h file into python using pyuic, whilst Glade operates by importing the XML directly. This solution seems a little neater.
Arevos is offline   Reply With Quote
Old Nov 20th, 2005, 4:59 PM   #19
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Fairly trivial to work around, surely? All it would take is a simple function that runs pyuic on the .ui file, imports the created .py file, and returns the freshly imported module? Like 6 lines long.
Cerulean is offline   Reply With Quote
Old Nov 20th, 2005, 6:01 PM   #20
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by Cerulean
Fairly trivial to work around, surely? All it would take is a simple function that runs pyuic on the .ui file, imports the created .py file, and returns the freshly imported module? Like 6 lines long.
Piping code from a external binary and executing it on the fly still isn't as neat as having a native python function to do it. It's not really major problem, just something that seems more neatly done in Glade.

When I wrote my comparison, I was still thinking that Python code had to be written inline in the .ui.h file, which was why I said it was the main disadvantage. Now I consider the main disadvantage to be Glade's layout manager, which is a bit more rigid than QtDesigner's.
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:33 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC