Qt4 GUI in Ruby for Sketchup plugin's
-
I have been looking into using Qt4 for making nice UI's for Sketchup plugin's
I'm looking into how to make it work runtime in a sketchup plugin, and there is very little documentation to be found anywhere.
So, basically I'm posting to see if anyone else interested in this, have you been working this way, or is there any good reason not to use Qt4 for UI's.My goal is to post a solid "How-to" use/setup Qt4 UI's in Sketchup plugin's.
If you don't know Qt4 - Qt4 is an IDE made by Nokia, very powerful and used for very sophisticated UI's.
Part of the IDE is Qt4-designer - a graphical interface WYSIWYG kind-of-thing, very cool and considered by many the best around.
Qt4-designer is free and open source.
Screenshot Qt4 here: http://qt.nokia.com/images/products/qt-designer-screenshot-mac/viewThe workflow goes like this:
- Layout your UI with widgets, buttons, sliders, dials, combo's and what have you.
- Set properties to get behaviour and look you want.
- Set signals/slots to connect UI with you main RUBY plugin file.
- Qt4 saves as an XML file.
- Run the XML file through a program/compiler ("rbuic4" in linux-terminal) with Ruby bindings and output is a ready-to-go UI in RUBY.
- You can re-work/tweak the RUBY UI or leave and use as is.
Pro's for this workflow:
- Fast way to make some really cool UI stuff.
- The RUBY UI runs and looks native in both Windows AND Mac-OSX - from the SAME UI-file.
- Keep plugin's in only RUBY - you can scramble the UI if you are into that kind-of-thing.
- The UI file is separated from the logic.
- Should you be trembling over Trimble in the future - at least your UI can easily be converted to python/java or whatever you require.
Con's for this workflow
- There is very little documentation around.
For some documentation of this I found this link: http://techbase.kde.org/Development/Tutorials/Developing_Qt4_Applications_using_Qt_Designer_and_Ruby_on_Kubuntu
Right now I'm trying to figure out the runtime dependencies/libraries needed and where to locate/put them.
If you have anything you want to share - PLEASE post -
Sounds like a full Ruby install will be needed by all end users.
Easy on PC... but on MAC it requires changing symbolic links. Do a search on this forum (or check the indexes in the Code Snippets Sticky we have other threads on these topics.
-
One thing to investigate for this project is if all the frameworks required overrides any of the core methods - can can cause problems.
If you require the Standard Ruby Library there might very well be problems. The Set class in SketchUp conflicts with the Set class in the Standard Library for instance. -
@thomthom said:
The
Set
class in SketchUp conflicts with theSet
class in the Standard Library for instance.I just happened to be working on a fix, as I need to use a gem that requires the standard
Set
class.see: http://forums.sketchucation.com/viewtopic.php?f=180&t=45443#p406187
-
Just wanted to point out wxSU. Similar idea to yours, but uses wxWindows. Perhaps there is some ideas that could be applied to Qt4.
-
@jim said:
Just wanted to point out wxSU.
Didn't SU4Thea use that at some point - and it caused conflicts and issues. Messed around with lots of stuff, even attached hidden windows to the SketchUp window etc...? Or was that something else?
-
@jim said:
Just wanted to point out wxSU. Similar idea to yours, but uses wxWindows. Perhaps there is some ideas that could be applied to Qt4.
That is a very good idea - will have a look
-
Yes thomthom, WxSU creates an invisible toplevel windowframe around the SketchUp application window, so that Wx messages can bubble up to that window object and be processed. (It changes the SU app window class to be a child of this invisible window.)
I wonder if this can cause problems for plugins that use
EventRelay
, or plugins that are searching for window objects using Win API calls viaWin32API
?? -
@dan rathbun said:
I wonder if this can cause problems for plugins that use
EventRelay
, or plugins that are searching for window objects using Win API calls viaWin32API
??Yes it can.
-
Hi guys - thank you for your input.
It might be that Dan is right and a complete ruby installation is needed at runtime, but that is not the easy lightweight solution I was hoping for.
Here is what I was hoping to achieve.main.rb cotains
require 'your_ui.rb'
and
require 'Qt4'
I want to track down the files/libraries that are sought by
require 'Qt4'
The files required by Qt4 is placed inside the sketchup tree, maybe in /Resources/Qt/, as standalone dependencies for plugin's.
Then require the files directly with a path to the files... /Resources/Qt/QtcoreAs I understand Sketchup runs its own ruby interpreter 1.8.6, and I want the interpreter to run the GUI also.
Should this work? or is it a really bad idea?
Sorry, I have a stupid question - I can't get my head around the require.
When you require 'Sketchup' or 'Qt4' - what actually happens, which files are actually sought? - I sure there is an easy way to track them down, I just can't find it ....
Can anyone give me a hint. -
@moghouse said:
Sorry, I have a stupid question - I can't get my head around the
require
.
When you require 'Sketchup' or 'Qt4' - what actually happens, which files are actually sought?The
require()
method is defined in mixin moduleKernel
, which is "mixed into" classObject
, using the C-side of theinclude
method.Therefore... since ALL objects in Ruby are subclasses of
Object
, EVERY object's pedigree will containObject
andKernel
. You can see this with theancestors()
method. Subclasses inherit their ancestors methods, but can be overridden locally within a class or module, or locally undefined (which is rare.)You should read up on the
Kernel.require
andKernel.load
methods.. and understand howrequire
uses the global arrays$LOAD_PATH
(aka$:
,) and$LOADED_FEATURES
(aka$"
.)Get the Standard Ruby 1.8.6 Reference (CHM) here, or access the online web editions for the Core and Libs.
-
@moghouse said:
The files required by Qt4 is placed inside the sketchup tree, maybe in /Resources/Qt/, as standalone dependencies for plugin's.
Then require the files directly with a path to the files... /Resources/Qt/QtcoreShould this work? or is it a really bad idea?
Bad idea.
1) the Resouces path is a application OEM path and should remain "hands off"
2) it is very difficult to install anything into that path
Ruby libraries, other than a few win32ole.so and Win32API.so (for historical reasons,) need to stay in the Ruby lib directories. (And even those 2 mentioned here, should stay in the full Ruby install folders, if possible.)
We just cannot copy all of the Ruby extended library files into the Sketchup plugins folder. It will create havoc.
-
@moghouse said:
main.rb cotains
require 'your_ui.rb'
and
require 'Qt4'
Actually the 'author_subdir/your_ui.rb' file would have statement(s) at or near the top that are:
require('!loadpaths') require('Qt4')
See my post: [ Code ] Ruby LOAD PATHs script (Win32) : ver 3.0.1
-
@moghouse said:
I want to track down the files/libraries that are sought by Qt4
I do remember seeing a Ruby script that would go through a file looking for
require
statements, and search each dependency in turn for their dependancies.It would print out a report. Either was something Rick Wilson wrote, .. or something that disro'd with the Full Ruby install.
But cannot locate it now.
-
I've found this project....what do u think??
-
It has nothing to do with Qt4, uses GTK+ and should not work under SketchUp Ruby, as is.
You should start a new topic just for this (VisualRuby/Glade) subject. -
I also want to use QT for user interface. Is there any examples?
I decide to create thread and execute main loop of QT application in this thread.
[pre:g779cno0]DWORD WINAPI mainLoop(CONST LPVOID lpParam) {
coreDataStruct * data = (coreDataStruct *)lpParam;int argc = 0; char **argv = 0; data->app = new QApplication(argc, argv); data->app->setQuitOnLastWindowClosed(false); data->app->exec(); data->active = 0; ExitThread(0);
}
VALUE cModule_initialize(...) {
if (coreData->active == 0) {
HANDLE thread = CreateThread(NULL, 0, &mainLoop, (void*)coreData, 0, NULL);
coreData->mainThread = thread;
coreData->active = 1;
return Qtrue;
}
return Qfalse;
}[/pre:g779cno0]
Thread is created in function cModule_initialize that should be executed in the begining
To create window I have this function:
[pre:g779cno0]VALUE cModule_createWin(...) {
if (coreData->active == 0) return Qfalse;
QDialog *dialog = new QDialog;
dialog->show();
return Qtrue;
}[/pre:g779cno0]
Is that correct?
Advertisement