matplotlib.widgets.TextBox: change color - python

Is there a way to change TextBox text color at any moment? I tried Google already; my question looks too trivial, but I am still at a loss.
TextBox methods:
: dir(matplotlib.widgets.TextBox)
Out[63]:
[
...
'active',
'begin_typing',
'connect_event',
'disconnect',
'disconnect_events',
'drawon',
'eventson',
'get_active',
'ignore',
'on_submit',
'on_text_change',
'position_cursor',
'set_active',
'set_val',
'stop_typing']
AxesWidget superclass methods:
: dir(matplotlib.widgets.AxesWidget)
Out[64]:
[
...
'active',
'connect_event',
'disconnect_events',
'drawon',
'eventson',
'get_active',
'ignore',
'set_active']
Nothing suggestive. At least, to my eye.

A partial answer only - without knowing the fuller application it isn't obvious whether this helps you. There are 2 pieces of text that you can change the color of: the label and the edit box. Below shows how to change each, once.
import matplotlib.widgets
import matplotlib.pyplot as plt
plt.figure(1)
ax = plt.subplot(111)
tb = matplotlib.widgets.TextBox(ax, "Name:", initial="Jane Doe")
tb.label.set_color('red') # label color
tb.text_disp.set_color('blue') # text inside the edit box
If you just want the label text to be different, that persists. But whenever the text inside the edit box (text_disp) is changed, it will be in black again.
This is because widget recreates the text
(by removing and then re-generating and it will be in black again.
The source for the text create method does not have any arguments that the user could modify (color, font size/weight etc) or include as a TextBox instance attribute.
You could write your own subclass that overrides this method. Or perhaps simply setting it after text has been entered is enough for you?

Related

How to remove space between radiobuttons in pyqt5

How To Remove Padding Between Male And Female RadioButtons?
Here's My Code :
def UiComponents(self):
self.gridbox=QGridLayout()
self.label=QLabel("What's Your Gender?")
self.r1=QRadioButton("Male")
self.r2=QRadioButton("Female")
self.r3=QRadioButton("Rather Not To Say")
self.button=QPushButton("Submit")
self.gridbox.addWidget(self.label,0,0)
self.gridbox.addWidget(self.r1,1,0)
self.gridbox.addWidget(self.r2,1,1)
self.gridbox.addWidget(self.r3,1,2)
self.gridbox.addWidget(self.button,2,0)
self.setLayout(self.gridbox)
self.show()
Try changing spacing attribute at setStyleSheet() method like so
r1.setStyleSheet("""
QRadioButton {
spacing : 20px; #(<- example value)
}
""")
QGridLayout works like html table - you got columns and rows, column width is equal to wider widget in column, in your case it's label. To avoid stretching first column, span label across all columns using columnSpan argument of addWidget (and button too).
self.gridbox.addWidget(self.label,0,0,1,3)
...
self.gridbox.addWidget(self.button,2,0,1,3)
I would recomend using QtDesigner to create ui, it saves a lot of time and effort and also wysiwyg.

Change the font on odfpy?

How can I change the font on odfpy for example, using Arial or comic sans. I've seen some examples but they only use the params "fontsize" and "fontweight". I can't find any example changing the font and the param "font" doesn't seem to work.
Section 5.15.39 in api-for-odfpy.odt lists the style.TextProperties as:
5.15.39 style.TextProperties
Requires the following attributes: No attribute is required.
Allows the following attributes: backgroundcolor, color, condition, country,
countryasian, countrycomplex, display, fontcharset, fontcharsetasian,
fontcharsetcomplex, fontfamily, fontfamilyasian, fontfamilycomplex,
fontfamilygeneric, fontfamilygenericasian, fontfamilygenericcomplex, fontname,
fontnameasian, fontnamecomplex, fontpitch, fontpitchasian, fontpitchcomplex,
fontrelief, fontsize, fontsizeasian, fontsizecomplex, fontsizerel, fontsizerelasian,
fontsizerelcomplex, fontstyle, fontstyleasian, fontstylecomplex, fontstylename,
fontstylenameasian, fontstylenamecomplex, fontvariant, fontweight, fontweightasian,
fontweightcomplex, hyphenate, hyphenationpushcharcount, hyphenationremaincharcount, language, languageasian, languagecomplex, letterkerning, letterspacing, scripttype,
textblinking, textcombine, textcombineendchar, textcombinestartchar, textemphasize,
textlinethroughcolor, textlinethroughmode, textlinethroughstyle, textlinethroughtext,
textlinethroughtextstyle, textlinethroughtype, textlinethroughwidth, textoutline,
textposition, textrotationangle, textrotationscale, textscale, textshadow,
texttransform, textunderlinecolor, textunderlinemode, textunderlinestyle,
textunderlinetype, textunderlinewidth, usewindowfontcolor.
I assume they are accessible in the same way as fontsize and fontweight, as in:
h1style.addElement(TextProperties(attributes={'fontsize':"24pt",'fontweight':"bold" }))
Although, I personally have no intention of loading software this old to test it.

Simultaneous bold and italic text in bokeh

How can I specify that I want text (say an axis title) to be both bold and italic in bokeh?
This is bold: text_font_style = 'bold'
This is italic: text_font_style = 'italic'
How do I do both simultaneously? I assume this is possible because of this response on the issue tracker
Some things I have tried without success include:
text_font_style = 'bolditalic'
text_font_style = 'bold+italic'
text_font_style = ('bold', 'italic')
text_font_style = set('bold', 'italic')
# together (in a last ditch effort):
text_font_style = 'bold'
text_font_style = 'italic'
As of Bokeh 0.13 this does not appear to be possible. The FontStyle enum is currently defined as:
FontStyle = enumeration("normal", "italic", "bold")
Which means that a Bokeh text_font_style property will only accept any one on those, i.e. you can only have bold or italic, but not both. I would describe this as a simple oversight that no one has noticed until now. I think fixing this would be as simple as adding new values for the combinations, e.g. "italic bold", to the enum value (and fixing up some some related tests), so I would encourage you to submit a new feature request issue on GitHub.

reportlab borderRadius is not working

I'm using reportlab 3.2 with python 2.7.
I'm trying to make put some text in a rounded panel like so:
but I'm getting:
I've tried using borderRadius but it is not making the corners round:
ps_title2 = ParagraphStyle(styles['Normal'],\
fontName=helper.REG_FONT, fontSize=18, textColor=DARK_BLUE,\
leading=22, backColor=LIGHT_BLUE, borderRadius=15)
pr2 = Paragraph('Interpretation summary<br/>something<br/>another thing', ps_title2)
pr2 = Paragraph('my paragraph<br/>something<br/>another thing', ps_title2)
elements.append(pr2)
I know another approach is using a table and know how to make a table an put the info in a table but do not know how to make the table corners round.
Drawing canvas is not a good idea because I don't know the coordinates of the section because depending on the content length it would change.
Any ideas how to make the corners round?
For borderRadius to work, you need to set the following values as well:
borderWidth
borderPadding
borderColor
borderRadius
I looked through the code and figured out that when border color is not set, border radius will not work; also you need to set borderWidth and borderPadding.
Here is what works:
ps_title2 = ParagraphStyle(styles['Normal'],\
fontName=helper.REG_FONT, fontSize=18, textColor=DARK_BLUE,\
leading=22, backColor=LIGHT_BLUE, borderRadius=15, borderColor=LIGHT_BLUE, borderWidth=1, borderPadding=5)

Gtk Popover Menu is not using the default padding

I created a GtkPopoverMenu and added some text buttons to it, but I can't get it to follow the same padding as other popovers, like the one in Nautilus.
The default style classes are being applied, and GtkInspector shows the same padding values as the popover in Nautilus, but, visually, the padding isn't there.
Here is the relevant part of the code:
pbox = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
popover.add(pbox)
one = Gtk.ModelButton.new()
one.set_label("Button One")
pbox.pack_start(one, False, False, 0)
two = Gtk.ModelButton.new()
two.set_label("Button Two")
pbox.pack_start(two, False, False, 0)
three = Gtk.ModelButton.new()
three.set_label("Button Three")
pbox.pack_start(three, False, False, 0)
And how it looks vs how the one in Nautilus looks: Image
And the full code: Code
Am I missing something here?
Nautilus uses a combination of margin and padding for its Popover.
I hope the screenshot demonstrates it. The first is the Popover as it is with your code. The second one has a margin but as you can see, the selection directly touches the text. Therefore the third Popover has margin and padding.
The margin can be set with widget.set_property('margin', 10) and the padding with a css file.

Categories