adding submenu in pyqt QWidget - pyqt4

I know its very basic question but I am little bit confused, probably I am forgetting something.
I am trying to add a sub menu "Preview" to the "Tools" in the QMenuBar()
so far this is what I am trying to do
tools = fileMenu.addMenu('&Tools')
prevAction = QtGui.QAction('Preview',self)
prevInNuke = QtGui.QAction("Using &Nuke",prevAction)
tools.addAction(prevAction)
prevAction.addAction(prevInNuke)
but I guess this is not the correct way to add a sub menu

Sub menu should be a QMenu, not QAction:
tools = fileMenu.addMenu('&Tools')
prevMenu = QtGui.QMenu('Preview',self)
prevInNuke = QtGui.QAction("Using &Nuke",prevAction)
tools.addMenu(prevMenu)
prevAction.addAction(prevInNuke)
It can be a bit more simple if you used convenience methods:
tools = fileMenu.addMenu('&Tools')
prevMenu = tools.addMenu('Preview')
prevAction = prevMenu.addAction('Using &Nuke')

Related

Testing excel with Winappdriver

Where can i find a good example of testing an excel addin project with custom ribbon elements, using winappdriver.
What i have so far throws an exception:
System.InvalidOperationException
An element could not be located on the page using the given search parameters.
I am using latest winappdriver
Code:
private const string ExcelAppId = #"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE";
private const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", ExcelAppId);
appCapabilities.SetCapability("deviceName", "WindowsPC");
appCapabilities.SetCapability("platformName", "Windows");
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
session.FindElementByName("Blank workbook").Click();
I'm working on automated testing of an Excel add-in with WinAppDriver.
In my case I started Excel without the splash screen. Supply /e as app parameter to achieve it.
session.SetCapability("appArguments", "/e");
From this point onward, you'll be able to find the "File" menu and "New" menu by name and click them.
Add a few seconds of explicit wait and proceed to finding "Blank Workbook" WindowsElement the same way.
I hope this answers your question, post here if more help is needed.
I've been experimenting with WinAppDriver for a few months now, also preparing a Udemy course on the subject which is almost ready to publish. It's an interesting toolkit.
You need to install Appium.WebDriver, Selenium.support, Selenium.webDriver from "Manage Nuget packages"
you can use appium code like:
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
class Excel
{
public void ExcelCase() {
WindowsDriver<WindowsElement> driver;
AppiumOptions desiredcap = new AppiumOptions();
desiredcap.AddAdditionalCapability("app", #"C:\Program Files\Microsoft Office\Office16\EXCEL.EXE");
driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), desiredcap);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
if (driver == null)
{
Console.WriteLine("App not running");
return;
}
}}
Try this code and comment if you face any issue.
I prefer to use: session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); instead of Thread.sleep(5).
Does it even open the excel when you start the test?
If by Name is not working, it doens't work to me sometimes either, you can use the accessibilityId
session.FindElementByAccessibilityId("AIOStartDocument").Click();
or use the keyboard shorcut to open the blank workbook, like this:
session.Keyboard.SendKeys(Keys.Alt + "f" + "l" + Keys.Alt);

How to give data dynamically in a dialog box using visual c++

How can I send data to a dialog box dynamically?
In a previous project I used edit boxes (e.g for 3 conductors) and gave those data separately for each conductor. Now I have to give them dynamically and I don't have standard number of conductors and I can't use edit box again.
Could you please give me an idea or a good link describing step by step how to create a table in a dialog box dynamically?
I have created a dialog box in which I insert data about conductors (resistivity, permeability, diameter etc (electric power systems Smile | :) )) in edit boxes but I have done it only for 3 conductors. I have to insert-edit the number of conductors and then edit their characteristics. But I can't use again edit boxes because this is static. I want something like a dynamic table which will have rows=number of conductors and columns about is characteristic (resistivity, permeability, diameter)and edit them in dialog box. I don't know how to upload my executable to male clear what I have done but here is a part of my code for the static case of three conductors Smile | :) I want another dynamic way to edit data :/
void CInputView::OnLinefeaturesFeatures()
{
// TODO: Add your command handler code here
CInputDoc* pDoc = GetDocument();
CFeaturesDialog DialogWindow;
DialogWindow.m_DialogCon = m_NumCond;
DialogWindow.m_DialogLayers = m_Layers;
DialogWindow.m_DialogPermeability = m_AirPermeability;
DialogWindow.m_DialogAirConductivity = m_AirConductivity;
DialogWindow.m_DialogAirPermittivity = m_AirPermittivity;
DialogWindow.m_DialogEarthPermeability1 = m_EarthPermeability1;
DialogWindow.m_DialogEarthConductivity1 = m_EarthConductivity1;
DialogWindow.m_DialogEarthPermittivity1 = m_EarthPermittivity;
DialogWindow.m_DialogDepth = m_depth;
DialogWindow.m_DialogEarthPermeability2 = m_EarthPermeability2;
DialogWindow.m_DialogEarthConductivity2 = m_EarthConductivity2;
DialogWindow.m_DialogEarthPermittivity2 = m_EarthPermittivity2;
DialogWindow.m_Dialogfrequency = m_frequency;
if (DialogWindow.DoModal() == IDOK)
{
m_NumCond = DialogWindow.m_DialogCon;
m_Layers = DialogWindow.m_DialogLayers;
m_AirPermeability = DialogWindow.m_DialogPermeability;
m_AirConductivity = DialogWindow.m_DialogAirConductivity;
m_AirPermittivity = DialogWindow.m_DialogAirPermittivity;
m_EarthPermeability1 = DialogWindow.m_DialogEarthPermeability1;
m_EarthConductivity1 = DialogWindow.m_DialogEarthConductivity1;
m_EarthPermittivity = DialogWindow.m_DialogEarthPermittivity1;
m_depth = DialogWindow.m_DialogDepth;
m_EarthPermeability2 = DialogWindow.m_DialogEarthPermeability2;
m_EarthConductivity2 = DialogWindow.m_DialogEarthConductivity2;
m_EarthPermittivity2 = DialogWindow.m_DialogEarthPermittivity2;
m_frequency = DialogWindow.m_Dialogfrequency;
}
}

