HC Text Editor

This is a Python script for editing text files that uses Qt for the graphical user interface. It provides syntax highlighting for PageStream text codes.


Known Issues

I really hate to put something like this up front, but PySide versions after 1.0.4 introduced various bugs. Fun things like when you save a file it actually makes it empty. This text is being typed on Linux using PySide 1.1.0 and it is actually saving the file, but typing is slow. Due to time constraints the performance issues have not been pursued.


In addition to the script files included in the archive both Python and PyQt are required.


Use your distributions package manager to install Python and PySide. Python is probably already installed, PySide most likely will not be. For Ubuntu (or any debian derived distro) you can use sudo add-apt-repository ppa:pyside, sudo apt-get update and then sudo apt-get install python-pyside. In general, go to www.pyside.org and click the download link.


To get python try www.python.org and follow the download link in the upper left. You will need a 2.x version of Python (3.x is not backwards compatible). PySide can be obtained from developer.qt.nokia.com—all that is needed is a binary version to match the installed version of Python. If you have installed Python 2.7 then you will need a version that ends with Py2.7.


Python is already installed, but PySide must be downloaded and installed. It can be obtained from developer.qt.nokia.com—all that is needed is a binary version to match the installed version of Python. For most people this will be a version ending in apple.pkg indicating it is for use with the Apple provided Python. PySide also provides a version for the official version of Python.


So its a text editor, what documentation do you need to use it? Well, specifically, this is an implementation of the Qt TextEdit widget so all of its capabilities are present. This gives a solid, though basic, text editor. In addition, some basic syntax highlighting has been implemented with a focus on PageStream file formats and a few niceties for programmers. Note that the menu structure may vary by platform—for example, on OS X the Preference menu item is moved from Tools to the Apple menu.


HCTextEditor uses the concept of profiles for determining settings for displaying and editing a document. Profiles are included for PageStream text codes or resource files, python scripts, HTML, rich text, and plain text. Profile settings are loaded when the application is run and any changes made via the Preferences dialog are saved when the application is closed. A profile can be restored to the built in default settings using the Restore Defaults button in the Preferences dialog.


There are two settings for tabs: the number of spaces represented by a tab character and whether or not to convert tabs to spaces. For normal text editing it is desirable (and often necessary) to leave tabs alone. However, when maintaining a proper indentation scheme tabs complicate matters because different editors will display the tabs differently. When tabs are converted to spaces the editor will still delete them as if they were tabs, minimizing the number of key strokes required when manually adjusting the indentation of a line.

Maintain Indent

Some file formats are more readable if the contents follow a consistent indentation. This is true of program source files in general and Python in particular requires it. PgSTextEditor provides two methods for automatically indenting lines: "normal" and "smart".

Normal indentation simply keeps the current level. If the line is indented four spaces, when return is hit the new linen will automatically be indented four spaces.

Smart indentation increases and decreases the level of indent based on the profile. For example, in the Python profile if a line ends with a colon the next line has the level of indent increased by one tabset. This is a convenience to minimize the amount of manual tabbing (and tab deletion) that a programmer needs to do.


A macro is a sequence of key strokes that can be played back at arbitrary times in the future. Macros are recorded literally—they are subject to interpretation for the current rules of the profile. For example, recording a macro with tabs will result in tab characters if the profile does not expand tabs, but in spaces if the profile expands the tab.

A recorded macro is stashed by the document window that it was recorded in. If multiple document windows are open the macro will not be available in other windows. A stashed macro is lost when the application is closed. However, a named macro can be used in any document window and will be available the next time the application is started.

To name a stashed macro use the Manage dialog from the Macro menu. The first entry will be the stashed macro, if any, and will be named "current macro". Select that entry and change the name in the edit line field. A new entry will be immediately added with that name. To delete a macro select it and click the delete button. To undo any changes made in the dialog click the "Reset" button.

Character Encoding

First and foremost this text editor is conceived as being used for UTF-8 encoded text. That is the default codec used when creating a new document or opening an existing document. However, it is possible to select a different codec from the Character Encoding Tool menu. As a codec is only applied when loading or saving a file the file is automatically reloaded whenever the codec is changed. To avoid losing changes the menu is ghosted if the file is modified.

