Category Archives: Programming

Holmes Card Workshop – A Real Drag

Progress has been slow.Partly because I’ve been moving code around so it makes more sense – more for my own piece of mind rather than anything else. However, I also have been aware that sizing images using the slider was painfully slow. This is because I was processing and cropping with every step.  Now, the image is cropped and scaled live by nesting elements inside each other and scaling those. This gives a much faster result than before.

The other thing that has been bugging me with this was the UI for positioning images. Before, I was using sliders controlling the size of the images, and the gap between them. It seemed to me that, really, that should be a mouse drag operation, so I spent a fair amount of time finding out what was needed to make that happen, and get that working. 

And, finally, yes, there are undos. Not for everything yet, but I’ve started adding that in. An undo requires you to give the application a route forward (ie the change the user is making), and a route back to the previous state. It sounds more complicated than it actually seems to be, but everything needs coding for, and it’s a bit of a faff to do. Maybe I’ll find that I can bunch a few of these operations into one in the future, but for now, it seems to be working well as it is.

Holmes Card Workshop – See it Work!

It has been a while since I looked at this, because I get distracted, and there are also times when other things need my attention.  However, this has been in the back of my mind for a while, so I took another look at it. This is where I am right now. The application will take an MPO file, split it up, and create a Holmes Card type image from it. It will also take an image with both left and right images side by side, and split that in two as well, so images from real film cameras can be brought in.

But It’s All Wrong!

Actually, what brought me back to this was the niggle that really this should be working at the document level. Making it work on documents would allow me to (eventually) get it to save the file for future loading and editing. So I’ve started on that. I realised that I had made some fundamental mistakes which need sorting out too, so more time has been spent on getting that fixed than anything else.

Right now, I have something that is part way to what you see in the video. This time, you can create a new document in a new tab and work on that. It’s now possible to have more than one card being worked on at once. I have a few more things to add in – the selectors at the bottom for cards, shapes and filters aren’t there yet, as well as finish up the existing image controls to the right. Once that’s done, I can think about saving and loading, which I expect will be a Google-busting marathon of searching and reading.

Holmes Card Workshop – UI Refinements

Feeling rather pleased with this today. I’ve been doing some UI refinements, most of which has needed work in the background which haven’t really had much front-facing action. However, the screen shot shows what’s been achieved.

Most importantly (for me), the selections for the various card settings has been moved from sheets that appear to a carousel kind of selection at the bottom of the window. It’s now a case of scrolling and clicking, and the result is shown instantly. Importantly, for me, is that the filters selection uses the image the user is working on, rather than a dummy image. This also reflects the zoom setting as well. In fact, any of the image control options will also feed into these filters, so the user always sees a quick view of what the main image will look like. I’m rather pleased I managed to do this. Again, I’m thinking “this will be really hard to do” and surprising myself that, in most cases I just need make a small adjustment to existing code.

I’ve also been playing the Core Image filters to make more effects. Not too sure if I like the results yet, but I’m sure I can refine them.

Still not even thought about the “save this as a document” option yet – but I do feel that needs to happen. I’ll need to hit Google a lot of that, I think.

Holmes Card Workshop – New UI

I bit the bullet. After some thought, I decided that it was better to present the options in a pane below the card preview, rather than have the slide over and back. The reduces the number of mouse clicks from three to one to see the result of the chosen option. This brings it into line with the controls to the right which are as instant as I can make them. A much better experience, I believe.

Next – clean up the presentation of the thumbnails (they all have to occupy the same vertical space now), remove some buttons and look at what happens when the window is resized (which isn’t great at the moment).

Continuing with Holmes Card Workshop

Things have moved on a bit since the last post on this subject. The first thing that is noticeable is that it looks much more like a proper application. The tools to the right are lined up better, and when the window is resized, the window’s contents don”t completely fall apart!

Continue reading Continuing with Holmes Card Workshop

Metric Time on an Apple Watch

I have a small fascination with Metric Time. The continuance of the French project to measure the world in sensible, easy to understand units. Like the Metre, the Litre and other metric units, Metric time divides the day up into easy to comprehend units. So, you get 10 hours in a day (instead of the normal 24), and each hour is divided into 100 minutes, and each minute divided into 100 seconds.

Continue reading Metric Time on an Apple Watch

Stereo Camera UI

After my last post, I’ve been looking at a number of GUI tools that I can use to create a control system in Python. I finally settled on WXGlade, simply because it’s pretty much as close to what I am familiar with as I can get.

I say “as familiar with” because the way it works seems to be much the same way that web sites were once constructed – by using tables to handle the layout. This seems to be the way of things with this kind thing in the world of Python, and it seems to be that it works this way because that’s how people choose to work. So no dragging elements around like you would, say, in Xcode on a Mac when creating a UI for a phone or desktop machine. Continue reading Stereo Camera UI

Getting all Swifty

It had to happen eventually. It’s not the first time I looked into this area, but this time I have got further than I have ever done before.

