Category Archives: Uncategorized

Calibre E-book – Authoring Plugins with a Custom Context Menu

I’ve been hacking with the Calibre ebook reader for a few hours, and I’d like to share with you some notes of how to add a custom context menu to a book, so that we can open a secondary folder where the book has been exported to.

A good place to start is to download the from the Plugins documentation. Unzip the directory, and run Calibre in debug mode from that directory.

mkdir demo
cd demo

REM loads calibre plugin from the current directory
../calibre-customize.exe  -b .

REM launch calibre gui in debug mode
../calibre-debug.exe -g

Next, add the custom action to the context menu manually through the preference toolbar. I’ve taken some screenshots below:

That done, we can go in and hack on the plugin until it works.

In my particular case, I’ve got an alternate filepath stored in a custom metadata field, and I’d like to open the alternate containing folder.

#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai

__license__   = 'GPL v3'
__copyright__ = '2014 Chui Tey'
__docformat__ = 'restructuredtext en'

from calibre.gui2.actions import InterfaceAction
import os

class InterfacePlugin(InterfaceAction):

    name = 'Open Oracle Folder'
    action_spec = ('Open Oracle folder', 'images/blank.png',
                   'Open the file in the Oracle folder', 'CTRL+O')
    dont_add_to = frozenset(['context-menu-device'])
    action_type = 'current'

    def genesis(self):
        #icon = get_icons("images/blank.png")

    def open_folder(self):
        rows = self.gui.current_view().selectionModel().selectedRows()
        if not rows or len(rows) == 0:
        not_found = []
        for i, row in enumerate(rows):
            if i > 5: continue
            mi = self.gui.library_view.model().db.get_metadata(row.row())
            filepath = mi.get('#filepath', None)
            if filepath:
                import os
                folderpath = os.path.split(filepath)[0]
                if os.path.isdir(folderpath):
        if not_found:
            if len(not_found) > 1:
                raise Exception("Folders %s not there!" % ", ".join(not_found))
                raise Exception("Folder %s not there!" % ", ".join(not_found))

            # actual path
            # path = self.gui.library_view.model().db.abspath(row.row())

    def location_selected(self, loc):

        enabled = loc == 'library'

Note to myself.

NodeJS requires VS2010 to build some binary components. If you install Visual C++ 2010 Express, you only get to build 32bit binaries. Therefore, you should install the 32-bit NodeJS msi.

Learning Cobol Round #1

My mum learnt COBOL and FORTRAN when she was in university back in the 60s. Although I have used FORTRAN77 in a professional capacity, I still haven’t had the opportunity to try COBOL.

Since being retro is the harbinger of cool, I’ll spend the next few articles blogging about my experience working with COBOL.

Visual Cobol

There is a free non-commercial use license granted by Visual Cobol. This is sufficient for my learning purposes.

In terms of resources, Teach yourself COBOL is 21 days seems to be a good starting point.

The download is a little tricky. After receiving the confirmation email, I was presented with a screen but the download link wasn’t apparent. It’s tucked under the Software/Licenses tab (see red arrow). The download was 417MB, and I was a little concerned I’ll not have much space left on my SSD, which is burgeoning with several virtual machines. However, the promise of the familiarity of Visual Studio and having access to the .NET framework beckons me to try it out.

In comparison, the OPENCOBOL 1.1 source download is 1 Mb. That’s very inviting, although I don’t really like the idea of building GNU autoconf project on Windows.  There’s never a nice ending.  I found prebuilt-binaries for OPENCOBOL on Windows, and given the download size of 7.3 Mb,  I downloaded it as well.

Upon creating the first COBOL project with Visual Studio, I was prompted for a license key. It wasn’t immediately apparent, but all I had to do was to provide the email address I had used to register with Microfocus, and that activated my free copy automatically.

Running Hello World from a Visual Cobol Console project was simple enough.

       identification division.
       program-id. Program1.

       environment division.
       configuration section.

       data division.
       working-storage section.

       procedure division.

       DISPLAY "Hello World".
       end program Program1.


OpenCobol was straightforward. Unzip the 64bit binaries to C:\OpenCobol, and run vcvars64.bat to set up the path to Visual C (OpenCobol translates COBOL to C and then uses the platform compiler to build executables). The command below builds hello.exe

