I'd like to format function argumetns in a way similar to the PyCharm default formatting - see image. Meaning no new line after '(' and before ) so it does NOT look like in the second image. It looks cleaner to me when function name is more visible.
I want this:
I do NOT want this:
Black is a highly opinionated formatter with the stated goal of making diffs shorter and consistent.
This is what you get.
The only thing you can configure for Black, at the time of writing, is the line length.
Related
With md2pptx the user generally supplies colours as RGB values. I'd like an alternative where they can use eg ACCENT_1 or whatever the template presentation calls it. Motivation: You probably don't know the RGB value of a colour in a template you're handed.
Is there a programmatic method - either in python-pptx - or spelunking in the XML to retrieve the colours' RGB values, along with their names? I don't mean "pale violet"; I do mean eg "ACCENT_1".
If not I suppose I could be confecting XML that uses these names. Might that be a better idea anyway?
Anywhere you can specify an RGB color you can also specify a so-called "theme" or sometimes called a "scheme" color.
Like:
from docx.enum.dml import MSO_THEME_COLOR
font.color.theme_color = MSO_THEME_COLOR.ACCENT_2
I want to read in a given datalabel's text.
What I have tried:
print(plot.series[0].points[0].data_label.text_frame.text)
Snippet above tries to print the 1st series' first point which is '16' but it prints nothing.
How can I obtain what is in the datalabel?
I want to read the text in, concat something new to it and reinsert it into the data label. Something like this
dltext = plot.series[0].points[0].data_label.text_frame.text
plot.series[0].points[0].data_label.text_frame.text = dltext + "Foo"
The data_label.text_frame only contains text if you put it there explicitly. Otherwise what is rendered is a function of the value of that data-point and the settings .show_value and show_percent, etc. documented here: https://python-pptx.readthedocs.io/en/latest/api/chart.html#pptx.chart.datalabel.DataLabels
If you want to match what shows to the user you'll need to duplicate that logic.
If you wanted to accomplish that for the general case, it would take some doing because you'd need to compute the effective value of properties like DataLabel.show_value, which would require reverse-engineering the style hierarchy for that setting.
But the 95% solution would just be to assume what is showing is the value and go with that. That's the default data label, at least for bar charts (pie charts may default to percent).
I've been assembling a text editor based on this example by Peter Goldsborough, but modified for the PyQt bindings of Qt for Python.
In Goldsborough's code, there are a number of text-formatting methods that follow this pattern:
def bold(self):
if self.text.fontWeight() == QtGui.QFont.Bold:
self.text.setFontWeight(QtGui.QFont.Normal)
else:
self.text.setFontWeight(QtGui.QFont.Bold)
The if/else is supposed to check what the format of the current selection is; if it's not yet the format that the method implements, it sets it to that format, otherwise, if it is already that format, it sets it back to normal again. Typical toggleable formatting behavior for a word processor.
Unfortunately this implementation does not appear to do quite that. The fontWeight() method retrieves the "current" format for the QTextBrowser, which means the format that it will render newly typed text in - in other words, continuing from the format of whatever is just before the cursor.
This means that there will be weird behavior which is not right for a word processor: if the text is all normal, then it will change formats fine, but if you change the format of an internal segment of text, then try to change it back afterwards, the text will erroneously remain in the formatted state.
Ideally what should happen is that the if/else should operate on the formatting of the text inside the selection instead of right before it. But I cannot find a method that does this. Thinking that I have missed something substantial along the way here - thank you for any suggestions you may have!
How can I invert (rotate 180 degrees) a text object so that the text is kerned appropriately?
My example uses Python and the svgwrite package, but my question seems about any SVG.
Suppose I use the following code:
dwg = svgwrite.Drawing()
dwg.add(dwg.text(fullName, (int(width/2.),gnameHeight),
font_size=gnameFontSize, text_anchor="middle"))
The above code generates text looking like this:
dwg.text() objects accept a rotate parameter that is applied to all characters in a text string, so I've used the following code to reverse the string first:
pcRotate = [180]
ngap = 1
revFullName = fullName
rcl = []
for c in revFullName:
rcl.append(c)
for i in range(ngap):
rcl.append(' ')
rcl.reverse()
revFullName = ''.join(rcl)
dwg.add(dwg.text(revFullName, (int(width/2.),pcnameHeight),
font_size=gnameFontSize, text_anchor="middle", rotate=pcRotate))
But, this produces the very ugly version below:
and this is using an artificial space gap between characters to make it slightly less unreadable.
What's the best way to tap into whatever kerning is being used by standard text in this inverted situation?
The rotate attribute of a <text> element is intended for situations where you want to rotate individual characters. If you want to rotate the whole text object then you should be using a transform instead.
http://pythonhosted.org/svgwrite/classes/mixins.html#transform-mixin
I'm posting this as a self-answer, only to make formatting more clear. Two useful hints from #paul-lebeau happily acknowledged.
While the svgwrite package seems solid, its documentation is a bit thin. The two things I wish it had said:
The rotate attribute of a <text> element is intended for situations where you want to rotate individual characters. If you want to rotate the whole text object, then you should be using a transform mixin instead.
If you need to center the transformed text with respect to some center (other that the default current user coordinate system), add two additional parameters xctr,yctr. This differs from the doc which calls for a single center argument that is a (2-tuple).
The correct code is:
pcRotate = 'rotate(180,%s,%s)' % (int(width/2.),pcnameHeight)
textGroup = svgwrite.container.Group(transform=pcRotate)
textGroup.add(dwg.text(fullName, (int(width/2.),pcnameHeight),
font_size=gnameFontSize, text_anchor="middle"))
dwg.add(textGroup)
I'm new to Python and I want to know what this kind of graph is called.
I particularly want to know how to generate those white lines. Those white lines should go up to infinite (the maximum of the Y-axis). The white lines represent a roadblock, as it were.
Anyway, I don't know the name for these white lines, or for the graph in general!
I have scipy suite of software.
Solved it. Simply add another x and y axis which used the '--' line type. And my function was like this in the end:
x1.append(stepid)
y1.append(danger)
x2.append(stepid)
y2.append(dlimit)
x3.append(stepid)
y3.append(dlimit)