I have a related question regarding pop-up menus:
The macro Wayne posted shows an example of how to make a custom pop-up menu. This is very useful; I have added something similar to my startup macro file, to present a custom list of what to do with an image. This approach works well when there is no ROI, but if you click inside an ROI, the recently added ROI pop-up menu shows instead. This is not always desirable, especially when you want to use your custom menu and the ROI is covering all or the majority of the image area. So, is there any way to disable the built-in ROI pop-up menu, to use the image pop-up menu instead? Perhaps one could use a modifier key for this; e.g. the image pop-up would show also inside an ROI if the shift key is held down. Stein -----Original Message----- Sent: 16. desember 2020 18:16 Subject: Re: calling macros or functions from within a macro > On Dec 16, 2020, at 9:44 AM, Cammer, Michael <[hidden email]> wrote: > > I would like to use the pull down menu to run a macro that is in the same text file or a function in the same file. runMacro() requires a file on disk and trying to call a function I defined returns an error message. The following macro code, when saved as a file and installed using Plugins>Macros>Install, creates an image popup menu that with a "My Function" command that calls the function myFunction(). -wayne var pmCmds = newMenu("Popup Menu", newArray("My Function","Fire","Invert LUT")); macro "Popup Menu" { cmd = getArgument(); if (cmd=="My Function") myFunction(); else run(cmd); } function myFunction() { print("successful"); } > For instance, based on https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fimagej.nih.gov%2Fij%2Fmacros%2FCustomPopupMenu.txt&data=04%7C01%7Cstein.rorvik%40sintef.no%7Cb07634b77f3e4a91787008d8a1e67726%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637437358518535936%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=00eCiXUdNGBuoXh1dAI9%2Bf2GfAKCX4n5fjKFm6nooCM%3D&reserved=0, I tried the following with my function testPulldownMenu(). The other commands in the list are mostly macros in the same file. And the B&C commands works fine. > > > Is there a way to call my own functions or macros? Any help greatly appreciated. > > > var pmCmds = newMenu("Popup Menu", > newArray("testPulldownMenu", "Prepare image for markup", "Mark Distal", "Mark Nucleus", "Add Line Segment", "Grays LUT", "Color LUT", > "Brightness/Contrast...")); > > macro "Popup Menu" { > cmd = getArgument(); > run(cmd); > //runMacro(cmd); > } > > function testPulldownMenu() { > print("successful"); > } -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
> On Dec 18, 2020, at 11:03 PM, Stein Rørvik <[hidden email]> wrote:
> > I have a related question regarding pop-up menus: > > The macro Wayne posted shows an example of how to make a custom pop-up menu. This is very useful; I have added something similar to my startup macro file, to present a custom list of what to do with an image. > > This approach works well when there is no ROI, but if you click inside an ROI, the recently added ROI pop-up menu shows instead. This is not always desirable, especially when you want to use your custom menu and the ROI is covering all or the majority of the image area. > > So, is there any way to disable the built-in ROI pop-up menu, to use the image pop-up menu instead? Perhaps one could use a modifier key for this; e.g. the image pop-up would show also inside an ROI if the shift key is held down. With the 1.53h11 daily build, alt-right-click or shift-right-click inside an ROI and ImageJ will show the image pop-up menu instead of the ROI pop-up menu. -wayne > -----Original Message----- > Sent: 16. desember 2020 18:16 > Subject: Re: calling macros or functions from within a macro > >> On Dec 16, 2020, at 9:44 AM, Cammer, Michael <[hidden email]> wrote: >> >> I would like to use the pull down menu to run a macro that is in the same text file or a function in the same file. runMacro() requires a file on disk and trying to call a function I defined returns an error message. > > The following macro code, when saved as a file and installed using Plugins>Macros>Install, creates an image popup menu that with a "My Function" command that calls the function myFunction(). > > -wayne > > var pmCmds = newMenu("Popup Menu", > newArray("My Function","Fire","Invert LUT")); > > macro "Popup Menu" { > cmd = getArgument(); > if (cmd=="My Function") > myFunction(); > else > run(cmd); > } > > function myFunction() { > print("successful"); > } > > >> For instance, based on https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fimagej.nih.gov%2Fij%2Fmacros%2FCustomPopupMenu.txt&data=04%7C01%7Cstein.rorvik%40sintef.no%7Cb07634b77f3e4a91787008d8a1e67726%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637437358518535936%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=00eCiXUdNGBuoXh1dAI9%2Bf2GfAKCX4n5fjKFm6nooCM%3D&reserved=0, I tried the following with my function testPulldownMenu(). The other commands in the list are mostly macros in the same file. And the B&C commands works fine. >> >> >> Is there a way to call my own functions or macros? Any help greatly appreciated. >> >> >> var pmCmds = newMenu("Popup Menu", >> newArray("testPulldownMenu", "Prepare image for markup", "Mark Distal", "Mark Nucleus", "Add Line Segment", "Grays LUT", "Color LUT", >> "Brightness/Contrast...")); >> >> macro "Popup Menu" { >> cmd = getArgument(); >> run(cmd); >> //runMacro(cmd); >> } >> >> function testPulldownMenu() { >> print("successful"); >> } > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Using the shift-key to disable the ROI menu works well, thanks!
Using the alt-key does not work so well because the right mouse button must held down until the sub-menu choice has been selected, or else the context menu disappears when it is released. I think it is most natural to release the right mouse button while moving the mouse to select the relevant menu entry. This works as expected when using the shift key. However, there seems to be a glitch in that the key-down status of the shift-key seems to be stuck, so if the context menu entry calls a macro or functions that has modified behaviour depending on the key down status, it may not work as intended, even when the shift-key is released upon triggering the menu. Please try this test macro, modified from Wayne's example: var pmCmds = newMenu("Popup Menu", newArray("My Function","Fire","Invert LUT")); macro "Popup Menu" { print("Popup Menu"); cmd = getArgument(); if (cmd=="My Function") myFunction(); else run(cmd); } function myFunction() { if (isKeyDown("shift")) print("shift"); if (isKeyDown("alt")) print("alt"); if (isKeyDown("control")) print("control"); print(""); } If you press the shift key to trigger the image context menu also inside an ROI, then release it, and then select "My Function", the function prints "shift" even though the shift key is no longer pressed. This problem is not limited to this specific case of using the context menu. If you have a macro calling isKeyDown installed in some sub-menu in ImageJ (e.g. under plugins), the key down state applied will be the one that was active when the parent menu was activated, not the sub-menu entry. Perhaps this is a Java or Windows issue? I am using Windows 10/64. Stein -----Original Message----- Sent: 19. desember 2020 18:40 Subject: Re: Disabling the ROI pop-up menu > On Dec 18, 2020, at 11:03 PM, Stein Rørvik <[hidden email]> wrote: > > I have a related question regarding pop-up menus: > > The macro Wayne posted shows an example of how to make a custom pop-up menu. This is very useful; I have added something similar to my startup macro file, to present a custom list of what to do with an image. > > This approach works well when there is no ROI, but if you click inside an ROI, the recently added ROI pop-up menu shows instead. This is not always desirable, especially when you want to use your custom menu and the ROI is covering all or the majority of the image area. > > So, is there any way to disable the built-in ROI pop-up menu, to use the image pop-up menu instead? Perhaps one could use a modifier key for this; e.g. the image pop-up would show also inside an ROI if the shift key is held down. With the 1.53h11 daily build, alt-right-click or shift-right-click inside an ROI and ImageJ will show the image pop-up menu instead of the ROI pop-up menu. -wayne > -----Original Message----- > Sent: 16. desember 2020 18:16 > Subject: Re: calling macros or functions from within a macro > >> On Dec 16, 2020, at 9:44 AM, Cammer, Michael <[hidden email]> wrote: >> >> I would like to use the pull down menu to run a macro that is in the same text file or a function in the same file. runMacro() requires a file on disk and trying to call a function I defined returns an error message. > > The following macro code, when saved as a file and installed using Plugins>Macros>Install, creates an image popup menu that with a "My Function" command that calls the function myFunction(). > > -wayne > > var pmCmds = newMenu("Popup Menu", > newArray("My Function","Fire","Invert LUT")); > > macro "Popup Menu" { > cmd = getArgument(); > if (cmd=="My Function") > myFunction(); > else > run(cmd); > } > > function myFunction() { > print("successful"); > } > > >> For instance, based on https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fimagej.nih.gov%2Fij%2Fmacros%2FCustomPopupMenu.txt&data=04%7C01%7Cstein.rorvik%40sintef.no%7Cc812c0beee334b58c6a308d8a5ec2003%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637441780869545440%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=k4rl3ggX1NjcVudKVgL9VfGWKeBTPyNsHUpLxO2alks%3D&reserved=0, I tried the following with my function testPulldownMenu(). The other commands in the list are mostly macros in the same file. And the B&C commands works fine. >> >> >> Is there a way to call my own functions or macros? Any help greatly appreciated. >> >> >> var pmCmds = newMenu("Popup Menu", >> newArray("testPulldownMenu", "Prepare image for markup", "Mark Distal", "Mark Nucleus", "Add Line Segment", "Grays LUT", "Color LUT", >> "Brightness/Contrast...")); >> >> macro "Popup Menu" { >> cmd = getArgument(); >> run(cmd); >> //runMacro(cmd); >> } >> >> function testPulldownMenu() { >> print("successful"); >> } > > -- > ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.no%7Cc812c0beee334b58c6a308d8a5ec2003%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637441780869545440%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=voDtQCruxuiXE1wLVK9mj2Ttncx7WsU2rt2Pdj3RiH0%3D&reserved=0 -- ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.no%7Cc812c0beee334b58c6a308d8a5ec2003%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637441780869545440%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=voDtQCruxuiXE1wLVK9mj2Ttncx7WsU2rt2Pdj3RiH0%3D&reserved=0 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |