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
Related
I've essentially recreated the matlab data cursor on my custom pyplot figure tool. It allows dragging and left/right arrow key presses to update an annotation box's position along a line, etc. My problem comes from when there are a large number of lines. The data cursor still works, but dragging its position around is a nightmare and is extremely slow. The problem stems, I'm rather certain, from my canvas.draw() calls since it's redrawing the entire figure every time the data cursor moves.
I'm working towards implementing options like blit() and "restore_region()", but I'm having great difficulty implementing them. Can anyone provide even a shell of how to make this work? I can't include actual code due to the classification of the code itself, but I can give a small pseudo-code example.
def create_anno(self):
# Do annotation creation stuff here
self.background = self.figure.canvas.copy_from_bbox(self.axis.bbox)
def key_press(self):
self.figure.canvas.restore_region(self.background)
# Do update position/text stuff here
self.figure.canvas.blit(self.axis.bbox)
self.figure.canvas.flush_events()
The key_press function is called normally, but the annotation box doesn't move anymore. Most examples use draw_artist() between their restore_region() and blit() calls, but annotation doesn't have that. I just want to update a little annotation box's position across a figure without having to redraw the entire axis. Any ideas?
Thanks!
I'm making a simple word game simulation in Python and need a way to visualise a grid of coordinates. The input would be a simple 2D array with either '' or a character in each spot.
I need each spot in the grid to either be blank or have one letter. The x and y axes need to have arbitrary start points, such as -20. It seems like Matplotlib might do what I want, but having looked around on a bunch of Stackoverflow questions and Matplotlib help pages, I can't find what I need.
The question here partly has what I need:
Show the values in the grid using matplotlib
Except I want no colour, the values are single characters, and the axis labels need to allow arbitrary start points.
Does anyone know whether Matplotlib is the right library to do this sort of thing, or if I should try something else? Performance matters but it's not the most important thing. I don't need any interactivity with the display window, it's purely read only.
I have hierarchy of objects with animation on translation and rotation, the scale xyz are equal and static but not 1. When I freeze scale on a parent mesh it's children's animation goes wild. Is there any way to prevent this from happening?
I have found a workaround, but it's not perfect yet. Let's say we have simple setup like this:
parentObject=>childObject
I put childObject in a group "childObjectGroup"
parent childObjectGroup to the world and zero out it's transforms excluding scale.
Bake childObject's trasformations to the world so we don't need a group anymore. (found a good script for that)
Freeze scale transforms on parentObject and childObject
Reparent them back
It works for simple hierarchies like that, but not sure how to apply it for more complicated ones with deep tree and several brunches. Probably I'm missing something and there is really simple solution to that.
Any time you change the scale of a parent node, the translation for it's children is going to change - at least, if you're measuring in world space units. So, moving 10 units under a parent scaled to 0.5 will actually move 5 world space units (for example).
I'm pretty sure your rotations should be fine since scale doesn't really change how rotation around a pivot works; however, if you're rotating something from a pivot that is not in the center of the object and you have non-uniform scaling (xyz are not all equal) the rotation inside of the squashed space will feel more like an oval than a circle.
If that's not a problem, the main thing to worry about is the translation positions - you basically need to get the world space positions of each object at each key, 'fix' the scale, then go through the keys and set the world space position again (I would use the xform command for that since you can query and set position with world space values). So, the steps you outlined will probably be the best bet...
If you have non-uniform scales though, you may not actually be able to get the rotations to work out in a way that gives you the same results (just depending on positions/pivots and consecutive descendant positions/pivots). If the parent's scale isn't actually hurting anything and isn't supposed to be keyed/animated, it might be ok to just lock and hide it without any adverse effects.
So I've been making a game using Python, specifically the PyGame module. Everything has been going fairly well (except Python's speed, am I right :P), and I've got a nice list of accomplishments from this, but I just ran into a... speedbump. Maybe a mountain. I'm not to sure yet. The problem is:
How do I go about implementing a Camera with my current engine?
That probably means nothing to you, though, so let me explain what my current engine is doing: I have a spritesheet that I use for all images. The map is made up of a double array of Tile objects, which fills up the display (800 x 640). The map also contains references to all Entity's and Particles. So now I want to create a a camera, so that the map object can be Larger than the display. To do this I've devised that I'll need some kind of camera that follows the player (with the player at the center of the screen). I've seen this implemented before in games, and even read a few other similar posts, but I need to also know Will I have to restructure all game code to work this in? My first attempt was to make all object move on the screen when the player moves, but I feel that there is a better way to do this, as this screws up collision detection and such.
So, if anyone knows any good references to problems like this, or a way to fix it, I'm all ears... er.. eyes.
Thanks
You may find this link to be of interest.
In essence, what you need to do is to distinguish between the "actual" coordinates, and the "display" coordinates of each object.
What you would do is do the bulk of the work using the actual coordinates of each entity in your game. If it helps, imagine that you have a gigantic screen that can show everything at once, and calculate everything as normal. It might help if you also designed the camera to be an entity, so that you can update the position of your camera just like any other object.
Once everything is updated, you go to the camera object, and determine what tiles, objects, particles, etc. are visible within the window, and convert their actual, world coordinates to the pixel coordinates you need to display them correctly.
If this is done correctly, you can also do things like scale and otherwise modify the image your camera is displaying without affecting gameplay.
In essence, you want to have a very clear distinction between gameplay and physics logic/code, and your rendering/display code, so your game can do whatever it wants, and you can render it however you want, with minimal crossover between the two.
So the good news is, you probably don't need to change anything about how your game itself works. The bad news is, you'll probably have to go in and rewrite your rendering/drawing code so that everything is drawn relative to the camera, not to the world.
Since I can't have a look into your code, I can't assess how useful this answer will be for you.
My approach for side scroller, moveable maps, etc. is to blit all tiles onto a pygame.Surface spanning the dimensions of the whole level/map/ etc. or at least a big chunk of it. This way I have to blit only one surface per frame which is already prepared.
For collision detection I keep the x/y values (not the entire rect) of the tiles involved in a separate list. Updating is then mainly shifting numbers around and not surfaces anymore.
Feel free to ask for more details, if you deem it useful :)
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.