pytextedit 0.3: macros

The primary new addition to pytextedit 0.3 will be a simple macro system. It will have a simple editor for writing them, in addition to keybindings and the like.

The commands are all really simple; basically they’re just text equivalents of existing features. There are no loops, conditional, variables, operators, etc., although I might add these in the future.

The current list of commands:

  • set_insert location – sets the cursor position.
  • insert location string – inserts the string at the given location. Note that locations used by Tk such as “insert” and “sel.first” work here.
  • delete location1 location 2 – deletes all text between the two given locations.
  • new – opens a new file.
  • open filename – opens a file.
  • open_url url – reads from a URL.
  • open_sel – opens a file using the selected text as the filename.
  • reload – reloads the file.
  • save – saves the file.
  • save_as filename – saves the file under the given name.
  • save_copy filename – saves a copy of the file under the given name.
  • revert_save – reverts to the last save.
  • insert_file filename – inserts the text from  a file into the current document.
  • delete  – deletes the current file.
  • rename filename – renames the current file.
  • print – prints the file.
  • exit – closes pytextedit.
  • undo – undoes the last action.
  • redo – redoes the last undo.
  • cut – cuts the selected text.
  • copy – copies the selected text.
  • paste – pastes the current clipboard.
  • clear_clip – clears the clipboard.
  • copy_path – copies the full path of the file.
  • copy_file – copies the filename.
  • copy_dir – copies the directory the file is in.
  • lock – toggles the file lock.
  • case_lower – changes the selected text to lowercase.
  • case_upper – changes the selected text to uppercase.
  • case_cap – changes the selected text to be capitalized.
  • case_rev – reverses the case of the selected text.
  • join_lines – joins the selected lines.
  • copy_line – copies the current line.
  • cut_line – cuts the current line.
  • rev_line – reverses the current line.
  • dup_line – duplicates the current line.
  • del_line – deletes the current line.
  • sel_all – selects all text.
  • desel_all – deselects all text.
  • sel_from location1 location2 – selects the text between the given locations.
  • sel_before – selects the text before the cursor.
  • sel_after – selects the text after the cursor.
  • del_sel – deletes the selected text.
  • del_nonsel – deletes the nonselected text.
  • new_doc – opens a new document.
  • close_doc – closes the current document.
  • prev_doc – goes to the previous document.
  • next_doc – goes to the next document.
  • find sting – finds the given string.
  • find_sel – finds the next occurrence of the selected text.
  • find_in_sel string – finds the given string in the selected text.
  • goto location – goes to the given location.
  • replace string1 string2 – replaces one string with the other.
  • replace_sel string2 – replaces the selected text with the given string.
  • replace_in_sel string1 string2 – replaces one string with the other in the selected text.
  • jump_top – goes to the top of the text.
  • jump_bottom – goes to the bottom of the text.
  • jump_insert – goes to the cursor.
  • open_url_wb – opens a web browser with the selected text as the URL.
  • search_site site – searches the selected text on the given site.
  • add_bookmark – adds a bookmark on the current line.
  • clear_bookmarks – clears the list of bookmarks.
  • save_bookmark file – saves the current list of bookmarks.
  • insert_time – inserts the time.
  • insert_date – inserts the date.
  • insert_line – inserts the line number.
  • insert_pos – inserts the position.
  • insert_path – inserts the full path of the file.
  • insert_filename – inserts the filename
  • insert_dir – inserts the directory the file is in.
  • indent – indents the text.
  • unindent – unindents the text.
  • replace_ts – replaces tabs with spaces.
  • replace_st – replaces spaces with tabs.
  • open_web – opens the file in a web browser.
  • run_python args – runs the file in Python.
  • run_perl args – runs the file in Perl.
  • run_php args – runs the file in PHP.
  • compile_c args – compiles the file in C.
  • compile_cpp args – compiles the file in C++.
  • compile_java args – compiles the file in Java.

This list includes just about every menu option, with the exception of those that are too dependant on their GUI. (So there’s a command for saving bookmarks, because the only dialog that has is to get the filename, but not one for opening bookmarks, as that requires a more complex Listbox.)

