What are good options for Windows GUI toolkits for a Perl program? - windows

I am considering doing some automation of tasks on my Windows desktop (e.g. sorting through large collections of music/text/photo files, etc...).
Seeing how my main area of developer expertise is Perl on Unix, I'd prefer to stick to Perl for coding the business logic of whatever I need done, just for the sake of development efficiency.
The question is, if I want to slap some GUI on top of the work (ala Perl::Tk on Unix), what are my GUI toolkit options and which one would you recommend using?
Please note that I'd like this question to be a good learning opportunity to other SO users, so I would welcome ANY answers even if they don't necessarily satisfy my own limitations/needs listed below, although notes elaborating on how your solution relates to these considerations would be very welcome.
My considerations are mostly driven by the fact that I want a quickly developed tool for personal use to save myself time on tasks I now do manually.
Main consideration is Perlishness of development - "Easy things should be easy and hard things should be possible" as a Perl slogan goes. Especially the first part :)
Prefer (but not insist) to be as native as possible as far as components used. E.g. rather re-use Windows' file open dialog vs. having some custom Java dialog.
I would prefer to use something that would have a small learning curve (e.g. no need to learn intricacies of OLE/COM), since the goal here is speedy development of tools I need to simplify my life as opposed to developer education which I concentrate on areas more relevant to my day job :).
But I definitely would love to get exposure to something new/cool while doing this, e.g. if some nice Monad based GUI components are suggested I'm definitely curious.
Performance matters (e.g. I may need to display a directory listing with >10000 files), but is not of paramount concern - I am a pretty good GUI designer and developer and can always architect my app and design a GUI to scale well if needed).
I would strongly prefer (though not insist on) a framework that does not force me to compile stuff. e.g. Perl libraries are more preferable to custom Java stuff I need to compile. But if the framework is perfect in all other respects, I'm open to a compiled solution (as long as it doesn't required me to purchase Visual Studio or somesuch - I want to build a Windows GUI front-end for personal use, not invest in becoming a Windows developer).
I'm pretty open and flexible outside of above constraints. Some ActivePerl/Strawberry Perl libraries, MS PowerShell based components - heck, if nothing better shows up I'll just install Apache on my PC and build a web front-end :)

With respect to "perlishness" of the interface, I'd suggest plain old Tk. Unfortunately, it looks quite antiquated and non-win32-ish.
If you want native widgets, I think your best shots are using the native Windows GUI via Win32::GUI or Wx. I have no experience with Win32::GUI, but Wx is quite nice. It does, however, have a rather steep learning curve and the interface isn't very "perlish". The C++ roots show a little bit (for better or worse).
There are a few Tk-replacements that are actually thin wrappers around Tcl/Tk (I think Tcl::Tk and Tkx). They look more modern than Perl/Tk, but I have no hands-on experience with these either. If you're developing for Windows only, have a look at ActivePerl which comes with (I think) Tkx. Their ppm4 package manager is written using it and looks pretty nice!

There are a number of options listed in perlfaq3 and some additional ones that aren't. I'm only familiar with the Tk-based ones.
Perl/Tk has the most "perlish" interface but it hasn't been updated to take advantage of tile (native/themed widget) support in the current version of Tk (and probably never will be). Tkx uses a different bridge to Tk. It allows access to everything in Tk (and it's faster, too) but the syntax is less perlish. Tkx is designed to be a thin wrapper over Tk; you have to consult the Tk documentation for most things and translate for using it from Perl. The Tcl/Tk module uses the same bridge as Tkx but supports a syntax that's mostly the same as Perl/Tk.
Whether or not you need to compile anything depends on which version of Perl you use. If you use Strawberry Perl you'll probably have to compile something no matter what toolkit you choose. ActivePerl distributions have included Tkx since sometime in the 5.8.x cycle and stopped bundling Tk as of 5.10, although it's still available via PPM. Tcl/Tk is available from CPAN but I haven't been able to get it to work with the Tk library that comes bundled with ActivePerl; you may need to install Tcl separately to use it.
Personally, I used to use Perl/Tk but now use Tkx.

