Announcement

Collapse
No announcement yet.

How to write code to click on buttons

Collapse
X
Collapse
  •  

  • How to write code to click on buttons

    One of the easiest ways to get started writing Igor code is to write something that simply clicks on Asylum buttons in a certain order. Here is how to get started with that.

    1) Bring up the panel that has the button you want to click on.

    2) Hit Ctrl + T to bring up the tools for the panel.

    3) Click on the second button on the left that now shows.

    4) Double Click on the button you want to use.

    5) For buttons there are 2 things you need to get from this dialog. The Control name (First field of the control dialog), and the function the button calls (listed in the procedure popup in the control dialog). You can click on the edit button, and then copy the function's name.
    For example here is the dialog for the Do Scan Button:

    Click image for larger version

Name:	ControlDialog.jpg
Views:	1
Size:	71.7 KB
ID:	19921


    So from this you need to get that the name is DoScan_0, and the function is DoScanFunc. Since this is a button (Checkboxes, popups, etc are all different), the function has 1 argument, and it is probably a string. OK This is where things get a little complicated. Since Igor 5 we have 2 ways we can write control functions, either with a structure or with the classical input arguments. Most of our controls use the classical input arguments, but if you click on edit in the control dialog and see something like this:


    Click image for larger version

Name:	OfflineGraphFunc.jpg
Views:	1
Size:	79.7 KB
ID:	19922



    Which is the function dialog for the little "3D" buttons on the offline image graphs.
    Note that the input argument is Struct WMButtonAction &InfoStruct
    Which is the new style. So you have 3 options:
    A) Always use our function ARExecuteControl, explained below.
    B) If it is a classic style function (Single String argument), write the call to it, such as:
    DoScanFunc("DoScan_0")
    C) If it is a new style function (Single Struct argument), write the call to it, such as:
    Struct WMButtonAction &InfoStruct
    InfoStruct.CtrlName = "DisplayArgyle"
    InfoStruct.Win = "Display0Image0000" //name of graph the button is on.
    InfoStruct.EventCode = 2 //Buttons almost always get event code 2.
    InfoStruct.EventMod = 0 //This tells us things like shift click, or Ctrl click.
    //and finally call the function
    OfflineGraphFunc(InfoStruct)
    If you notice in the dialog above, we put in comments for each field of the structure we use. This is not always 100 % accurate, but should be all the fields we use most of the time. So for the example above, we use the eventMod, which if you want a normal click would be 0. Other functions may use other fields. Now if you were to do this with ARExecuteControl, it is not going to know about these other fields, so if you wanted to call the 3D button with a shift click, then you would have to write a call to OfflineGraphFunc directly.

    How to use ARExecuteControl
    This function tries to click on the control specified, it can handle buttons, Checkboxes, SetVars, Popups, or a tabControl.

    Function ARExecuteControl(ControlName,GraphStr,VarNum,VarSt r)
    String ControlName,GraphStr
    Variable VarNum
    String VarStr
    //This function executes a control of types:
    //Button, Checkbox, Popup, SetVariable, or TabControl
    //The controlName is the name of the control
    //GraphStr is the name of the window the control lives on
    //VarNum is a variable describing the state of the control you want to be in. (i.e checked for a checkbox)
    //VarStr is the same deal as VarNum, just for strings, i.e PopStr for Popups.
    //Note that for popups, VarNum is ignored, the popup list is obtained,
    //and the popNum is found based on the VarStr.


    //error returns
    //0, all is good (as far as we know)
    //1, control does not exist
    //2, Control it not a supported type
    //3, Control does not have a function to call
    //4, Number of arguments does not match control type.
    //7, Function does not exist as a user function
    //9, should be impossible, this should have exited on 2, means this function is screwed up.


    So to use ARExecuteControl, you also need to know the window name the control is on. To get that, bring up the window, and hit Ctrl + Y, copy out the name in the second field, Window Name (not window Title). The up side is that you don't need to know anything about the button's function.
    So for the DoScan button example:
    ARExecuteControl("DoScan_0","MasterPanel",0,"")
    Buttons don't use VarNum, or VarStr
    And to call OfflineGraphFunc: ARExecuteControl("DisplayArgyle","Display0Image0000",0,"")
      Posting comments is disabled.

    article_tags

    Collapse

    Latest Articles

    Collapse

    • Software version compatability
      by Bemis
      There is an issue with the XYZ gains and older versions of the software.
      If you go to version 12 or above, then your system will be using the new gain system. Once you go to the new gains, your instrument should not use versions < 101010.

      If you want to continue using 101010, you need to make sure it is >= 101010+4706
      http://downloads.asylumresearch.com/...01010+4706.zip If you want to continue using 111111, you need to make sure it is > 1126 ...
      2015-05-08, 01:14 PM
    • Building a New real time computer
      by Bemis
      Current recommended system:

      Dell Precision T3500 Workstations
      Intel QuadCore Xeon 3500 series (2.80GHz)
      6GB DDR3 RAM
      2 320GB SATA Hard Drives (RAID1 mirror)
      2012-05-24, 11:14 AM
    • How to install Asylum USB Drivers
      by Bemis
      There are currently 2 versions of the USB drivers, we will refer to them as old and new. The version of the MFP3D software you want will determine if you need old or new drivers.

      MFP3D Version Old Drivers New Drivers
      ...
      2011-06-28, 10:02 AM
    • How to write code to click on buttons
      by Bemis
      One of the easiest ways to get started writing Igor code is to write something that simply clicks on Asylum buttons in a certain order. Here is how to get started with that. 1) Bring up the panel that has the button you want to click on. 2) Hit Ctrl + T to bring up the tools for the panel. 3) Click on the second button on the left that now shows. 4) Double Click on the button you want to use. 5) For buttons there are 2 things you need to get from this dialog. The Control name (First ...
      2011-02-02, 08:39 AM
    • Running Copies of the Igor Pro / AR Software
      by Bemis
      There are typically two main reasons to make a copy of the Igor Pro / AR Software, and they are slightly different.
      1. You want to try out some new MFP3D code. There is a new feature that is in the unstable code that you want to try out, but it is the new code. There are going to be bugs, and so you want to be able to go back quickly, and you don't want other people in the lab to have to deal with the new bugs. This is by far the most common reason, and the easier way to make a Igor
      ...
      2010-03-17, 03:11 AM
    • Reporting Bugs
      by ARadmin
      Send bug reports to [email protected], but to help us resolve it quickly, please read on and learn how to compose a useful report for us to work from.

      Composing your Bug Report

      Effective bug reports are the most likely to be fixed. These guidelines explain how to write such reports.
      Principles

      • Be precise
      • Be clear - explain it so others can reproduce the bug
      • One bug per report
      • No bug is too trivial to report - small bugs may hide big
      ...
      2010-03-17, 01:51 AM
    Working...
    X