I use Coded UI in VS2012.
I would like to solve an interesting problem.
For example, there is an application which has got a window and it has got a title with dynamic content.
I would like to search this window via it's title.
The next titles are the possible cases:
"AAAAAAAA This is a window title ASDASDASD or"
"BBBBBBBB This is a window title WSDWSDWSD or not"
"CCCCCCCC This is a window title ASDASDASD or"
"........ This is a window title ASDASDASD"
I would like to search something which contains "This is a window" and "or not".
If i could use regex, i use the following expression to find this title: *This is a window*or not*.
I emphasize, that is only an example. The essential is there is a title which contains some fix strings.
I know, that a UITestControl has PropertyExpressionCollection which name is SearchProperties.
I can add to it a PropertyExpression(propertyName, propertyValue, conditionOperator) object.
The problem is: i can decide the SearchProperties with two step (formally):
WinWindow.SearchProperties.Add(WinWindow.PropertyNames.Name,"This is a window", PropertyExpressionOperator.Contains);
WinWindow.SearchProperties.Add(WinWindow.PropertyNames.Name,"or not", PropertyExpressionOperator.Contains);
How can i do it in one simple step?
Or which solution can implement this requirements?
Thanks in advance,
Peter
For reasons mentioned above it seems the best solution is to iterate thru all the windows under the desktop. Here's a snippet (for testing I'm looking for a notepad window) I'm not too proud of, but works and finishes under one second:
UITestControl result = null;
var TM = Playback.GetCoreTechnologyManager("MSAA");
var desktop = UITestControl.Desktop.GetChildren()[1].GetProperty(UITestControl.PropertyNames.UITechnologyElement) as UITechnologyElement;
var windowEnumerator = TM.GetChildren(desktop, null);
windowEnumerator.Reset();
while (windowEnumerator.MoveNext())
{
UITechnologyElement current = windowEnumerator.Current as UITechnologyElement;
if (current.Name != null &&
current.Name.Contains("Notepad") &&
current.Name.Contains("Untitled"))
{
result = UITestControlFactory.FromNativeElement(current.NativeElement, "MSAA");
break;
}
}
}
I used the MSAA technology manager because it was about seven times faster than using the UITestControls. Going down to MSAA level (IAccessible) can finish the job in about 50 milliseconds but using WinApi functions may get you the same results.
I'm sorry, I can't think of any simpler solution for this problem at the moment.
There are couple of ways to do it,
1. If you know how the Title of the page is dynamically generated,
create a static variable/class and generate the title at run time and use your code.
If you are aware of the possible Title's, create a static class and hardcode the values there.
Related
One of my dialog window's title is shortened (like "My Dialogt..."). If the dialog was slightly wider, the whole title would be completely displayed, which would look nicer.
It seems as if there is no setting in Qt to do that. I have found a hack for a QMessageBox here: Can QMessageBox::about adjust size to title length?, but it is not general. For example it would have to take also the sizes of the icons to the left and to the right of the window title into account to compute a really good minimal size where still the title is completely shown.
Is there a general way to accomplish that? Is there also a simple way to do that? Or is this overengineering?
Not only this goal is questionable (see vahanco comment) but it is hard to achieve, because the window title bar is not Qt territory at all: apart from being able to set its text and manage to show or hide close/min/max button using window flags, there is little else in control, there.
By the way, a very raw way to set a dialog minimum width which could (could) make room to the whole text is the following:
const QString text = "Very very very very very very very very very very very very very long window title";
setWindowTitle(text);
QFontMetrics metrics(font(), this);
setMinimumWidth( metrics.horizontalAdvance(text));
This won't work out of the box, and it's very likely that the text stay cut, because the font used is supposed to be the same used in the title bar (which usually isn't) and we're not taking into account the frame width, the icon width, the title bar buttons width, and everything else which is owned by the window manager and is totally unknown to Qt.
So, you can figure out how much extra space is needed by all these stuff, and adjust the width with a totally arbitrary extra padding like
setMinimumWidth( metrics.horizontalAdvance(text) + 256);
and maybe get what you wanted in the first place (if you still really want it).
The accepted answer did not work for me.
The below code works in QT 5.15. According to the documentation after you call setMinumumWidth() you must call updateGeometry() update geometry docs. Setting minimumWidth should update the sizeHint. That was not happening for me. Also QFontMetrics::horizontalAdvance was not returning the width of the text. I had to use QFontMetrics::boundingRect({title_string}).width().
Calling resize on the dialog is what finally got it working for me. If the accepted answer doesn't work for you give this a try.
QString message = "Message for the user";
QInputDialog dialog = QInputDialog(this);
dialog.setLabelText(message);
QString longTitle = QString("Super long test title for making sure the widget will show all of the stupid long title.");
dialog.setWindowTitle(longTitle);
dialog.setInputMode(QInputDialog::TextInput);
auto fontMetrics = dialog.fontMetrics();
auto width = fontMetrics.boundingRect(longTitle).width();
dialog.resize(width + 200, dialog.rect().height());
const int ret = dialog.exec();
I've got a pretty old MFC application that's been touched by many people over the years (most of them probably not even CS guys) and it follows, what I like to call the "anarchy design pattern."
Anyway, one of the dialogs has a series of 56 vertical sliders and check boxes. However, there are additional sliders and checkboxes on the dialog as shown below.
Now, the problem is that the additional sliders and checkboxes take on IDs that are in sequence with the slider/checkbox series of the dialog. My task is to add more sliders and checkboxes to the series (in the blank space in the Slider Control group box) Unfortunately, since IDC_SLIDER57 through IDC_SLIDER61 are already in the dialog (same goes for the checkboxes), existing code, such as the snippet below will break:
pVSlider = (CSliderCtrl *)GetDlgItem(IDC_SLIDER1+i);
Is there a better way to modify the resource file without doing it manually? I've seen a third party tool called ResOrg that looks like it'll help do what I want, but the software is a bit pricey, especially since I'll only use it once. I guess I can give the demo a try, but the limitations might restrict me.
FYI, I'm using Visual C++ 6.0 (yes...I know, don't laugh, it's being forced upon me).
Instead of writing:
pVSlider = (CSliderCtrl *)GetDlgItem(IDC_SLIDER1+i);
you could write:
pVSlider = (CSliderCtrl *)GetDlgItem(GetSliderID(i));
where GetSlider is a function that returns the id of slider number i.
GetSlider function
int GetSliderID(int nslider)
{
static int sliderids[] = {IDC_SLIDER1, IDC_SLIDER2, IDC_SLIDER3, .... IDC_SLIDERn};
ASSERT(nslider < _countof(sliderids));
return sliderids[nslider];
}
With this method the IDC_SLIDERn symbols dont need to have sequential values.
I'm having a problem when trying to show a context menu (resource) on a right-click at the systray.
I've detected that this line:
CMenu menu;
menu.LoadMenu(IDR_MENU1);
HMENU hMenu2 = menu.GetSubMenu(0)->Detach();
--> m_pTrayMenu = theApp.GetContextMenuManager()->ShowPopupMenu(hMenu2, point.x-5, point.y, this, TRUE);
Stalls the program for about ~1.5 seconds. Edit: But only the first time this code is being run.
However, it only stalls if I have this line:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
If I change that to Office2003 instead, it works (though it doesn't get the nice visuals that I want)
I've tried looking on MSDN and different forums but it doesn't say anything about *Office2007 non-compatible with ShowPopupMenu().
I'm out of ideas. Can anyone help me shed some light on this issue?
Best regards,
Anton.
I've gotten a response from the MSDN forums:
(after being taken to the devs, this is the response I got):
As per the devs this behavior is by design. The delay is mainly
because of some XML parsing being done to load the office colors. The
color details are stored in an XML resource file.
The thread can be found here:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/32d796a3-7b42-431e-9e1e-f58fb0dee0be/cmfcpopupmenu-and-cmfcvisualmanageroffice2007-not-a-good-match
Thank you all for your response and help.
My current solution is doing this:
CMFCPopupMenu *c = new CMFCPopupMenu;
delete c;
directly at the start of the program (thus having a ~1 second load before showing the main window).
Thank you all.
Best regards,
Anton.
I searched for the answer in the forum, but I didn't find anything, if I am wrong, I am sorry.
Anyway, question is simple, I have this Frame, with a Status Bar I use to print messages or notifies.
I would like to use it for mistakes or not permitted operations. But I would like these messages to be coloured. I am looking for a solution on wxPython demo -because i read somewhere on the web to get some inspirations by it-, but i still did not find anything.
Do you have any ideas or solutions?
thank you in advance.
I would try the SetForegroundColour or SetBackgroundColour methods of the status bar widget. These methods don't always work on every platform though as each OS has its own rules and wxPython follows those rules. If they do not work, then you'll have to roll your own statusbar, probably by using a couple of panels in a sizer or a splitter window.
There is also the 3rd party EnhancedStatusbar widget which might work for you. It can be found at http://xoomer.virgilio.it/infinity77/main/EnhancedStatusBar.html
Simple solution: pin wx.StaticText on the status bar and write text in it. Text coloring in wx.StaticText works well.
For example:
self.sb = self.ws.CreateStatusBar()
self.sbtext = wx.StaticText(self.sb, -1, '', pos=(8, 4))
...
self.sbtext.SetForegroundColour(wx.Colour(color))
self.sbtext.SetLabel(text)
We're using Infragistics grid (most probably, we'll have 8.2 version at the end) and we want to configure row/cells appearances "on-demand" in order to be able to provide sort of "dynamic appearance".
For example, I want some cell to be red or green, depending on its value. We might want to tweak other characteristics as well (font, size, image, etc).
A perfect place to do it would be some event, that happen before a cell gets repainted... But it seems there is no such event in Infragistics...
Or am I wrong? Any help?
Clarification: I'm talking about WinForms Infragistics UltraGrid
I had to do exactly this with the IG WebGrid a few years back, and it was ... shall we say ... painful. However, the WebGrid had the advantage of a single render point -- once the HTML was emitted, we were set!
For dealing with this in WinGrid, I tried a variety of different events, both on the grid and the datasource, and met with abject failure every step of the way. The only event I got to work was Paint, which will likely create a performance issue.
For Paint, here's what I hacked together. I'm not proud of this code, and I likely wouldn't put it in production, but here it is anyway (C#):
private void UltraGrid1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
foreach (UltraGridRow r in UltraGrid1.Rows)
{
foreach (UltraGridCell c in r.Cells)
{
if (c.Text == "foo")
c.Appearance.BackColor = Color.Green;
}
}
}
and VB:
Private Sub UltraGrid1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles UltraGrid1.Paint
For Each r As UltraGridRow In UltraGrid1.Rows
For Each c As UltraGridCell In r.Cells
If c.Text = "foo" Then
c.Appearance.BackColor = Color.Green
End If
Next
Next
End Sub
There is an event. I don't remember exactly what it's called, but it's got to be something like 'DataRowBound' or 'ItemDataBinding', etc..
Also, this article might help.
Not that this has anything to do with your question, but I'd stay away from heavy use of Infragistics controls - they're very heavy and will slow down the page rendering process considerably. Just my $0.02.
We have finally come up with two solutions for that problem.
For some of the dynamic content we use grid elements appearance and reinitialize it "on-demand".
For the extremely resource-critical appearance we use UltraGrid.DrawFilter (see also IUIElementDrawFilter interface).