cobc -x hello.cob

Project scope

In terms of project, I’d like to try my standard project, involving authorization, data validation and persistence (both NoSQL and SQL). I’m mindful that my projects will be un-COBOL-like, but that can be refined with time.

Next article – Round #2

Saw this in my email today wizpert – billed as “is a fast growing community of experts, where users seek advice and coaching on a range of programming languages, including Python, HTML, PHP, JavaScript and more.


Powershell equivalent of xargs

I wanted to be able to build extmap.xml for all the files that were in my packages\ directory. I had a Powershell script called ToExtMap which automated most of my tasks, and a little experimentation with Powershell gave me this one liner:

PS C:\Users\Chui\Projects\SAM-GET\packages>
Get-ChildItem -Filter *.dll -Recurse -name |
%{ ToExtMap $_ | Out-File ($_ -replace "dll", "extmap.xml") -encoding ASCII}

A bit of explanation might be in order:

  1. Get-ChildItem -Recurse finds all the files I require.
  2. The %{} is the shortcut for the foreach operator.
  3. Powershell is object oriented. $_ -replace ... executes a string substitution

Over at Forbes

It started with making one presentation slide for each idea. Each slide would have a heading and several bullet points defining the scope of the feature and metrics describing what success would look like and how it would impact the business. That’s all people got to make their case. And given the speed of the whole process, there was little time for precision.

Dell Service Drop off Brisbane

The Dell service center in Brisbane has moved to 8 Castlemaine St, Cooparoo (effective 6 Jan 2014). It is in the big courier’s shed, and there’s a small narrow storefront. If you need to drop off your computer for repairs, it is no longer at Mowbray Tce.

Hopefully this post finds you before you get lost.

Piano Teacher in Toowoomba

My kids have been taking piano lessons with Marie Kilpatrick in Toowoomba and I liked her style of communicating musical ideas to the children. For example, in Mozart’s Andante, she likened the left hand to rustling wind, while a diva sings on the right hand, and then she works through with the children the kind of touch necessary. Another way she communicated this is by explaining that the triplets on the left hand outnumber the melody on the right hand, and therefore has to be much much softer.

Caliburn Micro Navigation for Silverlight

Users who are accustomed to browser based apps find navigating between screens and having a back button to be a very natural way to interact with applications. In addition, they also make it easy for screens to be bookmarked.

In Silverlight, navigation is integrated with the web browser through the use of Uri fragments. Uri fragments look like this:

. When the Uri fragment is changed, it triggers a Frame control to load new content in two steps:

  1. Firstly, the fragment is mapped to the path to a XAML file using the frame’s UriMapper
  2. Then, the XAML file referred to in the previous step is loaded and the navigation events are raised.

Caliburn.Micro, being a ViewModel-First framework can integrate with the Silverlight Navigation Framework. Rob Eisenberg has already provided one for the Windows Phone. With a little work, we can make it work for Silverlight as well. I have provided it in this GitHub project.

A quick note on how Caliburn.Micro integrates navigation: Caliburn.Micro defines an INavigationService interface that includes methods like Navigate() and GoBack(). The implementation, called a FrameAdapter, calls the equivalent methods on the Frame control.

The best way to apply the FrameAdapter is in the bootstrapper, once the RootVisual has been loaded. There is a bit of fiddling around initially, and we cannot inject a Frame into the ShellViewModel’s constructor because the ShellView’s Frame isn’t loaded yet. So there is a precise order we need to apply to bootstrap this properly. All is done for you in the sample. We load the ShellView, find the frame, and then inject it back into the ShellViewModel.

	protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)

            // finds the Frame control in the ShellView, 
            // registers it, 
            var frame = FrameAdapter.FindFrame(App.Current.RootVisual, null);
            container.RegisterInstance(typeof(System.Windows.Controls.Frame), null, frame);

            // and then reinitialize the shellviewmodel
            BuildUp((App.Current.RootVisual as System.Windows.Controls.UserControl).DataContext);

Here’s a sample ShellViewModel that gets injected with INavigationService during the BuildUp() call.

public class ShellViewModel
        public INavigationService NavigationService { get; set; }

        public void Link1()
            NavigationService.UriFor<Page1ViewModel>().WithParam<int>(p => p.PageId, 42).Navigate();