pythonui:
--------------------------------------------------------------------------------
@vbr
Could you please share demo example of python script for PSPAD? (If you can)
--------------------------------------------------------------------------------


Hi, I'm glad, it helped, 
I actually normally don't use python for PSPad scripting, but here is an ad hoc
coded demo.
It should show the current character before the caret, its unicode number, name
and category using the unicodedata module.

There are some limitations of this approach - there may be no text selection on
calling this function; non-printing system characters are not handled. More
importantly the "foreign" characters not supported in the respective
ansi-codepage (e.g. win 1252) are not shown - due to the limitation of the
script interface; however, the data for such characters should be shown
correctly (for characters in the basic multilingual pane - up to U+FFFF).

It's rather a demo code, my previous attempts on using tkinter gui in connection
with pspad scripting were not fully successful and I am therefore not using
python for this - unless you plan to utilize some already available python
library, I don't see strong advantages for this usage.

hth,
   vbr 

(Should the formatting and whitespace get mangled, you can obtain the original
text in the editing window, if you click to quote my message;)

cite:
--------------------------------------------------------------------------------
#! Python

module_name = "py_char_inf"
module_ver = "0.1"

pspad = globals()['global']

import unicodedata

def py_char_info():
    """Show some basic unicodedata information about the current character."""
    if pspad.editorsCount() < 1: # quit if no editor panels are open
        return False
    act_ed = pspad.newEditor()
    act_ed.assignActiveEditor()
    act_ed.command("ecSelRight")
    char_after_caret = act_ed.selText()
    char_inf = u"Character info:\nunknown"
    if len(char_after_caret) == 1:
        act_ed.command("ecLeft")
        unicode_nr = "U+"+str(hex(ord(char_after_caret)))[2:].upper().zfill(4)
        unicode_categs = {"":"??", "Lu":"Letter, Uppercase", "Ll":"Letter,
Lowercase", "Lt":"Letter, Titlecase", "Lm":"Letter, Modifier", "Lo":"Letter,
Other", "Mn":"Mark, Nonspacing", "Mc":"Mark, Spacing Combining", "Me":"Mark,
Enclosing", "Nd":"Number, Decimal Digit", "Nl":"Number, Letter", "No":"Number,
Other", "Pc":"Punctuation, Connector", "Pd":"Punctuation, Dash",
"Ps":"Punctuation, Open", "Pe":"Punctuation, Close", "Pi":"Punctuation, Initial
quote (may behave like Ps or Pe depending on usage)", "Pf":"Punctuation, Final
quote (may behave like Ps or Pe depending on usage)", "Po":"Punctuation, Other",
"Sm":"Symbol, Math", "Sc":"Symbol, Currency", "Sk":"Symbol, Modifier",
"So":"Symbol, Other", "Zs":"Separator, Space", "Zl":"Separator, Line",
"Zp":"Separator, Paragraph", "Cc":"Other, Control", "Cf":"Other, Format",
"Cs":"Other, Surrogate", "Co":"Other, Private Use", "Cn":"Other, Not Assigned
(no characters in the file have this property)"}
        unicode_name = unicodedata.name(char_after_caret, "??")
        unicode_categ_abbr = unicodedata.category(char_after_caret)
        unicode_categ = unicode_categs.get(unicode_categ_abbr, "??")
        char_inf = u"Character info:\n%s - %s %s (%s - %s)" % (char_after_caret,
unicode_nr, unicode_name, unicode_categ_abbr, unicode_categ)
    pspad.echo(char_inf)

def Init():
    pspad.addMenuItem("char info","","py_char_info", "Ctrl+Alt+Shift+C")

--------------------------------------------------------------------------------


-- 
<http://forum.pspad.com/read.php?2,65617,65660>
PSPad freeware editor http://www.pspad.com

Odpovedet emailem