Insert Date

The current date/time can be inserted using the edit menu item of that name. Currently there is no keyboard shortcut for this action. The format to use can be set with the Set Date Format... menu action and is saved along with preferences when the document is closed. The format specifiers are indicated in a combobox which can be used to insert them. Fuller explanations are available as tooltips, but regrettfully only after they have been inserted. The table is replicated here.

%a: wkdyLocale's abbreviated weekday name
%A: WeekdayLocale's full weekday name
%b: monLocale's abbreviated month name
%B: MonthLocale's full month name
%c: localized date/timeLocale's appropriate date and time representation
%d: dayDay of the month as a decimal number
%f: μ secondsMicrosecond as a decimal number, zero-padded on the left
%H: 24HHour (24-hour clock) as a decimal number
%I: 12HHour (12-hour clock) as a decimal number
%j: day of yearDay of the year as a decimal number
%m: moMonth as a decimal number
%M: miMinute as a decimal number
%p: pmLocale's equivalent of either AM or PM
%S: secondsSecond as a decimal number
%U: week numberWeek number of the year as a decimal number, Sunday as first day of week
%w: weekday numberWeekday as a decimal number
%W: week numberWeek number of the year as a decimal number, Monday as first day of week
%x: localized dateLocale's appropriate date representation
%X: localized timeLocale's appropriate time representation
%y: yrLast two digits of year
%Y: YearFour digit year
%z: UTC offsetUTC offset
%Z: tzTime zone name
%%: %Literal '%' character


New Document
Create a new document tab in the current window
New Window
Create a new document in a new window
Open a new file
Save the current file—if it has not been previously saved a file dialog will be presented
Save As
Save the current file—always opens a file dialog
Reloads the current file from disk
Prints the current file—a print dialog is always opened
Closes the application—if there are unsaved changes a dialog will be opened
Undoes the last action
Redo the last undone action
Cuts the currently selected text from the document and puts it on the pasteboard
Copies the currently selected text to the pasteboard
Replaces current selection with contents of the clipboard
Select All
Selects the entire document
Converts selected text to all lower case letters
Converts selected text to all upper case letters
Lower cases all selected text, except the first letter of each word which is capitalized
Increase Indent
Increases the indentation of the currently selected lines by one tabstop
Decrease Indent
Decreases the indentation of the currently selected lines by one tabstop for lines starting with at least one tabstop
Insert Date
Inserts current date and time with the current format specification
Set Date Format...
Opens a dialog that allows setting the format to use when inserting the date
Opens the find requester
Find Selection
Finds next occurance of currently selected text
Find Prev Selection
Finds previous occurance of currently selected text
Find Next
Finds next occurance of text to find
Find Previous
Finds previous occurance of text to find
Opens the replace requester
Replace Next
Replaces the next occurance of text to replace
Replace All
Replaces all occurances of the text to replace
Go to line
Opens dialog allowing specifying the line to go to by line number
Starts recording key presses
Stops recording key presses, stashes any that were recorded
Stops recording key presses, discards any that were recorded
Plays back stashed key presses
Opens dialog allowing selection of a macro to play and the number of times to play it
Allows naming a stashed macro (only named macros are retained between runs of the application), renaming and deleting macros
Sorts currently selected text on a per-line basis
Opens dialog for configuring profiles
Select Font...
Opens font selection dialog—this only affects the current session
Reset Font
Clears the font selection for the current session, returning the font to that set for the style
Set Tabstop...
Opens a dialog for setting the tab stop—this only affects the current session
Show Line Numbers
Toggles the display of line numbers—this only affects the current session
Highlight Current Line
Toggles the backlighting of the current line with the current highlight color
Highlight Color...
Opens a dialog for setting the highlight color—this only affects the current session
Maintain Indent
Select the method for maintaining indentation—this only affects the current session
Word Wrap
Select the method for wrapping words—this only affects the current session
Select Profile
Override the automatically selected profile—this only affects the current document
Select Codec
Set the code used to interpret the text—this only affects the current document (the default codec is UTF-8)
Opens a dialog giving basic information about the application
Displays this file