wxPython - wx.TextCtrl - forcing styles - python

just a simple question on a wx.TextCtrl element.
i have this text field where on an application, where the user can add a string on it.
i want a text field with a red text on it.
so i've generated this code:
self.hRepositoryTextfield = wx.TextCtrl(self.hPanel)
self.hRepositoryTextfield.SetDefaultStyle(wx.TextAttr(wx.RED))
if the user copy on this text field some string with applied font on it (for example a black coloured string, or a string with a particular font) the red color, anyway the default style is not respected.
i would like the style i decide for my wx.TextCtrl is always forced according my settings.
how can i do?
thank you in advance
axel

The SetForegroundColor might work on one OS and not on another. It depends on the native widget. I would set the TextCtrl's style flag to wx.TE_RICH. Check out the wxPython demo for an example. You can also use the StyledTextCtrl or FancyText of even the HTMLCtrl.

self.hRepositoryTextfield.SetForegroundColor(wx.RED)
that should work ....

i solved the problem in this way:
in the first part of the code it is defined my textfield style...
self.hRepositoryTextfield.SetStyle(0, len(self.hRepositoryTextfield.GetValue()), wx.TextAttr(wx.RED))
self.hRepositoryTextfield.SetFont(self.hFontLabel)
self.hRepositoryTextfield.Bind(wx.EVT_TEXT, self.forceDefaultStyle)
... then i bind every text change to my forcing-style function:
def forceDefaultStyle(self, event):
hEventObject = event.GetEventObject()
hEventObject.SetStyle(0, len(self.hRepositoryTextfield.GetValue()), wx.TextAttr(wx.RED))
hEventObject.SetFont(self.hFontLabel)
and it works!

Related

How do you get the current value of a QtLabel in python? - PyQt5 [duplicate]

I now how to set value(number) but can i read that label in some variable. if can't read, in which similar widgets can i put value and read it. Any help would be halpful or someone has an other idea. Maybe like LCD number, spin box
Like this?
QString text = someLabel->text();
Here is the documentation. QLabel.text()
EDIT:
QString text = theLabel.text();
//or with pointer
QString text = theLabel->text();
have you tried :
QString s = YourQLabel->text();
This should work, I guess.
// Thelepaty mode on
You need to use editor widgets, for example QLineEdit or QTextEdit. You may customize it via QSS to look like a QLabel.
P.S. try to improve your English. It is hard to understand, what you are asking.
// Thelepaty mode off

listctrl new line for an data item

I have created a listctrl with some of the data in the listctrl are very long, and instead of showing all of the text it ends with .... For example Att PSSM_r1_0_T is [-10.179077,0.944198]|Att PSSM_r1_0_Y is.... How would i be able to make it so it shows all of the text. Something like
Att PSSM_r1_0_T is [-10.179077,0.944198]|Att PSSM_r1_0_Y is
[-4.820935,9.914433]|Att PSSM_r1_2_I is [-8.527803,1.953804]|Att PSSM_r1_2_K is [-12.083334,-0.183813]|Att PSSM_r1_2_V is
[-14.112536,5.857771]|1
As the text is very long I would prefer if it covered more than one line.
I don't think that is possible to do with a standard listctrl.
Try poking around at the UltimateListCtrl, being a full owner drawn listctrl it has the ability to change the way its looks far more than a standard listctrl.

How to display rich text in a gtk.MenuItem label?

I would like to display rich text in a gtk.MenuItem(), e.g. displaying bold text. So far I have only found that one could pass in a string.
Is it possible to display rich text in such a label? If so, how?
If not, how appalling that would be! :)
Thanks.
You cannot set the menu bold, but you may set the label on it as bold by calling the child :
label = menuItem.get_children()[0]
label.set_markup("<b>Hi Pete!</b>")

How to place a combobox in wxgrid (python)?

I can't find any good information on how to place a combobox inside a cell in a wxgrid. I tried Google, but maybe I'm blind. Anyone have a simple sample to share?
Take a look at GridChoiceCellEditor. You can use it as follows:
choice_editor = wx.grid.GridCellChoiceEditor(choices_list, True)
grid.SetCellEditor(row, col, choice_editor)
The wxPython demo has an example that shows how this is done in the GridStdEdRend.py file itself or from within the demo itself, see the "Editors and Renderers Demo" part of the grid demo. What you're looking for is the GridCellChoiceEditor. See also: http://wiki.wxpython.org/GridCellChoiceEditor

Changing the title of a Tab in wx.Notebook

I'm experimenting with wxPython,
I have a tabbed interface (notebook) and each tab is basically a file list view (yes, I'm trying to make a file manager)
The file list inherits from wx.ListCtrl, and the tabbed interface inherits from wx.Notebook
I'm just starting .. and I had it so double clicking on a folder will cd into that folder, but I want to also change the title of the tab.
How do I do that?
I have the object that represents the file list and the title I want to set it to,
[ EDIT Notebook.SetPageText() takes a number, so I can't pass the tab object directly to it ]
my current approach is to cycle through the tabs until one of them matches my tab:
for tab_id in range(self.GetPageCount()):
if self.GetPage(tab_id) == tab:
self.SetPageText(tab_id, title)
break
This seems rather naive though, isn't there a smarter approach?
I don't know wxPython, but I assume it wraps all the methods of the C++ classes.
There is wxNotebook::GetSelection() which returns wxNOT_FOUND or the index of the selected page, which can then be used to call wxNotebook::SetPageText().
Or use wxNotebook::GetPage() with this index to check whether it is equal to tab.
I think doing something like this helps :
notebook.get_tab_label(notebook.get_nth_page(your_page_number)).set_text("Your text")
If you want to have a reference to the current tab always, you must connect the "switch-page" signal, and save the page in a variable.
As .GetPage returns a wx.Window, I think tab.Label = title should work.

Categories

Resources