python leo/extensions/myleoqt.py
For the little it is worth, in so far as I understand Vitalije, and I don't completely understand him, I think he is right.
About clones, we always talk about cloning nodes, but it seems to me that what actually gets cloned is an entire subtree - that is, the clone includes (clones of) a node's descendants. Perhaps a change in the conceptual model of clones from nodes to subtrees would make it easier to work out how to handle them.I'm not sure how a subtree is currently modeled in Leo. Since a tree can be built out of nodes that have child and parent nodes, one can be constructed without an explicit model for a (sub)tree. But since many operations we want to do are really on (sub)trees and not nodes, maybe an explicit tree concept in addition to a node concept would be useful(if there isn't one already).
interesting stuff - but I want to check.question an assumption here. As far as I know tk has not been retired, and Leo 'must' continue to support it. Or have I missed some news?Jon N
The relevant code is in the mvc-prototype branch in leo/extensions/myleoqt.py.Leo architecture follows MVC design pattern. However during its long history some code parts ended up misplaced. In this post I'll try to explain why I think that the present split between Model, View and Controller is not optimal.
def make_undoable_move(self, oldparent, srcindex, newparent, dstindex):
t = self.tree
root = t.invisibleRootItem()
trash = []
newitems = [(x, oldparent.child(srcindex).clone())
for x in all_other_items(root, newparent)]
def domove():
for item in all_other_items(root, oldparent):
trash.append(item.takeChild(srcindex))
for item, child in newitems:
item.insertChild(dstindex, child)
curr = move_treeitem(oldparent, srcindex, newparent, dstindex)
self.tree.setCurrentItem(curr)
def undomove():
for item, child in newitems:
item.takeChild(dstindex)
for item in all_other_items(root, oldparent):
item.insertChild(srcindex, trash.pop())
curr = move_treeitem(newparent, dstindex, oldparent, srcindex)
self.tree.setCurrentItem(curr)
domove()
self.c.addUndo(undomove, domove)
My apologies for the noise in that case. I had not realised that tk was no longer supported. "at least a decade"? - wow, how time flies...
in this prototype all those outline operations are made at the same time in both tree widget data-model and in v-nodes. This eliminates need for synchronization between these two models. No need for c.redraw_after..., c.redraw, c.redraw_later,... No need for several locks, for checking if the selected position is visible or not, is it outside hoist/chapter,...
several months ago, I concluded that Leo-Editor positions are a very bad idea and that using GNX's instead would be much simpler and much more robust.
I also concluded that in a directed graph, I don't need clones because multiple parents is no big deal in a directed graph.
Consequently, I stopped worrying about clones. So I don't know if clones make GNX's inadequate as pointers, requiring that v-nodes be used as pointers instead of just GNX's.
For the little it is worth, in so far as I understand Vitalije, and I don't completely understand him, I think he is right.
About clones, we always talk about cloning nodes, but it seems to me that what actually gets cloned is an entire subtree
I'm not sure how a subtree is currently modeled in Leo.
Since a tree can be built out of nodes that have child and parent nodes, one can be constructed without an explicit model for a (sub)tree. But since many operations we want to do are really on (sub)trees and not nodes, maybe an explicit tree concept in addition to a node concept would be useful(if there isn't one already).
What about user scripts that modify outline?User scripts should work without any modification. They can freely modify outline using the standard Position class or even directly manipulating v-nodes. This will certainly cause tree widget data model to get out of sync. The possible solution would be to make a snapshot of the current outline shape before executing user script. When the script finishes, Leo will compare outline shape with the last snapshot and apply differences to the tree data-model to re-synchronize it. The code for this re-synchronization can be found in another branch tree-refresh.
I checked out tree-refresh, then attempted to clone qt_tree.py:Traceback (most recent call last):
File "c:\leo.repo\leo-editor\leo\core\leoCommands.py", line 2282, in executeAnyCommand
return command(event)
File "c:\leo.repo\leo-editor\leo\core\leoGlobals.py", line 245, in commander_command_wrapper
method(event=event)
File "c:\leo.repo\leo-editor\leo\commands\commanderOutlineCommands.py", line 736, in clone
c.redraw(clone)
File "c:\leo.repo\leo-editor\leo\core\leoCommands.py", line 2950, in redraw
p2 = c.frame.tree.redraw(p)
File "c:\leo.repo\leo-editor\leo\plugins\qt_tree.py", line 309, in full_redraw
self.drawTopTree(p)
File "c:\leo.repo\leo-editor\leo\plugins\qt_tree.py", line 635, in drawTopTree
apply_deletes(deletes)
File "c:\leo.repo\leo-editor\leo\plugins\qt_tree.py", line 596, in apply_deletes
v2i[vch].remove(chitem)
ValueError: list.remove(x): x not in listEdward
For outline modifications initiated by scripts we will have to redraw the outline. To make it quick I plan to use diff algorithm similar to one I wrote earlier in the tree-refresh branch.
I would still recommend that p.clone and other methods for model modifications get redirected to tree.clone_node, tree.move_node_up,... and others. They will automatically update view. This updates should be quite fast and no need to distinguish them from pure model modifications. This screen updates can be prevented by using tree.blockSignals if necessary.
The only way to modify the outline that we can't really control is when scripts use only v-nodes for making direct links like parent_v.children.append(child) or similar. For those modifications we need to redraw the tree after each script execution.
All modifications from the Leo core, should be just redirected to their doubles implemented in tree (c.clone -> tree.clone_node, c.moveOutlineUp -> tree.move_node_up, ...)
I've expressed before that I feel that the use of the word "clone", does not really capture what we are doing here, in fact, due to its use in biology
Leo does not support a tk gui. It hasn't for at least a decade. See leoPlugins.leo#Plugins-->Gui.It's possible to run tk code from Leo, but that is another matter entirely.
I'm not saying that the term that the term should be abandoned, just that it should have the points that you see, mentioned more explicitly in the documentation. Personally, my understanding of cloning from biology lead me astray.
"Clone" is as term of art, it's just that it's meaning in Leo is more specialized than it is in general usage.
I've had trouble in the past trying to get my point across to Edward, I suspect that in part, this is due to different thinking styles, I tend to see thinks visually, coming up with a mental model, and elaborating on that so it has all the behavior of the system I'm modeling.
Leo sucks me in every time I come back for a visit, (it's a pleasant side trip each time), currently, I've been pulled towards a review of the documentation. Going round and round with Sphinx trying to get a PDF rendering as I find that easiest to review.
In a week or so, I'd like to do some teleconferencing with Edward, (not Zoom, but something with the ability to share computer screens), so I can do a show and tell on some of the stuff in Leo I'm working on.
Tom
>>> I've never had a problem with the term as used in Leo. To me, it conveys 1) that a (clone) node looks different from another because it appears in a different place, but 2) if you look closer, it's exactly the same inside.I'm not saying that the term that the term should be abandoned, just that it should have the points that you see, mentioned more explicitly in the documentation. Personally, my understanding of cloning from biology lead me astray.
In a week or so, I'd like to do some teleconferencing with Edward, (not Zoom, but something with the ability to share computer screens), so I can do a show and tell on some of the stuff in Leo I'm working on.
Actually, Zoom does let you share your screen. The host can let any participant take control, and they can share their screen.
Thanks for this update. Vitalije recently created a prototype in Tk, so there is actually some code available.The great advantage Qt has (or had) over Tk was in the appearance of text. Has Tk improved in that regard?
On Windows, a new API call tells Windows that tk scales for DPI. On Windows 8.1+ or 10, with DPI compatibility properties of the Python binary unchanged, and a monitor resolution greater than 96 DPI, this should make text and lines sharper. It should otherwise have no effect. (Contributed by Terry Jan Reedy in bpo-33656.)
Thanks Matt and Thomas, I'll look into that. It's not that I want to avoid Zoom so much, I want to demonstrate some work flow stuff, (Windows 10, some Powershell stuff, and It's virtual workspace), so that's why I need to show what's on my screen.
If anyone is interested, and it's okay with Edward more people could jump on the call .
The great advantage Qt has (or had) over Tk was in the appearance of text. Has Tk improved in that regard?