Gtk.CellRendererText makes itself really tall when I wrap it - python

I'm trying to allow wrapping of the text in a Gtk.CellRendererText but I have small problem:
Those rows are very large.
The only code I changed was this:
cell = Gtk.CellRendererText(markup=0)
cell.set_property("wrap_mode", Pango.WrapMode.WORD)
cell.set_property("wrap_width", 20)
And that makes it wrap, but it also seemed to make this visual issue appear

I seem to remember reading something about this on a blog at planet gnome quite a while ago. From what I remember there is something to do with the height-for-width drawing model that means when wrapping is enabled GtkLabel etc request enough height to reflow the text for wrap-width even if there is more horizontal space available which leaves loads of empty space when the width is wider. There was a fix but I'm afraid I can't remember it at the moment, I'll try and find the original post later.
I've tried but I can't find the post, however having read some more I'm pretty sure this is the problem. There is some discussion related to GtkTable doing similar things at https://bugs.launchpad.net/ubuntu/+source/gtk+3.0/+bug/825173 I've a nasty feeling the fix I can't remember properly might have been to turn off wrapping. I guess it would be possible to get a notification when the column width changes and make wrap-width the correct width for that value but that's a bit of a pain.
If you can live with the column being a fixed width, set the expand property of the column to False and the fixed-width property to True then set the wrap-width, width-chars and max-width-chars properties of the renderer all to the same value then the text wraps without any extra space.

Related

How are font variations written

