QML notebook - phase zero - toy ui ;-)

72 views
Skip to first unread message

Ville M. Vainio

unread,
Apr 26, 2012, 5:47:05 PM4/26/12
to leo-editor
Ok, I now created a toy UI demo for how "cell" based leo (like ipython
notebook) could operate.

It's probably the first stab at using QML to solve a problem in Leo.
It doesnt' run from leo yet (it's not a plugin, more protoing needed
before it's worthwhile to make it a plugin.

When you add and delete text, the cells resize naturally.

To try it, launch the launchqmlnb.py script that I pushed to bzr.
qml_notebook.png

Terry Brown

unread,
Apr 27, 2012, 10:55:15 AM4/27/12
to leo-e...@googlegroups.com
Played with it. I guess the next step would be demo of python handling
events from the QML UI elements, and of python finding and manipulating
the QML UI elements.

I'm wondering about the advantages of this approach over the "regular"
QWidget approach. QML is perhaps a more terse and elegant language for
defining a UI, and it has scripting of UI behavior in javascript. And
perhaps it has a more tablet friendly widget set?

But I wonder what it lets you do that you can't do with the QWidget
stack, given that mixing the two seems to mean that Leo is using two
GUI systems - they may be very tightly integrated, but mind-space wise
it's two complex systems instead of one.

Which isn't a reason not to use QML, just wondering if it has
advantages I'm missing.

Cheers -Terry

Terry Brown

unread,
Apr 27, 2012, 11:10:02 AM4/27/12
to leo-e...@googlegroups.com
Here's a demo to run Ville's QML thing in a free_layout pane.
Requires rev. 5284 so the .qml file in leo/plugins/qmlnb/ is available.

Paste this into a node, run-script on the node, right click a splitter
handle, Insert, click the Action button, select "Add QML shower".

Note that you can flick the text boxes it shows up and down with the
mouse, in a tablet / phone ui kind of way.

---cut here---
from PyQt4.QtCore import QUrl
from PyQt4.QtDeclarative import QDeclarativeView
class QMLShower:
def __init__(self, c):
self.c = c
c._qml_shower = self
self.w = None
c.free_layout.get_top_splitter().register_provider(self)
def ns_provider_id(self): # allow for re-registering, mainly for dev.
return '__qml_shower'
def ns_provides(self): # what we can provide
return [("Add QML shower", '__add_qml_shower')]
def ns_provide(self, id_): # provide it
if id_ == '__add_qml_shower':
g.unregisterHandler('select2', self.update)
g.registerHandler('select2', self.update)
if not self.w:
self.w = self.make_widget()
return self.w
def make_widget(self):
view = QDeclarativeView()
path = g.os_path_join(g.computeLeoDir(), 'plugins', 'qmlnb', 'qml', 'leonbmain.qml')
view.setSource(QUrl(path))
view.setResizeMode(QDeclarativeView.SizeRootObjectToView)
# Display the user interface and allow the user to interact with it.
view.setGeometry(100, 100, 400, 240)
view.show()
# rootObject = view.rootObject()
return view
def update(self, tag, kwords):
pass
def closed(self, event):
g.unregisterHandler('select2', self.update)

QMLShower(c)
---cut here---


Cheers -Terry

Ville Vainio

unread,
Apr 27, 2012, 11:23:03 AM4/27/12
to Terry Brown, leo-e...@googlegroups.com
Qml version was the one I got done quickly, since it has better layout
mechanism. If we come up with qwidget way, let's use that :). I tried
to find one, but didn't

Sent from my Windows Phone
From: Terry Brown
Sent: 4/27/2012 5:55 PM
To: leo-e...@googlegroups.com
Subject: Re: QML notebook - phase zero - toy ui ;-)
--
You received this message because you are subscribed to the Google
Groups "leo-editor" group.
To post to this group, send email to leo-e...@googlegroups.com.
To unsubscribe from this group, send email to
leo-editor+...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en.

Ville M. Vainio

unread,
Apr 27, 2012, 4:49:27 PM4/27/12
to leo-e...@googlegroups.com
Ok, this should serve as a basis for ipython nicely.

However, a problem - it worked once, but now (after restarting leo,
many times) I always get this traceback;

