« first day (4324 days earlier)      last day (607 days later) » 

3:44 AM
stackoverflow.com/questions/52931928 Is there a canonical for this? it's similar to the problem of binding a Button to its own command callback (stackoverflow.com/questions/10865116), but when you actually get an event from Tkinter it contains the widget information so you don't need to do your own binding.
 
 
4 hours later…
Closed
 
 
2 hours later…
9:51 AM
Hi, would somebody like to have a look at my MWE for an animation with matplotib in a tkinter GUI by any chance? It is in post 3 and my last post contains some other explanations. discourse.matplotlib.org/t/…. Many thanks
 
 
2 hours later…
11:51 AM
Hi. Is there a way to replace: x in ['str1', 'str2'] with something like x in AllowedStringsEnum? My goal is to ensure that str1 and str2 are only typed once (when defined) and all checks of them are done in a safe way. (i know i can define a list, but i d like to know if it can be done with an Enum)
 
But you want x to be a string, not an instance of said Enum?
 
yes. In other words, is there a shortcut for this: 'str1' in AllowedStringsEnum.__members__.values()
and my enum will look like this:

class AllowedStringsEnum(str, Enum):
str1 = 'str1'
str2 = 'str2'
Failed at formatting :(
 
@Skyler There are a few posts about drawing circular arcs using Bézier curves on Math.SE. Here's one for cubic Béziers: math.stackexchange.com/q/873224/207316
 
@Riya You can do 'str1' in AllowedStringsEnum.__members__ or 'str1' in set(AllowedStringsEnum)
Those two do subtly different things, but eh
 
12:01 PM
But what even is the point of a string enum where the name of each member is the same as the value? Isn't this just an over-engineered set? Why not just ALLOWED_STRINGS = {'str1', 'str2'}?
 
@Skyler That's a demo in Sage. I guess I should do a plain Python version...
 
@Aran-Fey indeed, that can work. It's rather odd that they dont have this implemented.
 
Much of that Math.SE post is not comprehensible to me, but I'm guessing it implies that it's impossible to draw a perfect circular arc using bezier curves. I wondered whether that might be the case last night. I tried making a couple half-circles using MS Paint's curve tool, but they were all a bit off.
It's easy enough to draw a C shaped curve whose endpoints are tangent to a horizontal line, but I wasn't sure how to get the width of the curve to be exactly half of the height of the curve
Maybe I can find it algebraically... Let me get my cocktail napkins
 
12:29 PM
@Aran-Fey Good point. But I need to use them in other parts of my code like so: if y is AllowedStringsEnum.str1: ..do something. When it's an Enum (instead of a str) refactoring becomes easier and less error prone.
 
12:40 PM
Here's a comparison of a circle (red) vs a bezier curve (green). The purple dots are the control points, numbered by the order that MS Paint expects.
 
they look the same, no?
 
The math cancels out nicely for bezier curves whose control points form a rectangle. the width of the final curve is 3/4ths of the width of the control point box. Here, the box is 4 arbitrary units wide; so the curve peaks at a width of 3 arbitrary units.
@Hakaishin Yes, but only to the human eye. if you overlay them and zoom in, the paths are noticeably different.
 
I see
Kevin doing Kevin stuff :D
 
There's a little bit of red visible under the green. I was careful to place the circle and control points with pixel perfect precision, so any divergence is the fault of the algorithm
 
12:59 PM
I have a weird problem with django, it only translates one item and the rest stays english. No clue why
 
@Hakaishin Did you look at my demo? At the bottom of the page there's a link to a SVG version, which makes it easier to zoom in & see the detail. I draw a thick blue circle, then draw the Bézier arcs over the top of that. If you select 2 sectors, the error's obvious. With 8 sectors, it's virtually invisible.
 
@PM2Ring didn't see it before, now I did
 
The Bézier curves are using cubic polynomials for x & y to approximate y = sqrt(r**2 - x**2). It can get very close, but it can't get an exact match. You'd need an infinite number of polynomial terms for an exact match.
OTOH, Bézier arcs are quite good when the sector angle is small. And they're fast to calculate because they avoid square roots. PostScript & PDF always use Bézier curves to draw circular arcs, and I assume SVG does too. You just need to make the sectors small enough so that the error is less than a pixel.
I mostly draw Bézier curves by calling library functions that do the low-level arithmetic. But sometimes I do the polynomial calculations myself. However, there's a neat algorithm that draws Béziers by reducing their degree until you get to the 1st degree, which is just a line. De Casteljau's Algorithm
 
1:15 PM
When I approximate a half-circle of radius 1 using a bezier curve, it has a radius of 1 at t=0 and t=1/2 and t=1. But at t=1/4, it has a radius of exactly sqrt(265/256).
(insofar as you can say that a bezier curve has a "radius". More accurately, I mean the distance between the origin and a point on the curve, uniquely identified by t)
 
Wikipedia has an anim that shows the reduction of a quadratic Bézier to a line:
 
Incidentally, SVG supports other kinds of curves besides bezier curves. If I'm reading their stuffy specification document properly.
 
I don't think svg has anything besides quadratic and cubic beziers, plus circular arcs I guess
 
SVG specs are "fun" to read. The Mozilla versions are a bit more user-friendly.
 
The table of contents for w3.org/TR/SVG/paths.html#PathData mentions "cubic bezier curve", "quadratic bezier curve", and "elliptical arc curve". I might have spotted others during my expedition, but no guarantees.
 
1:20 PM
What PeterT said. Unless they've recently added some new stuff.
 
elliptical might be new-ish.
 
Well, elliptical arcs are just scaled circular arcs. And as I said above, under the hood, they probably do circular (and elliptical) arcs using Bézier.
 
when we used to draw cubics we also approximated them with quadratics as well, so it's kind of reducable if you're willing to sacrifice some quality
 
Sounds reasonable to me :-) I think the spec leaves such decisions up to the implementation.
There are other parts of the spec that suggest providing the mutually exclusive flags "fast" and "accurate" for various primitives. Perhaps an implementation might use a bezier curve for a fast <circle>, and laboriously calculate the exact circular path for an accurate <circle>.
I appreciate that the document has anticipated that many implementations will do a less than perfect job. "You're going to screw this up, no doubt. But at least let the user customize the type of screw-up they prefer"
 
