qt_connect 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,257 +1,276 @@
1
- qt\_connect
2
- ==========
3
-
4
- This project provides a Qt programming API for JRuby with a high degree of compatibility
5
- with the existing Qt interface for Ruby. The API is implemented using Qt Jambi, the Java version
6
- of the Qt framework. The interface consists of two software components: the actual Ruby
7
- bindings (qt\_jambi) and a compatibility layer (qt\_compat) which makes it easier to run
8
- existing Qt Ruby code using JRuby.
9
- A third component (qt\_sugar) introduces the Qt Jambi signals interface to QtRuby. With this interface
10
- there is no need to use C++ signatures or slots on the application level.
11
- The three components are packaged in a single, pure-Ruby gem package 'qt\_connect'. The same gem
12
- can be installed on Ruby and JRuby installations.
13
-
14
- ### prerequisites and usage
15
- **Ruby**
16
- >*prerequisite:* qtbindings Ruby gem package
17
- >>download from: <http://github.com/ryanmelt/qtbindings>
18
- >>installation: follow qtbindings instructions
19
-
20
- >`require 'qt_connect'` to use Qt Jambi Signals interface
21
-
22
- **JRuby**
23
- >*prerequisite:* qtjambi Java library
24
- >>download from: <http://qt-jambi.org>
25
- >>installation: install two jar-files on CLASSPATH (e.g. C:/jruby-1.6.7/lib or /usr/lib/jruby/lib)
26
- >>qtjambi-`<version>`.jar (e.g. qtjambi-4.7.1.jar)
27
- >>qtjambi-`<platform>`-`<version>`.jar (e.g. qtjambi-win32-msvc2008-4.7.1.jar)
28
-
29
- >`require 'qt_jambi'` for basic Qt Jambi bindings only
30
- >`require 'qt_connect'` for Qt Jambi bindings + QtRuby compatibility layer
31
-
32
-
33
- ### tested environments
34
-
35
- **[Windows 7 Home Premium]**
36
- >ruby 1.9.1p429 [i386-mingw32]
37
- > qtbindings-4.6.3.2-x86-mingw32
38
- > qt_connect-1.5.1
39
- >
40
- >jruby 1.6.7 [Windows 7-x86-java]
41
- >qtjambi-4.7.1.jar
42
- >qtjambi-win32-msvc2008-4.7.1.jar
43
- >qt\_connect-1.5.1
44
-
45
- **[Mac OS X : NOT TESTED]** ; *please report your experiences*
46
-
47
- **[Linux : ubuntu 11:10]**
48
- >ruby 1.8.7p352 [x86_64-linux]
49
- >qtbindings-4.6.3.4
50
- >qt\_connect-1.5.1
51
- >
52
- >jruby 1.5.1p249 [amd64-java]
53
- >qtjambi-4.7.0.jar
54
- >qtjambi-linux64-gcc-4.7.0.jar
55
- >qt\_connect-1.5.1
56
-
57
- >>Note: Under Ubuntu I could only run the programs using administrator privilege
58
- >>e.g. sudo jruby ..... My Linux expertise is limited but it seems that
59
- >>the operating system itself uses the Qt library and that maybe jruby loads (part of)
60
- >>the qtjambi library not from the jar but from somewere else on the loadpath. I have
61
- >>the same problem with the QtJambi demo programs if I just install QtJambi (nothing
62
- >>to do with JRuby). Any help would be appreciated.
63
-
64
-
65
- qt\_jambi
66
- --------
67
- Provides the basic Ruby bindings for the Qt Jambi Java classes and an interface to the
68
- Signals and Slots mechanism. Appropriate classes are extended with overloaded operators
69
- such as +, - , | and &. Both Ruby-ish underscore and Java-ish camel case naming for
70
- methods can be used. Like with Qt Ruby, constructors can be called in a conventional
71
- style or with an initializer block. If you want an API which follows closely the QtJambi
72
- documentation and programming examples all you need to do is `'require qt_jambi'`. A
73
- minimalist example to display just a button which connects to a website when clicked:
74
-
75
- require 'qt_jambi'
76
-
77
- app=Qt::Application.new(ARGV)
78
- button=Qt::PushButton.new( "Hello World")
79
- button.clicked.connect{ Qt::DesktopServices.openUrl(Qt::Url.new('www.hello-world.com'))}
80
- button.show
81
- app.exec`
82
-
83
-
84
- The QtJambi documentation contains a large number of examples written in Java. Even with
85
- a moderate knowledge of Java it is fairly easy to translate these to Ruby or
86
- use them as examples for new Ruby programs.
87
-
88
- qt\_compat
89
- ---------
90
- A compatibility layer which can be installed on top of the 'qt\_jambi' bindings.
91
- Including this layer makes it possible to run existing Qt Ruby code with no or only minor
92
- modifications using JRuby.
93
- Since the QtJambi API is build on the same underlying C++ library as the Qt Ruby API, the
94
- Qt(C++) classes are mostly mapped to equivalent Qt Jambi(Java/Ruby) and Qt Ruby(Ruby)
95
- classes. The majority of Ruby classes exposed through the Qt Jambi API are therefore
96
- identical to the classes exposed through the Qt Ruby API. There are however differences
97
- due to different language capabilities and limitations in converting C++ types to Java and
98
- Ruby 'types'. The two most notable differences are the handling of Enums and the abstract
99
- value type QVariant
100
-
101
- ### Enums
102
- Enums are used widely throughout the Qt framework, mostly as integer constants and
103
- bit flags. Using Qt Jambi, Java Enums are accessible through JRuby as constants. Individual
104
- values are accessed combining namespace with enum type name and enum value name:
105
-
106
- Qt::Alignment::AlignCenter
107
- Qt::Alignment::AlignLeft
108
- Qt::Font::StyleHint::Times
109
- Qt::Font::StyleStrategy::ForceOutline
110
-
111
- QtRuby accesses the same values using a shorthand notation omitting the type name:
112
-
113
- Qt::AlignCenter
114
- Qt::AlignLeft
115
- Qt::Font::Times
116
- Qt::Font::ForceOutline
117
-
118
- Using the compatibility layer the same shorthand notation constants are defined in addition
119
- to the existing ones. If the shorthand notation clashes with other entries or existing class
120
- names, the default mapping can be overruled.
121
-
122
- ### QVariant
123
- The Qt API provides an abstract value type, QVariant, which can hold values of many
124
- C++ and Qt types. In Java - like Ruby - there is no real need for such a type because
125
- the language already provides Object as an abstract type. This works because all Java
126
- classes inherit Object. For that reason, the Qt Jambi API uses Object where Qt uses
127
- QVariant.
128
- To maintain code compatibility with QtRuby a dummy constructor method
129
- is defined which basically returns the original object unchanged:
130
-
131
- size=Qt::Size.new(100,200)
132
- variant=Qt::Variant.new(size) #=> size
133
-
134
- This works in many cases, but not always. QtRuby code using the Qt::Variant class may
135
- need to be adjusted for use with the QtJambi bindings.
136
-
137
-
138
- ### Slots and Signals
139
- Although QtJambi supports a simpler mechanism to deal with signals which does not need
140
- the C++ signatures and uses methods or code blocks in stead of slots, a full set of compatible
141
- routines to handle Slots and Signals is included for compatibility with QtRuby. This includes
142
- slots and signals functions, SLOT and SIGNAL 'macros', connect, disconnect, emit and sender
143
- methods:
144
-
145
- slots 'documentWasModified()'
146
- signals 'contentsChanged()'
147
-
148
- connect(@textEdit.document(), SIGNAL('contentsChanged()'),
149
- self, SLOT('documentWasModified()'))
150
-
151
- emit contentsChanged
152
-
153
- ### Custom adjustments
154
- A number of individual class definitions are 'tweaked' or extended to make the QtRuby API
155
- fit on the QtJambi API. This is still very much work in progress
156
-
157
- qt\_sugar
158
- --------
159
-
160
- Provides added functionality to the current signals/slots API in QtRuby
161
- It avoids the need to use C++ signatures and signal/slots functions in applications.
162
- The syntax is similar to the one used in QtJambi (the Java version of the Qt framework):
163
- Each Signal-emitting Qt class is extended with a method for each Signal it may emit.
164
- The default name of the method is the same as the signature name. In case of ambiguity
165
- when the signal has arguments or overloads, the default name for a given signature can be
166
- overruled through an entry in the **Signature2Signal** table. The initial entries in the table
167
- are the same as used in the QtJambi interface.
168
- Example:
169
-
170
-
171
- require 'qt_connect'
172
-
173
- button=Qt::PushButton.new
174
-
175
- #connecting signal to a Ruby Block:
176
- button.clicked.connect{ puts "Hello World"}
177
-
178
- #connecting to receiver/method
179
- button.clicked.connect(self,:methodname)
180
-
181
- #disconnect all connections originating from this button
182
- button.clicked.disconnect
183
-
184
- #emitting the signal (normally done internally by Qt)
185
- button.clicked.emit
186
-
187
- #example passing String as argument
188
- label=Qt::Label.new
189
- label.linkActivated.connect{ |s| Qt::DesktopServices.openUrl(Qt::Url.new(s))}
190
-
191
- Custom components can define their own signals and emit them like this:
192
-
193
- @signal=Qt::Signal.new
194
- @signal.connect{ |a1,a2| puts "someone send me #{a1} and #{a2}"}
195
- .
196
- .
197
- @signal.emit(100,200)
198
-
199
- background
200
- -----------
201
- For several years I have been an enthusiastic user of the excellent Ruby bindings to the Qt APIs as provided
202
- by Richard Dale and others as part of the Korundum/QtRuby project. With the becoming of age of JRuby
203
- I became interested in running my applications using JRuby, mainly for reasons of packaging and deployment.
204
- The [qtjruby-core gem](https://github.com/nmerouze/qtjruby-core) provided by Nicolas Merouze
205
- was a good start for a JRuby interface to QtJambi, but to get a reasonable compatibility with an existing
206
- code base in QtRuby a lot more was required. I decided therefore to develop a new gem package which
207
- would make it easy to port existing applications to JRuby or better use the same code for deployment
208
- under Ruby and JRuby.
209
- Because of the inherent differences between the two interfaces it will never be possible to have complete inter
210
- operability, but it is certainly possible to write code in such a way that it will work with both Ruby and JRuby.
211
- As a proof of principle I have a large Qt application (>10000 lines Ruby Code) which runs with the 'qt\_connect'
212
- gem both under Ruby and JRuby. This allows me to do development under Ruby and package and deploy under JRuby.
213
-
214
- Through the years I have seen several suggestions for changes to the slots and signals interface used by QtRuby.
215
- The existing API is based on C++ signatures and not very appropriate for Ruby programming. The solution
216
- provided by the QtJambi interface is quite elegant and in my opinion also suitable for Ruby. I have therefore included a
217
- QtJambi based signals interface for Ruby programs in the gem package.
218
-
219
- ### examples and testing
220
- The example programs should run both in a Ruby (qtbindings + qt\_connect gem packages) and a JRuby
221
- (qt\_connect gem + Qt Jambi jars) setting. The Class Explorer is for JRuby users only.
222
- This browser extends the Javadoc documentation for the com.trolltech.qt Javapackages that
223
- form the basis for the JRuby Qt Jambi API.
224
- If you install the Ruby qtbindings gem package, the example directory includes more than 75 example programs.
225
- Of these programs about a third run unchanged with JRuby and the qt\_connect gem. Of the remaining programs
226
- quite a few can not run for the same reason in that they make use of the Qt's resources system which is different
227
- from the Qt Jambi resource management (these are all the examples using files with the .qrc extension). Some programs
228
- run after minor modifications and more may run with appropriate extensions of the qt\_compat module, I have not had
229
- much time to test this out.
230
-
231
- ### packaging and deployment
232
- When it comes to packaging your Qt JRuby application, there is a great gem package to help you called
233
- [Rawr](http://rawr.rubyforge.org). With Rawr, a simple, pre-generated configuration file turns your code into
234
- an executable jar, a .exe for Windows, and a .app for OS X.
235
-
236
- ### documentation
237
- If you install the full Qt Jambi package, it comes with extensive documentation for the Java API and a large number
238
- of Java demonstration programs. Use these together with the class explorer program (*part of this gem package*) to write
239
- your Ruby programs.
240
- The example programs (*deform.rb*, *qtmapzoom.rb* and *classexplorer.rb*) also show how to program the signal interface
241
- in Ruby.
242
- For Qt Ruby programming in general have a look at the demonstration programs included with the qtbindings gem package.
243
- There is also an ebook
244
- ([Rapid GUI Development with QtRuby](http://pragprog.com/book/ctrubyqt/rapid-gui-development-with-qtruby)
245
- by Caleb Tennis) published by The Pragmatic Bookshelf. Although the book itself is somewhat out of date, it is still a good introduction
246
- to Qt Ruby programming.
247
- In addition to the [Qt Jambi documentation](http://doc.trolltech.com/qtjambi-4.4/html) there is also a lot of Qt documentation
248
- online at the [Qt Developer Network](http://qt-project.org).
249
- For information about JRuby look at <http://jruby.org> , read the [JRuby Cookbook](http://shop.oreilly.com/product/9780596519650.do)
250
- published by O'Reilly or [Using JRuby](http://pragprog.com/book/jruby/using-jruby) from The Pragmatic Bookshelf.
251
-
252
- ## license
253
-
254
- Copyright &copy; 2010-2012 Cees Zeelenberg (<c.zeelenberg@computer.org>)
255
- This software is released under the LGPL Version 2.1.
256
- See COPYING.LIB.txt
257
-
1
+ qt\_connect
2
+ ==========
3
+
4
+ This project provides a Qt programming API for JRuby with a high degree of compatibility
5
+ with the existing Qt interface for Ruby. The API is implemented using Qt Jambi, the Java version
6
+ of the Qt framework. The interface consists of two software components: the actual Ruby
7
+ bindings (qt\_jambi) and a compatibility layer (qt\_compat) which makes it easier to run
8
+ existing Qt Ruby code using JRuby.
9
+ A third component (qt\_sugar) introduces the Qt Jambi signals interface to QtRuby. With this interface
10
+ there is no need to use C++ signatures or slots on the application level.
11
+ The three components are packaged in a single, pure-Ruby gem package 'qt\_connect'. The same gem
12
+ can be installed on Ruby and JRuby installations.
13
+
14
+ ### prerequisites and usage
15
+ **Ruby**
16
+ >*prerequisite:* qtbindings Ruby gem package
17
+ >>download from: <http://github.com/ryanmelt/qtbindings>
18
+ >>installation: follow qtbindings instructions
19
+
20
+ >`require 'qt_connect'` to use Qt Jambi Signals interface
21
+
22
+ **JRuby**
23
+ >*prerequisite:* qtjambi Java library
24
+ >>download from: <http://qt-jambi.org>
25
+ >>installation: install two jar-files on CLASSPATH (e.g. C:/jruby-1.6.7/lib or /usr/lib/jruby/lib)
26
+ >>qtjambi-`<version>`.jar (e.g. qtjambi-4.7.1.jar)
27
+ >>qtjambi-`<platform>`-`<version>`.jar (e.g. qtjambi-win32-msvc2008-4.7.1.jar)
28
+
29
+ >`require 'qt_jambi'` for basic Qt Jambi bindings only
30
+ >`require 'qt_connect'` for Qt Jambi bindings + QtRuby compatibility layer
31
+
32
+
33
+ ### tested environments
34
+
35
+ **[Windows 7 Home Premium]**
36
+ >ruby 1.9.1p429 [i386-mingw32]
37
+ > qtbindings-4.6.3.2-x86-mingw32
38
+ > qt_connect-1.5.1
39
+ >
40
+ >jruby 1.6.7 [Windows 7-x86-java]
41
+ >qtjambi-4.7.1.jar
42
+ >qtjambi-win32-msvc2008-4.7.1.jar
43
+ >qt\_connect-1.5.1
44
+
45
+ **[Mac OS X]**
46
+ >jruby 1.6.7 [darwin-i386-java]
47
+ >qtjambi-4.7.0.jar
48
+ >qtjambi-macosx-gcc-4.7.0.jar
49
+ >qt\_connect-1.5.1
50
+
51
+ >>Note: You need to use a 32-bit JVM because the qtjambi binaries are 32-bit only for the moment.
52
+ >>You can do this by opening the "Java Preferences" application and drag the system 32-bit JVM at the top
53
+ >>
54
+ >>You also need to set up the right environment: classpath, java options, ...
55
+ >>You might want to use this script:
56
+ >>
57
+ >> ``` bash
58
+ #!/bin/sh
59
+ QJ=path/to/qtjambi-macosx-community-4.7.0
60
+ export CLASSPATH=$QJ/qtjambi-4.7.0.jar:$QJ/qtjambi-macosx-gcc-4.7.0.jar:.
61
+ export JAVA_OPTS="-XstartOnFirstThread -Djava.library.path=$QJ/lib"
62
+ export QT_PLUGIN_PATH=$QJ/plugins
63
+ JRUBY=path/to/jruby/bin/jruby
64
+ $JRUBY -rubygems $@
65
+ ```
66
+
67
+ **[Linux : ubuntu 11:10]**
68
+ >ruby 1.8.7p352 [x86_64-linux]
69
+ >qtbindings-4.6.3.4
70
+ >qt\_connect-1.5.1
71
+ >
72
+ >jruby 1.5.1p249 [amd64-java]
73
+ >qtjambi-4.7.0.jar
74
+ >qtjambi-linux64-gcc-4.7.0.jar
75
+ >qt\_connect-1.5.1
76
+
77
+ >>Note: Under Ubuntu I could only run the programs using administrator privilege
78
+ >>e.g. sudo jruby ..... My Linux expertise is limited but it seems that
79
+ >>the operating system itself uses the Qt library and that maybe jruby loads (part of)
80
+ >>the qtjambi library not from the jar but from somewere else on the loadpath. I have
81
+ >>the same problem with the QtJambi demo programs if I just install QtJambi (nothing
82
+ >>to do with JRuby). Any help would be appreciated.
83
+
84
+
85
+ qt\_jambi
86
+ --------
87
+ Provides the basic Ruby bindings for the Qt Jambi Java classes and an interface to the
88
+ Signals and Slots mechanism. Appropriate classes are extended with overloaded operators
89
+ such as +, - , | and &. Both Ruby-ish underscore and Java-ish camel case naming for
90
+ methods can be used. Like with Qt Ruby, constructors can be called in a conventional
91
+ style or with an initializer block. If you want an API which follows closely the QtJambi
92
+ documentation and programming examples all you need to do is `'require qt_jambi'`. A
93
+ minimalist example to display just a button which connects to a website when clicked:
94
+
95
+ require 'qt_jambi'
96
+
97
+ app=Qt::Application.new(ARGV)
98
+ button=Qt::PushButton.new( "Hello World")
99
+ button.clicked.connect{ Qt::DesktopServices.openUrl(Qt::Url.new('www.hello-world.com'))}
100
+ button.show
101
+ app.exec`
102
+
103
+
104
+ The QtJambi documentation contains a large number of examples written in Java. Even with
105
+ a moderate knowledge of Java it is fairly easy to translate these to Ruby or
106
+ use them as examples for new Ruby programs.
107
+
108
+ qt\_compat
109
+ ---------
110
+ A compatibility layer which can be installed on top of the 'qt\_jambi' bindings.
111
+ Including this layer makes it possible to run existing Qt Ruby code with no or only minor
112
+ modifications using JRuby.
113
+ Since the QtJambi API is build on the same underlying C++ library as the Qt Ruby API, the
114
+ Qt(C++) classes are mostly mapped to equivalent Qt Jambi(Java/Ruby) and Qt Ruby(Ruby)
115
+ classes. The majority of Ruby classes exposed through the Qt Jambi API are therefore
116
+ identical to the classes exposed through the Qt Ruby API. There are however differences
117
+ due to different language capabilities and limitations in converting C++ types to Java and
118
+ Ruby 'types'. The two most notable differences are the handling of Enums and the abstract
119
+ value type QVariant
120
+
121
+ ### Enums
122
+ Enums are used widely throughout the Qt framework, mostly as integer constants and
123
+ bit flags. Using Qt Jambi, Java Enums are accessible through JRuby as constants. Individual
124
+ values are accessed combining namespace with enum type name and enum value name:
125
+
126
+ Qt::Alignment::AlignCenter
127
+ Qt::Alignment::AlignLeft
128
+ Qt::Font::StyleHint::Times
129
+ Qt::Font::StyleStrategy::ForceOutline
130
+
131
+ QtRuby accesses the same values using a shorthand notation omitting the type name:
132
+
133
+ Qt::AlignCenter
134
+ Qt::AlignLeft
135
+ Qt::Font::Times
136
+ Qt::Font::ForceOutline
137
+
138
+ Using the compatibility layer the same shorthand notation constants are defined in addition
139
+ to the existing ones. If the shorthand notation clashes with other entries or existing class
140
+ names, the default mapping can be overruled.
141
+
142
+ ### QVariant
143
+ The Qt API provides an abstract value type, QVariant, which can hold values of many
144
+ C++ and Qt types. In Java - like Ruby - there is no real need for such a type because
145
+ the language already provides Object as an abstract type. This works because all Java
146
+ classes inherit Object. For that reason, the Qt Jambi API uses Object where Qt uses
147
+ QVariant.
148
+ To maintain code compatibility with QtRuby a dummy constructor method
149
+ is defined which basically returns the original object unchanged:
150
+
151
+ size=Qt::Size.new(100,200)
152
+ variant=Qt::Variant.new(size) #=> size
153
+
154
+ This works in many cases, but not always. QtRuby code using the Qt::Variant class may
155
+ need to be adjusted for use with the QtJambi bindings.
156
+
157
+
158
+ ### Slots and Signals
159
+ Although QtJambi supports a simpler mechanism to deal with signals which does not need
160
+ the C++ signatures and uses methods or code blocks in stead of slots, a full set of compatible
161
+ routines to handle Slots and Signals is included for compatibility with QtRuby. This includes
162
+ slots and signals functions, SLOT and SIGNAL 'macros', connect, disconnect, emit and sender
163
+ methods:
164
+
165
+ slots 'documentWasModified()'
166
+ signals 'contentsChanged()'
167
+
168
+ connect(@textEdit.document(), SIGNAL('contentsChanged()'),
169
+ self, SLOT('documentWasModified()'))
170
+
171
+ emit contentsChanged
172
+
173
+ ### Custom adjustments
174
+ A number of individual class definitions are 'tweaked' or extended to make the QtRuby API
175
+ fit on the QtJambi API. This is still very much work in progress
176
+
177
+ qt\_sugar
178
+ --------
179
+
180
+ Provides added functionality to the current signals/slots API in QtRuby
181
+ It avoids the need to use C++ signatures and signal/slots functions in applications.
182
+ The syntax is similar to the one used in QtJambi (the Java version of the Qt framework):
183
+ Each Signal-emitting Qt class is extended with a method for each Signal it may emit.
184
+ The default name of the method is the same as the signature name. In case of ambiguity
185
+ when the signal has arguments or overloads, the default name for a given signature can be
186
+ overruled through an entry in the **Signature2Signal** table. The initial entries in the table
187
+ are the same as used in the QtJambi interface.
188
+ Example:
189
+
190
+
191
+ require 'qt_connect'
192
+
193
+ button=Qt::PushButton.new
194
+
195
+ #connecting signal to a Ruby Block:
196
+ button.clicked.connect{ puts "Hello World"}
197
+
198
+ #connecting to receiver/method
199
+ button.clicked.connect(self,:methodname)
200
+
201
+ #disconnect all connections originating from this button
202
+ button.clicked.disconnect
203
+
204
+ #emitting the signal (normally done internally by Qt)
205
+ button.clicked.emit
206
+
207
+ #example passing String as argument
208
+ label=Qt::Label.new
209
+ label.linkActivated.connect{ |s| Qt::DesktopServices.openUrl(Qt::Url.new(s))}
210
+
211
+ Custom components can define their own signals and emit them like this:
212
+
213
+ @signal=Qt::Signal.new
214
+ @signal.connect{ |a1,a2| puts "someone send me #{a1} and #{a2}"}
215
+ .
216
+ .
217
+ @signal.emit(100,200)
218
+
219
+ background
220
+ -----------
221
+ For several years I have been an enthusiastic user of the excellent Ruby bindings to the Qt APIs as provided
222
+ by Richard Dale and others as part of the Korundum/QtRuby project. With the becoming of age of JRuby
223
+ I became interested in running my applications using JRuby, mainly for reasons of packaging and deployment.
224
+ The [qtjruby-core gem](https://github.com/nmerouze/qtjruby-core) provided by Nicolas Merouze
225
+ was a good start for a JRuby interface to QtJambi, but to get a reasonable compatibility with an existing
226
+ code base in QtRuby a lot more was required. I decided therefore to develop a new gem package which
227
+ would make it easy to port existing applications to JRuby or better use the same code for deployment
228
+ under Ruby and JRuby.
229
+ Because of the inherent differences between the two interfaces it will never be possible to have complete inter
230
+ operability, but it is certainly possible to write code in such a way that it will work with both Ruby and JRuby.
231
+ As a proof of principle I have a large Qt application (>10000 lines Ruby Code) which runs with the 'qt\_connect'
232
+ gem both under Ruby and JRuby. This allows me to do development under Ruby and package and deploy under JRuby.
233
+
234
+ Through the years I have seen several suggestions for changes to the slots and signals interface used by QtRuby.
235
+ The existing API is based on C++ signatures and not very appropriate for Ruby programming. The solution
236
+ provided by the QtJambi interface is quite elegant and in my opinion also suitable for Ruby. I have therefore included a
237
+ QtJambi based signals interface for Ruby programs in the gem package.
238
+
239
+ ### examples and testing
240
+ The example programs should run both in a Ruby (qtbindings + qt\_connect gem packages) and a JRuby
241
+ (qt\_connect gem + Qt Jambi jars) setting. The Class Explorer is for JRuby users only.
242
+ This browser extends the Javadoc documentation for the com.trolltech.qt Javapackages that
243
+ form the basis for the JRuby Qt Jambi API.
244
+ If you install the Ruby qtbindings gem package, the example directory includes more than 75 example programs.
245
+ Of these programs about a third run unchanged with JRuby and the qt\_connect gem. Of the remaining programs
246
+ quite a few can not run for the same reason in that they make use of the Qt's resources system which is different
247
+ from the Qt Jambi resource management (these are all the examples using files with the .qrc extension). Some programs
248
+ run after minor modifications and more may run with appropriate extensions of the qt\_compat module, I have not had
249
+ much time to test this out.
250
+
251
+ ### packaging and deployment
252
+ When it comes to packaging your Qt JRuby application, there is a great gem package to help you called
253
+ [Rawr](http://rawr.rubyforge.org). With Rawr, a simple, pre-generated configuration file turns your code into
254
+ an executable jar, a .exe for Windows, and a .app for OS X.
255
+
256
+ ### documentation
257
+ If you install the full Qt Jambi package, it comes with extensive documentation for the Java API and a large number
258
+ of Java demonstration programs. Use these together with the class explorer program (*part of this gem package*) to write
259
+ your Ruby programs.
260
+ The example programs (*deform.rb*, *qtmapzoom.rb* and *classexplorer.rb*) also show how to program the signal interface
261
+ in Ruby.
262
+ For Qt Ruby programming in general have a look at the demonstration programs included with the qtbindings gem package.
263
+ There is also an ebook
264
+ ([Rapid GUI Development with QtRuby](http://pragprog.com/book/ctrubyqt/rapid-gui-development-with-qtruby)
265
+ by Caleb Tennis) published by The Pragmatic Bookshelf. Although the book itself is somewhat out of date, it is still a good introduction
266
+ to Qt Ruby programming.
267
+ In addition to the [Qt Jambi documentation](http://doc.trolltech.com/qtjambi-4.4/html) there is also a lot of Qt documentation
268
+ online at the [Qt Developer Network](http://qt-project.org).
269
+ For information about JRuby look at <http://jruby.org> , read the [JRuby Cookbook](http://shop.oreilly.com/product/9780596519650.do)
270
+ published by O'Reilly or [Using JRuby](http://pragprog.com/book/jruby/using-jruby) from The Pragmatic Bookshelf.
271
+
272
+ ## license
273
+
274
+ Copyright &copy; 2010-2012 Cees Zeelenberg (<c.zeelenberg@computer.org>)
275
+ This software is released under the LGPL Version 2.1.
276
+ See COPYING.LIB.txt
@@ -67,6 +67,7 @@ class ClassExplorer < Qt::MainWindow
67
67
  #initial selection: all packages
68
68
  @package_list.select_all
69
69
  update_class_panel
70
+ on_package_clicked(0)
70
71
 
71
72
  end
72
73
 
@@ -204,7 +205,8 @@ class ClassExplorer < Qt::MainWindow
204
205
  size = settings.value("size", Qt::Size.new(1000,768))
205
206
  @linkto_box.checked=Qt::Variant.toBoolean(settings.value('linkto_box')) || false
206
207
  @inherit_box.checked=Qt::Variant.toBoolean(settings.value('inherit_box')) || false
207
- @splitter.sizes=Qt::Variant.toList(settings.value("splitter")) || [200,800]
208
+ sz=Qt::Variant.toList(settings.value("splitter"))
209
+ @splitter.sizes= (sz.size==2) ? sz : [300,700]
208
210
  @root=Qt::Variant.toString(settings.value("root")) || "http://doc.trolltech.com/qtjambi-4.4/html"
209
211
  state=settings.value("state")
210
212
  resize(size)
@@ -250,7 +250,7 @@ module Qt
250
250
  elsif block.arity == 1
251
251
  block.call(instance)
252
252
  else
253
- raise ArgumentError, "Wrong number of arguments to block(#{block.arity} for 1)"
253
+ raise ArgumentError, "Wrong number of arguments to block(#{block.arity} ; should be 1 or 0)"
254
254
  end
255
255
  end
256
256
  return instance
@@ -634,9 +634,18 @@ QtJambi::QTimer.class_eval {
634
634
  #in an uninitialized object unexpected things don't work
635
635
  #e.g. it can't process plug-ins like jpeg
636
636
  #java_send used to avoid confusion with Ruby initialize constructor
637
- def new(args)
637
+ def new(args,&block)
638
638
  java_send(:initialize,[java.lang.String[]],args.to_java(:string))
639
639
  $qApp=self
640
+ if block_given?
641
+ if block.arity == -1 || block.arity == 0
642
+ instance_eval(&block)
643
+ elsif block.arity == 1
644
+ block.call(self)
645
+ else
646
+ raise ArgumentError, "Wrong number of arguments to block(#{block.arity} ; should be 1 or 0)"
647
+ end
648
+ end
640
649
  return self
641
650
  end
642
651
 
@@ -1,3 +1,3 @@
1
1
  module QtJambi
2
- Version='1.5.1'
2
+ Version='1.5.2'
3
3
  end
Binary file
metadata CHANGED
@@ -1,22 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qt_connect
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 5
9
- - 1
10
- version: 1.5.1
4
+ prerelease:
5
+ version: 1.5.2
11
6
  platform: ruby
12
7
  authors:
13
- - Cees Zeelenberg
8
+ - Cees Zeelenberg
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2012-05-16 00:00:00 +02:00
19
- default_executable:
13
+ date: 2012-05-16 00:00:00 Z
20
14
  dependencies: []
21
15
 
22
16
  description: "Qt bindings for JRuby with (optional) extension to provide backward\n compatibility with Qt Ruby programs. The API is implemented using Qt Jambi, the\n Java version of the Qt framework. For Qt Ruby programs it provides a QtJambi\n inspired interface to the Signals/Slots system without the need to use\n C++ signatures.\n "
@@ -28,63 +22,55 @@ extensions: []
28
22
  extra_rdoc_files: []
29
23
 
30
24
  files:
31
- - lib/Qt.rb
32
- - lib/qt_connect/qt_compat.rb
33
- - lib/qt_connect/qt_jbindings.rb
34
- - lib/qt_connect/qt_sugar.rb
35
- - lib/qt_connect/version.rb
36
- - lib/qt_connect.rb
37
- - lib/qt_jambi.rb
38
- - java/SignalActions.java
39
- - lib/signalactions.jar
40
- - examples/classexplorer/classexplorer.rb
41
- - examples/classexplorer/menus/helpmenu.rb
42
- - examples/classexplorer/menus.rb
43
- - examples/classexplorer/packagetree.rb
44
- - examples/classexplorer/qt_extensions/htmldelegate.rb
45
- - examples/classexplorer/qt_extensions/line_edit.rb
46
- - examples/classexplorer/qt_extensions.rb
47
- - examples/deform/arthurframe.rb
48
- - examples/deform/deform-demo.png
49
- - examples/deform/Deform.html
50
- - examples/deform/deform.rb
51
- - examples/deform/qt-logo.png
52
- - examples/deform/Thumbs.db
53
- - examples/qtmapzoom/qtmapzoom.rb
54
- - COPYING.LIB.txt
55
- - Rakefile
56
- - README.md
57
- has_rdoc: true
25
+ - lib/Qt.rb
26
+ - lib/qt_connect.rb
27
+ - lib/qt_jambi.rb
28
+ - lib/qt_connect/qt_compat.rb
29
+ - lib/qt_connect/qt_jbindings.rb
30
+ - lib/qt_connect/qt_sugar.rb
31
+ - lib/qt_connect/version.rb
32
+ - java/SignalActions.java
33
+ - lib/signalactions.jar
34
+ - examples/classexplorer/classexplorer.rb
35
+ - examples/classexplorer/menus.rb
36
+ - examples/classexplorer/packagetree.rb
37
+ - examples/classexplorer/qt_extensions.rb
38
+ - examples/classexplorer/menus/helpmenu.rb
39
+ - examples/classexplorer/qt_extensions/htmldelegate.rb
40
+ - examples/classexplorer/qt_extensions/line_edit.rb
41
+ - examples/deform/arthurframe.rb
42
+ - examples/deform/deform-demo.png
43
+ - examples/deform/deform.html
44
+ - examples/deform/deform.rb
45
+ - examples/deform/qt-logo.png
46
+ - examples/qtmapzoom/qtmapzoom.rb
47
+ - COPYING.LIB.txt
48
+ - Rakefile
49
+ - README.md
58
50
  homepage: https://github.com/CeesZ/qt_connect
59
51
  licenses:
60
- - LGPLv2.1
52
+ - LGPLv2.1
61
53
  post_install_message:
62
54
  rdoc_options: []
63
55
 
64
56
  require_paths:
65
- - lib
57
+ - lib
66
58
  required_ruby_version: !ruby/object:Gem::Requirement
67
59
  none: false
68
60
  requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
75
64
  required_rubygems_version: !ruby/object:Gem::Requirement
76
65
  none: false
77
66
  requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- hash: 3
81
- segments:
82
- - 0
83
- version: "0"
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
84
70
  requirements: []
85
71
 
86
72
  rubyforge_project:
87
- rubygems_version: 1.3.7
73
+ rubygems_version: 1.8.15
88
74
  signing_key:
89
75
  specification_version: 3
90
76
  summary: Uniform Qt bindings for JRuby and Ruby
Binary file