On Thu, Mar 15, 2018 at 7:45 AM, Edward K. Ream <edream...@gmail.com> wrote:

>
> Contrary to your statement in #808, the recommended css is:
>

​Sorry, I was confused.  In #808 talk about other css.  You say:

This is the Leo recommended css to add an image to the background.

QTextEdit#richTextEdit {
  background-image: url(dark/logo.png);
}

...

The following *does *work...

QTextEdit#richTextEdit {
  background-image: url(/home/chris/leo-editor/leo/themes/dark/logo.png);
}

...

[This *doesn't* work]

QTextEdit#richTextEdit {
  background-image: url(~/leo-editor/leo/themes/dark/logo.png);
}

Ok.  This definitely *is* a teachable moment.

We programmers often have to understand the process by which things
happen.  We try to shield users when we can, not always successfully.

Themes are a middle ground.  Theme designers (devs) sometimes can act like
users, and sometimes they must know all the grungy details.

In this case, the principle is that the *final* stylesheet must have
absolute url's everywhere.  That is, Qt is going to look *in one place only*
for each piece of data.

In *my *case, print-style-sheet shows the following:

QTreeView::branch:closed:has-children{
image:
url(C:/leo.repo/leo-editor/leo/Icons/nodes-dark/triangles/closed.png);
}
QTreeView::branch:open:has-children{
image: url(C:/leo.repo/leo-editor/leo/Icons/nodes-dark/triangles/open.png);
}

Which means that (some part of) Leo has resolved:

@string tree-image-closed = nodes-dark/triangles/closed.png
@string tree-image-open = nodes-dark/triangles/open.png

to full paths.  The question is, which parts (of Leo) convert relative
paths to absolute paths?
*Basic Skill 1*

The relevant code turns out to be ssm.expand_css_constants & helpers.

I could have found this by finding the StyleSheetManager (ssm) class in
qt_gui.py. A non-word search on "class style" finds this class.

So the first basic skill is knowing the classes that are relevant to the
task at hand. For themes, the two classes are the ssm class and the
LoadManager (LM) class in leoApp.py.

*Basic Skill 2*

I'm working on themes at present, so I had clones of most of the relevant
code in an organizer node.  I named this node "#766: Create Theme menu,
etc."

This node was already the last top-level node of the outline, but it could
have been near the bottom of *another *organizer node called "Recent code".
The recent code organizer hides nodes so I don't get overwhelmed by all the
stuff on my plate.

The second basic skill is to keep clones of your recent work, where you can
find them easily.

*ssm.expand_css_constants *

To recap, the theme designer (dev) must ensure that stylesheets contain
only absolute urls.

The dev could encode those url's directly in the stylesheet, but that would
make the stylesheet limited to a particular environment.  So devs will use
settings, and the css will include @constants referencing those settings.
Like this:

QTreeView::branch:closed:has-children{
    image: @tree-image-closed;
}

In short, ssm.expand_css_constants replaces those @constant with absolute
urls.

*A hack that must be generalized*

Now we come to one of Leo's best features/conventions:

    *A method's children are its helper methods*

Indeed, this was the first Aha in Leo's history: webs are outlines in
disguise. It was very difficult to see that Knuth's sections were organized
(in his mind only!) as an outline.  Leo makes this explicit.

This matter a great deal!  I *always* forget implementation details, but
the helpers show me where the details lie.

In this case, one of ssm.expand_css_constants's children is
ssm.set_indicator_paths. Here is its docstring:

    In the stylesheet, replace (if they exist)::
        image: @tree-image-closed
        image: @tree-image-open
    by::
        url(path/closed.png)
        url(path/open.png)

    path can be relative to ~ or to leo/Icons.

...

And voila, we see:

A. Where absolute urls get created.

B. Why only certain paths work.

C. How this "hacky" method might/must be extended to handle other
@constants.

*Summary*

It's much slower to explain all this than to do it. *Processes are easier
than descriptions*.

I want you to learn the processes involved, not the details.

ssm.set_indicator_paths must look in more places for icons.  One way to
reduce the need for herding cats is to create common utility methods.  I'll
look into this.

Leo's tree-handling code resolves icon boxes completely independently of
stylesheets. It may be that this *other* code needs generalization to
handle theme.  FYI, the code is qt_gui.getImageImageFinder.  I didn't
remember this code, I found it in a recent clone.

HTH.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to