There's actually a way of drawing exact circles without square roots, but it uses rational functions, not polynomials. I posted a demo the other day in Math chat.
 
1:31 PM
(Here I categorize "render perfectly, but take a long time" as a screw-up. Mathematics says it's fine, but business says it's bad for customer retention)
 
In Sage, you can use ^ instead of ** for powers.
 
Ooh, neat. For both your rational function demo, and the nice ^ syntax.
 
@PM2Ring I see you are still spreading the sage gospel ;) Gods work
 
If Sage did not exist, it would be necessary to invent it
 
It's pretty handy when you're doing mathematical stuff, especially for mathematicians familiar with Latex. And of course Sage can automatically format expressions as Latex, although they sometimes need tweaking if the expression is complicated.
 
1:37 PM
ugh Latex, a wonder how it still persists
 
I'm spinning my Wheel Of Hypotheses... It says "the alternatives are worse"
 
Sage can do amazing things, but because it's so huge, and built on top of multiple systems, it can be difficult to discover stuff. Fortunately, a lot of it is intuitive, once you've had a bit of experience with it. But it's not unusual to stumble across really handy stuff in obscure corners of the docs.
 
"Can do many things, difficultily" is precisely the hazy impression of LaTeX that I have had for my entire career
 
To paraphrase Churchill, LaTeX is the worst system for typesetting mathematics, apart from all the other systems we've tried.
12
 
Valid :-)
 
1:47 PM
It'd be pretty hard to replace LaTeX, it's too entrenched. And it's not easy to get mathematicians to learn any form of coding language. Sure, there are some mathematicians who are also excellent coders in mainstream languages, but they are the exception, not the rule. A fair few mathematicians do use things like Mathematica, though.
Also, it's better to just deal with the annoying parts of LaTeX than to introduce a new system & have competing standards. xkcd.com/927
Some people attempt to typeset mathematics with Word. But that's generally regarded as an abomination. ;)
 
@PM2Ring For everybody except professional mathematicians it's pretty good
 
