Highlight certain text in a PyGTK TextView - python

I have TextView with pages of text, but I want to be able to highlight (change the background color) of specific strings in different colors. Is this possible? If so, can anybody point me in the right direction? Thanks

Haven't tried this myself, but TextBuffer.insert_with_tags with a properly configured TextTag looks promising.

If the specific strings are always the same, as in a programming language, then use GtkSourceView instead.

Related

How to remove borders on Tkinter buttons & frames?

I am currently building a simple app to encrypt files using AES encryption in python but the biggest downside of using Tkinter is the look of the UI. I did some research and found examples of what I want but do not know how to recreate it. (Example)
My problem is that when I replace buttons with images (like the OP of the Reddit post said he did in order to have a decent looking UI) I end up with an ugly bar of grey. (Image of the button)
I also want to remove the same type of bar with frames so if you have the answer for specifically that it would still be appreciated.
Support for for styles and themes has existed in tkinter for some time. A theme being a collection of styles for different widgets.
You can read more about style and themes here.
To the best of my knowledge, the standard widgets to not support rounded corners. All widgets have rectangular shapes.
You might be able to create something like that using a Canvas, but it would be a significant amount of work.
A more relevant point is that it might confuse your users if you don't reproduce the way the standard controls work.
UI elements are standardized for the same reason the controls in a car are; once you know one of them you can use all of them.

Get color scheme from GTK

I am developing a desktop app using Python 3 and GTK3.
I need a button to change its background color when hover, which can be done with this:
self.uploadbutton.modify_bg(Gtk.StateType.PRELIGHT, self.color)
Until now, I defined a RGB color that matches my own theme, but as I have to release this code, I would like to change that color to one of the established theme colors.
Searching the web, I found there's a way to do it with GTK2, but since version 3.8 of GTK, the gtk-color-scheme property has been deprecated.
Is there any other way to respect the user theme colors without using this property?
For now I have found two ways. Both of them are not the answer to your question, because as far as I understand in GTK3 every single element can have it's own styling (including color).
The first one is official and says not to mess with themes unless you have tested them and know how exactly your modifications would look. I think it's the best solution since it's not clear at compile-time whether your self.color will make it look ok or totally unreadable.
The second solution is to obtain full CSS and parse it yourself.
gset = Gtk.Settings.get_default ()
themename = gset.get_property ("gtk-theme-name")
prefdark = gset.get_property ("gtk-application-prefer-dark-theme") # it's a boolean
cprov = Gtk.CssProvider.get_named (themename)
print (cprov.to_string())
Parsing the theme is outside of this question.

PyQt QTextCharFormat mixing the font

I am going to make the selected text italic in PyQt text editor
Scenario 1
Scenario 2
The images are pretty self explaining.You will probably say then why don't you
just you textEdit.setFontItalic() then actually I am already using that but
textEdit doesn't have overline and strikeout while QTextCharFormat has ton of
properties but it has it's problems
textEdit.setCurrentCharFormat(),setCurrentFont(),setStyleSheet,setFont() but all
cause the same problem as QTextCharFormat
is there a way around this
thanks
Hey guys I have got the answer.
instead of cursor.setCharFormat() use cursor.mergeCharFormat()

python treeview cell/row borders

I have a python tk treeview for listing items, what I couldn't find is a way to stilysh a bit the whole list. i've done a massive google search but didn't find a way to add vertical line borders between each item, maybe it's not possible? I don't like the alternate-line-colors style. I tried tag_configure method but as far as i know it only allows font/foreground/background options.
thank you in advance

Is there any good python library for generating and rendering text in image format?

I'm developing a CMS like application where the user should be able to create the menu the way he wants. Ideally, each menu object wouldn't be a text with a background but rather an image of the text. I envision this in either of these 2 ways:
a) By rendering a font in a/several image file/s with every letter and a script that given a word would give me either the sequence of images to string together or a single image file with the combination of all letters. I understand this could be done manually, but I feel there's probably a library to help with this.
b) With some kind of imaging library that would be able to render text with several blending effects such as gradient color, shadows, glow, etc. While I believe this one's a bit harder, maybe there's something that suits this need.
Any tips on any library that does this or anything similar?
Thanks in advance!
Bruno
We are using Imagemagick.
http://www.imagemagick.org/Usage/text/#attributes
This will render a simple button with text:
convert -background white -fill dodgerblue -font Candice -strokewidth 2 -stroke blue -undercolor lightblue -size 165x70 -gravity center label:Anthony label_color.gif
Wrapping this into a Python module is straight forward.
Although nowadays I'd settle to go with web fonts and CSS,a couple of years ago I faced this problem, and put together a small project that would generate text-within a templated image on the file, according to passed URL parameters.
The project is still publicized here: https://bitbucket.org/jsbueno/dynabutton -- it is made to work as a CGI script, but could be easily adapted to work with a more eficient server (I'd recomend some security tunning as well, if you are putting it online). You can also use it to generate all your images with a server side script, and just put the resulting image files online.
(it does use PIL underneath)
Ah yes, it can do shadow, and glow with proper parameters, can use any server-installed font, and will use an image template for providing the background, so you can apply any effect manually. (the included temlates, though, are quite amateurish)
Check out pycairo, bindings for the cairo rendering package. It can render text as well as graphics.
Well, with modern CSS techniques, the issue of nonmatching client-side fonts is less of a problem these days. Still there's demand for text-to-image tools.
PIL is often given as the answer to this question, but personally, I would give a good, hard look at pythonmagick as well. Pick the one that works best for you.
Actually the pygtk also has a pango renderer, as well.

Categories