Tree List In A Popup Window


EOlsen

Recommended Posts

I wanted to create a function that would return an item from a modal popup window. The initial problem was once Page.MyPage.PopUpModal() the rest of the calling function continues to execute. My solution was to have the TreeList script set a global variable and then close the window. The calling function would watch for the global variable to be set and then return its value. But this approach is hanging DAQFactory. I'm using a modal window because I want the user to make a selection from the popup window  before moving on and doing something else.

 

The problem seems to be with the while loop waiting for the global variable to be set. If I comment out the while loop, the popup opens up and the global variable gets set as desired. But before all that has taken place the calling function has completed with the global variable still empty. So clearly I'm doing something wrong. What's the right way to go about this?

 

Attached is my testing ctl file.

Select-1.ctl

Link to comment
Share on other sites

Yes, the popup functions are non-blocking.  This was actually done because Windows can't popup windows from secondary threads without servicing the message pump, and DAQFactory sequences don't by default, service the message pump (though in the latest release you can manually service the pump).  So, when you do popupModal(), DAQFactory puts the request into its own queue in the primary application thread, and then returns immediately.  Its funny because you can do system.entrydialog() and system.messageBox() from secondary threads and they both block.

 

But I digress...  Looping while waiting for a user interaction is generally a bad idea.  You should instead consider designing your system to be event driven.  So instead of waiting for some flag, trigger the code that you want to occur when the window closes from the button that actually closes the window.  And if you want to make the popup somewhat generic, use a global variable to store some data so the correct event handling code is fired, or to pass data to that event.  For example, you could set a global variable that holds the object that triggered the popup, then have it call some secondary member function on that object as the event handler.  Something like:

 

class testClass

   function displayPopup()

      global selectionPopupOb = this

      page.selection.popupModal()

   endfunction

 

   function endPopup()

      page.selection.closePopup()

      // do something on end      

   endfunction

endclass

   

Then in the close button in the popup window (the button you create), put:

 

selectionPopupOb.endPopup()

 

This works fine in this multithreaded environment because DAQFactory only allows a popup to be popped up once.  You can't have 3 popup windows all showing the same page.  So as long as the global variable has a unique name for each page, you are ok.

Link to comment
Share on other sites

What I was trying to create was a function like system.entrydialog() but for making a selection from a list of options. And I wanted to use it within another function to assign a value to a local (private) variable. This user selection would  determine what logic path the function followed before returning a value to the function that called it. So having a separate end popup function isn't going to make that possible. The function calling the popup will have exited and the local variable will no longer exist. The correct logic path won't get followed and the function calling the popup will return an incorrect value to the function that called it.

 

My thinking was it wouldn't hurt system performance because the I/O and control logic would continue to run in the background on their own threads while the user interface thread was waiting for user input.

 

Sounds like you are saying I can't get there from here?

 

I still curious why what I tried to do did not work. In my code why was the while loop keeping the popup from popping up?

Link to comment
Share on other sites

Yes you can, and your code works just fine.  The issue is that you are trying to call it from the command alert window, which means it actually runs in the user interface thread.  Once it gets to that while() loop, its going to block servicing the messagePump and DAQFactory is going to appear hung.  If, however, you were to do test.userINput(MyList) from a secondary thread (i.e. another sequence), then it works just fine.

 

A few things:

1) with the just released 5.90.9 there is a function called system.messagePump() that you could put inside of your while loop (with a shorter delay, say 0.05) and your script would probably even work from the command / alert window

2) Your sequence is priority 2 - User Interface.  This does not mean it runs in the user interface thread (the main application thread).  It means it runs at the same priority as the main application thread.  Of course that only applies to the script that gets executed, which in this case is the ClearGlobals(), global test = , and global string MyList = .  The class declaration isn't really run, and its member functions run in whatever thread calls them.

Link to comment
Share on other sites

Yes, it is working when I call it from another sequence. Any chance of being able to change the font size of tree lists? The default font size is smaller than I would like for this use, and I'm guessing other DAQFactory users might appreciate being able to change the tree list font size like we can with other components.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.