Cute Monkey!

Monkey Archive Forums/Monkey Projects/Cute Monkey!

Brucey(Posted 2011) [#1]
It's more of an experiment of creating a new Target, than being an "App Project" per se...

To wrap Qt for Monkey and enable the creation of native desktop applications, with little effort.



This screenshot shows that Monkey is quite capable of plugging into an existing C++ framework, with a bit of work in the code generation department - well, since it is a new target, we can be a bit more free with the backend stuff.

As you can see from the code, it's pure Monkey :


There are some things that are going to be difficult to implement without some language enhancements, or I'll just need to try to come up with something more clever... but for now, I think it works great! Monkey Magic! :-)


ziggy(Posted 2011) [#2]
This looks great!!


okee(Posted 2011) [#3]
Excellent


Amon(Posted 2011) [#4]
There has to be more than one Brucey? I mean there's one Brucey but several clones, like that film multiplicity.....why?...no man can do this much work; note the mass of Brucey Modules for BlitzMax, and still have timje to eat, sleep and breathe...

:)


Raz(Posted 2011) [#5]
Nice one :D What a cute lil monkey, yes you are, yes you are!


Brucey(Posted 2011) [#6]
This is a minimal example which shows how little code is required to make a basic, empty window :
Import qt.core
Import qt.qapplication
Import qt.qwidget

Class Window Extends QWidget

End

Function Main()
	
	Local app:QApplication = New QApplication

	Local window:Window = New Window
	window.show()
	
	app.exec()

End



Warpy(Posted 2011) [#7]
You could make it even shorter by saying Local app := New QApplication and Local window := New Window!


Brucey(Posted 2011) [#8]
You could make it even shorter...

Haw haw! :-p

Here's another of the Qt example programs, Monkeyfied :

...showing the widget localisation in action.
(probably supports umlauts too!)

..and a code snippet from said example :
	Method reformatCalendarPage:Void() slot
		If firstFridayCheckBox.isChecked()
			Local firstFriday:QDate = New QDate(calendar.yearShown(), calendar.monthShown(), 1)
			While firstFriday.dayOfWeek() <> Qt.Friday
				firstFriday = firstFriday.addDays(1)
			Wend
			Local firstFridayFormat:QTextCharFormat = New QTextCharFormat
			firstFridayFormat.setForeground(Qt.blue)
			calendar.setDateTextFormat(firstFriday, firstFridayFormat)
		EndIf
		
		' May First in Red takes precedence
		If mayFirstCheckBox.isChecked()
			Local mayFirst:QDate = New QDate(calendar.yearShown(), 5, 1)
			Local mayFirstFormat:QTextCharFormat = New QTextCharFormat
			mayFirstFormat.setForeground(Qt.red)
			calendar.setDateTextFormat(mayFirst, mayFirstFormat)
		EndIf
	End Method



Shinkiro1(Posted 2011) [#9]
Looks really cool
Can you use Qt for commercial apps?


Brucey(Posted 2011) [#10]
Can you use Qt for commercial apps?

Yes. Qt is LGPL, which means that you can make commercial or open source apps with it.


Hima(Posted 2011) [#11]
Awesome! Writing tools should be much easier now :D


Tibit(Posted 2012) [#12]
Cool! So TED can be (or is?) written in Monkey using this?

Did this project continue? Is there a working download?


ziggy(Posted 2012) [#13]
The problem I think we havw is that non mojo c++ code does not have a proper garbage collector. This is something Mark said he was going to fix at some point, but it's been like 6 or more months and it hasn't happened so not sure this is possible just yet, unless Brucey has addeed his own garbage collection


AdamRedwoods(Posted 2012) [#14]
You can add classes to be counted by the GC, but i'm not sure if this works yet or not. Trying this with wxMonkey.


ziggy(Posted 2012) [#15]
The problem is that collection seems to be tied to Mojo leaving the OnRender, OnUpdate pseudo-events. It would be nice to have an official word on this.


marksibly(Posted 2012) [#16]
Hi,

Qt's object memory management is semi-automatic. Objects are arranged in a hierarchy and deleting a parent object automatically deletes it's children too - much like Blitz3D's entity system I think.

To integrate this with Monkey, you probably need all extern classes to Extend Null (which will mean they're ignored by Monkey GC) and write a bunch of extern wrapper functions to create and delete objects. It'd then be up to the user to manually manage objects.

Then there's the signals/slots system which involves preprocessing C++ to pure C++. This is a pretty fundamental aspect of Qt which would be hard to emulate without writing a ton of interface/glue code. Qt is very much tied to C++ due to this. There is a JS 'layer' too, but I haven't really played with that.

Finally, there are quite a few 'Variant' classes that are passed around 'by value' that would need some clever handling.

There are quite a few classes too:

http://doc-snapshot.qt-project.org/4.8/classes.html

All in all, a very big job!


AdamRedwoods(Posted 2012) [#17]
Thanks for the info Mark.

My question would be, if a library uses "new" and "delete" for it's classes, then shouldn't monkey be able to manage those references?