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.
Requirements
- Python 2.5 or newer
- PyQt 4.5 or newer
Installation
In addition to the script files included in the archive both Python and PyQt are required.
Linux
Use your distributions package manager to install Python and PyQt. Python is probably already installed, PyQt may not be depending on your distribution. For Ubuntu (or any debian derived distro) you can use sudo apt-get install python-qt4
Windows
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). PyQt can be obtained from www.riverbankcomputing.com—all that is needed is a binary version to match the installed version of Python. If you have installed Python 2.5 then you will need a version that starts with PyQt-Py2.5. Unless you want to develop PyQt applications there is no need to download the source, install SIP, etc. Just the binary will do.
OS X
Python is already installed, but PyQt must be downloaded and installed. It can be obtained from www.riverbankcomputing.com—all that is needed is a binary version to match the installed version of Python. Unfortunately, there doesn't appear to be any binary versions for Qt4. This means installing Apple's XCode development environment, SIP, the PyQt source and compiling from source code is required. I hope to provide pre-compiled binary versions, but have no idea when that will happen.
Using
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.
Profiles
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.
Tabstop
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.
Macros
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: wkdy | Locale's abbreviated weekday name |
%A: Weekday | Locale's full weekday name |
%b: mon | Locale's abbreviated month name |
%B: Month | Locale's full month name |
%c: localized date/time | Locale's appropriate date and time representation |
%d: day | Day of the month as a decimal number |
%f: μ seconds | Microsecond as a decimal number, zero-padded on the left |
%H: 24H | Hour (24-hour clock) as a decimal number |
%I: 12H | Hour (12-hour clock) as a decimal number |
%j: day of year | Day of the year as a decimal number |
%m: mo | Month as a decimal number |
%M: mi | Minute as a decimal number |
%p: pm | Locale's equivalent of either AM or PM |
%S: seconds | Second as a decimal number |
%U: week number | Week number of the year as a decimal number, Sunday as first day of week |
%w: weekday number | Weekday as a decimal number |
%W: week number | Week number of the year as a decimal number, Monday as first day of week |
%x: localized date | Locale's appropriate date representation |
%X: localized time | Locale's appropriate time representation |
%y: yr | Last two digits of year |
%Y: Year | Four digit year |
%z: UTC offset | UTC offset |
%Z: tz | Time zone name |
%%: % | Literal '%' character |
Menus
- File
- New
- Create a new document—currently opened document is cleared and the undo stack is reset
- Open
- Open a new file
- Save
- 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
- Reload
- Reloads the current file from disk
- Print
- Prints the current file—a print dialog is always opened
- Quit
- Closes the application—if there are unsaved changes a dialog will be opened
- Edit
- Undo
- Undoes the last action
- Redo
- Redo the last undone action
- Cut
- Cuts the currently selected text from the document and puts it on the pasteboard
- Copy
- Copies the currently selected text to the pasteboard
- Paste
- Replaces current selection with contents of the clipboard
- Select All
- Selects the entire document
- lowercase
- Converts selected text to all lower case letters
- UPPERCASE
- Converts selected text to all upper case letters
- Capitalize
- Lower cases all selected text, except the first letter of each word which is capitalized
- 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
- Search
- Find...
- 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
- Replace
- 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
- Macro
- Record
- Starts recording key presses
- Finish
- Stops recording key presses, stashes any that were recorded
- Cancel
- Stops recording key presses, discards any that were recorded
- Replay
- Plays back stashed key presses
- Repeat
- Opens dialog allowing selection of a macro to play and the number of times to play it
- Manage
- Allows naming a stashed macro (only named macros are retained between runs of the application), renaming and deleting macros
- Tools
- Sort
- Sorts currently selected text on a per-line basis
- Preferences...
- 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
- Help
- About
- Opens a dialog giving basic information about the application
- Contents
- Displays this file
History
- 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
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
Bugs
- tabset preference not loaded from profile
Limitations
- 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