I'm currently designing a GUI to display images on screen using Python 2.6, Glade-3 and GTK. It uses 2 sliders (2 x GtkHScale) in order to "clip" the image of any bright/dark areas. (like below)
upper clip ----------------|====
lower clip ===|-----------------
I think that it would look much neater if the two sliders were combined onto one GtkHScale giving the "blue line" between the 2 sliders in order to show which bits of the image are being clipped. (much like the mock up below)
Clipping -----|============|----
I'm using Glade-3 to create the slider but i think this customisation will have to be included in the Python code and not the Glade file? Any ideas on how to create a custom GtkHScale?
Related
I'm learning and experimenting with the graphics stuff. In this little project, I'm trying to output the graphic result just by printing to the terminal without using other libraries. I have chosen to use python seems more straightforward to implement, and I can focus on understanding the maths. I will move back to C# or C++ later.
What I have implemented:
I have used a list to store all canvas values (two different symbols the ██ for the dots and ░░ for the background).
And I have created a function that creates a dot on the canvas. By taking x and y to calculate the position in the list and change the symbol.
Then I create a function that can draw a line by creating dots on the canvas.
Lastly, I have to use the projection matrix and rotation matrix to create a rotation cube on the canvas.
I have (kind of)successfully output the cube on the terminal and python shell. The shape is still a little bit weird, but I will work on that.
My question:
But when I want to print out like an animation, the output jiggles; sometimes, there are a few lines of delay. I have searched online and seen others creating ASCII graphic engines. Their production is at a fixed rate and fixed position. How can I print out the screen statically? Is there a way I don't need to implement other game engines or graphic libraries to complete the task?
Or do I need to create my window using API and output the result?
PS: I have used os.system('cls') to clear it each time, but it's too slow and is far from the high frame rate ASCII engine I've seen, and the delay still appears, which makes the canvas jiggles a bit.
Output Result:
https://www.youtube.com/watch?v=ZDe2IXKNpYk
Output code:
I just simple get all the values that plug into the list and print the canvas out
while 1:
createCanvas()
createAngleMatrix(angle)
setCube()
angle += 0.05
printCanvas(canvas)
time.sleep(0.05)
Thank you for your time reading or answering my question.
Updates:
I have found some different methods to stabilize the canvas. I have used os.system('cls'), but it's too slow and flickers. And I have tried using the '\r' in print by printing from the start of the line, but my canvas string contains a '\n' new line, so it doesn't work. Then I find the '\033[1A' and '\x1b[2K'which can clear line by line. But because the canvas is a brick of SCKII text, every time it deletes all and reprints again, it will flicker like crazy similar to using the os.system('cls'). But the update speed is very fast. Currently, the splashing effect caused by reprinting all over each time is the problem. Are there any other methods that can static print out the canvas?
The canvas at the end will be a string something like this:
['+++++++\n++++++\n++++++\n+++++++\n']
Update2:
As I have mentioned, I have used the remove line method, and I have created some tests for the rendering time. The coloring (I used the color escape code to color the text) has slowed down the render time, creating flickering. I have run some more tests, and the render time for the coloring will be about 4.5 to 6 seconds, and the black and white will only need 3 to 4.4 seconds for 100 frames. Is there any way I can improve this or other ways to output the canvas?
output result:
No color: https://youtu.be/q7ujCopm0bo
Color : https://youtu.be/cPvuxrcaWy4
Source code:
https://gist.github.com/KPLAYING77/417591578d01bd07e40ff846ec878773
I expected to output the canvas at a fixed rate in any size of the canvas and any size of the window.
I have been using an edited version of the graphics.py library by John Zelle which is based upon TKinter for some time now, but this question always confused me:
Why is the resolution of the screen (the pixels/unit) of the TKinter screen lower than my computer's?
Now what I mean by this is, if I draw a point on window like so:
the pixel is VERY clearly visible. However, I know for a fact that my computer can display higher resolutions (obviously). When I use a vector graphic editing software, I can't make out individual points on the window - so why can I over here. How much ever I have tried increasing the resolution of the window, the pixel size remains the same.
The size is very different to if I used vector graphics - If I had a curve, I would see a curve, not some anti-aliased pixels. So why is this? Why can't I draw smaller pixels on a TKinter screen?
The same thing happens with PNG Images - Why can't I export in a higher resolution so that I don't see any of the anti-aliasing (yes the size would increase, but why isn't the option available), why is this a limitation when I can clearly see that it is not when I am using vector graphics?
Vector graphics can be zoomed in infinitely, but that is not my point. My question is if my computer's screen is capable of displaying far higher resolutions than what I can in TKinter, why can't I display them?
I have a custom object(a small circle) placed at some point inside a Gtk.Fixed() widget .Is there a way to drag this object around using the mouse. I am not able to map the Mouse Press/Release/Motion events to make this work.
I would prefer solution in Python using PyGobject but any other language will do also be fine if explanation is provided
More Details:
I am trying to make a font editor where these objects I mentioned above will be the control points of the bezier curves in the Glyph outlines
Here is an image of the concept design:
https://github.com/sugarlabs/edit-fonts-activity/blob/gh-pages/files/img/wireframe_concept_01_first_prototype.svg
I need to able to move the points shown to edit the outline of the letter shown
GtkFixed is not designed to do drawing work. It's made to locate widgets (such as buttons and such) on a fixed grid (á la Windows).
If you would like to move elements of a drawing, have a look at eg. GooCanvas. Each element on a goocanvas can have events connected, which can then be used to move it around. You can even use CanvasGroup to group primitives (circle, rectangle etc), and move them together (even change other properties such as color, linewidth). The toolbox actually contains curves etc. It's easy to create a 'handle' using a small rectangle.
Here's an example of a simple goocanvas program, and you can find download links, references manuals and other useful stuff here.
I don't know if this is a tool you need, or just a learning exercise. If the former, then do have a look at FontForge, an open source font editor, and incredibly versatile.
I'm testing an algorithm that finds a shortest path between two certain vertexes in graph and gives a list of vertexes after each turn (actually it gives three paths - one of them is a shortest path in this graph and two others are some kind of extra paths that are also important for us and are used for further shortest path calculations). On each turn the weights of graph edges change somehow so every turn we get a new triple of lists (paths). I would like to visualize the evolving of these paths by drawing a graph (this graph is actually a grid that represents a city, e.g. New York) and each kind of path would be represented with certain colour (so on each turn there would be a grid with three coloured paths). One more time - on every turn the paths will be different so the picture will change. What is the best way to represent it? And one more question - sometimes there would be edges that belong to two or maybe even three of these pathes and I'd like to show it, so it would be nice if there is an opportunity to colour this edge with two/three colours at once. It would be perfect if it was possible to make it look like two/three thinner edges put along together, but I could only find a situation where we draw several lines of different colour that are being put together consecutively (like that: enter image description here). Is there a way to make it the first way?
I'm sorry for being discursive but I've never dealt with graphics in Python and I desperately need help. Thanks!
If you want to show the image in a GUI, it depends on the GUI toolkit that you want to use. In the Tkinter toolkit that comes with most Python distributions you could use the Canvas widget. There are several tutorials online [1], [2]. Most GUI toolkits have a similar functionality, but they can have different names.
If you want to save an image to a file, there are many graphics libraries you could use, depending on what kind of format you want to save it to.
For example the Python bindings to the Cairo library can save a picture as PDF or SVG vector formats.
The Pillow library on the other hand supports many bitmap formats.
There are many others; matplotlib, agg, gd are just some examples.
I am working on a program for machine vision. I am trying to do the following:
Grab image at a certain zoom level and find borders.
Take that image and subdivide into a fixed sized grid (which is pre-determined).
Project the image+grid in a UI and allow a user to select/deselect individual grid boxes.
Currently I am using PyQt+Python2.7 with C++ for the computations. I am just wondering if there is a good tutorial for the UI grid section.
Use the Graphics View Framework. Add each grid item as a separate pixmap using scene->addPixmap. Make items selectable using item->setFlag(QGraphicsItem::ItemIsSelectable);. Use scene's selectionChanged signal and scene->selectedItems() to know about selected items.
You can use QPixmap::copy to cut off a rectangle.