Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Sunday, March 23, 2025

PhotoTool Project Updates Ep 1 - Initial Steps Towards Scripts to Ease + Automate Import + Backup of Media Data

For the past few weeks, I've been having a blast hacking away at a pair of scripts for automating some steps of my current photo management workflow that have thus-far been very labour-intensive to perform:  Namely, importing/backing up photos and videos from my camera (R5)'s memory card, and doing the same with my phone (Android).

Wednesday, April 19, 2023

Python 3.11 - IntEnum str() representation changes

Got an unwanted surprise today trying to run my codebase ("TPMS Studio") using the latest Python (3.11) instead of the 3.7 / 3.8 combos I've been using for the past few years.

Turns out the core team made a breaking change to the behaviour of enums, which breaks our file format + causes the code to crash on startup (assert failures)!

The cause:
`str(eMyEnum.Value_1)` now evaluates to "1" instead of "eMyEnum.Value_1"

(Note: eMyEnum is defined as an IntEnum)

 

The solution I ended up with was based on:
https://github.com/python/cpython/issues/94763#issuecomment-1313058070

 

[EDIT: This was the old solution. I have since learned of an even easier fix, from the official docs. See below]

In short, I now do something like:
```

import sys
import enum

if sys.version_info >= (3, 11):
    # Python 3.11+ hack
    class IntEnum(int, enum.Enum):
        # Get back old "EnumName.VariantName" str() behaviour
        pass
else:
    # Use old defines for older Python versions
    IntEnum = enum.IntEnum

```

 

[Latest Update: This solution is easier to use. It comes from the official docs (i.e. example 2)]

```

from enum import Enum, IntEnum

class eMyEnum(IntEnum):

    __str__ = Enum.__str__      # <--- That's the key right there

``` 


 Reposting from my original Mastodon posts for easier searchability

Friday, April 8, 2022

Getting rtree (0.9.7) and PyInstaller (3.4) to Work Together

This is a quick note on how to get RTree (0.9.7) and PyInstaller (3.4) to play nicely together, so that if you've got a script using RTree (e.g. for example, a script that calls trimesh.proximity.thickness()) that you need to compile into a .exe so that non-technical users can run it as a standalone binary without setting up a Python dev environment first.

These instructions are based on what worked on the project I'm working on, and are only tested with the versions listed on Windows 10. I haven't actually tested this on Linux, since most of the Linux users of this program are already doing a lot more coding work and will have dev environments set up anyway, that it doesn't matter for them.

Hopefully this helps someone else someday. 


Friday, November 14, 2014

Text Editor Project Started

With a long weekend holiday here, I finally bit the bullet and started work on building a new text editor for myself. This comes after years of trialling different solutions - including giving some of the latest newfangled web-tech based ones out there a second chance with an open mind (in the end, a combination of critical quirky flaws and horrid colour schemes inducing eye pain - including one nasty bout of red-eyed discomfort for a few hours) as replacements or "secondaries"... Unfortunately, nothing is quite cutting it anymore :/

So, introducing "Nippy" - a PyQt + QScintilla based text editor, heavily inspired by Notepad++


Currently, there's not much to see. It's only a single-document text editor window right now, with a lexer hardcoded to treat everything as Python code, and with no session storage. But at least I can use it to load up any of the code for my Python-based projects, and use it for some simple coding tasks (bookmarks, duplicate-lines, move up/down, go to line, tab-based indentation, and file open/save all work, with the rest provided by QScintilla already - in other words, the bare basics I need from an editor to do stuff; a working function list + find in files + multiple tabs would just make things easier).


Friday, November 8, 2013

WIP Experiment - Including Relevant Parameters in Keymap Names

Today for a bit of a challenge, I've been playing around with the keymaps editor UI to try and get it to display more helpful names for operators. As anyone who's played with this knows, it's not terribly helpful right now when you're faced with a list of 10 items in a row labelled "Context Enum Toggle" and each with different hotkeys ;)

DISCLAIMER: The following screenshots merely demonstrate a highly proof-of-concept hack aimed at establishing techniques for successfully extracting the necessary info out of the PyAPI. In practice, this has been much less cooperative than I'd have liked, so the ways that these things are actually presented is less than optimal.


Tuesday, August 20, 2013

PyQt Widgets - TagLabels and Canvas.Backdrop

As part of my research work, I'm currently spending quite a bit of time developing prototype interfaces/widgets. In my case, my current "weapon of choice" is Python2 + PyQt (with progress logged in Git), as it gives me fast turnarounds, nice and familiar API's, and a modern + industrial-grade base UI library.

Today, I'm going to release a few "support" widgets which I've developed for use as part of my toolkit/workflow:

1) TagLabels

https://bitbucket.org/Aligorith/pyqttooltipslib  (Currently in "TagLabels" branch)


2) Canvas.Backdrop



