Difference between revisions of "Dialog basics"
m (-g switch) |
m (tabs + radio button groups) |
||
Line 25: | Line 25: | ||
dialog [-l] name { | dialog [-l] name { | ||
− | title "text" | + | title "text" |
− | icon filename, index | + | icon filename, index |
− | size x y w h | + | size x y w h |
option type (dbu, pixels, notheme) | option type (dbu, pixels, notheme) | ||
− | text "text", id, x y w h, style (right, center, nowrap) | + | text "text", id, x y w h, style (right, center, nowrap) |
− | edit "text", id, x y w h, style (right, center, multi, pass, read, return, hsbar, vsbar, autohs, autovs, limit N) | + | edit "text", id, x y w h, style (right, center, multi, pass, read, return, hsbar, vsbar, autohs, autovs, limit N) |
button "text", id, x y w h, style (default, ok, cancel, flat, multi) | button "text", id, x y w h, style (default, ok, cancel, flat, multi) | ||
− | check "text", id, x y w h, style (left, push, 3state) | + | check "text", id, x y w h, style (left, push, 3state) |
− | radio "text", id, x y w h, style (left, push) | + | radio "text", id, x y w h, style (left, push, group) |
− | box "text", id, x y w h, style | + | box "text", id, x y w h, style |
scroll "text", id, x y w h, style (top left bottom right horizontal range N N) | scroll "text", id, x y w h, style (top left bottom right horizontal range N N) | ||
− | list id, x y w h, style (sort, extsel, multsel, size, vsbar, hsbar, check, radio) | + | list id, x y w h, style (sort, extsel, multsel, size, vsbar, hsbar, check, radio) |
− | combo id, x y w h, style (sort, edit, drop, size, vsbar, hsbar) | + | combo id, x y w h, style (sort, edit, drop, size, vsbar, hsbar) |
− | icon id, x y w h, filename, index, style (noborder top left bottom right small large actual) | + | icon id, x y w h, filename, index, style (noborder top left bottom right small large actual) |
− | link "text", id, x y w h | + | link "text", id, x y w h |
− | tab | + | tab "text", id, x y w h |
− | tab "text", id | + | tab "text", id |
− | menu "text", menuid [, menuid] | + | menu "text", menuid [, menuid] |
− | item "text", id [, menuid] | + | item "text", id [, menuid] |
− | item break, id [, menuid] | + | item break, id [, menuid] |
} | } | ||
Line 61: | Line 61: | ||
'''Ok and Cancel buttons'''<br> | '''Ok and Cancel buttons'''<br> | ||
You can specify an ok and/or cancel button, and when a user clicks the ok or cancel buttons, the dialog is closed. You can prevent the dialog from closing if a user clicks the ok button by using /halt. | You can specify an ok and/or cancel button, and when a user clicks the ok or cancel buttons, the dialog is closed. You can prevent the dialog from closing if a user clicks the ok button by using /halt. | ||
+ | <br><br> | ||
+ | '''Grouping radio buttons'''<br> | ||
+ | Radio buttons can be grouped together using the 'group' style, followed by the radio buttons you want in the group without the 'group' style. E.g; | ||
+ | radio "Group 1 Option 1", 1, 10 10 100 20, group | ||
+ | radio "Group 1 Option 2", 2, 10 30 100 20 | ||
+ | radio "Group 2 Option 1", 3, 10 50 100 20, group | ||
+ | radio "Group 2 Option 2", 4, 10 70 100 20 | ||
+ | The above would create two radio button groups, each starting where the 'group' style is entered. | ||
<br><br> | <br><br> | ||
'''Default position and size'''<br> | '''Default position and size'''<br> |
Latest revision as of 01:11, 10 November 2008
Basic dialog commands and switches
/dialog -mdtsonkcvie name [table] [x y w h] [text]
Where name is the name by which you'll refer to the dialog, and table is the dialog table name used to create dialog
-m create a modeless dialog using 'table' /dialog -m name table -a used with -m, uses currently active window as the parent -x close a dialog without triggering any events -d open dialog on the desktop, used with -m -h make dialog work with active server connection -t set dialog title /dialog -t name text -s set dialog size/pos /dialog -s name x y w h -r centers dialog -bp interprets size as dbu or pixels -o set dialog ontop of all windows -n unset ontop setting -k click ok button -c click cancel button -v makes the dialog the active window -ie minimize/restore the dialog if created on the desktop -g renames existing dialog using <name> <newname>
The dialog table
You can use the dialog prefix to create a dialog table called name in a script using this format:
dialog [-l] name { title "text" icon filename, index size x y w h option type (dbu, pixels, notheme) text "text", id, x y w h, style (right, center, nowrap) edit "text", id, x y w h, style (right, center, multi, pass, read, return, hsbar, vsbar, autohs, autovs, limit N) button "text", id, x y w h, style (default, ok, cancel, flat, multi) check "text", id, x y w h, style (left, push, 3state) radio "text", id, x y w h, style (left, push, group) box "text", id, x y w h, style scroll "text", id, x y w h, style (top left bottom right horizontal range N N) list id, x y w h, style (sort, extsel, multsel, size, vsbar, hsbar, check, radio) combo id, x y w h, style (sort, edit, drop, size, vsbar, hsbar) icon id, x y w h, filename, index, style (noborder top left bottom right small large actual) link "text", id, x y w h tab "text", id, x y w h tab "text", id menu "text", menuid [, menuid] item "text", id [, menuid] item break, id [, menuid] }
The -l switch makes a dialog table local, so that it can only be accessed by other scripts in the same file.
Dbu vs. Pixels
The dbu option makes mIRC use dialog base units when creating the dialog, this ensures that the dialog will look the same for all users under any size display, etc. Pixels is the default however to maintain compatibility with previous scripts.
The identifiers $dbuw and $dbuh return the dbu per pixel width and height values for the current display. This may or may not be an integer value.
Ok and Cancel buttons
You can specify an ok and/or cancel button, and when a user clicks the ok or cancel buttons, the dialog is closed. You can prevent the dialog from closing if a user clicks the ok button by using /halt.
Grouping radio buttons
Radio buttons can be grouped together using the 'group' style, followed by the radio buttons you want in the group without the 'group' style. E.g;
radio "Group 1 Option 1", 1, 10 10 100 20, group radio "Group 1 Option 2", 2, 10 30 100 20 radio "Group 2 Option 1", 3, 10 50 100 20, group radio "Group 2 Option 2", 4, 10 70 100 20
The above would create two radio button groups, each starting where the 'group' style is entered.
Default position and size
If you specify -1 for any of the x y w h values in the size setting for the dialog, a default setting is used. To make mIRC center the dialog in a window, specify x y as -1 -1. The size setting can be over-ridden in the init event (see below) by using /dialog -s name x y w h.
Example
;create a dialog table with name 'dialogtest' dialog dialogtest { ;set the titlebar text of the dialog to "testing dialog" title "testing dialog" ;define the position and size of the dialog, x and y set to -1 so the dialog is created to the middle of mirc window, width set to 150 and height to 200 size -1 -1 150 200 ;dpu, dialog basic units, so the dialog will be the same size in every resolution option dbu ;a text item that says "Random text", assigning id 1 for the item, x=5, y=10, w=100, h=10, no style text "Random text", 1, 5 10 100 10, } ;now you can call this dialog by writing: /dialog -m dialogtest dialogtest
A bit more in-depth example
; this dialog will calculate how long it is since/untill a specific day ; alias to open the dialog faster alias dt { .dialog -m dialogtest dialogtest } ; the dialog table dialog dialogtest { title "Testing" size -1 -1 200 200 option dbu ; we'll use 2 tabs here, make them start from x/y -1 and w/h 202 so we'll have nice borders when it goes a bit over tab "From ", 1, -1 -1 202 202 tab "Untill", 2, -1 -1 202 202 ; 2 boxes for both tabs to create a nice title and frame (note tab1 and tab2 at the end) box "Time from date calculator" , 3, 2 15 195 183, tab1 box "Time untill date calculator", 4, 2 15 195 183, tab2 ; the dropdown combo boxes for date/month/year selection, we'll do 2 different boxes for the year selection ; one that has past years, and the other one has upcoming years (for different tabs) ; this way we don't have to update the one everytime you change the tab combo 5, 10 25 20 10, drop combo 6, 31 25 20 10, drop combo 7, 52 25 24 10, drop tab1 combo 8, 52 25 24 10, drop tab2 ; buttons for calcultaing the result and to clear the list button "Calculate", 9, 78 24 37 12, button "Reset" , 10, 153 24 37 12, ; show the text above the list, and the empty one (ID 12) is there for an error message, empty at the time being text "Last calculations:", 11, 12 42 50 20, text "", 12, 105 42 100 8, ; then the lists to store earlier calculations, 1 for each tab list 13, 10 50 180 80, sort tab1 list 14, 10 50 180 80, sort tab2 } ; the init event, this event triggers every time the dialog opens, so here we will fill those controls on *:dialog:dialogtest:init:0:{ ; 2 first ones loops through days/months and adds them into dropdown combos var %x = 1 | while (%x <= 31) { did -a $dname 5 %x | inc %x } var %x = 1 | while (%x <= 12) { did -a $dname 6 %x | inc %x } ; these two are for the year selection, first starts from "this year -10 years", and is shown in the 1st tab ; second one starts from this year and goes 10 years forward, this is for the second tab var %x = $calc($asctime(yyyy) -10) | while (%x <= $asctime(yyyy)) { did -a $dname 7 %x | inc %x } var %x = $asctime(yyyy) | while (%x <= $calc($asctime(yyyy) +10)) { did -a $dname 8 %x | inc %x } } ; sclick event for the "Calculate" button on *:dialog:dialogtest:sclick:9:{ ; we'll use these variables for the sake of clarity ; so %day, %month, %year to implode into %date ($base for zeropadding 5 -> 05 etc.) var %day = $base($did($dname,5),10,10,2) var %month = $base($did($dname,6),10,10,2) var %year = $did($dname,$iif($dialog($dname).tab == 1,7,8)) var %date = $+(%year,-,%month,-,%day) ; from $dialog().tab we'll see which tab is active, and choose the right list ID by that var %target = $iif($dialog($dname).tab == 1,13,14) ; again check the tab, and calculate the right duration (ctime - %date, or %date - ctime) if ($dialog($dname).tab == 1) { var %duration = - $duration($calc($ctime - $ctime(%date))) } else { var %duration = + $duration($calc($ctime(%date) - $ctime)) } ; check for errors, if day/month/year is empty (not inputted), or if the calculation returns a negative number if ($mid(%duration,3,1) == -) || (!%day) || (!%month) || (!%year) { ; so we have an error, show it in the empty text field we created, and use timer to clear it after 4 seconds (/did -r) did -a $dname 12 Parameters missing, or wrong date .timerClearError 1 4 did -r $dname 12 halt } ; no errors if we're here, so, just show the result in %target ID in the form of "yyyy-mm-dd + 3days" did -a $dname %target %date %duration } ; sclick event for the reset button on *:dialog:dialogtest:sclick:10:{ did -r $dname $iif($dialog($dname).tab == 1,13,14) } ; dclick event just for echoing a line from the list, when you double click it on *:dialog:dialogtest:dclick:13,14:{ echo -ag $did($dname,$did,1).seltext }