How to report if a control exists more than once in a web page?

Can anybody say that if a control for example a button is available more than once, we have to say that the button is available more than once.
Look at below Code sample, which might help:
WinButton button = new WinButton(parent);
button.SearchProperties[WinButton.PropertyNames.Name] = propertyValue;
int buttonCount = button.FindMatchingControls().Count();
if(buttonCount > 1)
//then it means that button is available more than once.

Combination button/dropdown in office

How do I add a combination button/dropdown in office (see below). Preferably with code.
Update: If it helps any, code isn't needed.
you can do it, based on the following ActiveX controls:
Microsoft ImageList Control, Version 6
Microsoft ImageComboBox Control, Version 6
Manually, you select "More Controls..." from the [Control Toolbox] menu bar and double click the mentioned controls to get them on your sheet. Position the ComboBox where you want it to be, and disregard the position of the ImageList, it is visible only in design mode. By now you have two embedded contros named
ImageList1
ImageCombo1
The insertion of the two components also creates a reference to ...\system32\MSCOMCTL32.OCX.
Then you
manually add icons (GIF, BMP, etc) to the Image list
manually set the Combo's ImageList property to "ImageList1"
manually set the Combo's AutoLoad property to True
By now you have a Combo with the error but no icons.
Then you execute this code
Sub FillCombo()
Dim SH As Worksheet, OO As OLEObjects, Idx As Integer
Set SH = ActiveSheet
Set OO = SH.OLEObjects
With OO("ImageCombo1").Object
.ComboItems.Clear
For Idx = 1 To OO("ImageList1").Object.ListImages.Count
.ComboItems.Add , , , Idx
Next Idx
End With
End Sub
I've tried hard to create the objects by VBA, but the ImageCombo seems to behave different when created as
Set SH = ActiveSheet
Set OO = SH.OLEObjects
OO.Add "MSComctlLib.ImageComboCtl.2"
' .... etc ....
The combo is created, but the dropdown arrow is not displayed no matter what I do, allthough debugger shows that all ListView elements are neatly attached. Lots of colleagues seem to have problems with that ActiveX, there's loads of posting on the net.
Further reading here

Can you set the FileFilters for a Gtk Dialog in Glade?

In my code, I have lines like this:
Builder builder = new Builder();
builder.AddFromFile(gladefile);
FileChooserDialog dialog =
(FileChooserDialog) builder.GetObject("dialog");
FileFilter[] filters = new FileFilter[2];
filters[0] = new FileFilter();
filters[0].Name = "Some filter";
filters[0].AddPattern("*.someextension");
filters[1] = new FileFilter();
filters[1].Name = "All files";
filters[1].AddPattern("*");
foreach (FileFilter filter in filters)
dialog.AddFilter(filter);
dialog.Filter = filters[0];
dialog.SetFilename(defaultFile);
Is there a way to set up these filters in Glade, rather than doing it manually?
It is possible now. The code snippet should probably look something like this:
builder = Gtk.Builder()
builder.add_objects_from_file("***name of glade file****.glade",
("filechooserdialog1", "filefilter1"))
dialog = self.builder.get_object("filechooserdialog1")
filefilter = self.builder.get_object("filefilter1")
dialog.add_filter(filefilter)
No. You can create a file filter object in glade (version 3.6 and up) and add it to the dialog, but since you can't actually set the name or pattern of the file filter, it's fairly useless.

Resources