Vague geometry problem: I have a closed curve, and a point P. Call a point Q on the curve "lucky" if line PQ is exactly perpendicular to the curve. How do I find all lucky points on the curve?
 
@Hakaishin and anybody else writing math professionally
 
Here's an example. The figure eight is the curve, the dot in the upper left is point P, and the red line segments intersect the curve at right angles. Or as close as I could get with my imperfect human eyes.
 
@Kevin "perpendicular to the curve" how? Is it a planar curve? Or is it perpendicular to the local tangent?
 
1:54 PM
I don't know the terminology, but "local tangent" sounds like what I want
 
me neither
How is your curve defined?
 
Well, those red lines look like they're perpendicular to the local tangents to me.
I assume your curve is defined parametrically, somehow.
 
Yeah. That's the vague part. It will probably be parametric. If I need to define it more rigorously somehow, I'm willing.
 
if it's parametric then you can differentiate with respect to the parameter to get the velocity (tangent vector), and then check for each parameter the dot product of the tangent vector with P - P'
 
I did something like that a year or so ago. I was just doing it with an ellipse. The algebra gets ugly...
 
2:00 PM
my assumption is that you'll have to find numerical roots in the general case
 
Aw, but I was hoping the algebra would be beautiful :-(
 
not without a specific curve
For instance a circle with P on its "rotational axis" is made up entirely of lucky points. If you move P a bit (off axis), you end up with fewer points (2? maybe more?)
 
You might get lots of lucky points, which implies the solution is an equation of high degree, and those are generally only solvable via numerical methods.
 
I wonder if this is chaotic for a given curve as a function of P. At least around special points.
 
I think you'll get 2 lucky points from a circle, if P isn't the center. For vaguely the same reason that you can draw two lines tangent to the circle passing through p.
... Except you can't do that if P is inside the circle. Then it has zero tangents and 2 lucky points. Hmm.
 
2:04 PM
I give that a vagueness level of 99%
 
It's only 90% vague in my head, so my brain-to-chat pipeline is about as lossy as usual
I bet winding number is involved here
 
I wager a half-penny
This is all somewhat inspired by Skyler's question. The shortest line between P and the curve will always intersect a lucky point... I think.
 
I think so. Because you can draw a tangent plane perpendicular to PQ.
 
Agreed
 
2:11 PM
Imagine blowing up a sphere centered around P. The first hit will be tangential.
 
Yep, checks out
 
I assume you're talking about:
19 hours ago, by Skyler
hey guys, are there any clean ways to define a closed loop/path and then define distance away from its boundary
IIRC, it's a hard problem, in general. But it'd be nice to know how PostScript & SVG do it to draw thick curves.
I guess you can just slide a circle along the path, but that doesn't sound very efficient.
 
I've considered the sliding circle approach for some of my own graphical projects, but I find it inelegant
Especially if you're a vector graphics library, because a sliding circle is so... Raster-y.
Of course, a vector graphics library will necessarily produce rastered output. But you want to keep all the rasterness in the Hot Zone, and only touch it after you've put on your hazmat suit
 
Indeed. Slightly less raster-y is to draw your curved path multiple times, with its origin tracing out a circle. Like drawing the circle with a curve-shaped brush.
 
2:28 PM
Oh, true. How nicely commutative.
 
2:46 PM
@PM2Ring Wow, what a lineup, what a tune!
 
Anybody have a good dupe for "How to I extract different parts of a string?" - basically, a quick review of slicing.
 
@0x263A :) It would've been amazing to be in the audience.
 
3:04 PM
@0x263A Are you familiar with Wildfire by Mandolin Orange (now known as Watchhouse)? It's a beautifully poignant song about the aftermath of the US Civil War, written by a man from North Carolina.
 
Love Mandolin Orange! Old Ties and Companions is such a great tune. They have quite a knack for songs that land somewhere between melancholy and hopeful.
 
Such a sweet tune
 
@0x263A He's a great songwriter, and I love the mood they evoke. Check out this new version, by Watchhouse combined with The Punch Brothers and Sarah Jarosz: youtu.be/lXHya-wkAQU
 
