SketchUcation Plugin Store

 

 

Qt4 GUI in Ruby for Sketchup plugin's

Qt4 GUI in Ruby for Sketchup plugin's

Postby MOGhouse » Fri May 18, 2012 9:53 pm

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- ... t-mac/view

The 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/Tut ... 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 :)
MOGhouse
 
Posts: 7
Joined: Mon Jan 30, 2012 6:57 pm
Name: Torben Mogensen

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby Dan Rathbun » Fri May 18, 2012 10:12 pm

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.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby thomthom » Sat May 19, 2012 10:23 am

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.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17562
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby Dan Rathbun » Sat May 19, 2012 4:26 pm

thomthom wrote:The Set class in SketchUp conflicts with the Set 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: viewtopic.php?f=180&t=45443#p406187
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby Jim » Sat May 19, 2012 8:43 pm

Just wanted to point out wxSU. Similar idea to yours, but uses wxWindows. Perhaps there is some ideas that could be applied to Qt4.

http://wxsu.sourceforge.net/
Jim
Global Moderator
 
Posts: 4126
Joined: Mon Nov 12, 2007 10:13 pm
Location: NEOH
Name: Jim
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: other
Level of SketchUp: Intermediate

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby thomthom » Sat May 19, 2012 9:27 pm

Jim wrote: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?
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17562
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby MOGhouse » Sun May 20, 2012 6:08 pm

Jim wrote:Just wanted to point out wxSU. Similar idea to yours, but uses wxWindows. Perhaps there is some ideas that could be applied to Qt4.

http://wxsu.sourceforge.net/


That is a very good idea - will have a look :)
MOGhouse
 
Posts: 7
Joined: Mon Jan 30, 2012 6:57 pm
Name: Torben Mogensen

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby Dan Rathbun » Sun May 20, 2012 6:13 pm

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 via Win32API ??
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby thomthom » Mon May 21, 2012 8:50 am

Dan Rathbun wrote:I wonder if this can cause problems for plugins that use EventRelay, or plugins that are searching for window objects using Win API calls via Win32API ??

Yes it can.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17562
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby MOGhouse » Mon May 21, 2012 3:37 pm

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
Code: Select all
require 'your_ui.rb'
and
Code: Select all
require 'Qt4'

I want to track down the files/libraries that are sought by
Code: Select all
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/Qtcore

As 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
 
Posts: 7
Joined: Mon Jan 30, 2012 6:57 pm
Name: Torben Mogensen

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby Dan Rathbun » Mon May 21, 2012 8:02 pm

MOGhouse wrote: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 module Kernel, which is "mixed into" class Object, using the C-side of the include method.

Therefore... since ALL objects in Ruby are subclasses of Object, EVERY object's pedigree will contain Object and Kernel. You can see this with the ancestors() 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 and Kernel.load methods.. and understand how require 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.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby Dan Rathbun » Mon May 21, 2012 8:17 pm

MOGhouse wrote: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/Qtcore

Should 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.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby Dan Rathbun » Mon May 21, 2012 8:22 pm

MOGhouse wrote:main.rb cotains
Code: Select all
require 'your_ui.rb'
and
Code: Select all
require 'Qt4'


Actually the 'author_subdir/your_ui.rb' file would have statement(s) at or near the top that are:
Code: Select all
require('!loadpaths')
require('Qt4')


See my post: [ Code ] Ruby LOAD PATHs script (Win32) : ver 3.0.1

:idea:
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Qt4 GUI in Ruby for Sketchup plugin's

Postby Dan Rathbun » Mon May 21, 2012 8:56 pm

MOGhouse wrote: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.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Need Authorised SketchUp Training by experts in various disciplines? Check out our Training details.

Ad Machine
Robot
 
Posts: 2012


Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 9 guests