Advertisements

pytextedit 0.2.2

Another minor update.

Download

Main.
Linux installer.

Changelog

  • Fixed opening a file in python 2 not catching IOError exceptions.
  • Fixed incorrect use of print() function.
  • Improved comments a bit.
  • Added “Bookmarks -> Save Bookmarks…”.
  • Added “Bookmarks -> Open Bookmarks…”.
  • Added code to check that the configuration files exist before loading them, and give an error message and exit if any are not there.
  • Added error checking for loading configuration files. It will now catch any IOError or TypeError exceptions for each file.
  • Added keybinding for “Tools -> Insert Time”.
  • Added keybinding for “Tools -> Insert Date”.
  • Added “return 0” to the end of main() in the Linux binary, I have no idea how I forgot this.
  • Added icon and .desktop file to Linux installer.

What’s next?

This will be the last update until the next major release, which will be 0.3. The biggest addition for that release will be a basic macro system. Other improvements will include the ability to easily restore default settings, the addition of a fullscreen mode, etc.

pytextedit 0.2.1

This is just a minor update, there are a few changes but nothing major.

Download

You can download it here. Additionally, I figured out the Linux installer for this version, so you can get that here. (I wasn’t having problems with the installer itself, but rather with how the main file switches directories.)

EDIT: fixed links

Changelog

As I said, there was nothing big this version. Most of the changes are things that the user would never see, but that improve the code.

  • Added “File -> Save Copy…”.
  • Added “Edit -> Clear Clipboard”.
  • When opening a file from the command line it now explicitly checks which version of python it’s running in, and if running in python 2 it will not attempt to open with Unicode. (Before it would fail on the first three attempts, then succeed in binary mode.)
  • Improved error messages. The dialog now has the title set to the name of the command that was run. In some places the errors were made more descriptive. Also, the exclamation marks were removed.
  • In open/save functions, instead of using try-except blocks to check for everything, there is now one except block for Unicode errors (which will fail silently), and one except block for IOErrors (which will show an error message then exit the function). Also, the try-except block that surrounded almost everything in those functions is now gone, as there was absolutely no point to it.
  • Simplified try-except blocks in a lot of functions.
  • Fixed/improved/simplified a lot of little stuff. (Removing unnecessary global declarations, making things slightly more useful, etc.)
  • Clicking “Cancel” in the dialog that appears if you click on a blank area of the “Favorites” dialog will no longer close the dialog.

What’s next?

There really isn’t anything I want to do now that doesn’t require a lot of work (syntax highlighting and all that), so it will probably be a while still until I get 0.3 done. However, there are still a few small things I’d like to do that weren’t done in time for this release, so they’ll probably go into 0.2.2.

pytextedit: syntax highlighting

I’ve been working on the syntax highlighting a lot, this is what I have so far:

tk_002

As you can see, keywords, numbers, operators, and booleans all work, and comments partially work. Strings, meanwhile, don’t work at all.

This is the current code to check for each type (tags are defined beforehand):

        if i in keyword.kwlist:
            text_box.tag_add("keyword", sel_str % (line, start), sel_str % (line, end))
        elif i in ("True", "False"):
            text_box.tag_add("boolean", sel_str % (line, start), sel_str % (line, end))
       # elif i == "\"":
        #    next_occur = text_box.search("\"", sel_str % (line, start), backwards = True)
        #    if next_occur == -1:
        #        next_occur = "end"
        #    text_box.tag_add("string", sel_str % (line, start), next_occur)
        elif i in ("+", "-", "*", "/", "%", "=", "!"):
            text_box.tag_add("operator", sel_str % (line, start), sel_str % (line, end))
        elif i == "#":
            text_box.tag_add("comment", sel_str % (line, start), line + ".end")
        else:
            for index in range(len(i)):
                try:
                    int(i[index])
                    text_box.tag_add("number", sel_str % (line, start + index))
                except ValueError:
                    pass

This is checked on every keypress. It could probably be a lot more efficent, but for now I’m more concerned with actually getting it working.