A GUI for wmllint

Discussion of all aspects of the game engine, including development of new and existing features.

Moderators: Forum Moderators, Developers

A GUI for wmllint

Postby Elvish_Hunter » May 5th, 2014, 4:04 pm

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:
wmllint tab.png
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. 8)
Current maintainer of The Sojournings of Grog, Children of Dragons, A Rough Life and Wesnoth Lua Pack
Co-author of The White Troll
On Wesbreak until the 21th of December
User avatar
Elvish_Hunter
Developer
 
Posts: 1359
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: A GUI for wmllint

Postby Dugi » May 5th, 2014, 4:11 pm

Looks nice, good idea doing it. A pity there is no thumbs up button on these forums.
User avatar
Dugi
 
Posts: 4768
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains

Re: A GUI for wmllint

Postby zookeeper » May 5th, 2014, 5:38 pm

What is this sorcery? I can double-click on it and it just works? Nice.
User avatar
zookeeper
WML Wizard
 
Posts: 9618
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: A GUI for wmllint

Postby vultraz » May 5th, 2014, 10:23 pm

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?
User avatar
vultraz
Community Manager
 
Posts: 824
Joined: February 7th, 2011, 12:51 pm
Location: Dodging Daleks

Re: A GUI for wmllint

Postby H-Hour » May 6th, 2014, 10:35 am

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.
H-Hour
 
Posts: 183
Joined: April 14th, 2010, 12:27 pm

Re: A GUI for wmllint

Postby Elvish_Hunter » May 6th, 2014, 2:43 pm

Dugi wrote:Looks nice, good idea doing it. A pity there is no thumbs up button on these forums.
Thank you. ;)
zookeeper wrote:What is this sorcery? I can double-click on it and it just works? Nice.
Yep. There are two secrets here: file extension and shebang :eng: . 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 line
Code: Select all
#! /usr/bin/env python2
signals that this is a Python 2 script. I went for this, instead of the usual /usr/bin/env python because some distros are starting to use Python 3 as their default version.
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.
OK then. I'm waiting for your suggestions!
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).
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:
Code: Select all
sudo apt-get install python-tk
That should solve your issue.
Current maintainer of The Sojournings of Grog, Children of Dragons, A Rough Life and Wesnoth Lua Pack
Co-author of The White Troll
On Wesbreak until the 21th of December
User avatar
Elvish_Hunter
Developer
 
Posts: 1359
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: A GUI for wmllint

Postby H-Hour » May 6th, 2014, 3:30 pm

Elvish_Hunter wrote:Let me guess: are you on Ubuntu or one of its derivatives?


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:

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>


Maybe I just need to install a new version of Python. Does the version number matter?
H-Hour
 
Posts: 183
Joined: April 14th, 2010, 12:27 pm

Re: A GUI for wmllint

Postby Elvish_Hunter » May 6th, 2014, 7:10 pm

H-Hour wrote:Even worse! Win 7.
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:
GUI.png
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.
The Windows installer automatically installs Tkinter, so you don't need to install anything else. At least this point is OK. :)
H-Hour wrote:Maybe I just need to install a new version of Python. Does the version number matter?
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).
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 The Sojournings of Grog, Children of Dragons, A Rough Life and Wesnoth Lua Pack
Co-author of The White Troll
On Wesbreak until the 21th of December
User avatar
Elvish_Hunter
Developer
 
Posts: 1359
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: A GUI for wmllint

Postby Groggy_Dice » May 13th, 2014, 4:06 am

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.
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)
Groggy_Dice
Developer
 
Posts: 163
Joined: February 4th, 2011, 6:19 am

Re: A GUI for wmllint

Postby Elvish_Hunter » May 14th, 2014, 9:00 am

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.

Haha, thanks :D . 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 :augh: . 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.
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.
However, if you look at the wmllint code, you'll see that each -v adds 1 to the verbosity level.

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:
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

I was planning to fix them, at least partially, but so far I lacked the time to do so, and even to file a proper bug report. Can you do it on my behalf?
Convert EOL characters to Unix style:
List files before processing:
Enable experimental conversions:
Disable checks for unknown units:
Ignore newlines in messages:

Really short question: should I remove the checkbuttons for these options?
Current maintainer of The Sojournings of Grog, Children of Dragons, A Rough Life and Wesnoth Lua Pack
Co-author of The White Troll
On Wesbreak until the 21th of December
User avatar
Elvish_Hunter
Developer
 
Posts: 1359
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: A GUI for wmllint

Postby vultraz » May 15th, 2014, 2:14 am

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 :P

  • 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?
User avatar
vultraz
Community Manager
 
Posts: 824
Joined: February 7th, 2011, 12:51 pm
Location: Dodging Daleks

Re: A GUI for wmllint

Postby Groggy_Dice » May 16th, 2014, 8:00 am

Elvish_Hunter wrote:This, IMO, is a serious design flaw. By the way, I found some mistakes in the wmlscope switches as well:


Well, as someone once said, "(given enough eyeballs, )all bugs are shallow." :lol:

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)
Groggy_Dice
Developer
 
Posts: 163
Joined: February 4th, 2011, 6:19 am

Re: A GUI for wmllint

Postby Elvish_Hunter » May 21st, 2014, 8:57 am

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
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).
Done.
vultraz wrote:Remove the folder image on the Browse button only. It results in ugly whitespace above and below the path textbox
I went for an intermediate solution: I used a 16x16 icon (formerly it was 32x32), and replaced fill=X with fill=BOTH, so the Entry will take up all the available space. ;)
vultraz wrote:Keep uniform spacing between options.
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. :hmm:
vultraz 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.
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 :twisted: . That's why I went for the 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:
bad.png
worse.png
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.
Groggy_Dice wrote:I would prefer "terse" to "normal" to describe level 0, I "normally" go with level 1.
Done.
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.
Given that probably I'll end up removing the checkboxes related to these options (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. :hmm:
Current maintainer of The Sojournings of Grog, Children of Dragons, A Rough Life and Wesnoth Lua Pack
Co-author of The White Troll
On Wesbreak until the 21th of December
User avatar
Elvish_Hunter
Developer
 
Posts: 1359
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: A GUI for wmllint

Postby vultraz » May 25th, 2014, 1:01 am

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?
User avatar
vultraz
Community Manager
 
Posts: 824
Joined: February 7th, 2011, 12:51 pm
Location: Dodging Daleks

Re: A GUI for wmllint

Postby Elvish_Hunter » May 29th, 2014, 1:12 pm

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.
Perfect 8) But you may want to backport two changes that I pushed today, since these days I lack the time to do so.
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...
vultraz wrote:Keep uniform spacing between options.
I answered that it was hard to do. Well, I found out that there is a way to do it:
Code: Select all
self.options_with_regexp.rowconfigure(row,uniform="regexp")
Yes, the uniform= key does exactly what you asked :D . But this option is almost undocumented in Tkinter documentation: it isn't cited at effbot, nor it is in any of the resources that I linked earlier. Do you want to know how I found it? By browsing the Tcl/Tk documentation :augh: .
Current maintainer of The Sojournings of Grog, Children of Dragons, A Rough Life and Wesnoth Lua Pack
Co-author of The White Troll
On Wesbreak until the 21th of December
User avatar
Elvish_Hunter
Developer
 
Posts: 1359
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Next

Return to Coder’s Corner

Who is online

Users browsing this forum: No registered users and 1 guest