While Tk and Qt are also available (more general frameworks originally intended for other languages, on which you can also use Perl), and Tk probably most popular as it's been around longest, Win32::GUI would seem to meet your requirements best. If you like WISIWYG GUI designers, you could use Loft on top of Win32::GUI, but you don't have to if you'd rather do everything programmatically.

Shameless plug - I am in the process of writing a pure Perl GUI toolkit, XUL::Gui that renders its GUI using Firefox. It allows you do anything Firefox can (XUL, HTML, JavaScript, Flash, other web tech). Firefox uses the native look and feel of the OS (or any other theme you want), and is available for most platforms.
use XUL::Gui;
display Window title=>'My Application',
Button( label=>'click me', oncommand=>sub{ shift->label = 'ouch'} );
It's currently under development, but probably stable enough to start working with. The idea is to be as simple and perlish as possible. Nearly all boilerplate is optional, with sensible defaults. For example, the Window tag is only needed because I wanted to title the window.
The module is up on CPAN. I'd encourage anyone to take a look, and send me feature requests or bug reports.

I'd just stick with Tk myself. It runs on Windows and you already know it.

I would choose GTK because because it has a study guide (at the moment I'm using Wx and there's plenty of available source code in Perl using Wx but no actual official documentation .. apart from some articles, so no book ... no official stuff) , if not Qt is an option also , and it has some proper documentation(but I haven't tried it).
Tk has very big problems and I won't use it.
As for your performance problems ... I'm pretty sure no decent application would be concerned if it's displaying 100000 or 10^100 files , since very few fit on your
screen, so you can do some clipping.

If it is just to get a simple GUI on top of your scripts then the easiest path is VB.NET (or C#). That is what I do.
With Visual Studio's designer it is just a matter of designing the form, double click on the button that will that start processing, add code to read off parameters from the GUI elements (e.g. file paths in TextBox'es) and pass the information to the script through environment variables or command line parameters.
Example from one of my applications (used by real users):
Dim inputFolder As String = txtInputDataMGFfolder.Text
Dim outputFile As String = txtOutputMGFfile.Text
Dim ws As WshShellClass = New WshShellClass
Dim objEnviron2 As IWshRuntimeLibrary.IWshEnvironment = _
ws.Environment("PROCESS")
objEnviron2.Item("INDIR") = inputFolder
objEnviron2.Item("OUTFILE") = outputFile
'It may or may not help for this: the user dialogs for selecting
'files may change the current directory and running the Perl
'script or one of the .pm files would fail.
ws.CurrentDirectory = appPath()
ws.Run("%COMSPEC% /K perl -w MultRawPrepare.pl", 1, False)
Note that use of Windows Script Host for this may not be strictly neccessary, but if it
is then this is needed:
'Requires adding reference to project:
' menu Project/Add Reference/COM/Windows Script Host Object Model
' Note: "Windows", not "Microsoft".
'
'Note: the DLL may not be registered;
' D:
' cd \WINNT\system32
' regsvr32 wshom.ocx
Imports IWshRuntimeLibrary 'For WshShellClass.
appPath() is defined as follows (and required "Imports System.Reflection" in the beginning of the VB.NET file):
Public Shared Function appPath() As String
'"[Assembly]" requires System.Reflection
Dim strAppDir As String = _
Path.GetDirectoryName( _
[Assembly].GetExecutingAssembly().GetModules(False)(0).FullyQualifiedName)
Return strAppDir
End Function 'appPath
User selection of files or folders is easy to add, but is helped by HOW-TO instructions and a little bit of boilerplate code.
The Express edition of Visual Studio for VB.NET is free.

Related

Quick and simple programming language

Is there someone that can suggest me a programming language that allows you to write quickly GUI programs (on windows platform)?
P.S. I am interested on only languages that do not rely on virtual machines and then have a compiler that produces executable code directly on the machine
I would go with AutoIT, it's a very easy to learn windows scripting language with tons of functionalities: http://www.autoitscript.com/autoit3/index.shtml
I'm using it to automate some tasks, but it can do way more than that.
EDIT
Just to make things a little bit clearer for everybody:
You can create new applications using AutoIT and the Aut2Exe compiler provided. The .exe files created are stand-alone, thus require no other files but the files that you might need in your app. Everything is free and the AutoIT scripting language has a BASIC-like syntax.
The GUI that you'll use are standard Windows controls. Among the functionalities you have the possibility to automate keystrokes/mouse movements, call the Windows API and external .dlls, manipulate windows and processes and through user created libraries (called UDFs) you can even acces local databases, manage networking tasks, encryption, archiving and many more.
All I can say is that it's worth take a look and the first app I built with AutoIT was done in roughly 8 hours since I started learning. It took a folder as the source and copied everything in a chosen directory, copying files in folders named as the date when the files were created. So the destination directory would have a series of subfolders like:
11.11.2010
whatever.txt
whatever.png
12.11.2010
archive.zip
and so on. Just 8 hours and got me rid of a lot of effort ordering the files myself.
Any .NET will probably be what you're after.
Start with VB.NET which is now called Visual Basic CCYY eg (Visual Basic 2005, Visual Basic 2008, Visual Basic 2010).
If you want something not using .NET framework, you might as well go back to older version of VB and if you want something compilable that'd be like C++ with their MFC (Microsoft Foundation Class).
You need to give more info on the type of gui and what you're using it for. This could be accomplished with Microsoft Access forms and VBA, or you could make an HTML Application (.hta).
I'll put in a vote for Delphi. You can easily write applications by dragging and dropping components on to a form and doing minimal coding in Pascal, which isn't hard to learn. Later, if you decide to go deeper, you can do pretty much whatever you want. And it compiles to native executable code.
Is an executable bundler, that combines the script with the framework/interpreter, good enough?
If so, you might look at Tcl/Tk or Lua.
http://www.powerbasic.com/
http://www.powerbasic.com/aboutpb.asp
Seems like it has a RAD GUI and of course it's BASIC, plus it compiles down to .exe (as I understand it.) Might be worth checking out.
A 'quick and simple' language will only allow you to do 'quick and simple' things - and for those, having a VM or not wont make much of a difference to you.
For quick and simple & native code, about all I can think of is RealBasic. Its cross platform Windows/Mac/Linux. I find their IDE to be difficult to work with due to its inflexibility and the help system last I looked wasnt that great, but the underlying language isnt bad and does compile to native code. So it might do the trick for you.

Best approach for building a multiplattform graphical interface for a command-line application

I developed a command line application, whose binary runs in Linux, Windows and Mac OSX. It reads some text input files, but I realize that some special users can not handle this. I would then like to build some kind of graphical interface, where the user only finds buttons and scroll bars for selecting the input parameters, a big "run" button, and then it reads the output of the program and makes some figures.
I also need that everything gets finally packed in a single file, which uses only static libraries, so the user just needs to copy the file to his/her machine and run it.
I would like to know what is the best open source and multi-platform approach to do this. 10 years ago I played a bit with something similar on DEC machines, so I guess that nowadays the situation has probably improved a bit.
P.S. For designing the graphical interface, I am looking for a graphical approach, where you add buttons, scroll bars with the mouse
P.S. 2: the interface is really simple, just need less than 10 buttons, 5 text fields and 2 scrolla bars
Thanks
For advanced UIs, I would generally recommend writing a different UI for each platform (since each platform has its human inteface guidelines). However, is this going to be a simple UI, then one of the cross-platform UIs.
You also didn't mention what language you want to use.
Lastly your "1 exe file" is a bit of a myth - it applies only to Windows. On MacOSX, we use the magic app folders, so it doesn't matter how many files comprise your app, you still get drag-n-drop installs.
Look into GTK+ which originated on Linux, or wxWidgets.
Tcl/Tk is a perfect choice. No other language provides as good of a deployment solution. You can create a virtual filesystem that has your application along with icons, sound files, etc into a single file for each platform (called a 'starpack'). You can even include binary executables and libraries, though those have to be copied to the actual filesystem at runtime to be used.
You also have the option of a two-file deployment -- a platform-specific runtime called 'tclkit', and a platform-independent application file called a 'starkit'. The one starkit will work on all platforms without recompiling, rebundling, etc. It can even have platform-specific parts built-inside and chosen at runtime.
A professional Tcl/Tk developer could do a front end to a command line program in a day without a graphical GUI design tool, easily. If you're new to tcl it will obviously take longer, but that is true of any language. The point being, Tk is remarkably easy to use and doesn't require a graphical GUI designer.
For a cross platform UI, you can use GTK (if using C) or QT (if using C++).
If you can live with a rather huge application package to deliver be sure to look at https://electronjs.org/ You can keep your functionality in your commandline apps and build a modern look and feel UI using HTML5 CSS JS and before thinking "this is ridiculous" consider that Microsoft's Visual Studio code is built on this and compared to GTK / wxWidgets you can do wonders with this. It isn't even hard to do but you either love it or hate it. I'm still undecided...

Scripting language that can produce a small, independent, Windows EXE?

I'd like to do some light data processing - a little binary data manipulation followed by conversion to text serialization. The result is written to a file, and processed by an external program (run by my program). The data processing is more than I'd care to consider doing in batch files.
I'd prefer to use a scripting language, but not have to install the language first. The target computers are mostly older Windows boxes, which are disconnected from the network (no updates, such as PowerShell)
I'm not familiar with the various language's tools for creating EXE files. Which ones have solutions that work well and don't produce huge files? (i.e., whole interpreter package plus my script.)
For my money (its free) AutoIt 3 is exactly what your looking for. AutoIt produces relatively (250k is the standard overhead) small stand alone exes. It has a full perl like regex engine so your light data processing should be a breeze (I've written some pretty heavy data processing scripts in it myself). When downloading autoit be sure to get the full version including Scite this makes compile to exe a one click operation.
I know I might get flamed for this, but VB 6 is a viable option. Since XP SP2 (I think, possibly earlier), Windows has come with its runtimes installed. Not sure about vista.
Theres also the Windows Scripting Host that uses VBScript and JScript.
http://en.wikipedia.org/wiki/Windows_Script_Host
Lua is an excellent choice for that kind of stuff. You can integrate it in your executable or use the standalone Lua interpreter to run your scripts.
While waiting for answers I ran across Shoes, which can make Ruby .exe (I'm most familiar with Ruby) I got it mostly working, although the size of 2.4MB was a bit larger than I'd like. However, I found that it would crash when changing application focus.
I switched to a 'regular' terminal script, and found rubyscript2exe, which, after working around a problem with rubygems, seems to work, and creates a ~700kb file.
I did rather like some of the options presented, but it's not worth redeveloping at this point.
Python with py2exe. Depends on what you mean by small though.
Would using PowerShell script be something you've considered. The data processing might be richer there.
Why not knock up a .NET application? There are free editions of the IDE, and the Framework comes with Windows as a standard component (which also includes a C# compiler, as it happens.)

Programming language for GUI compilable to native binary

I need to write an app that reads a config file with info on the menu bars it needs to create.
Normally, I'd just use java, but I need the application to have the least run-time dependencies possible, this includes not forcing the user to download anything, even JRE, let alone something like NET Framework.
So I need something that can compile to an EXE (windows only for now), and that will allow me to CODE the GUI, so I can dynamically create it from my config.
BTW: something like C++ is a bit too low level, all I need is to create menus, and display HTMLs in a panel.
How about wxPython together with py2exe?
There is a nice tutorial on how to do it here.
If Java's too high-level and C++ too low-level, there ins't much in-between. Maybe Delphi?
I wouldn't totally write off using Java and/or Python for a few reasons.
1) py2exe can compile your Python code to an exe.
2) GCJ can compile your Java code to an exe.
Delphi is best chose for you. Because Delphi compile source code into native x86.
Unless you have serious reasons to avoid interpreted languages, I would suggest you better look into ways of packaging or compiling interpreted scripts because doing this will likely reduce your learning and development time.
I would write a simple GUI in Tcl/Tk, and then package it as a Starpack.
ActiveState provides a distribution (ActiveTCL) and a decent editor (Komodo Edit), and it is fairly easy to get simple GUIs going with Tk. Check out TkDocs for some hand holding.
Once you're done, you can package your code, a Tcl runtime, a database, and a virtual filesystem, all into a single executable that you can easily distribute.
Earwicker is right. You can use HTA:
http://www.interclasse.com/scripts/htanotepad.php
But if you know C++, then creating this type of an application is actually very easy with Visual C++. Use MFC, and statically link everything. You can draw the menu in the resource editor, and attach events to the menu items. I wouldn't use HTML if I were you. Just use regular Windows controls. But if you're really set on using HTML, you can embed a Browser control in the formview.
Have you considered D ? It has a syntax that is like a mixture of Java, C++ and Python with the ability to make native windows apps. The tutorials on dprogramming.com are great to get up and going with the language. For quick GUIs you'd be interested in The D Forms Library and the Entice Designer.
Here are some short video tutorials to get up and running with Entice.
Alternatively, have you tried Qt & Qt Creator? It takes a lot of the hair pulling out of C++ Programming and it's also cross-platform.
You say:
all I need is to create menus, and
display HTMLs in a panel.
A lot like a Web browser, then. If it's going to run on Windows, then the user has IE. Why not use IE to do all the work for you?
You can make something a lot like an .exe with IE, called an .hta:
http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx

What is the quickest path to writing a lightweight GUI program on Windows?

I want a small (< 30MB) standalone Windows executable (a single file) that creates a window which asks the user for the location of a directory and then launches a different program in that directory.
This executable has to run on XP, Vista, Server 2003, and Server 2008 versions of Windows in 32-bits and 64 bits on x86-64 architecture as well as Itanium chips.
It would be spectacular if we only had to build it once in order to run it on all these platforms, but that is not a requirement. This is for a proprietary system, so GPL code is off-limits.
What is the fastest way to put this together?
These are some things I'm looking into, so if you have info about their viability, I'm all about it:
Perl/Tk using perl2exe to get the binary.
Ruby with wxruby
Learn MFC programming and do it the right way like everybody else.
What about a WSH script? It won't be an exe, right, but to ask for a folder I don't see the need for an exe file, much less a 30Mb one...
A 1Kb script, save it as whatever name you like with vbs extension and run it. This, in case it's not clear, asks you for a folder name and then runs calc.exe from the system32 subdirectory. You can of course do a lot better than this in 2 or 4 Kb.
Set WshShell = WScript.CreateObject("WScript.Shell")
win = InputBox("Please type your Windows folder location.")
If Right(win,1) <> "\" Then
win = win & "\"
End If
WshShell.Run win & "system32\calc.exe"
To add a Folder Browser dialog instead of an InputBox, check this out.
Clear benefits are:
Simplicity (well, VB is ugly, but you can use JScript if you prefer), no need to compile it!
Compatibility, works on every windows machine I have available (from 98 onwards)
I'd use .NET and WinForms. The idea of scripted solution is appealing, but in practice I often find you end up jumping through hoops to do anything beyond the basic case and still don't have the flexibility to do everything you want.
Quickest way on Windows for a lightweight and fast GUI? One word.. Delphi! It lacks the 64 bit support for now but then FreePascal would come to the rescue.
Having a small stand-alone application and developing it quickly are, I'm sorry to say, usually conflicting requirements.
To be honest, given how incredibly simple the application is, I would write it in C with direct Win32 calls: one call to SHBrowseForFolder() to get the directory, and one to ShellExecuteEx() to run the program. Even MFC is far too heavy-weight for such a modest application. Set the C runtime to be statically linked and you should be able to keep the size of the stand-alone executable to less than 100k. A decent Windows C coder should be able to knock that up in less than an hour, assuming you have one to hand.
Python with either wxWidgets or Tkinter should be able to do this with almost no effort at all. Runs on everything, and py2exe will get you a standalone executable.
Tcl/tk is one solution. You can have a single file executable (including custom images, dlls, etc) using something called a "starpack" -- a virtual filesystem that is both tcl interpreter and application code. I think it would weigh in at maybe a couple megabytes.
From your specifications it would take me personally maybe 15 minutes to get a first working version.
Tcl/Tk has a BSD license.
For all of its flaws, Visual Basic has historically been great for super-simple apps like this.
I agree with the Tcl/Tk answer above. For more information about the starpack that he refers to, see: http://www.equi4.com/tclkit/ it's a Tcl/Tk interpreter available for various OS's all in about 1MB. In the past there apparently has been concerned about the look and feel of Tcl/Tk UI's, but this has been addressed by a new framework named "Tile" that supports the native look and feel of the user's OS.
For a quick and dirty GUI program like you said, you can use an AutoIt script. You can even compile to an exe.
For an GUI example of AutoIt, you can check my stdout redirect script in a previous answer here
wxWidgets; it's cross platform, free, open source and easy to learn
You could do this in MFC and have an executable in under 100k. In general, if you want to keep the size of your executables down, you can use UPX to perform exe compression. If you want an example, take a look at uTorrent. It's a full featured BitTorrent app in less than 300k of executable.
I use HTA (HTML Application) for quick-and-dirty form & script applications. See Microsoft's HTA Developers Center for details and examples. This basically uses HTML for the form, and any HTML-accessible scripting language for the script. Normal browser security is bypassed so that you can get at almost all OS internals. The above site also contains links to several tools that nearly automate the scripting part for you.
PyQt works really well for this. Binaries for Windows here:
http://www.riverbankcomputing.co.uk/software/pyqt/download
A good book here:
http://www.amazon.com/Programming-Python-Prentice-Software-Development/dp/0132354187/ref=sr_1_1?ie=UTF8&qid=1295369454&sr=8-1
And you can freeze these using various methods if you need exe(s).
Similar to what Vinko Vrsalovic said, you can use a HTA application. It is as easy as building a webpage with windows scripting host functionality. I have built a few utilities with jscript and it is really easy and quick
http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx
These responses are unbelievable.
Visual Studio Forms editor lets you draw out WinForms and autogenerates the boilerplate GUI code (which is a pain in the ass at best for most other languages and toolkits). Then you can use C# or any other .NET language. .NET has stock widgets for file pickers. I could write that script in 20 minutes and it will run on every one of your target platforms for free. Draw out the GUI, drag-n-drop a file picker, fill out maybe two hooks to do the "launch a different file than they wanted" thing, done.
I suggest Autohotkey (AHK) or Autoit. Both support win95+ (with caveats for certain functions). They can be compiled into small .exe without external dependency (besides native DLL's).
Pros:
small size
easy to write code
useful for simple - complex operations
can create GUI easily
Cons:
learning curve (as syntax is unusual)
30MB is pretty huge!
Qt (C++) may be the best choice. It is portable, quick to develop and relatively fast to run. With UPX (Ultimate Packer for eXecutables) your program will be 10M+.
Qt (Python) is OK too, but will be slower.
If you want it less than 1M and/or you want it quick, you can write it in C with win32 api, or use Delphi.

Resources