New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drawing gradients question #1460
Comments
One approach I've seen for things like this is to draw a series of concentric rounded rectangles. First the black one, then a series of rectangles with a progressively more opaque border pen, and a transparent brush. The last one will use a fully opaque brush for the fill. It won't be exactly like your sample, but you can probably get pretty close by playing around with border thicknesses, corner radii, etc. Another possibility is in wxPython 4.1, where there is support for applying a gradient brush to a stroked Yet another option, if Finally, if your graphics don't need to be super dynamic, then you can use SVG files in wxPython using the |
@RobinD42 Just checked the demo, and a bit off subject but I'm guessing you at least tested the wx.svg render demo on mac... it doesn't appear to be completely working on windows, tho the svg bitmap demo is working. ...maybe something needs tweaked to get the render demo working on windows... |
Oops. Yes, that demo is slightly unfinished. On windows the default |
I had thought about doing a recursive rectangle getting smaller each loop and adjusting the alpha each loop to a higher number. the problem with this method is you end up with a visual anomaly in the rendering called Moiré Almost everyone has seen Moiré and never put much thought to it. so for those of you that want to put a name to that anomaly you have seen and never thought twice about. here is an image that will help you out. I have tried on many occasions to do a manual gradient using wxPython and 100% of the time i have gotten this anomaly I find it to be a particularly unattractive thing to look at. |
I went to look at the demo code for the SVImage_Render sample today and saw that it's already using the Direct2D renderer on Windows. So the glitches you were seeing are probably some off-by-one or floating point truncation issues in the the C++ code for the Direct2D renderer. When I was working on the SVG stuff I noticed that there were some cases there where a floating point calculation was being assigned to an integer that probably shouldn't have been. It's also possible to use the Cairo GraphicsRenderer on Windows, and it does an excellent job with the SVG rendering. |
OK I am going to need an education here.. what is the Cairo GraphicsRenderer? |
The Cairo is an advanced 2D vector based drawing library. It was designed to be used as part of the GTK family of libraries, but it is generic enough that it can be used on other platforms and even in non-GUI use cases. With a couple extra dependencies[1] you can use Cairo directly from Python in a wxPython application. The The Cairo
[1] The dependencies are the |
@kdschlosser iirc pycairo is the easiest way to get the cairo official demo stuff working, so this should work last I checked...
...otherwise when you fire up the cairo demos in the wxPy Demo it might spit back some missing dependencies message errorpanel. |
I had to install pycairo using a prebuilt binary. it will not insutall using pip. I get a compilation error. |
cairocffi is easier. It is pure Python so there isn't any need to build an extension module. Instead it dynamically invokes the Cairo API functions via cffi. |
Also, using |
OK so now my question is how do I obtain the Cairo binary for Windows without installing GTK or any other package.. I only keep on finding it prepackaged with something else. I also read that the Cairo source is not MSVC compatible and needs to have changes made to it to make it MSVC compatible. Now This information is gotten from the internet so I do not know the age of the information nor do I hold it as absolute truth LOL.... I am sure with spending half a day I will be able to build or locate Cairo, but for the sake of saving me the effort if someone has the information and they are willing to share it.. I am all ears.. (eyes really) |
The DLLs are included with wxPython. No need to build anything or extract from other packages. I've already done the latter for you. See the docstring for |
I am good to go.. I have it running.. The only thing I dislike about the current interface to cairocffi is the voodoo magic code that does not allow an IDE to autocomplete or show type hints.. so a lot of poking through the wx code and then the cairocffi code to see what can be done.. and then you toss in the heap of voodoo magic code cairocffi is using as well, makes everything a mystery!... So I have already ported all of the header files for Cairo to python. this way I have a reference. need to deep six the voodoo magic code and code it the good ol fashion way.. subclass the cairocffi classes so a data path can be seen. Better yet use my port of the Cairo headers and build classes from that. so a full data path is available and an IDE will work properly all the way back to the shared lib for every available exported function the lib has to offer. my port already has all of the structures, enums, constants and functions coded. need to assemble them into python classes. I am going to have to check again. but I think that Cairo has private objects that get passed as parameters to public functions.... |
Ah... IDE stuff. Yea that is always an issue with people depending on how much they know python. ... Which IDE are you using? Sounds like maybe PyCharm...? |
actually there is quite a bit of PyCharm written in python.. The bits that deal with the stub files is written in python. The issue I have with PyCharm is it doesn't do well with large projects.. 150K lines and up. or a single file that has say... 30K lines of code in it. Other then that it works pretty well. The default JVM settings are for the birds.. those need to be changed right out of the gate.. once that is done you will find that PyCharm runs pretty decent. it is also pretty simple to use. You will want to install their version of the JVM "OpenJDK by JetBrains. It will give you the option to use that when you install PyCharm. then go into the help menu and click on "Edit Custom VM Options" It will probably tell you that it needs to make a file. say yes.. and paste in the code below, the only 2 options that you will need to change are -Xms2g and -Xmx12g this is where you set the memory to allocate to PyCharm.. the -Xms2g is the smallest size the heap will be. 2 gig in my case.
I like the type hinting and the autocomplete. But when there is voodoo magic code involved unless there is a stub file specifically written to handle it there will be no type hinting or autocomplete.. and if you are going to go through the work of writing a stub file.. why not just write the code in a manner that will provide the type hinting right out of the gate... I think the intention of a stub file is for extension libraries. (pyd files) because there is no way to sneak a peek at what's inside in order to provide the information needed, stub files can be used in order to achieve this. There is really no reason as to why a stub file should need to be created for python code. and the issue with an IDE being written in python is the speed of Python. I have tried Spyder, It really doesn't play nice with large projects. Worse then PyCharm actually. The other thing is PyCharm is a "full featured" IDE and the code inspections for the most part work properly unlike Visual Studio's Python integration. I am not an advocate for PyCharm. It has some really big flaws and problems, I would love to change to a different IDE. I am unable to find anything that is close to providing the same features and functionality that PyCharm has. I'm 45 years old. The gray matter is not what it used to be.. so type hinting and also autocomplete are must have features. code inspections are also a must have. I can't keep track of what syntax works with that version of python. or what is depreciated and what is not.. Far easier to have the IDE inform me of these things before run time. |
VS Studio gets very close for most features that were important to me in PyCharm, exceeds it in a few features too. I recently had to fire up PyCharm while working on a hairy problem, but that was the first time in probably a year. Also, VS Studio is a lot less resource hungry. And, as an added bonus: https://marketplace.visualstudio.com/items?itemName=RobinD42.robins-blue-theme 😉 |
It has been over a year since I have tried the Visual Studio Python extension.. The last time I had tried it it would should that a variable did not exist if the variable was in the parent scope. some_variable = 'whatever'
def go():
print(some_variable) it would say that some_variable in the function go didn't exist.. when we know it does.. There were other issues similar to that when dealing with imports. I do not remember if it handled type hinting either. It could now.. It may be the time to have a look at it again. PyCharm does have a pretty large memory leak in it's code inspections. that is the reason why it cannot handle large files. The leak occurs because of the creation of inspection objects over and over again that are the same error but in different parts of the code. If the same error is repetitive for some reason ram disappears FAST. 70K line file. my server which has 128GB of ram I set the heap size to 100GB and I ran out of heap inspecting the code in that file and it crashed PyCharm.. I do know that VS has a far smaller memory and processor footprint then PyCharm does. Now on the flip side the disk footprint of VS compared to PyCharm is massive.. That is strange actually.. I opened the exact same project and took the memor samples while a code inspection of the whole project was running. The project has 750K lines of Python code.
I just gave the python extension for VS another go. It does appear they have fixed the variable issue i outlined above.. also as you can see above it is much lighter on the resources. but the UI does the same thing that PyCharm does when dealing with large files/projects.. It studders and becomes a pain to use. I would have to use it more to see if this goes away once it finishes up with the inspection.. PyCharm will rescan the whole file if you make a change and that causes it to keep on having issues. I do not know if VS does the same or not. I am going to use it for a while and see if I encounter the same effects.. I already found one thing that I do not like/does not work.. when I set the error window (inspections) to only do the inspections for the current file it doesn't. it still does the inspection for the whole project and also displays the results for the whole project. I may be doing something wrong i am going to have to mess around with it a bit more. the theme is nice as well. it is a little to hard on my eyes with the blue.. But your point is correct about the code editor and it almost always being the same color as the rest of the UI.. It gets lost. I would probably use 45, 45, 45 for the editor and 60, 60, 60 for the rest of the UI..I think that might be enough of a shade difference to make the editor different from the rest of the UI while retaining the dark to reduce the eye strain. I have photophobia so I like to have a UI stay pretty dark in color for the majority of it. |
Oh and the other thing I just noticed is that you are using Visual Studio Code.. and not Visual Studio. I did not know there is a python extension for VSCode. is it the same extension that is used for VS? |
I'm not sure. I know the debugger backend is shared between them, I expect there's some other overlap as well. |
Visual Studio and Visual Studio code end up with GUI hiccups just like PyCharm does. They don't crash but the studdering of the GUI make it almost unusable. |
OK I am trying to draw a rounded rectangle that has a gradient inside of it. the rectangle to 300x150 and the gradient is going to go from red to transparent. I have attached an image that shows what I am looking to do.
For the life of me I cannot figure out ho to go about making the gradient. I tried DC.GradientFillConcentric and this only drew a gradient circle in the middle. The name of this function is misleading. It should be GradientCircleConcentric not fill. fill leads you to believe that it fills the whole rect not just making a circle. I would have thought there would be a simple method that can be used maybe a blending mode and making a really wide line. IDK I can't find an easy way, I also tried googling for an example and came up with a single mailing list entry for someone asking the exact same thing. they were given a link to wxWidgets API docs specifically the wxGraphicsContext portion of it. and the user only said "It works!" and didn't provide any kind of an example. So I am going to make the assumption that what I need is in there I am not sure how to go about writing the code.
If someone can shed some light on this for me it would be appreciated.
Thank you for any assistance you can offer.
Kevin.
The text was updated successfully, but these errors were encountered: