Repository navigation
Conversation
There was a problem hiding this comment.
This seems to work as expected, and the style & use of existing GG functions fits well with the existing code - thank you.
I have a few questions/suggestions:
- Would it be better to pass the file path into
add_css_filerather than just the filename? It would need to extract the filename internally to add to the start/end lines. This would mean that the function could be used for loading files from other directories in future. Also, it would avoid having the directory location under GGprefs being referenced in two separate places. - I wonder if the directory should be
cssrather thanCSS? Since the files need a suffix of.css, some users may not often consider upper/lowercase in filenames, and either make the directory lowercase or the suffix uppercase, causing confusion. - Line 1369 can be made clearer by using a feature of Tk index strings to increment by one line, and move to start of line:
end_pos += "+1l linestart"
Or you could usef"{end_pos} +1l linestart"where you useend_poslater - Lines 1371/2 can be combined in one call to
`maintext().replace(begin_pos, end_pos, f"{begin_marker}{css_text}{end_marker}\n") - L 1355/58 - no need to specify
regexp=False- that's the default. - I suggest adding a call to make the inserted CSS visible on-screen, something like:
maintext().set_insert_index(maintext().rowcol(f"{insert_pos}+1l"), top_of_page=True)
You might decide you want to restructure slightly to avoid duplicate calls to undo_block_begin, replace & set_insert_index for the two cases. It should be safe to call undo_block_begin early in the routine if that helps - it doesn't matter if you end up returning without making any edits
The following are more general questions about how to best make use of this feature. I'm happy to discuss them here, or feel free to message me via PM if that's easier. None of this is meant to be negative - just trying to explore the consequences of what would be quite a significant change to the way CSS has been provided by GG2 (and GG1 before it) for a long time.
- At the moment, the default CSS header contains CSS, that as you say, is not used in most projects, e.g. sidenotes, footnotes, poetry, index. Are you thinking we should remove some/all of that CSS from the default, and require the PPer to add in the CSS files they need?
- If the footnote CSS was removed, for example, is there a danger that a PPer might do their HTML conversion, then be confused by the fact that footnotes don't look right, or even submit it without noticing?
- If we did remove CSS from the default header, where would we put it so that PPers could access it? Perhaps in a
data/html/cssdirectory under the release. Would we then want a second HTML menu entry, "Add Default CSS" that lists the CSS files in that directory, and maybe rename your first entry to "Add Custom CSS", for CSS files that the user creates? - Possibly overkill, but another option might be to have a "Configure Default CSS" menu entry too (probably need to put all 3 into a CSS submenu at this point). This would pop a dialog which lists the CSS files in
data/html/csswith a checkbox next to each. When they run HTML autogenerate, it would automatically import all the checked ones. They could then use the Add CSS options to add any more later at any point. The list of checked CSS would be stored as a preference, so persistent from one project to the next. This would have two advantages that I can see: First, a user who would prefer to just get all the default CSS and delete the lines they don't want (as is currently the case) can have that. Second, a user who does mostly simple fiction could have most CSS files unchecked, but one who regularly does non-fiction with footnotes, could have the footnote CSS file checked, so they don't need to keep importing footnote CSS manually for every project. Perhaps the "Configure Default CSS" button should also be in the HTML generation dialog, so when a user is about to create the HTML , they can tweak what will be imported.
I tried both in macOS. Default install isn't case-sensitive, so both worked. But it's a good idea to be aware that some systems are case sensitive. Perhaps make sure that both are acceptable?
As always, there's a balance between providing new and desirable functionality and keeping it recognizable to existing users. I honestly don't see a down-side to reducing the effort it takes PPers to customize CSS.
I think that this comment applies to the above 4 bullet points. If we make CSS fully customizable, and not added 100% automatically while leaving the PPer to remove any unused CSS if they wish to, I think we need to leave the default configuration such that those who don't immediately notice the change won't be surprised by the change, so
I also like the idea of being able to navigate to the extra CSS file so that one can have project-specific extra CSS that is not stored in the GGprefs directory. I can see the value of having both. The people who are most likely to face potential confusion are those who have already customized their CSS per the current method. I haven't thought through how to alert them to the change. |
I don't think there will be a need for a
I'm not sure of the purpose of project-specific CSS files. If you are truly just using the CSS for project X, then edit it into the style section at the top of the file after you create the HTML - if it is that specific, it's likely you won't get it right until after you create the HTML and look at it in the browser anyway. But if you want to use the CSS in several projects (e.g. you enjoy doing drama and have specific CSS for them) put the CSS in your GGprefs, and include it in the relevant projects.
I don't think it will affect them if they use the recommended method, nor if they use the alternative method. In the first case, they will just get whichever files are included by the checkbox list (by default all of them) and their custom CSS will follow it, as it does now. With the alternative method, their custom CSS completely replaces all the GG-supplied CSS, which will continue to be the case. |
|
I've made changes 2-5; see below re:1. 5 was a little surprising since I just copied that from html_convert.py line 1056, but no matter. To respond to your general questions I'll try to describe where I see this going. I'd meant to hold off on this until I had time to try doing it, since in practice my ideas tend to evolve as I work, and I don't really know how feasible this is (especially for me). But here goes... The goal would be to have both GG2-level default and additional css, and user-level default and additional css. GG2-level default is a subset of the full header that gets added by HTML Generator now; additional css is /data/html/css/ (or wherever), sidenotes.css, footnotes.css, etc. At the user-level, there's prefsdir/html-header.txt (which I really want to rename to .css; I imagine most people who'd use this also use a text editor with syntax-coloring based on filename extension, so .css is a functionally better choice than .txt) for default/always include, and prefsdir/css/ for additional .css files. GG2 and user .css filenames are merged into a deduplicated & sorted CSS submenu. If the same file is in both directories, the user's prevails, so e.g. a user can override the default footnotes.css with their own if desired. That's why (for now) I haven't made change 1. I want to pass just the filename to add_css_file, and have that function check first for a user .css file, and then if there isn't one use the GG2 .css file. Can't do that if I pass filepath. On Generate HTML, automatically add css if needed for the project. For example, if there are footnotes, call add_css_file(footnotes.css). The function will then apply the user's footnotes.css if there is one, else the GG2 footnotes.css. If there aren't footnotes, skip it, save the user deleting it later. So, I don't think there would be a need for the complexity of letting the user manually choose css blocks to always include whether needed or not. If it's not needed, it's probably not wanted (but available in the CSS submenu just in case, e.g. if a book has no TOC but someone wants to see the TOC css for reference when setting up a different flex-list). Or put another way, something that has a fair chance of being wanted even when not needed belongs in the default, not a seperate .css file. Let me know what you think, or if I've missed something, etc. For me I think the next step is trying this with probably footnotes.css, see how it goes with something I'm familiar with and use in many though not all projects. An open question is where to draw the line between always-added and added-as-needed. |
It's no problem to specify regexp=False, and I'm not surprised you found an example of it elsewhere, especially since when I started writing GG2 I was also teaching myself python/Tkinter.
Thanks - this overview is very helpful in understanding your idea.
The ".txt" extension is what was always used for the header. I don't know why the original author of GG1 chose that, but perhaps because back then editing a text file (at least on Windows) was easy, by double-clicking it, or perhaps because the default version, included by GG, is not just CSS, since it includes the Then it would insert the default.css file using your mechanism.
That makes sense. There is one subtlety in the current code (not sure if you've come across it), but I think we could argue that it could be removed if we have your new mechanism. It is that if the user's I can see a possible similar danger in your scheme. If we change the default It's not clear to me from your description above (and I understand you are thinking it through yourself too) whether the user's
Subject to my thoughts above about replacement/addition of default CSS, I agree.
I'm very happy to help with any of that - feel free to message with any specific questions |
windymilla
left a comment
There was a problem hiding this comment.
Thanks - your changes look good.
I think it's better for you to continue work and add commits to this PR, but I would be open to merging this into the master branch and you starting a new PR if you'd prefer. This work is harmless to existing users, and they wouldn't see it anyway unless I released a new version, which there is no rush to do.
|
I was thinking that the user's defaults would be added to what comes from GG2, not replace it. But I was aware of the full replacement option (and chose not to use it myself because of not getting updates when the official CSS changes). I think that can still be an option for those who want it, and perhaps something with the release notes could help with user awareness, e.g. if the release notes for the recentmost version contains footnotes.css, then HTML Generate can add a comment about that if the user's footnotes.css is overriding. Just for some extra awareness of the change. But that's just off the top of my head. As for merging to master I'll trust your judgement, it's ok with me to keep this as a branch as I continue working. |
|
Just checking I've understood:
The only other alternative that comes to mind is to allow the custom footnotes.css to either augment or replace GG2's, possibly controlled by a naming convention, e.g. footnotes.css replaces, but footnotes_additional, or footnotes_user, or something like that would add. Or possibly, like the current scheme for the default, it could check if footnotes.css has the GG2 header |
in add_css_file, add support for project-supplied .css files add project-supplied transcriber_note.css file edit html_header.txt to no longer include transcriber note css
|
Merged cleanly with 2.1.8. |
Sounds good.
If I understand correctly there is already a mechanism for this situation: if you look at line 1177 in html_convert.py, it says: It is deciding whether to use the user's header.txt file. When testing, we don't want the user's versions. So, I think at about L1207, you could add a call to Is that what you need? |
I would hold off on this feature for now. I don't really see the need for project specific CSS. If something is specific to a project, then the PPer can just put it in the header of the HTML file after autogeneration. That kind of thing typically needs you to view the book in the browser after autogeneration, then to customize the CSS, so it's better done in the actual HTML header, rather than an external file, I would have thought. |
I know I was initially thinking it would be good to have the option for project-specific CSS, but after re-thinking, I agree. |
|
There might be some misunderstanding here, caused by my misuse of the word "project"? I want GG2-supplied css files (from ../data/html/), in addition to user-supplied css files, to be in the CSS submenu. |
That was exactly it. I read "project" to mean a DP project (i.e. a book) and we don't need CSS on a per-book basis. Everything else you wrote makes complete sense, and I'm happy to go ahead with that plan. After the CSS has been split up a bit more, we'll get Sharon to do some testing on it. |
Ok, good. I'd meant it as in, GG2 is a project (and the endtable I'm building is a project, etc.) but I totally get the confusion. Anyway I'll keep working towards something I can point to and say, here's what I mean... And your response re: testing is just what I needed, thanks. It's obvious in hindsight; I was just going the long way round. |
footnotes.css has been split off from html_header.txt; is applied on html autogenerate if needed the css submenu includes gg2-supplied default css in addition to user-supplied css if the user is fully overriding the html_header.txt with their own, gg2-supplied default css will not be used.
|
Merged with 3.19. Added some functionality we discussed earlier. footnotes.css is now added "if needed" during html generate, and gg2-supplied css files (currently just footnotes.css and transcriber_note.css) will show in the CSS submenu along with user-supplied css files. |
Thanks @arbayai
Agreed
I think this would be good to do, and then we can do some more thorough testing. Are these the blocks you were thinking of?
As you can see, not much work has gone into maintaining the tests after my initial work to add them. I would suggest leaving this initially. After we've done some manual testing / tweaking, perhaps we could add new tests or improve the existing ones. I feel as though to do a proper job on enhancing the testing might be quite a bit of work. |
Looks in user's prefsdir for a css folder. If present, adds a CSS submenu to the HTML menu with the contents of that folder.
Choosing a file from that menu inserts the file's contents, and BEGIN/END markers, at the end of the <style>..</style> section of the HTML. A warning message prompts the user to replace if the file is already present.
A further improvement would be to also look in a project-controlled folder. Then relatively niche standard css, currently added as part of HTML generation (e.g. sidenotes) could be added by the user as-needed instead of adding to every project and requiring manual removal later. Happy to work on that if you'd like.