Niw Markdown Editor

For the past three weeks I’ve been working on an editor for working with plain text files and making it easy to add markdown syntax to them. My main goal is to make it easier to format the large number of ebooks I have. Almost all of them are plain text files. It’s a python project using PyQt4 and I’m hosting it on Launchpad. here is the project page and you can find some screen shots here....

August 30, 2009 · John

QPlainTextEdit With In Line Spell Check

Update: Simplified Highlighter.highlightBlock function One thing Qt lacks is an integrated spell check in the text entry components. For a project I’m working on this is necessary. Using python-enchant and the QSyntaxHighlighter I was able to implement this functionality. Here is how to add an in line spell check support to a QPlainTextEdit. #!/usr/bin/env python # -*- coding: utf-8 -*- __license__ = 'MIT' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' import re import sys import enchant from PyQt4....

August 22, 2009 · John

Better QPlainTextEdit With Line Numbers

My last post was an implementation of a Qt widget which displays text with line numbers. I found that it has a few limitations. The biggest was a performance penalty when dealing with large documents. I’ve since re-factored and rewritten the class to make the performance acceptable. I’ve also cleaned up the code a bit and added a highlight to the current line. ''' Text widget with support for line numbers ''' from PyQt4....

August 19, 2009 · John

QTextEdit With Line Numbers

Here is a Qt4 widget written in Python that allows for line numbers next to a QTextEdit. Similar to what is seen in a number of text editors such as gedit and kate. from PyQt4.Qt import QFrame, QWidget, QTextEdit, QHBoxLayout, QPainter class LineTextWidget(QFrame): class NumberBar(QWidget): def __init__(self, *args): QWidget.__init__(self, *args) self.edit = None # This is used to update the width of the control. # It is the highest line that is currently visibile....

August 15, 2009 · John

ASCIIize Text

One pet peeve of I have with my Cybook Gen 3 is its inability to properly display unicode characters in plain text files. I don’t need anything fancy like Japanese characters just simple things like “ and ” (as opposed to " and “). To solve this problem I’ve been thinking about adding an –asciize option to calibre. I say thinking because I didn’t really know where to start. Thankfully a user recently requested this very functionality in bug #2846....

July 24, 2009 · John

History Drop Down With Model

Following is a bit of python code that illustrates how to create a QComboBox that attaches to a model for listing history items. The main features of this code are items entered in the text area of the combo are added to the history. Selected items and items entered that already appear in the combo are moved to the top. When MAX_ITEMS is exceeded older items (items at the bottom of the drop down) are removed....

July 23, 2009 · John

QCompleter and Comma-Separated Tags

Here is a python script demonstrating how to use QCompleter to complete multiple tags in a QLineEdit. A few features of this script are: removing tags from the drop down that already appear in the QLineEdit, caching the tags, and inserting a , after completion to ease adding more tags. There are a few parts of this script that I’m going to go into detail about. #!/usr/bin/env python ''' Copyright (c) 2009 John Schember Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software....

July 4, 2009 · John

Calibre Week in Review

Not much happened this week. A few bug fixes and a new output format, RTF. It produces acceptable results. It also embeds images into the file. The output could use some tweaking, but this will come with time. The only caveat is the output is ascii only. This is to keep compatibility with Cailbre’s RTF intput which can only accept ascii rtf files. Pluginize has been merged back into trunk. Once a bit of testing is done by Kovid, he will be rolling out a beta for the 0....

May 31, 2009 · John

Changing Single Quotation Marks to Double in eBooks

As a person living in the USA I highly prefer double quotation marks to single quotes when denoting speech. Some authors use the single quote for effect but mostly it’s just a style choice. I find UK authors generally use the two interchangeably. Tolkien books are a good example. I have The Hobbit, The Lord of the Rings, and The Children of Hurin. The Hobbit use double quotes while the other two uses single quotes....

May 12, 2009 · John

Kindle Detection Bug in Calibre

The Kindle has been very tricky to get working in Calibre. However, it is finally working correctly (at least it should be). The latest issue with the Kindle driver was in the usbms core. The main memory location was never being set. On Windows the driver loops over all attached drives and matches the drive to the internal or card memory. At the end of the loop before it starts over there is a check to see if the main and card memory have been matched....

January 31, 2009 · John