! Simulating a button click - dealing with objects/classes/events - events

I have a python module abc.py which has numerous class and some class inherting from another classes. The entire file has classes that are connected to each other with objects/instantiation.
The function calls are all based off of GUI button clicks. So, functions get called in abc.py, when buttons are clicked.
I need to write a script which does exactly the same function of button clicking, but without me clicking on the actual GUI - you can imagine it automated.
The issue is, the button on the GUI, when clicked, an event is triggered and the button is associated with a function call "def button_press" which takes (self, event) as parameters.
How would I pass it self and event? I want to use the classes/functions in the module "abc.py" as is and also simulate the button click.. Could you give me some pointers on how I could do this?
Thanks

You can either:
Create an appropriate event, fill it with your test data and call self.button_press(your_test_event), from within your gui.
As above but from outside your gui call, app.topframe..button_press(your_test_event),
If your event handler does not use any data from the event then if you def button_press(self, evt=None) you can do a or b without creating an event first,
you can use any one of the excellent python GUI Test tools available - some are listed here.

You'll probably want to look at wx.PostEvent to send events to a button. Or if you're using wxPython 2.9.2 or better, then you can use the new UIActionSimulator, which you can read about here:
http://wxpython.org/Phoenix/docs/html/UIActionSimulator.html
I've heard a number of people who use sikuli for GUI testing. There's also COBRA, which I keep seeing listed on the Tested in Python user's group as a tool for GUI testing, although I'm not entirely sure if you can use it on a wxPython app.

Related

MFC:CDHtmlDialog Purpose/Usages to open other views?

I was thinking of writing a new app where a users selects an option of what procedure they want to perform and the view changes to that until done then goes back to the main menu. I came across CDHtmlDialog and looked like a nice easy way to add a nice looking menu using html. But I wonder if that is the purpose of that class? Can I set it up so when a button or graphic link is clicked it changes out the view to another one (I would need to use traditional things like CTreeView with CListView with a splitter) or is it more for staying within the HTML world?
Thanks.
From the MSDN MSDN documentation
CDHtmlDialog Class is used to create dialog boxes that use HTML rather than dialog resources to implement their user interface.
From what I can gather from your post, I think you should consider SDI application using view classes that you want. To switch views on the command you do not need a splitter window. A static splitter is used to display a number of views in a different part of the splitter simultaneously.

Removing a JavaScript comment through commands?

I am currently developing a website that relies heavily on large blocks of javascript for widgets. Some of these are demanding processes, such as running timers or clocks, so I only want these scripts to activate when their corresponding widget is activated. My proposed solution is to comment out each of these blocks of scripts, and "uncomment" them when the widget is active.
For example, if I have a countdown timer widget, I would like to have my code for the widget completely commented out until the user clicks the widget. When the user opens the widget, I would like the corresponding scripts to become "uncommented" and execute.
Is there any way I can programmatically add or remove comment marks to the Javascript code on the fly? I am looking for some method or command I could use; not something that requires me to physically alter the code.
I saw this in a Google I/O Conference Presentation, so I was just wondering if anyone knew how.
There is a better way to go about it. If you're worried about clogging the event loop: make sure widgets don't have access to the event loop but have to go through your framework to get to it. This allows you to 'sleep' a widget, stop all it's events.
Another thing to keep in mind that is that when widgets are removed you must also clean up any events they have scheduled or you will run into 'dead' code. All events must therefor be scheduled through your framework so you can clean them up if the widget is unloaded.
Code is read and loaded into the JavaScript engine, modifying the code after that point will do nothing.

How to programmatically invoke a Firefox button/addon

For a given button inside Firefox 4, how do I discover the appropriate way to simulate a click using XPCom/JavaScript? I'd like to programmatically invoke a dialog which is currently only reachable by clicking a toolbar button.
More info: I am happily using Mozilla's experimental F1 sharing extension from here:
http://f1.mozillamessaging.com
But I'd like to craft a custom keybinding or programmatic invocation for the share dialog (basically I want to hide my navigation bar but still invoke F1 easily).
I cannot find any straightforward way to do this? I suspect that I just need to peek at (the equivalent of) the onClick handler for the default button and then invoke that in my own XPCom code ... but this seems undiscoverable.
Any help would be much appreciated.
Peeking at the onclick handler might work, if they did it that way. But if they added the functionality using addEventListener then it would not. In that case, your best bet might be to use dispatchEvent to simulate the user clicking on that button.
https://developer.mozilla.org/en/DOM/element.dispatchEvent

How to create a view for a single control?

What is the best way to create a view for a single control that I need to load into a Shell region in a Prism app. I know I can wrap the control in a UserControl, but I suspect there may be a better way.
I am working on a demo app to learn Prism 4. Each module will load a navigation button into an ItemsControl in a region in the Shell. These navigation buttons will function like the Mail, Calendar, and other buttons in Outlook.
I am creating the view in each module that will hold the module's navigation button. The simplest way to create the view seems to be to wrap it in a UserControl. My question is this: Is there a better way to do it? Thanks for your help.
If you need graphical control, what you are doing is the way to go. If you find yourself making all of the buttons look the same (copy - pasting) you might find that a menu registration service is the way to go.
You'd have a service like IMenuService that you register with your container and modules can come around and register menu items to. You can then create buttons for the module. I've provided a sample for this here:
http://dl.getdropbox.com/u/376992/CAGMenus.zip
Your question, though, seems to be about whether or not you need to wrap a control in a UserControl to register them with a region? If that's the question, I believe the answer is no, although you might amend your question to tell us what you are running up against that makes you think this.
I ended up wrapping the control in a UserControl, and it seems to work fine. I am still interested in seeing if there is a better way to load the button, so I will hold this question open for a few days.
Edit 02/22/2011: I tried using a control without a UserControl wrapper, and I got the following error:
Library project file cannot specify ApplicationDefinition element.
I wrapped the control in a UserControl and the error went away.

lazarus gui main menu using forms?

i need to make a form where when a button is clicked then another form/page opens and from that for you can return to the original form in a similar fashion a main menu/sub menu works.
sorry im new to object pascal
Simply add the second form, and then in the button handler do a
secondform.showmodal;
Don't forget to add the unit where "Secondform" is in to the uses clauses of the first unit.
At the FreePascal Wiki you will find a tutorial on how to use Lazarus. You can read it in several different languages.
You can also see this Developing a GUI Application tutorial.

Resources