Hammurabi Concepts Text Editor

The HC Text Editor is a basic text editor with syntax highlighting for Python, HTML, PageStream text codes and PageStream resource files. It is available as a Python script (requiring Python and PyQt) or as an executable bundle. As a script it is launched by HCTextEditor.pyw although the module HCTextEditor.py has been written such that it will launch if invoked directly as opposed to being imported. The reason there are two Python scripts is that a GUI application uses the .pyw extension but modules must have the .py extension. Due to re-use of the editor in PgSTextEditor the text editor code was moved outside of the pyw file into a Python module.


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.


PgSTextEditor 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 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.

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


  • 1.1
    • Fixed a few minor bugs
    • Moved editor code into a module to facilitate the PgS Text Editor project
  • 1.0.13
    • Implemented insert date function per request
    • Renamed project to "HC Text Editor"
  • 1.0.12
    • Implemented repeat and manage macro dialogs, named macros are now saved and loaded in the global preferences
    • Fixed long standing bug relating to profiles
    • Corrected save designation for the settings
  • 1.0.11
    • Made platform-dependent GUI tweak work by detecting platform rather than being hard coded
    • New File menu option to open a new document window, thus allowing multiple documents to be open at one time
    • Implemented "Close" in file menu, same functionality as Quit—eventually Quit will close all open windows
    • fixed bug that caused top line number to sometimes be doubled with line number for previous (non-visible) line
    • Implemented macro recording and playback. Repeat and Manage are still not done.
    • 1.0.10
      • style names with a space in them were not recognized (fixed)
      • setting font for current session didn't work (fixed)
      • added menu item to reset font to the style
      • replace menu function broken (fixed)
      • replace all button added to replace dialog
    • 1.0.9
      • fixed some bugs with find/replace text history
      • Implemented regular expressions for find search terms (though not replace)
      • fixed bugs in looping find past beginning or end of document
    • 1.0.8
      • Implemented setting profile font
      • Implemented setting syntax highlighting color and emphasis
      • Implemented highlighting of current line (disabled due to issues with the undo/redo stack)
      • Implemented find/replace text history
    • 1.0.7
      • Fixed problem using backspace on an empty line
      • Initial implementation of profile preferences dialog
      • User selection of word wrap
      • Re-implemented line numbering from scratch due to performance issues
      • Undo/Redo menu items are enabled/disabled depending on availability of such actions
      • Implemented cursor position information in status bar
      • Implemented printing
      • Implemented sort
    • 1.0.6
      • Fixed case insensitivity in profile regexs
      • Kludge to fix some cases where comment syntax highlighting was erroneously applied
      • Profile selected for opened file is now indicated in Tools/Profile menu
      • Fixed various issues with applying profiles
      • No longer retains formatting of pasted text
      • Line numbering implemented
      • Kerning is disabled if fixed pitch is enabled
      • Smart and normal methods for maintaining indent implemented along with menu item for selection
    • 1.0.5
      • Implemented find selection backwards
      • Implemented reload file
      • Added full file path for recent files to status bar
      • Improved handling of recent files
      • Tweaked python syntax highlighter
      • Can now match multiple extensions for a profile (e.g., both .html and .htm)
    • 1.0.4
      • Code cleanup
      • restored separate setFont() function
      • Initial support for converting tabs to spaces
      • Saving and restoring the set font between sessions
      • implemented Find/Find Next/Find Selection
      • implemented Replace/Replace Next/Replace Prev/Replace All
      • implemented tabstop dialog and setting storage
      • implemented smart tab deletion when deleting tabs converted to spaces
      • improved syntax highlighting
      • added python, html and PgS resource file extension support to openfile
      • implemented profiles: default, PgS text codes, python and html (support for PgS resource files)
      • added profile selection to menu, current profile is checked
    • 1.0.3
      • fixed bug causing hang on OS X
      • updated documentation
      • implemented help menu
      • add stubs for search, macro and tools menus
      • moved setfont to tools menu
      • implemented recent files list
      • settings saved between invocations (window size and placement, recent files)
      • groundwork for preferences to customize color for highlighting
      • added undo/redo and select all to Edit menu
      • added lower(), upper() and capitalize() to Edit menu
    • 1.0.2
      • Initial release

    To Do

    Outstanding features to implement in no particular order:
    • allow for "smart" beginning of line (e.g., start of line goes before first non-whitespace, then start of line)
    • implement regular expressions for replace terms
    • on gain focus check to see if the file has changed, if so prompt user to reload
    • Add optional visual guide (vertical rule) to indicate desired maximum column position
    • add more actions to toolbar
    • move recent files from bottom of file menu to a submenu
    • refactor search functions
    • implement short cuts for named macros

    Wish List

    These are desired, but require an inordinate amount of time to implement.
    • implement status bar text for undo/redo actions
    Because of the ad hoc development of the application the code is not "clean"—in fact it is pretty ugly in parts. This will have to be addressed before the following can be implemented. Though not as big of a deal as the undo/redo issue it will require due care to avoid introducing bugs.
    • Add ability to open additional files in tabs


    • tabset preference not loaded from profile


    • Doing decent html syntax highlighting would require a much more complicated scheme than is currently implemented. There are no plans to improve on the current implementation.
    • Although most settings are saved, the profile overrides them and is automatically set whenever a file is loaded. Consequently there isn't much point to saving the non-profile settings.
    • As of Qt4.6 there is no way to get the undo/redo text out of the undo/redo command stack—this is hidden inside the QTextEdit implementation. The logical place for it (other than simply exposing the stack) would be to add a parameter to QTextDocument::undoCommandAdded() signal that contained the undo command added to the stack, or at least the hint text for it.
    • If the current line highlighting is enabled then the highlighting being activated counts as an action to be undone