|
Davy Mitchell's Meandering Weblog Home - Angus - Christian - Energy - Fun - General - Internet - IronPython - MoodNews - NintendoDS - Personal - Photos - Podcast - Politics - Python - Scotland - Software Blog Statistics Tag Cloud RSS More Feeds Archives2006-12-092006-12-02 2006-11-25 2006-11-18 2006-11-11 2006-10-14 2006-10-07 2006-09-30 2006-09-09 2006-08-19 |
Fast WinForms with TayLayout Permalink
Spend 2 minutes on this blog and you will realise I have been having fun mucking around with WinForms and IronPython. It is nice writing GUI's in pure code and no resource files or form editor to play with but you often have to write a fair few lines of code. Winforms is very Visual Studio centric in the sense that it expects you to use the designer. No thanks - at least not yet. I was looking at the layout classes available ( that is arranging controls on a form for you rather than specifiying positions) and there are 3 (flow, table and split). You can probably guess where this is going
I have made a start on a simple layout manager and GUI creation helper for IronPython, hopefully with the best bits of Swing, wxPython, TKinter and MFC etc. Small steps but should make writing a quick GUI for a script faster. Not ready for a release yet (soon) but here's the sample app: import clr
clr.AddReference('System.Windows.Forms') clr.AddReference('System.Drawing') from System.Drawing import Point from System.Windows.Forms import Application, Button, Form, Label, TextBox from ldlayout import * class MainForm(Form): def __init__(self): Form.__init__(self) self.ALayout = TayLayout() self.ALayout.parent = self self.textbox = self.ALayout.addNewTextBox("The Default Text",True,150,0) self.label = self.ALayout.addNewLabel("StarGate") self.piccy = self.ALayout.addNewPictureBox("title.gif", True, 244, 88) self.button1 = self.ALayout.addNewButton("Press Me") self.button2 = self.ALayout.addNewCheckBox("Some option") self.button3 = self.ALayout.addNewButton("OK", False) self.button4 = self.ALayout.addNewButton("Cancel", False) self.button5 = self.ALayout.addNewButton("Apply", False) # Finally set the size of the Form. self.ALayout.Complete() self.Show() Application.EnableVisualStyles() form = MainForm() Application.Run(form) TayLayout is a more sophisticated version of the flow layout. Items are added in a L to R fashion until you specify that a new line is required. Demonstrated above are the convenience functions for creating and adding a control in one step. Not shown above is a generic AddControl method which takes a sized control and adds it to the flow. The layout is currently 'one off' but that suits my needs for now and is better than hard coded positions.
Posted by Davy Mitchell on
2006-12-21 12:24:42. Creating An EXE with IronPython Permalink IronPython has a few useful samples up on the Codeplex site - today I got the chance to look at them. The most interesting one is PYC which shows how to create DLL's, Console and Windows applications with a single call to the script. Of course, you still need the Dotnet runtime and IronPython but this is even easier than say py2exe which I use for LDBackup. I tried it out on PictureJoiner and it worked first time. It was this straightforward:
I have figured out how to do drag and drop ( I was sure this worked in the CSharp version... ) so as time allows this utility will be polished up and an installer made.
Posted by Davy Mitchell on
2006-12-19 21:42:19. Picture Joiner 2 - Ponies! Permalink Here's an example output image from Picture Joiner.
Posted by Davy Mitchell on
2006-12-17 22:30:11. Picture Joiner Permalink I had great plans to polish and release a version of my IronPython photo tool this weekend but alas I have been a bit under the weather! However I have decided to uploaded the script here anyway. This little program lets you join 4 pictures together into one image. Click on each quadrant to select a picture. You can then drag and drop the pictures until you get a layout you like. Finally, go to the menu and click export to save to a file. Yes it should have a little more error handing and a choice of output image size. I'd also like to drag and drop files onto the picture box - sadly this is not working yet (lazy web?). Hopefully should be just the thing for your Christmas snaps.
Posted by Davy Mitchell on
2006-12-17 21:44:16. |
||