Alternate row coloring in Scintilla - python

I'm using wxStyledTextCtrl from wxPython, a wrapper around the Scintilla component.
Is there any way to get alternate row coloring on it (odd rows in one background color and even rows in another color)?
I'm using the builtin python styler to highlight keywords.

The background of lines can be changed, for example by markers (which is used for stuff like bookmarks or breakpoints, current execution point and the like in IDEs), but there is no built-in mode for changing the background colour of every other line.
You could simulate this by setting a special marker with a background colour for all odd or even line numbers (MarkerSetBackground() and MarkerAdd()). This would probably consume a lot of cycles, and each editing operation that splits or joins, inserts or deletes lines would need the markers to be reset. Still, it may be worth looking into, given that there seems to be no other way.

Related

Python pptx insert a picture in a table cell

Is there a way to insert a picture inside a cell using pptx python?
I'm also thinking of finding the coordinate of the cell and adjust the numbers for inserting the picture, but can not find anything.
Thank you.
No, unfortunately not. Note that this is not a limitation of python-pptx, it is a limitation of PowerPoint in general. Only text can be placed in a table cell.
There is nothing stopping you from placing a picture shape above (in z-order) a table cell, which will look like the picture is inside. This is a common approach but unfortunately is somewhat brittle. In particular, the row height is not automatically adjusted to "fit" the picture and changes in the content of cells in prior rows can cause lower rows to "move down" and no longer be aligned with the picture. So this approach has some drawbacks.
Another possible approach is to use a picture as the background for a cell (like you might use colored shading or a texture). There is no API support for this in python-pptx and it's not without its own problems, but might be an approach worth considering.

Python tkinter move

I have numerous lines on a graph, datalines, horizontal divider line, day and month indicator lines, etc. I have typically, probably until now, been adding lines in this fashion:
canvas_1.create_line(x1,y1,x2,y2)
I now have simple problem. I want to also add in a vertical scale to show how much above and below zero the line is...quite natural. The datafile is big, roughly 12,000 data units and growing so I have everything setup using the left and right arrow keys to allow scrolling through the data. It works great but I haven't added in the vertical scale yet. Right now everything moves:
canvas_1.move(ALL,x,y)
When I add in the vertical scale I don't want the vertical scale to move. I know by using the move(ALL) that the vertical scale will also move.
What do I have to change in order to get the vertical scale so it won't move? Do I have to go out and 'label' all create_line statements???
line1 = canvas_1.create_line....
If so when I have mega reference of lines that I want to move how do I put them into the move statement. Do I have to put all the labels into a list or what? I kinda really lost in the thought process on this concept.
I fess I'm still looking into scrollbars but haven't quite had any good luck with them yet and I have a feeling I will still have the same problem to be dealt with.
The move method takes either an id of a single object, or a tag that represents zero or more objects. ALL is a built-in tag (literally, the string "all") that refers to everything on the canvas.
So, to use the move method without moving the scale, give everything except the scale a unique tag, and then use that tag for the move command.
canvas_1.create_line(x1,y1,x2,y2, tags=("lines",))
...
canvas_1.move("lines")
For more information about tags, see http://effbot.org/tkinterbook/canvas.htm#item-specifiers

wxPython: how to lay one panel over another