Traceback (most recent call last):
File "/home/ville/b/leo-editor/leo/plugins/nested_splitter.py", line
489, in cb
self.place_provided(id_, index)
File "/home/ville/b/leo-editor/leo/plugins/nested_splitter.py", line
502, in place_provided
provided = self.get_provided(id_)
File "/home/ville/b/leo-editor/leo/plugins/nested_splitter.py", line
960, in get_provided
provided = provider.ns_provide(id_)
File "/home/ville/.leo/scriptFile.py", line 18, in ns_provide
g.unregisterHandler('select2', self.update)
File "/home/ville/b/leo-editor/leo/core/leoGlobals.py", line 2529,
in unregisterHandler
return pc.unregisterHandler(tags,fn)
File "/home/ville/b/leo-editor/leo/core/leoPlugins.py", line 730, in
unregisterHandler
self.unregisterOneHandler(tags,fn)
File "/home/ville/b/leo-editor/leo/core/leoPlugins.py", line 735, in
unregisterOneHandler
bunches = [bunch for bunch in bunches if bunch.fn != fn]
TypeError: 'NoneType' object is not iterable

Ville M. Vainio

unread,
Apr 28, 2012, 4:37:36 AM4/28/12
to leo-editor
Work ongoing.

bzr pull, and paste this into a node and press ctrl+b:

https://gist.github.com/2517158

Result is as attached. What it currently does is putting every node
wrapper in a list of QObjects, and use that as the model in QML side
(model is just a container that has the list of stuff to show in
Repeater).

So you can edit every node in a leo document in this "notebook".
Future version will probably only allow editing a subtree.

Note how headlines are "toned down" with small, grey font. Intention
is that e.g. with ipython notebook, the headline will just be a
running, uneditable sequence number basically.
leonb2.png

Ville M. Vainio

unread,
Apr 28, 2012, 4:38:53 AM4/28/12
to leo-editor
On Sat, Apr 28, 2012 at 11:37 AM, Ville M. Vainio <viva...@gmail.com> wrote:

> Result is as attached. What it currently does is putting every node
> wrapper in a list of QObjects, and use that as the model in QML side

BTW, forgot to mention that I put the NodeWrapper stuff under
leo.core. We can move it out eventually, but right now it seemed like
a natural place for this kind of cross-plugin utility.

Kent Tenney

unread,
Apr 28, 2012, 9:21:40 AM4/28/12
to leo-e...@googlegroups.com
Interesting ...

Am I correct: this is POC, edits in your serialized pane don't reflect
in the Leo file?

This is a hint of something I've long wanted, what I have called
'slurped' vs 'chunked'
Something I miss with Leo is the capability get an overview of a file,
I find myself
needing to 'open file with gvim' to grok at file level.

The pane you are generating offers both at once, I can see the linear
view of the file,
retaining the 'chunk' metadata (node headlines)

Ville M. Vainio

unread,
Apr 28, 2012, 1:33:38 PM4/28/12
to leo-e...@googlegroups.com

Yes, modifications are not saved yet. Also, modifications in normal body editors are not copied over to the notebook yet.  This is probably going to end up like tabula and stickynotes in this regard.

Getting an overview of a file could be an interesting extra usecase, my main interest is still in using it for interactive programming/computation (like ipython notebook) .

On Apr 28, 2012 4:22 PM, "Kent Tenney" <kte...@gmail.com> wrote:

Ville M. Vainio

unread,
Apr 29, 2012, 3:38:25 AM4/29/12
to leo-editor
This leo script is more polished version of the earlier work (ctrl+b
script). It uses QStandardItemModel to host the entries in the
notebook, so you can add / remove / modify items and the changes
reflect in the notebook in real time.

https://gist.github.com/2540690

Ville M. Vainio

unread,
Apr 29, 2012, 4:07:41 AM4/29/12
to leo-editor
Some modifications done, attached is screenshot with tree level
nesting as well. I moved the headistring to the left edge, since on
the right edge the tree structure looked weird.
leonb_nesting.png

Ville M. Vainio

unread,
Apr 29, 2012, 4:12:50 AM4/29/12
to leo-editor
And on related note: remember that with QML, sky is the limit as far
as the styling goes :). So if you have wild ideas about adding
customizable images, animated checkboxes, or other weird stuff next to
the nodes, fire away.

Ville M. Vainio

unread,
Apr 29, 2012, 9:25:22 AM4/29/12
to leo-editor
Update: qmlnotebook.leo (ctrl+b script + test outline) is now at
contrib branch. If you want to try it, open the .leo file, ensure you
are running latest Leo from trunk, and press ctrl+b on the first node.
Reply all
Reply to author
Forward
0 new messages