3:23 PM
Reminds me of Hozier, really nice live version
 
There's a bunch of videos from that gig. The sound quality isn't fantastic, but the atmosphere is incredible.
Something electric from South Carolina: Marcus King, Goodbye, Carolina
Marcus & Billy: Summertime
 
Check out this version of Goodbye Carolina as well relisten.net/marcus-king-band/2021/12/30/… also that site is pretty great if you weren't privy to it already.
 
3:43 PM
@0x263A Nice! I've only heard the versions on YouTube, and I don't think I've heard this one before.
 
4:04 PM
Is the rule of up/down-vote being locked after a certain time, apply to the OP too? I noticed that I lost 10 rep, which might be the OP removing their vote after almost a month
 
If the post was edited, up/down votes can be changed.
 
cabbage
@Kevin what happened to quatloos?
 
@MattDMo Weirdly, it was last edited on 22 July
 
What's the question?
 
4:20 PM
0
Q: Python Tkinter: Unbinding Mouse Scroll Wheel on ComboBox

Mongoose ManI have a combobox within a scrollable canvas frame- when I open the combobox and attempt to scroll through the options, the combobox and the entire window both scroll together. It would be nice to pause canvas scrolling while the combobox is open, but unbinding the mousewheel scroll from the comb...

 
Hmm. Maybe the OP came back to it recently and decided to un-reward you. Dunno.
Rep goes up. Rep goes down. Blessed be the name of the cabbage.
 
@Code-Apprentice They're still around. Biding their time.
 
@DelriusEuphoria IIRC, there's some weirdness with Tkinter mousewheel events. The event numbers may not be the same on Windows vs Linux.
 
4:49 PM
The demo only needs to change the capitalization of Tkinter to be 3.X compatible. here is a version with that change, plus a print statement so you can see what the event object contains.
On my Windows 10 machine, event.num is always "??', and event.delta is always either 120 or -120.
> Only Windows and macOS Aqua typically fire MouseWheel and Shift-MouseWheel events. On X11 vertical scrolling is rather supported through Button-4 and Button-5 events, and horizontal scrolling through Shift-Button-4 and Shift-Button-5 events.
 
And I guess you're out of luck if you want to detect Touch events, apart from the rudimentary ones that get duplicated to mouse events.
Sarah Jarosz & Chris Thile: Lost Dog
 
If it's possible to listen for touch events, it's not as easy as the common events listed on that page. I 75% suspect that you can still do it, if you're determined
Probably gotta pump the event queue yourself and look for WM_TOUCHSCREEN_WAS_TOUCHED or similar
WM_POINTER_DOWN. I was close.
Direct Manipulation, which I have never heard of before now, ostensibly lets you define touch behavior for your application without writing fiddly handlers for your various WM_ events. But it requires COM, so it's hard to say with a straight face that it's easier in the long run.
 
5:16 PM
To be honest, handling touch input (beyond simple equivalents to mouse click & drag events) gets complicated no matter how it's organised. Especially if your program has to work both with & without a mouse.
 
6:05 PM
@PM2Ring Ah I see
Tkinter communication with WM is okay for an old GUI toolkit
 
6:29 PM
@JonClements Blue Light, JE Sunde + Pomplamousse.
 
6:58 PM
that sounds like an especially awful mixed drink involving grapefruit liqueur and light beer
 
1 part pomple, 2 parts mousse
 
@Kevin I would start by finding a parametric equation for the curve, offsetting so that P is at the origin, and then taking derivatives. it should be possible to work out some equation in terms of x(t), y(t), dx/dt, dy(dt) and then solve for t and then plug it back in
it seems more like a calculus problem than an algebra one to me
 
derivatives in more than two dimensions is not my specialty, but it does seem promising
 
 
1 hour later…
8:07 PM
is file a keyword in python?
why my IDE, VSCODIUM detects 'file' keyword as file?
 
It was never a keyword, but in python 2 it was a builtin
 
what was its purpose?
 
I think it was equivalent to open
 
@discoMonkey I think it is because of __file__
 
ohh yess
 
8:11 PM
Just like how dir is also detected as a kw
 
got it
 

« first day (4324 days earlier)      last day (607 days later) »