wxPython - how to colour the text of a statusbar - python-2.7

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)

Related

Reordering MFC control IDs automatically

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.

Add accelerator ctrl+F for text search

I am trying to add a Ctrl+F accelerator to my gtkmm textview program. I already implemented the search function into an gtk Entry field, so the only thing I need is to get focus the find entry when Ctrl+F is pressed.
I googled and checked tutorials/reference of gtkmm (2.4, I'm working with that) but the only things I found were accelerators in context with menus and toolbars using UIManager, which I don't have in that .cc file I use (and I can't add them, cause its an existing program).
I tried to add an action with an AccelKey on a button or tried the function add_accelerator() but I wasn't able to use them properly (I am pretty new to gtkmm and there aren't enough samples - at least none I understand). Here some examples I tried:
_gtkActionGroup->add(
Gtk::Action::create("find", "Find", "search in file"),
Gtk::AccelKey("<control>F"),
sigc::mem_fun(this, &SrcFilesView::onGtkTxtFindAccKeyPressed));
I didn't know how to add this action to the button (in the toolbar) I created...
_gtkAccelGroup(Gtk::AccelGroup::create()) //initialized in the constructor of the class
...
_gtkBtnFind.add_accelerator("find", _gtkAccelGroup, GDK_Find,
Gdk::ModifierType::CONTROL_MASK, Gtk::ACCEL_VISIBLE);
I tried here something, but I didn't really understand neither the parameters I needed to enter here nor how this method works - ofc it didn't work...
I'd be really happy if anyone can explain me how this things work properly and sorry for my bad english. If there are any things you need just tell me please. Thanks in advance
Greetings
edit: I looked up in the gtk sources and tried to understand the parameters of add_accelerator. Now I tried this but still doesn't work...:
_gtkBtnFind.add_accelerator("clicked", _gtkAccelGroup, GDK_KEY_F /* or better GDK_KEY_f ?*/,
Gdk::ModifierType(GDK_CONTROL_MASK), Gtk::AccelFlags(GTK_ACCEL_VISIBLE));
_gtkBtnFind.signal_clicked().connect(
sigc::mem_fun(this, &SrcFilesView::onGtkTxtFindAccKeyPressed));
UPDATE:
Okay I have understood most I think now, and I know why it doesn't work. The problem is that I have to add the accel_group to the window widget, but I got only a scrolled window and boxes in my program....and now I have no clue how to continue... :)
UPDATE2:
Alright I managed to do it without accelerators by using the "on_key_press_event" handler by checking the state and keyval parameter. Hope this helps some ppl at least ^^.
bool on_key_press_event(GdkEventKey* event) { /* declaration in my constructor removed */
if(event->state == GDK_CONTROL_MASK && event->keyval == GDK_KEY_f
|| event->state == (GDK_CONTROL_MASK | GDK_LOCK_MASK)
&& event->keyval == GDK_KEY_F) {
_gtkEntFind.grab_focus();
}
return false;
}
I would be still interested in a solution with the accelerators if there is any ! Greetings

Search with regular expressions in Coded UI

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.

Extra Icon on NavigationToolbar2QTAgg

I have recently used a solution found in StackOverflow to remove icons on the Toolbar, however, I cannot remove one and I do not know why. I was wondering if anyone has seen and removed this extra icon successfully. The answer I used was: https://stackoverflow.com/a/15549675
This is how I used it:
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
class NavigationToolbar(NavigationToolbar):
# only display the buttons we need
toolitems = [t for t in NavigationToolbar.toolitems if
t[0] in ('Pan', 'Zoom', 'Save')]
And the extra icon looks like:
http://i.imgur.com/DQaq5Vj.png?1
Thanks!
See https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_qt4.py#L586 for where that icon is added. It is done outside of the toolitem list, hence why this method didn't work.
Adding
matplotlib.backends.backend_qt.figureoptions = None
will do what you want.

MFC: Delay when using GetContextMenuManager()->ShowPopup with Office2007 visuals

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.