A GUI for wmllint
Moderator: Forum Moderators
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
A GUI for wmllint
Following the discussion that started here, I committed a Tkinter-based GUI to allow running wmllint, wmlscope and wmlindent in an easier way.
First of all, have a screenshot: This GUI is completely written in Python, using Tkinter/ttk, and is able to run unmodified on both Python 2 and Python 3, so when the WML tools will be updated there won't be any need to modify it.
This program exposes all of the tools' command line switches, then runs them in a subprocess and posts their output in the text box. I tried to make the interface as self-explanatory as possible, but there are some things that may need improvement.
In order to run it, you must have Python 2.7 installed. Once that you have it, you just double-click on the data/tools/GUI.pyw file. That's it.
That said, please post any bug report or suggestion that you may have.
First of all, have a screenshot: This GUI is completely written in Python, using Tkinter/ttk, and is able to run unmodified on both Python 2 and Python 3, so when the WML tools will be updated there won't be any need to modify it.
This program exposes all of the tools' command line switches, then runs them in a subprocess and posts their output in the text box. I tried to make the interface as self-explanatory as possible, but there are some things that may need improvement.
In order to run it, you must have Python 2.7 installed. Once that you have it, you just double-click on the data/tools/GUI.pyw file. That's it.
That said, please post any bug report or suggestion that you may have.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: A GUI for wmllint
Looks nice, good idea doing it. A pity there is no thumbs up button on these forums.
Re: A GUI for wmllint
What is this sorcery? I can double-click on it and it just works? Nice.
Re: A GUI for wmllint
Looks pretty nice I have a few suggestions regarding labels and layout but I think I'll just create a patch when I get back to my computer, it's simpler.
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
Re: A GUI for wmllint
Thanks, this looks great Elvish_Hunter. Can you provide some basic details on installation requirements for us newbies? I'm fairly sure I've got Python on my system, but when I save the file as a .py or .pyw and run it, the process starts and stops immediately without opening any GUI (the .py opens the console briefly).
I've tried running it on my desktop and in /data/tools. But I'm not very experienced in these matters so not sure what I'm doing wrong.
I've tried running it on my desktop and in /data/tools. But I'm not very experienced in these matters so not sure what I'm doing wrong.
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: A GUI for wmllint
Thank you.Dugi wrote:Looks nice, good idea doing it. A pity there is no thumbs up button on these forums.
Yep. There are two secrets here: file extension and shebang . You may have noticed (and I also reported this fact in the script comments) that it ends with the .pyw extension, instead of the ususal .py. On Windows, this signals to the interpreter that this script must be opened in graphic mode, without creating a command prompt window. On Linux, the first linezookeeper wrote:What is this sorcery? I can double-click on it and it just works? Nice.
Code: Select all
#! /usr/bin/env python2
/usr/bin/env python
because some distros are starting to use Python 3 as their default version.
OK then. I'm waiting for your suggestions!vultraz wrote:I have a few suggestions regarding labels and layout but I think I'll just create a patch when I get back to my computer, it's simpler.
Let me guess: are you on Ubuntu or one of its derivatives? If yes, you must know that several Debian-based distros have two bad habits: first, they split Python in several packages, then they don't install some of them by default, even if said packages are part of the Python Standard Library. In your case, what's probably missing is the python-tk package, so you need to install it:H-Hour wrote:I'm fairly sure I've got Python on my system, but when I save the file as a .py or .pyw and run it, the process starts and stops immediately without opening any GUI (the .py opens the console briefly).
Code: Select all
sudo apt-get install python-tk
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: A GUI for wmllint
Even worse! Win 7. I was unable to find a download link on the python-tk wiki, but I realize it may not be that sort of thing. Here's the output when I try to run another python script in that folder then the GUI.pyw:Elvish_Hunter wrote:Let me guess: are you on Ubuntu or one of its derivatives?
Code: Select all
C:\Program Files (x86)\Battle for Wesnoth 1.11.12\data\tools>expand-terrain-macr
os.py
Usage: expand-terrain-macros.py [OPTIONS] filename1 [filename2 [...]]
Options:
-i Insert the expanded sections into the input file(s) immediately after
their macro definitions.
-a Append the expanded sections to the input file(s)
-r Replace the input file(s) with the resulting output. Previously generated
expansions will be removed. Implies -i if nothing else is specified.
If no options are specified, only the expanded sections will be printed to
stdout
C:\Program Files (x86)\Battle for Wesnoth 1.11.12\data\tools>GUI.pyw
C:\Program Files (x86)\Battle for Wesnoth 1.11.12\data\tools>
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: A GUI for wmllint
That's exactly the OS where I started developing the script! And, exactly as I expected, the script works fine on my computer. Here there is a screenshot proving it:H-Hour wrote:Even worse! Win 7.
The Windows installer automatically installs Tkinter, so you don't need to install anything else. At least this point is OK.H-Hour wrote:I was unable to find a download link on the python-tk wiki, but I realize it may not be that sort of thing.
Yes, it does matter. Mine is 2.7.5 / 32 bit, but any version of the 2.7.x series should do. The 2.6 series won't work as it doesn't have ttk (one of the modules that I use - it's the one that removes the old Windows 95/Motif look from Tk) - however this should print an error message. In case that you've multiple versions installed the question becomes more complex (I had to rework my file associations to be sure that it was opened with 2.7.5 and not with 3.4.0/64-bit).H-Hour wrote:Maybe I just need to install a new version of Python. Does the version number matter?
If you're already on the 2.7 series, you can try reinstalling it, and perhaps upgrading if it isn't already the latest version. I'm aware that, in some cases, this fixed the issue.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
-
- Inactive Developer
- Posts: 165
- Joined: February 4th, 2011, 6:19 am
- Contact:
Re: A GUI for wmllint
I haven't fired this up yet, but this looks like a great tool to make wmllint and the other maintenance tools more accessible. Looking at the code, which looks very clear and well-commented, should help me get to know tkinter and Python GUI development, which is a field I haven't explored at all. The following points have more to do with wmllint itself than with your work.
Verbosity:
I would prefer "terse" to "normal" to describe level 0, I "normally" go with level 1.
Also note that dryrun, which has a minimum verbosity of 1, will knock these settings off. At least as I read your code, you add any -v after --dryrun.
However, if you look at the wmllint code, you'll see that each -v adds 1 to the verbosity level. So -vd yields level 1 (-v sets level from 0 to 1, -d sees that the level is already 1 and does nothing on verbosity), while -dv yields level 2 (-d checks for a minimum level, bumps verbosity up from 0 to 1, -v adds 1 to that).
Convert EOL characters to Unix style:
Note that this won't work on Windows, where Python defaults to universal newlines support. Because it interprets "\n" as "\r\n", it doesn't detect any carriage returns to strip. And even if it did, it would just put them back in when it came time to write the files out.
In fact, any Unix-style files that get changed will get converted to CR/LF endings. If a Windows user really wants to strip the EOL, they should turn to wmlindent.
List files before processing:
Since -v -v will do essentially the same thing, and I like a minimum of level 1 anyway, I consider this option pointless. The difference is that -vv will put a colon after the filename, this option won't.
Enable experimental conversions:
There haven't actually been any experimental conversions since 1.4. I've been meaning to ask Boucman whether those "experiments" made it into Wesnoth 1.4, 1.5, or were discarded.
Disable checks for unknown units:
As part of making wmllint more accessible, you automatically include the core directory. But I designed this option for quick-and-dirty checks that skip the core. Say you just wanted to check real quick that your magic comments now cover all the character ids wmllint didn't recognize before. It would take a couple of minutes for wmllint to process the core files, whereas a check of the add-on directory alone, or just its /scenarios directory, would be much quicker. But without this option, skipping core (or era dependencies) would mean being overwhelmed with error messages about unknown units, unknown races, unknown movetypes, etc.
When the core is automatically included, this option only saves wmllint a little time.
Ignore newlines in messages:
This is the --stringfreeze option. Looking through the wmllint history, it appears that ESR would put this option in during stringfreezes, and take it back out when they were over. Last time, however, he simply left it in, perhaps as an oversight, perhaps because he was drifting away from Wesnoth by the time the stringfreeze ended.
In the wmllint help, it originally said that this option suppressed warnings about newlines in messages. However, the wmllint introduction says that it only suppresses repair attempts, not the warnings, and a look at the code bore that out. However, looking at the code more closely for this post, it appears that today it doesn't really concern newlines at all, but double-spaces after sentences (that is, Farhad Manjoo's notorious "space invaders.") It looks like at some point in the past, it may have also covered the "nonstandard word-wrap style within message" issue.
Verbosity:
I would prefer "terse" to "normal" to describe level 0, I "normally" go with level 1.
Also note that dryrun, which has a minimum verbosity of 1, will knock these settings off. At least as I read your code, you add any -v after --dryrun.
However, if you look at the wmllint code, you'll see that each -v adds 1 to the verbosity level. So -vd yields level 1 (-v sets level from 0 to 1, -d sees that the level is already 1 and does nothing on verbosity), while -dv yields level 2 (-d checks for a minimum level, bumps verbosity up from 0 to 1, -v adds 1 to that).
Convert EOL characters to Unix style:
Note that this won't work on Windows, where Python defaults to universal newlines support. Because it interprets "\n" as "\r\n", it doesn't detect any carriage returns to strip. And even if it did, it would just put them back in when it came time to write the files out.
In fact, any Unix-style files that get changed will get converted to CR/LF endings. If a Windows user really wants to strip the EOL, they should turn to wmlindent.
List files before processing:
Since -v -v will do essentially the same thing, and I like a minimum of level 1 anyway, I consider this option pointless. The difference is that -vv will put a colon after the filename, this option won't.
Enable experimental conversions:
There haven't actually been any experimental conversions since 1.4. I've been meaning to ask Boucman whether those "experiments" made it into Wesnoth 1.4, 1.5, or were discarded.
Disable checks for unknown units:
As part of making wmllint more accessible, you automatically include the core directory. But I designed this option for quick-and-dirty checks that skip the core. Say you just wanted to check real quick that your magic comments now cover all the character ids wmllint didn't recognize before. It would take a couple of minutes for wmllint to process the core files, whereas a check of the add-on directory alone, or just its /scenarios directory, would be much quicker. But without this option, skipping core (or era dependencies) would mean being overwhelmed with error messages about unknown units, unknown races, unknown movetypes, etc.
When the core is automatically included, this option only saves wmllint a little time.
Ignore newlines in messages:
This is the --stringfreeze option. Looking through the wmllint history, it appears that ESR would put this option in during stringfreezes, and take it back out when they were over. Last time, however, he simply left it in, perhaps as an oversight, perhaps because he was drifting away from Wesnoth by the time the stringfreeze ended.
In the wmllint help, it originally said that this option suppressed warnings about newlines in messages. However, the wmllint introduction says that it only suppresses repair attempts, not the warnings, and a look at the code bore that out. However, looking at the code more closely for this post, it appears that today it doesn't really concern newlines at all, but double-spaces after sentences (that is, Farhad Manjoo's notorious "space invaders.") It looks like at some point in the past, it may have also covered the "nonstandard word-wrap style within message" issue.
Ports:
Prudence (Josh Roby) | By the Sword (monochromatic) | The Eight of Cembulad (Lintana~ & WYRMY)
Resources:
UMC Timeline (Dec) | List of Unported UMC (Dec) | wmllint++ (Feb)
Prudence (Josh Roby) | By the Sword (monochromatic) | The Eight of Cembulad (Lintana~ & WYRMY)
Resources:
UMC Timeline (Dec) | List of Unported UMC (Dec) | wmllint++ (Feb)
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: A GUI for wmllint
Haha, thanks . As you may have noticed, I tend to use long variable names and commenting heavily my code, so when I have to modify it I don't become crazy trying to understand what the heck I wrote six months before . This is especially true for libraries that I seldom use, like subprocess (this was my first time using it, and the same could be said for threading and queue). I also tried to mark the differences between Python 2 and 3.I haven't fired this up yet, but this looks like a great tool to make wmllint and the other maintenance tools more accessible. Looking at the code, which looks very clear and well-commented, should help me get to know tkinter and Python GUI development, which is a field I haven't explored at all.
About tkinter: this wasn't the first toolkit that I attempted to learn. The first one was WxPython, but at the time the documentation was terrible, so I quickly dropped it. Later I tried PyGTK (that didn't seem to me much more powerful than Tk; by the way, now it's called PyGObjects) and QT/PySide (and I was really impressed by its sheer power: table widgets, HTML support, print support...).
Anyway, at first I tried with this tutorial in Italian, and by using the pack geometry manager (at first it's easier). Later, I found this guide and switched to the grid geometry manager and the themed widgets ttk. Other notable resources are effbot (although it's outdated), Thinking in Tkinter (doesn't cover ttk) and tkDocs.
That's all for the general advice. If you have more specific questions about learning Tkinter, please PM me.
I admit that I didn't read the whole code of wmllint. I tried to expose all the command line switches as they were reported by its built-in help; but honestly, when running a command line tool, a normal user expects that its switches could be used in any order, not only in a specific order. This, IMO, is a serious design flaw. By the way, I found some mistakes in the wmlscope switches as well:However, if you look at the wmllint code, you'll see that each -v adds 1 to the verbosity level.
Code: Select all
Two long switches are associated with the -d switch: --definitions and --progress
Using --help returns some incorrect switches:
* --deflist (should be --definitions)
* --progress (missing from the list)
* --typecheck (should be --typelist)
* --forced-used (should be force-used)
In some parts of its code, wmlscope is still called macroscope
Really short question: should I remove the checkbuttons for these options?Convert EOL characters to Unix style:
List files before processing:
Enable experimental conversions:
Disable checks for unknown units:
Ignore newlines in messages:
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: A GUI for wmllint
It seems I won't have a clone for awhile, so I'll just post my suggestions, keeping in mind you like verbose labels and I'm not the best GUI designer
- I think at least Maintenance tools output and Select a directory should be changed to Output and Directory just to make things cleaner. Other labels can stay verbose
- Remove the verbs (Set/Select) from the options list labels, so they just read Wmllint Options (etc) as opposed to Select Wmllint Options).
- Remove the folder image on the Browse button only. It results in ugly whitespace above and below the path textbox
- Keep uniform spacing between options. In, for example, the wmlscope tab, the two Exclude options are only one line of text each, resulting in their respecting textboxes to touch. This is visually unappealing, so I suggest keeping the distance beteween options (and so the textboxes) consistent
- Align the top row of buttons (Run, etc) to both the left and right edges, so that resizing horizontally doesn't result in whitespace on the right after the Exit button.
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
-
- Inactive Developer
- Posts: 165
- Joined: February 4th, 2011, 6:19 am
- Contact:
Re: A GUI for wmllint
Well, as someone once said, "(given enough eyeballs, )all bugs are shallow."Elvish_Hunter wrote:This, IMO, is a serious design flaw. By the way, I found some mistakes in the wmlscope switches as well:
I have pushed a fix for the wmllint dryrun issue to 1.12 and master. As for wmlscope, I plan to go bug-hunting when I have the time. About --progress: esr added that option to all his maintenance tools. I noted that I didn't see much use for it in wmllint because of -v -v. In wmlscope, I see --listfiles. I wonder how they differ on a practical level. Of course, I'm sure he meant to invoke it with -p, not -d.
Ports:
Prudence (Josh Roby) | By the Sword (monochromatic) | The Eight of Cembulad (Lintana~ & WYRMY)
Resources:
UMC Timeline (Dec) | List of Unported UMC (Dec) | wmllint++ (Feb)
Prudence (Josh Roby) | By the Sword (monochromatic) | The Eight of Cembulad (Lintana~ & WYRMY)
Resources:
UMC Timeline (Dec) | List of Unported UMC (Dec) | wmllint++ (Feb)
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: A GUI for wmllint
vultraz wrote:I think at least Maintenance tools output and Select a directory should be changed to Output and Directory just to make things cleaner. Other labels can stay verbose
Done.vultraz wrote:Remove the verbs (Set/Select) from the options list labels, so they just read Wmllint Options (etc) as opposed to Select Wmllint Options).
I went for an intermediate solution: I used a 16x16 icon (formerly it was 32x32), and replacedvultraz wrote:Remove the folder image on the Browse button only. It results in ugly whitespace above and below the path textbox
fill=X
with fill=BOTH
, so the Entry will take up all the available space.
That's not easy to do, for two reasons: first, the Checkbutton widget doesn't have a height option. Second, and more important, I'm not convinced at all of the Checkbuttons' texts themselves. Sure, I took the messages straight from wmlscope's --help, but I'm aiming for better descriptions; however, I don't have any idea about what good replacement messages could be.vultraz wrote:Keep uniform spacing between options.
That's a toolbar. I'm sure that you know how toolbars are usually made: a series of buttons (and occasionally other widgets), all placed on the left side . That's why I went for thevultraz wrote:Align the top row of buttons (Run, etc) to both the left and right edges, so that resizing horizontally doesn't result in whitespace on the right after the Exit button.
pack()
method instead of the grid()
one: it's one of the situations where pack()
yields better results than grid()
.That said, theoretically I can make it so that the buttons stretch when the window is resized, or I can make it so that the space between them stretches instead. But both options look terrible. See below: The most that I can do without making a total wreck is moving the Exit button (and perhaps also the About button) to the right side, and this is exactly what I pushed in master.
Done.Groggy_Dice wrote:I would prefer "terse" to "normal" to describe level 0, I "normally" go with level 1.
Given that probably I'll end up removing the checkboxes related to these options (Groggy_Dice wrote:About --progress: esr added that option to all his maintenance tools. I noted that I didn't see much use for it in wmllint because of -v -v. In wmlscope, I see --listfiles. I wonder how they differ on a practical level. Of course, I'm sure he meant to invoke it with -p, not -d.
subprocess.check_output()
posts the whole output in one go, not line by line), the best solution will be having a minimum of consistency between the tools: with that, I mean that the option should be the same for all three of them, be it --progress, --listfiles or another one. I'm not sure about which one will be better, though. Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: A GUI for wmllint
Just a heads up, I backported the GUI to 1.12; IMO it will come in handy for umc devs in the series. Hopefully everything works as expected.
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: A GUI for wmllint
Perfect But you may want to backport two changes that I pushed today, since these days I lack the time to do so.vultraz wrote:Just a heads up, I backported the GUI to 1.12; IMO it will come in handy for umc devs in the series. Hopefully everything works as expected.
First change: I crushed a bug in regexp handling. It turned out that the "r" in my regexps wasn't necessary, because the strings acquired from an Entry widget are already raw; and when they are passed to subprocess, they stay raw.
Second change: before you asked me...
I answered that it was hard to do. Well, I found out that there is a way to do it:vultraz wrote:Keep uniform spacing between options.
Code: Select all
self.options_with_regexp.rowconfigure(row,uniform="regexp")
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)