This is about wxPython.
I would like to have 2 Panels laying one over the other:
PanelBG should be some sort of a "background", with its own GridBagSizer with subPanels, StaticTexts and so on;
PanelFG should be the "foreground" panel, also with its own GridBagSizer with some StaticTexts, Buttons... but a transparent background, in such a way that PanelBG is visible wherever PanelFG doesn't lay widgets.
I need both Panels to stretch to all the sides of the frame, even when resizing the window, though never changing the reciprocal proportions, that's why I'm not sure if there's a way to use absolute positioning.
In case you are wondering, the reason why I don't want to use a single Panel is that merging the 2 GridBoxSizers would require me to place many many more cells in the sizer, because rows and columns of foreground and background don't always coincide, and I should split them in many cells, with grid dimensions growing up to hundreds**2.
Since the content I want to put in the foreground needs to be updated and refreshed quite often, this would require redrawing all the cells every time, which would take 10 - 20 seconds to complete the operation (tested). Updating only the foreground would require just some hundredths of a second instead.
Thank you!
This would be at least partially a change of direction, but it might be worth examining what other rendering options you have.
In particular, I'm thinking of wxWebKit (http://wxwebkit.kosoftworks.com/), which would let you do layering, etc. using the WebKit browser rendering engine. I'm not sure whether it's at a stage that would provide everything you need since I haven't actually used it, but even if it doesn't work then it may be an approach worth trying - using HTML/CSS for part of your display, while wrapping the whole in a wxPython app.
As I understand it, this is a calendar with rectangles for the days containing the events for the days.
The simple thing would be to use a wxGrid, with seven columns and four or five rows, to represent the months. You would then place the events into the grid cell for the correct date. The wxGrid widget would look after the details of refreshing everything properly.
Using wxGrid you might lose a little control over the exact appearance, though wxGrid is very flexible and feature rich once you learn its many methods, but you would save yourself having to write large amounts of code that would require significant effort to debug.

Tools to extract glyph data from bitmap font image

I have all the characters of a font rendered in a PNG. I want to use the PNG for texture-mapped font rendering in OpenGL, but I need to extract the glyph information - character position and size, etc.
Are there any tools out there to assist in that process? Most tools I see generate the image file and glyph data together. I haven't found anything to help me extract from an existing image.
I use the gimp as my primary image editor, and I've considered writing a plugin to assist me in the process of identifying the bounding box for each character. I know python but haven't done any gimp plugins before, so that would be a chore. I'm hoping something already exists...
Generally, the way this works is you use a tool to generate the glyph images. That tool will also generate metric information for those glyphs (how big they are, etc). You shouldn't be analyzing the image to find the glyphs; you should have additional information alongside your glyphs that tell where they are, how big they should be, etc.
Consider the letter "i". Depending on the font, there will be some space to the left and right of it. Even if you have a tool that can identify the glyph "i", you would need to know how many pixels of space the font put to the left and right of the glyph. This is pretty much impossible to do accurately for all letters. Not without some very advanced computer vision algorithms. And since the tool that generated those glyphs already knew how much spacing they were supposed to get, you would be better off changing the tool to write the glyph info as well.
You can use PIL to help you automate the process.
Assuming there is at least one row/column of background colour separating lines/characters, you can use the Image.crop method to check each row (and then each column of the row) if it contains only the background colour; thus you get the borders of each character.
Ping if you need further assistance.

Finding out how many lines can be displayed in wx.richtext.RichTextCtrl without scrolling

I'm writing an e-book reader in Python + wxPython, and I'd like to find out how many lines of text can be displayed in a given RichTextCtrl with the current formatting without scrolling.
I thought of using and dividing the control's height by RichTextCtrl.GetFont().GetPixelSize(), but it appears that the pixel size parameter of wx.Font is only specified on Windows and GTK. In addition, this won't cover any additional vertical spacing between lines/paragraphs.
I could of course get the font size in points, attempt to get the display's resolution in ppi, and do it that way, but 1) the line spacing problem still remains and 2) this is far too low a level of abstraction for something like this.
Is there a sane way of doing this?
EDIT: The objective is, to divide the ebook up into pages, so the scrolling unit is a whole page, as opposed to a line.
Source code of PageDown method suggest that there is not a sane way to do this...
Here is my insane proposition (which breaks widget content, caret, displayed position...) which scroll one page and measure how long this scroll is...
def GetLineHeight(rtc):
tallString = "\n".join([str(i) for i in xrange(200)])
rtc.SetValue(tallString)
rtc.SetInsertionPoint(0)
rtc.PageDown()
pos = rtc.GetInsertionPoint()
end = tallString.find("\n",pos)
lineHeight=int(tallString[pos:end])
return lineHeight
Did you try calling the GetNumberOfLines() method? According to Robin Dunn, that should work, although it doesn't take wrapped lines into account.

Categories

Resources