Nerd Babble

TL;DR; How to solve problems that should already have been solved vs. reinventing the wheel.

I have been programming in Python for a few years now. I like the amazing libraries it has, plus the power of the language. I dislike that it has weak typing.

In the languages I’ve used in the past, you declare a variable before you use it.

int integerVar;
double floatingPointVar;

Python doesn’t do it that way.

integerVar = 5
floatingPointVar = 5.0

The issue is that you can assign 3.1415 to integerVar and python will let you do that. I’ve recently learned about “TypedDict” which gives me structures and a package called “trycast”. I finally have the types of data structures I want from more structured languages, in python.

Add to that my discovery of the Language Server Protocol, which has turned Emacs into an IDE and interactive debugger, and my life is much, much better.

All of this was just a side project on top of what I was really doing, writing a tool to help teach English as a Second Language, or ESL.

The first day I did this, I had my e-reader program running. I had Google dictionary available. I had to open a Google meet, then share different screens, as needed, to show the different parts.

I had a markdown editor open to have words that I planned to pre teach. It was painful. Switching from one student to another was a good 5 minutes. Prep time was 30 minutes per 30-minute session.

The cure was clear, write my own tool to perform what I required. The framework I chose to use was Qt6. It has Python libraries, I was already using it for other tools. It should all just work.

First, I had to learn the format of EPub. From there I needed to import the book and prepare it to present. I decided to use a QTextEdit. This worked ok. It was nothing more than a weak version of the E-Reader I had been using.

What made it powerful, was that I could select a word in the QTextEdit. With the click of a button, pull up a definition.

I used the request package for my networking.

Over the following weeks, the tool got better and better. Combined with PipeWire and Open Broadcast Studio, I had a pretty clean interface. I could select a word, click the “define” button, the tool would check to see if we already had the definition, if not, it would fetch the definition from a remote server. It would then format everything and put it into its own QTextEdit and display the results.

My students liked it.

The problems started when I decided I wanted to be able to play a pronunciation. This required learning how to create a virtual microphone. Learning how to use the QMediaPlayer. Learning how to direct sound from my tool to the virtual microphone. Making sure that the patch was correctly created to send all the audio to the correct places.

I got that working.

Did you know that some words have multiple pronunciations? I did. I didn’t code for it. This is no real issue, I just need to connect a click on a button in the QTextEdit and when the signal is received, play the sound.

Do you know what you can’t put in a QTextEdit? That’s right, a button.

The QTextBrowser gives me clickable links, but those are not generating the types of signals I was looking for. Worse, I can’t use the CSS to format my text the way I want to.

There was only one thing to do. Roll my own. I needed to create my own wheel. I had to reinvent my own text browser widget.

Which took me to learning how to do low-level graphics in Qt.

As I dug through this mess, I found that built in tools that “just worked”. Which lead me to discovering I didn’t need my own settings/preferences system. Qt has QSettings which does everything I need plus more. That’s a win. I haven’t switched to it yet, but I will.

Having found QSettings, it occurred to me that Qt might have networking tools. I was just about to implement a caching system when that networking might be a part of QT struck me. Turns out that not only does Qt have a networking implementation, it has a caching networking implementation.

At the same time all of this is happening, I’ve gotten an API key from Merriam-Webster. I now have access to better dictionary information. And the data payload is entirely different. It is very complex. Three weeks of coding, and I’m at the 90% state.

This brings me back to “This must be a solved problem.” What is that problem? Drawing text that wraps.

Consider a logical line of text, 200 characters long. If your display is 80 characters wide, it will display 80 characters, 80 characters, 40 characters.

This would look bad. What you want to do is to find the first logical word break before the 81st character and break the line there. This is what your text editor does. This is what your browser is doing right now. Unless I type a very long word, your browser is moving to the next line between words.

Yes, QT has an option for doing exactly that type of word wrap. It looks great. It is precisely what I want to see.

It works perfectly until I need to start that logical line at someplace apart from the first character of the line.

Consider this text: specifically : the procedure of submitting a statement to such conditions or operations as will lead to its proof or disproof or to its acceptance or rejection.

This bit of text has three separate parts. The first part is in italics, the next is bold, and the rest is in standard text.

It is that long bit of text that I want to wrap. The issue is that the text exists within two different bounding boxes.

The first box exists from : to the edge of the window. The second bounding box exists from below the first line of text and spans from the left indent to the right edge of the window.

Qt either doesn’t have that option, or I have not found it.

So the next thing that could happen is for the code to provide me a way of determining where Qt is braking words. If I know that, then I can break the text into two parts and make this all work.

3 steps forward, 2 steps back.

Spread the love

Australia: Mass Casualty Event in Sidney.

UPDATE: 6 killed. Several injured including a nine-month-old baby.

72 hour waiting period applies, but Gun Control Zealots should not get upset since it did not involve guns.

“See” We don’t need guns! Unarmed hero confronted that bad guy!”

Not really, he was finally stopped by (drum roll) Good Gal with a Gun.

Spread the love

Guy on the internet knows nothing but still has opinion

Found this gem:

 

I guess he should have looked up the requirements for training to be a law enforcement officer in Tennessee through the Tennessee police academy.

 

Oh look, 40 hours of firearms training and 50 rounds.

Yes, this is the minimum, but I can’t imagine a police academy doing much more than the minimum to get people to pass.

If 40 hours is enough to train a cop to carry a gun, it should be enough for a teacher.

Now, frequent readers of this blog know that support training way beyond the bare minimum, and most cops are shitty shooters.

So, of course, we support teachers training regularly. But this guy clearly is of the mindset of the magic fairy dust of government authority, so private training is irrelevant to him, all that matters is official government traing.

He knows nothing about what the standards are for the police, but he knows equivalent standards for teachers is insufficient.

 

Spread the love

Friday Feedback

It has been a busy week for me. I’m still reading legal filings, but it is harder and harder to write about them.

The state says the same thing, over and over again. The courts keep looking for ways to avoid doing the right thing.

It reminds me so much of the aftermath of Heller.

I do remember freedom week in D.C. For about a week, I had a permit to carry in D.C. If you had a CCW or lived in a constitutional carry state, you could legally carry a concealed firearm in D.C.

A week later, that was gone.

It looks like the rogue courts have just about settled on how they are going to avoid obeying the Supreme Court.

At the same time, we are seeing more and more lawfare. Different entities suing people involved with the firearm industry to force them out of the business.

At the same time, the ATF is attempting to shut down private sales of firearms.

They just issued their final ruling on Thursday. Under the new ruling, just about anybody that transfers a firearm can be required to get an FFL or to go through an FFL.

We are getting closer to getting the next case before the Supreme Court. That is our only hope of bringing these rogue courts into line.

A reader passed this on:

It might be worth the read.  I found myself distracted by the content.

The comments are open, do you have anything you think we should read or which would be good for GFZ?

Spread the love