deadbug Posted January 26, 2009 Share Posted January 26, 2009 I'm plugging away at my first AutoIt GUI script. I'm looking for suggestions on the best way to organise it. If I put it all in one source file I end up with 1100+ lines, and I still have a few screens to go and I also need to write some actions (i.e. actually make it do something at the end of the day). The alternative seems to be to have a main gui.au3 source that then includes all the other compartmentalised bits (basically one source file per screen, one for gui-related utils, one for file handling etc.). So how does everyone else organise things? BTW: am I missing a really simple way to create structures (or even objects)? Right now I have a function that creates a checkbox and a couple of input boxes and a pair of clickable folder icons. I have to feed it an array (by ref) to keep the ids in (for later processing) and I have to have enums to define what's what (this id for the checkbox etc.). A structure would be ever so handy here ... Thanks for any pointers, -- deadbug Link to comment Share on other sites More sharing options...
Hawkwing Posted January 26, 2009 Share Posted January 26, 2009 (edited) I always create GUIs with KODA FormDesigner (http://www.autoitscript.com/fileman/users/lookfar/formdesign.html)Much easier! Edited January 26, 2009 by pigeek The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 27, 2009 Moderators Share Posted January 27, 2009 deadbug,I think coding style is as much a question of personal taste as anything - if it works and you can understand it when you look at it again after a period of time then it is fine. As to length, my longest script to date is 3000 lines with 12 AutoIt include files and 7 UDFs (mostly written by me). So size itself is not a bar to clear coding.One of the many advantages of the full SciTE package (and perhaps the one installed with AutoIt, but it is so long ago that I used it, I cannot be sure it works there) is the #Region - #EndRegion directive. This enables you to break your code into regions that can be shrunk to a single line. It also forces you to compartmentalise your code - which can only help make it more understandable.Personally I use a #Region system for all my AutoIt scripts (and something similar for all the programming I have done since I began 40-odd years ago) and a sample script would look something like this (each section is a separate region and, of course, not all are needed for every script):SciTE DirectivesShort comment on latest changesIncludesGlobal declarationsCheck if already runningSystem initialisation codeRead INI valuesRead in needed filesCreate tray menuCreate main GUICreate child GUIsMain GUIGetMsg Loop (I tend to use the GUIGetMsg mode as I prefer passing parameters rather than having lots of global variables)Function 1 (these can also be further divided into regions if they are too numerous)Function 2 (these can include further GUIGetMsg Loops if child GUIS are called)...Function nMisc functions (these tend to be little bits of code that are used by many functions)Help/InfoA word on comments. As has pointed out to me on several occasions, I tend to overcomment my code but I prefer to have too many comments to too few. Having had the dubious pleasure of trying to modify code written by an unknown predecessor who virtually never commented, I feel that my approach is the better. I am not suggesting that you comment every line - give the reader some credit - but make the logic and flow clear. You must explain where you could appear to have made an arbitrary decision - you may know why a certain value must be set just so, but will anyone else?Sorry to be so long-winded, but like all things, if you can begin in the correct manner, it makes it so much easier later on.Hope this helps. No doubt others will add their own thoughts - take what works for you.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
deadbug Posted January 27, 2009 Author Share Posted January 27, 2009 I always create GUIs with KODA FormDesigner (http://www.autoitscript.com/fileman/users/lookfar/formdesign.html)Much easier!I did use Koda to start off, but then I found that where, for example, I have a checkbox that decides whether two inputs and their associated folder icons should be enabled or disabled, there didn't seem to be a way to tie all that together. I may have missed a bit (I only spent a few hours playing and using it to proto some screens) but I ended up tweaking bits here and there anyway. Plus it looked like the code size would shrink and be easier to understand if I pushed things down into functions.I might go back to it - it was certainly useful in providing a starting point for my GUI.Thanks-- deadbug Link to comment Share on other sites More sharing options...
deadbug Posted January 27, 2009 Author Share Posted January 27, 2009 I think coding style is as much a question of personal taste as anythingI was careful not to wade in with "So, which is the best editor then" One of the many advantages of the full SciTE package (and perhaps the one installed with AutoIt, but it is so long ago that I used it, I cannot be sure it works there) is the #Region - #EndRegion directive.Ah, excellent. I'd completely missed that feature! Back to one source it is then (at least for now). If I've missed how to have split screen viewing in SciTE, now's the time to tell me, please! (Opening a source file twice would work as long I can mark one as read-only ... otherwise you know what I'll end up doing!).Thanks again,-- deadbug Link to comment Share on other sites More sharing options...
Developers Jos Posted January 27, 2009 Developers Share Posted January 27, 2009 I have coded the #region support in the standard lexer that comes with SciTE and is available in any editor using scilexer.dll and supporting AutoIt3. SciTE doesn't have a multi window option. The only thing you could do is have SciTE open an new session for each file in stead of creating tabs in the same session. To have the option to be able to open a file twice you will also have to tell SciTE not to check for that. Have a look in the SciTE documentation for the keywords to modify. (Ctrl+F1) Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now