Tuesday, June 11, 2013

Risk Scores - Alternative Blender Security Approach

Over on the blender-developers mailing list these past few days, there has been a lively discussion about the state of security in Blender. Of particular concern is the potential for malevolently-minded individals to create malware laden .blend files which then get distributed far and wide to unsuspecting users who were none the wiser about these problems. Particularly troubling too is that many virus scanners would probably not be able to detect these problems as they currently stand.


Perhaps I'm taking a much too simplistic view of these issues, but it seems that while we may never be able to achieve full bulletproof fortress status, there are a number of feasible steps which can certainly help to identify a large number of these types of attacks to allow users to make more informed decisions about their own safety and security. The following proposal is a just a random idea I had yesterday afternoon of an alternative solution that (at least given the facts I'm aware of now) sounds entirely feasible.


Sunday, August 19, 2012

"Remapped Shape Keys Transfer" Revisited

Over a year ago, I released an experimental tool for transferring shape keys between meshes ([1] [2]). Unlike the builtin copy shapekeys tool, this one was built specifically for the case where the vertex counts were different but where significant parts of the mesh were still relatively untouched. This commonly occurred when you've gone and added some extra geometry (e.g. extra limbs/edge loops etc.) to a mesh after adding shapekeys.



Today, by popular request (and for a little diversion before jumping into my next block of scheduled project work), I've taken some time to check on this tool and get it working in 2.63/4 again.

Key Changes:
  • Fixed a small bug which was preventing it from working in 2.6.
  • Added support for copying vertex groups  ("Remapped Vertex Groups Transfer")

Saturday, May 5, 2012

Blast from the past - Ludwig van Byteoven snippet


For a bit of Friday night entertainment, I dug up my first major/non-trivial programming project that I had started way back in 2005, and worked on for about a year before other projects took over most of my time. It was called "Ludwig" (after Ludwig van Beethoven) and was an attempt at creating a piece of software that could "compose" credible sounding pieces of music... or at least that was the goal ;)

Wednesday, January 11, 2012

PyGtk Tip - Spin Buttons and Misbehaving Arrows

Just a quick tip for something that I finally found the answer to after searching fruitlessly for for a while.

If for whatever reason the arrow buttons aren't behaving - as in, they won't do anything when you click on them normally, but will start zooming off increasingly fast when click+holding them - then you need to set "step_increment" on its "adjustment" object (a value of 1.0 for this serves most purposes well).

For all the failings (IMO) of Gtk, at least the "adjustment" object design is an example of one thing that they did right over other toolkits. I like this, since I've found that it makes it ridiculously easy to simply hook up all the various widgets that may be displaying a numerical value so that they update correctly when the others change, all without the need to write many tedious flushing event callbacks.

Saturday, December 17, 2011

PyGTK - Collapsible Panels

Mwahahaha... last night I finally managed to coerce PyGTK into giving me collapsible panels that looked the way I wanted.


Wednesday, April 27, 2011

Rigging Tool WIP - ShapeKey Transfer Continued (Part 2)

After doing a bit more hacking, I've now got this tool working better for the remaining troublesome cases, and also substantially faster! How much faster? Well read on and download the script yourself to see :)


Same links as last time, but here they are again in case you need a reminder:
https://sites.google.com/site/aligorith/remap_shapekeys.py?attredirects=0&d=1  <-- the script itself.
It's probably possible to try and register/install this as an addon, but for now, I'd recommend just loading in a text editor and running to get it ready for use.

https://sites.google.com/site/aligorith/remapShapekeys_Test-01.blend?attredirects=0&d=1 <-- the test suite

Tuesday, April 26, 2011

Rigging Tool WIP - Transferring Shape Keys Between Meshes

The other day I mentioned that I had started work on a mystery feature. Well, today I'll reveal that this feature is a tool to transfer shape keys from one mesh to another.

Now before someone gets overly excited and skips past the rest of this text, I am aware that a similar tool does exist in Blender trunk already. However, this and other tools which I've come across don't exactly fill the void that this tool aims to bridge. Let's look at a little example of the kind of situation that this aims to solve:

In this particular problem scenario, we have an original "source" mesh if you will, that had some shapekeys painstakingly defined (i.e. for facial expressions perhaps). Now, we then decide that we'd like to adjust the topology of parts of the rest of the body, or perhaps even add body parts (say, a gigantic 4ft long tail, or in the example above, hands and feet), so we go and start editing the mesh (having made a backup first of course).  The key thing to note here is that we're not touching the face or whatever part the shapekeys were on.

Wednesday, March 2, 2011

Behold the power of ctypes

Despite uncertainty over when the University year will resume here, I've been chipping away at a little assignment that was handed out on the first day of term (to be precise, it was the first lecture I had this year, and also the last course I had a lecture for so far, about 1 hour before the quake struck). Anyways, getting back to the main story for today.