I started writing an app. By this I mean that I have cracked open Apple’s Xcode 6 and started typing in their new programming language Swift. This time, I have got much farther than I have ever done before, and I suspect that the reason for this is that Swift is somewhat more palatable to me than Objective C . Swift feels a little more, though I know its is not, like JavaScript – something I have used for a long time in my web design activities. Now, I have a feeling that this could be deliberate. Someone at Apple may have  thought “you know, all those web people really need to be pulled into the fold of writing apps properly”. Certainly, Swift feels more comfortable to use.

So, I decided to have a go. Make something interesting to the onlooker, but something to challenge me. It just so happens that I had just the thing underway in Hype (a rather good HTML/JavaScript animation application). This is a Metric Clock – which divides the day into ten hours, and each hour into 100 minutes, each comprising of 100 seconds. My implementation can be found here:

So, I thought, why not try to make this run in iOS, as a native app? It would give me a target to aim for, and I should learn a few things along the way. So, time to make what others will see as a typical beginner’s mistakes.

Double vs CGFloat

I have run into a problem or two. This is partly down to the way Swift handles decimal numbers. There are three kinds of numeric value (that I know of):

Int – an integer is a whole number – so 3 is an integer, 3.1 is not, and if you try to set 3.1 as an integer, you’ll get an error message.

Double – this is a number held to 64-bit accuracy – and can hold numbers as decimals, so 3.1 can be held in a double variable.

CGFloat – this is also a decimal number, but held at 32-bit accuracy.

Unless you are explicit in your definitions, Swift will decide if a numeric value is an Int, a Double or a CGFloat.

So, in the context of my clock, I am running into some issues with this. For example, I will eventually be grabbing time from the system clock, and converting it to decimal time, and calculating the position in degrees (note, covering to radians is a whole other area of confusion to be dealt with another time), and rotating the hands accordingly. So, I am setting up some variables to help:

var secondHandTimer = 0.0
var secondTime = 0.864
var minuteTime = secondTime * 100
var hourTime = minuteTime * 100
var dayTime = hourTime * 10
var mySecondHandDegrees = 3.6 * decimalSeconds
var mySecondHandRemainderDegrees = 360-mySecondHandDegrees
let fullRotation = mySecondHandDegrees * ((M_PI)/180)
// Call to the second hand rotation function, with an initial rotation of 0 degrees
self.secondHandAnimate( mySecondHandRemainderDegrees , theDuration: 0.0 )

So far, so good. However, when we get to secondHandAnimate(), things start to get a little odd:

func secondHandAnimate( theRotation: Double , theDuration: Double ) {
    let opt1 : UIViewKeyframeAnimationOptions = .CalculationModeLinear
    let opt2 : UIViewAnimationOptions = .CurveLinear
    let options = opt1 | UIViewKeyframeAnimationOptions(opt2.rawValue)
    let fullRotation = theRotation*((M_PI)/180)
    UIView.animateKeyframesWithDuration( theDuration,
        delay : 0,
        options : options ,
        animations: {
            UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 1/3 , animations: {
                self.secondHand.transform = CGAffineTransformMakeRotation( 1/3 * fullRotation)
            UIView.addKeyframeWithRelativeStartTime(1/3, relativeDuration: 1/3 , animations: {
                self.secondHand.transform = CGAffineTransformMakeRotation(2/3 * fullRotation)
            UIView.addKeyframeWithRelativeStartTime(2/3, relativeDuration: 1/3 , animations: {
                self.secondHand.transform = CGAffineTransformMakeRotation(3/3 * fullRotation)
        completion: { finished in
            self.secondHandAnimate(360 , theDuration: 86.4)

This is where I start to get errors. Here’s a screenshot of what I get:

Screen Shot 2014-10-29 at 12.04.51
Screen Shot 2014-10-29 at 12.18.41

(For a full explanation about why I’m using keyframes, it’s to do with rotation start and end points being identical in Radians, even though the start is 0 degrees and the end is 360 degrees – more here

It seems that, to my untrained eye, the line starting UIView.addKeyframeWithRelativeStartTime does not seem to like the Double kind of number.

So, I make a small change to the function definition of secondHandAnimate():

func secondHandAnimate( theRotation: Double , theDuration: CGFloat )

and try another test build. This time, a completely different error:

Screen Shot 2014-10-29 at 12.22.49So, it seems that if I want to set the time for a duration of an animation, it HAS to be a Double. BUT keyframes don’t seem to like Double numbers when calculating the relativeDuration part. It seems that I have to very explicit in how I deal with numbers, by explicitly stating what I want them to be:

// assume a static starting point for the time
 var mySecondHandDegrees = CGFloat(3.6 * decimalSeconds)var mySecondHandRemainderDegrees = CGFloat(360-mySecondHandDegrees)


func secondHandAnimate( theRotation: CGFloat , theDuration: Double )
 let fullRotation = theRotation*(CGFloat(M_PI)/180)

With these in place, things start to work and I get successful builds, but it feels odd that I just can’t use an Int, CGFloat or Double for animation. I expect I am missing something important and fairly basic here.