I have been thinking for some time that variable fonts were simply combinations of multiple fonts, and that values were interpolated between them. However, I just read about this project, protottypo (which is unfortunately discontinued), and discovered about how they were storing their fonts as variables. See this screenshot from a promotional video, a few years ago:
And it seemed just so logical! Why not use a real language-like format, with variables and all. In the picture above, it (kinda) looks like python code.
And then I thought "It must have been thought through, let's look at how OpenType font variations are implemented."
And I looked on the web for the schema and the specification, but could not find it.
So the actual question(s):
How are variable fonts stored in otf files? Is it simply, as I thought before, multiple fonts and the other values are interpolated between them? Is there a variable language like the one above used to write the variable parts of the font (obviously)?
Where can I find the TTF specification for variable fonts? Is there any?
Is there a way to write a variable font with a regular text file (of course involving some vector graphics of some sort, like: const d = 'M23.6,0c-3.4,0-6.3,2.7-7.6,5.6C14.7,2.7,11.8,0,8.4,0C3.8,0,0,3.8,0,8.4c0,9.4,9.5,11.9,16,21.2 c6.1-9.3,16-12.1,16-21.2C32,3.8,28.2,0,23.6,0z' (this one makes a heart)
Thank you (that's what the heart is for :)

Control tick-labels from multi-level FactorRange

I've got a three-level bokeh.models.FactorRange which I use to draw tick labels on a vbar-plot. The problem is that there are dozens of factors in total and the lowest-level labels get very cramped.
I can use plot.xaxis.formatter = bokeh.models.PrintfTickFormatter(format='') to suppress drawing of the lowest-level labels, but this seems like an ugly hack. Also, I need to have the second-level tick labels to be rotated, yet plot.xaxis.major_label_orientation = ... only ever affects the lowest-level ticks (just like plot.xaxis.formatter does).
How to control each level of bokeh.models.FactorRange individually?
As of Bokeh 0.12.13, there is no way to control the individual orientations or formatting of different levels.
The basic initial work to revamp categorical support (for multi-level axes, etc) was a large update. Rather than add more even complexity and risk up front for features we were not sure anyone would want or need, we started with basic capability, expecting to hear from users in time what additional features were justified. This seems like it has come up a few times, so it would be reasonable to consider adding, but it would represent new work, so a GitHub feature request issue is the appropriate next step.
For completeness, I will mention that Bokeh is extensible, so it's always technically possible to create a Custom Extension. Axes are some of the most complicated code in Bokeh, and a full custom Axis would be non-trivial to write. However it's possible that would be sufficient to make subclass of CategoricalAxis and just override this one method:
https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/models/axes/categorical_axis.ts#L83-L110
That's where the currently hard-coded 'parallel' orientation are, and also where formatting could be overridden.
In latest Bokeh (2.2.0), the feature #bigreddot was talking about seems to have been implemented: you can call
p.xaxis.group_label_orientation = [angle in radians]
to set orientation of the outer labels, while as in the question
p.xaxis.major_label_orientation = [angle in radians]
sets the orientation of the inner labels.

Get dynamic text with python and present it in LaTeX, format depending on content

I try to gather some graphics and text from different folders and present them in a comprehensive way. For this I use python to copy them into one folder and derive a dynamic LaTeX presentation, where I plot the copied graphics and print the text. The problem I'm facing now is, that I can derive the title for a slide dynamically from a text file, but if it's too long it will obviously wrap around. This dynamic title can be pretty long, so it might fill the whole slide. What I'd like to do now is to limit the space used by this text, without losing its information. The non-elegant solution I have to this problem is to count the characters and if it's over a certain threshold, use a smaller font. This solution is tedious and not optimal, I'd love to hear a better idea.

What's the easiest way to make a table in Python?

I want to create a table with Python that looks like a simple excel table, therefore I have already used the pyExcelerator. But now I thought about just using pyplot.table which seems to be very easy. However, I need to make some changes and I don't know if this is possible in vpyplot.table`.
For example I want to add a cell in the upper left corner and I also want to make two cells beneath the cell t+1 (see the table example below).
So, is it possible to do these changes in pyplot.table or should I better use another way to make tables?
Building a program to generate an table in a image for inclusion into your word document is a bit overkill. Its a lot of added work and completely unnecessary effort. Make the table in Excel and then paste it into Word. It'll look good and will be easier to update and change.
If you are using this as an excuse to learn something new, that is all well and good, but you need to give us more to help you with. SO isn't a code factory. Offer up what you have tried, and samples of code you are having trouble with. We can help with that.

wxPython StyledTextCtrl Hexadecimal formatting

To whomever can lend a hand.
I'm building an app with BoaConstructor in Python which uses a wx.STC.StyledTextCtrl. In this styledtextctrl I am outputting hexadecimal data through Scapy's hexdump function. It adds the line numbers, hexadecimal dump and character transcode. Unfortunately, I cannot figure out how to format this text in the StyledTextCtrl so it displays like a regular hex editor would (see images here http://imgur.com/a/tqE02). Thanks!
Since you said that the output looks OK in other editors, I'm guessing the issue is that the font uses variable pixel widths for characters (e.g. if a wide character like "w" is 15 pixels wide then a thinner character like "i" may be only 10 pixels). In a fixed-width font (sometimes called monowidth font or typewritter text font) all characters have the exact same width.
You can see evidence of this in your screen shot; there is a slight extra indent on the second row right before the ".(." part. It seems that the space character is much thinner than numerals, so all those missing pixels make the third "column" of the bottom row appear too far left (while extra width in the second row pushes it slightly right)
You need to find a font such that IsFixedWidth() returns True then set up your STC to use that font. Normally, you'd set this using the SetFont() method but I happen to know that STCs prefer to use there own methods. I found this StyleSetFont() method that is specific to STCs, so that's probably a better bet.
As for choosing your font, here is a good tutorial about how fonts work in wxpython. The author actually is an active member here. Specially, search that article for his "wx.FontEnumerator widget" example. It should allow you to find fixed-widths fonts and view them to see if you like them. For a quick-and-dirty solution, this forum post talks about the wx.TELETYPE flag that guarantees fixed-width and these code samples should give you some idea how to use it.
Good luck!
----EDIT----
I'm not very familiar with STCs but I remember from a previous answer I gave to a question involving STCs that you might need to call StyleClearAll() after setting your font. See the EDIT section of that answer for more information about why this may be required.

Categories

Resources