spell checking contractions

18 views
Skip to first unread message

Christopher Barker

unread,
Mar 2, 2010, 12:24:34 PM3/2/10
to pepp...@googlegroups.com
Rob,

The spell checking seems got confused by contractions, like:

doesn't
weren't

etc. I suspect is it breaking up the word at the apostophe, and so
checking "doesn", which is, of course, a spelling error.

if I pass them straight into aspell, it works fine.

Any thoughts on how to fix that?

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris....@noaa.gov

Rob McMullen

unread,
Mar 2, 2010, 1:42:47 PM3/2/10
to pepp...@googlegroups.com
Chris,

On Tue, Mar 2, 2010 at 9:24 AM, Christopher Barker
<Chris....@noaa.gov> wrote:
> The spell checking seems got confused by contractions

Yep, this is a thorn in my side. My achilles heel probably got me and
I optimized too early. My intent was to minimize calls to the enchant
library because I was seeing slowdowns (mostly when testing on slow
machines like my old OS X laptop, but still. Typing lag is annoying).

> if I pass them straight into aspell, it works fine.
>
> Any thoughts on how to fix that?

No good ones yet. :( Part of it is a word-end position check, but
I've messed around with it before and never found a good solution.
Simply checking for the single quote character isn't enough because it
can mess up stuff around quoted text.

The other part is that I don't want to lose it being based on the stc
insert text/delete text event handling because I want macros and other
things that insert text to continue to work without them having any
knowledge of spell checking on their part.

Any ideas?

Rob

Don Dwiggins

unread,
Mar 2, 2010, 3:29:55 PM3/2/10
to pepp...@googlegroups.com
Rob and all,

> No good ones yet. :( Part of it is a word-end position check, but
> I've messed around with it before and never found a good solution.
> Simply checking for the single quote character isn't enough because it
> can mess up stuff around quoted text.
>
> The other part is that I don't want to lose it being based on the stc
> insert text/delete text event handling because I want macros and other
> things that insert text to continue to work without them having any
> knowledge of spell checking on their part.
>
> Any ideas?
>
The only thing that occurs to me is to loosen the requirement: rather
than "instantaneous" spell checking, delegate it to a background process
that deals with the recently entered text every so often, and marks
errors when it finds them. This means that, as you type, you may see a
mark on a word you typed several seconds ago.

Alternately, do both: have a "loose" spell check that catches the simple
cases, but delegates tougher cases (like words with apostrophes, dashes,
etc.) to the background.


FWIW,
Don

Rob McMullen

unread,
Mar 3, 2010, 10:53:23 AM3/3/10
to pepp...@googlegroups.com
On Tue, Mar 2, 2010 at 12:29 PM, Don Dwiggins <ddwi...@advpubtech.com> wrote:
> The only thing that occurs to me is to loosen the requirement: rather than
> "instantaneous" spell checking, delegate it to a background process that
> deals with the recently entered text every so often, and marks errors when
> it finds them.  This means that, as you type, you may see a mark on a word
> you typed several seconds ago.

Yeah, right now I'm checking at every idle block, so I could certainly
only check e.g. every 10 idle blocks.

Maybe I'm over-thinking the problem. I had tried messing with the end
of word algorithm to see if a single quote character was actually an
apostrophe as in 't or as an end of string marker... Maybe the end of
word boundaries are only whitespace and punctuation and let enchant
deal with the single quote. I'll have to check that.

Rob

Don Dwiggins

unread,
Mar 3, 2010, 12:26:20 PM3/3/10
to pepp...@googlegroups.com
Rob McMullen wrote:
> Maybe I'm over-thinking the problem. I had tried messing with the end
> of word algorithm to see if a single quote character was actually an
> apostrophe as in 't or as an end of string marker... Maybe the end of
> word boundaries are only whitespace and punctuation and let enchant
> deal with the single quote. I'll have to check that.
>
Hmmm. A single quote at the end of a word can also be an apostrophe
signaling possessive, for example "the soldiers' guns were unloaded".
It might require context to disambiguate that.


Don

Rob McMullen

unread,
Mar 3, 2010, 1:05:21 PM3/3/10
to pepp...@googlegroups.com
On Wed, Mar 3, 2010 at 9:26 AM, Don Dwiggins <ddwi...@advpubtech.com> wrote:
> Hmmm.  A single quote at the end of a word can also be an apostrophe
> signaling possessive, for example "the soldiers' guns were unloaded".  It
> might require context to disambiguate that.

Yep, that's right. I was hoping to avoid language-specific stuff in
my code; maybe enchant handles it itself if I just pass it the whole
string?

When I get some time (hopefully this weekend) I'll check it.

Rob

Christopher Barker

unread,
Mar 3, 2010, 1:34:33 PM3/3/10
to pepp...@googlegroups.com
Don Dwiggins wrote:
> Hmmm. A single quote at the end of a word can also be an apostrophe
> signaling possessive, for example "the soldiers' guns were unloaded".
> It might require context to disambiguate that.

sure, but I don't think you'd need to, as in that case, the word
following the apostrophe should be a valid word.

Christopher Barker

unread,
Mar 3, 2010, 4:07:45 PM3/3/10
to pepp...@googlegroups.com
Christopher Barker wrote:
> sure, but I don't think you'd need to, as in that case, the word
> following the apostrophe should be a valid word.

oops, make that "the word _before_ the apostrophe"

Rob McMullen

unread,
Mar 8, 2010, 11:09:00 PM3/8/10
to pepp...@googlegroups.com
Well, no updates yet... had no free time this past weekend.

Rob

Rob McMullen

unread,
Mar 13, 2010, 1:51:21 PM3/13/10
to pepp...@googlegroups.com
Think I may have fixed it. Give the latest svn a shot...

Rob

Christopher Barker

unread,
Mar 15, 2010, 1:43:50 PM3/15/10
to pepp...@googlegroups.com
Rob McMullen wrote:
> Think I may have fixed it. Give the latest svn a shot...

It seems to work great!

Thanks.

-CHB

Rob McMullen

unread,
Mar 15, 2010, 2:43:48 PM3/15/10
to pepp...@googlegroups.com
On Mon, Mar 15, 2010 at 10:43 AM, Christopher Barker
<Chris....@noaa.gov> wrote:
> It seems to work great!

Excellent. I accidentally left a debug flag turned on, so if you
notice a corner case or something, you can start it from the command
line forward me the stdout.

But I won't leave it that way for long -- it's been a long time since
I made a release, so I need to get that Freshmeat activity indicator
off the floor. :)

Rob

Christopher Barker

unread,
Mar 15, 2010, 7:33:52 PM3/15/10
to pepp...@googlegroups.com
While we are talking about spell checking...

aspell provides a LOT of suggestions for a misspelled word. however, the
one I want is usually on of the first 4 or so. As it is, Peppy gives me
a popup menu with a few entries at the top, each of which is fraction of
the suggestions, then I have to click that to get the list.

I'd like to be able to use one less mouse click most of the time. I
suggest the menu look like:

option1
option2
option3
option4
more suggestions...
----------
ctags
----------
undo
redo
cut
copy paste
----------
...


so if you wanted one of the first 4, you could get it with one click,
and you'd only get the bigger list if you really needed it.

just my $0.02


> But I won't leave it that way for long -- it's been a long time since
> I made a release, so I need to get that Freshmeat activity indicator
> off the floor. :)

By the way, I've been running the SVN version for a while now -- it
works great, at least on the Mac. On the Mac, I have a "alias app
bundle" built, so that it looks and acts like a regular app, you can put
an icon in the doc, drag and drop files on to it, etc, while it is still
running the SVN code.

Is there a way to accomplish something similar on Windows?

(I know this is not a Peppy Specific Question....)

-Chris

Rob McMullen

unread,
Mar 16, 2010, 6:27:38 PM3/16/10
to pepp...@googlegroups.com
On Mon, Mar 15, 2010 at 4:33 PM, Christopher Barker
<Chris....@noaa.gov> wrote:
> I'd like to be able to use one less mouse click most of the time. I suggest
> the menu look like:
>
> [good suggestion described here]

This was easy to implement, as it turns out. Check out the new svn.

> By the way, I've been running the SVN version for a while now -- it works
> great, at least on the Mac.

Yep, this is what I do on OS X as well, thanks to your suggestion a while ago.

> Is there a way to accomplish something similar on Windows?

Couldn't you just make a shortcut to wherever you have checked out the
svn code? I always do my windows development from a cygwin bash shell
so I haven't done it, but it seems like that should work.

Rob

Christopher Barker

unread,
Mar 16, 2010, 7:34:01 PM3/16/10
to pepp...@googlegroups.com
Rob McMullen wrote:
> This was easy to implement, as it turns out. Check out the new svn.

perfect! thanks.

> Couldn't you just make a shortcut to wherever you have checked out the
> svn code?

That is what I do now, but it brings up a "dos box", and I dont' get the
icons right, and it doesn't support drag and drop -- though maybe the
Windows version doesn't really support drag and drop anyway.

Maybe I'll play around with it a bit more.

Don Dwiggins

unread,
Mar 16, 2010, 9:49:02 PM3/16/10
to pepp...@googlegroups.com
Christopher Barker wrote:
That is what I do now, but it brings up a "dos box", and I dont' get the icons right, and it doesn't support drag and drop -- though maybe the Windows version doesn't really support drag and drop anyway.
It supports d'n'd for me, at least opening a file by dragging from Explorer to the tab bar in the Peppy window (but not into the "content" window).

FWIW, I've added the following to my registry, which gives me an "Edit with Peppy" on the context menu in Explorer.


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\OpenWithPeppy]
@="Edit with Peppy"

[HKEY_CLASSES_ROOT\*\shell\OpenWithPeppy\command]
@="C:\\ProgramFiles\\Python25\\pythonw.exe -um peppy_start  \"%1\" %*"


(I've added a little script called peppy_start in Scripts.)

You could probably tweak the command to run it from your svn working copy.


Don

Christopher Barker

unread,
Mar 17, 2010, 2:58:40 PM3/17/10
to pepp...@googlegroups.com
Don Dwiggins wrote:
> It supports d'n'd for me, at least opening a file by dragging from
> Explorer to the tab bar in the Peppy window (but not into the "content"
> window).

nice, I'll try that out. Is it possible to drag an drop onto the task
bar button -- or is that not "done" in Windows -- shows you how much I
use Windows....

> FWIW, I've added the following to my registry, which gives me an "Edit
> with Peppy" on the context menu in Explorer.

> ------------------------------------------------------------------------


>
> Windows Registry Editor Version 5.00
>
> [HKEY_CLASSES_ROOT\*\shell\OpenWithPeppy]
> @="Edit with Peppy"
>
> [HKEY_CLASSES_ROOT\*\shell\OpenWithPeppy\command]
> @="C:\\ProgramFiles\\Python25\\pythonw.exe -um peppy_start \"%1\" %*"

> ------------------------------------------------------------------------


>
> (I've added a little script called peppy_start in Scripts.)
>
> You could probably tweak the command to run it from your svn working copy.

Very cool, that was my next question -- now I need to figure out how to
edit the registry.

It might be nice to build that into an installer some day.

Speaking of which -- I was thinking of trying to make a real app bundle
for OS-X again -- last I tried it was really ugly figuring out how to
get the plugins and all in there -- has that changed any?

Rob McMullen

unread,
Mar 17, 2010, 3:50:57 PM3/17/10
to pepp...@googlegroups.com
On Wed, Mar 17, 2010 at 11:58 AM, Christopher Barker
<Chris....@noaa.gov> wrote:
> Don Dwiggins wrote:
>>
>> It supports d'n'd for me, at least opening a file by dragging from
>> Explorer to the tab bar in the Peppy window (but not into the "content"
>> window).
>
> nice, I'll try that out. Is it possible to drag an drop onto the task bar
> button -- or is that not "done" in Windows -- shows you how much I use
> Windows....

I don't think that's done on windows, but I'm no expert.

>> FWIW, I've added the following to my registry, which gives me an "Edit
>> with Peppy" on the context menu in Explorer.
>

> Very cool, that was my next question -- now I need to figure out how to edit
> the registry.

Yes that is a very cool trick, Don. I'll have to see about adding
that it when using the Nullsoft Windows installer.

> Speaking of which -- I was thinking of trying to make a real app bundle for
> OS-X again -- last I tried it was really ugly figuring out how to get the
> plugins and all in there -- has that changed any?

Nope, it is a big ol' fugly mess. Probably less of a mess than last
time you checked, Chris, but creating an app bundle for windows is not
straightforward at all. It still uses a makefile to create the
versioned archive, and uses cygwin on windows to allow me to automate
the build process. There are a bunch of hacks to place plugins in the
proper place for the py2exe install. Check the py2exe directory for
the scripts. Basically, most of the work goes into setting up the
directory structure in preparation for the "python setupy.py py2exe"
command.

Also to create the help files, you need sphinx installed. The
setup.py has improved a lot and is fairly well documented now.

Rob

Don Dwiggins

unread,
Mar 17, 2010, 6:43:19 PM3/17/10
to pepp...@googlegroups.com
Rob and Chris,

Is it possible to drag an drop onto the task bar
button -- or is that not "done" in Windows -- shows you how much I use
Windows....
    
I don't think that's done on windows, but I'm no expert.
  
I'm not sure what you mean by "the task bar button".  If you mean the Start button on the taskbar, I've never tried to drag anything to it, or learned what it might mean to do so (and I've been stuck in Windowsville for a long time 8^).

FWIW, I've added the following to my registry, which gives me an "Edit
with Peppy" on the context menu in Explorer.
      
Very cool, that was my next question -- now I need to figure out how to edit
the registry.
    
Just copy the lines I gave to a file with the extension ".reg", then right-click on it; you'll see a menu item named "Merge" -- click that and it'll install the contents into the registry.  (As always with that beast, make a backup first.)  You'll want to change the command line first, and check that it works on your machine.

If you want the item showing up only on certain extensions, you can use Explorer's Tools>Folder Options dialog; go the the File Types tab, select, say, PY, and click Advanced to add/edit context menu items for .py (and other Python extension) files.  (There's likely a utility somewhere on the net that allows doing all this stuff more conveniently and reliably -- let me know if you find one.  8^)


Regards,
Don

Chris Barker

unread,
Mar 19, 2010, 2:01:54 AM3/19/10
to pepp...@googlegroups.com
Don Dwiggins wrote:
> I'm not sure what you mean by "the task bar button". If you mean the
> Start button on the taskbar, I've never tried to drag anything to it, or
> learned what it might mean to do so (and I've been stuck in Windowsville
> for a long time 8^).

well, on the Mac, you can drop a file on an applications icon on the
"dock", which is much like the task bar. The file then opens in teh app
(if you've got the app set up to handle the message). It's a really nice
way to do it, 'cause you don't need the app to be visible to do it. I
don't know that Windows has anything like that, but adding peppy to the
right click menu will help a lot -- I've always liked that SciTe puts
that in for you.

> Just copy the lines I gave to a file with the extension ".reg", then
> right-click on it; you'll see a menu item named "Merge" --

got it -- thanks, that will help.

-Chris

Don Dwiggins

unread,
Mar 19, 2010, 12:09:18 PM3/19/10
to pepp...@googlegroups.com
Chris Barker wrote:
> Don Dwiggins wrote:
>> I'm not sure what you mean by "the task bar button". If you mean the
>> Start button on the taskbar, I've never tried to drag anything to it,
>> or learned what it might mean to do so (and I've been stuck in
>> Windowsville for a long time 8^).
>
> well, on the Mac, you can drop a file on an applications icon on the
> "dock", which is much like the task bar. The file then opens in teh
> app (if you've got the app set up to handle the message). It's a
> really nice way to do it, 'cause you don't need the app to be visible
> to do it. I don't know that Windows has anything like that, but adding
> peppy to the right click menu will help a lot -- I've always liked
> that SciTe puts that in for you.
Ahh, OK. My memory from the last time I used the Mac (many years ago)
was that each file had some sort of "type" information attached, so that
you could bring it up in the application associated with that type by
just double clicking on the file icon (or something like that). It's
actually similar to this in Windows -- the "type" information is given
by the filename extension, and installing an application creates
associations between one or more extension and the application. I very
seldom have to explicitly run an application from the .exe. (Explorer's
Tools>Folder Options>File Types dialog allows "managing" the
associations as well.)


Don


Christopher Barker

unread,
Mar 19, 2010, 3:12:06 PM3/19/10
to pepp...@googlegroups.com
Don Dwiggins wrote:
> Ahh, OK. My memory from the last time I used the Mac (many years ago)
> was that each file had some sort of "type" information attached, so that
> you could bring it up in the application associated with that type by
> just double clicking on the file icon (or something like that).

Sure, that's still there -- in fact, it goes one further, a "type"(text
file) and "creator" (Peppy).

That works great for something like a MSWord file, that you would only
want to open with one application, but for something like a jpg image or
a text file there might be a dozen different apps that I'd want to open
it with.

Even python files could be opened in Peppy, or run with python, or???

So I like to be more explicit.

Don Dwiggins

unread,
Apr 13, 2010, 6:18:05 PM4/13/10
to pepp...@googlegroups.com
I just loaded a wxPthon .py file and tried to execute it with F5. I got
the following traceback:

> Failed opening
> file:///c:/Dwig/Falcon/Development/Online/RCAServer/Utilities/ConfigEditor/⇒
> Started "C:\ProgramFiles\Python25\python.exe"
> "c:/Dwig/Falcon/Development/Online/RCAServer/Utilities/ConfigEditor/test_backup.py"
> on Tue Apr 13 15#14.
>
> Detailed error message follows:
>
> Traceback (most recent call last):
> File
> "C:\ProgramFiles\Python25\lib\site-packages\peppy-0.14.0-py2.5.egg\peppy\fileopener.py",
> line 174, in determineMajorMode
> self.scanBufferForMajorMode()
> File
> "C:\ProgramFiles\Python25\lib\site-packages\peppy-0.14.0-py2.5.egg\peppy\fileopener.py",
> line 197, in scanBufferForMajorMode
> self.modecls = MajorModeMatcherDriver.match(self.buffer, url=self.url)
> File
> "C:\ProgramFiles\Python25\lib\site-packages\peppy-0.14.0-py2.5.egg\peppy\majormodematcher.py",
> line 192, in match
> mode = cls.matchFile(buffer, magic_size, url, header)
> File
> "C:\ProgramFiles\Python25\lib\site-packages\peppy-0.14.0-py2.5.egg\peppy\majormodematcher.py",
> line 252, in matchFile
> metadata = cls.getFailsafeMetadata(url)
> File
> "C:\ProgramFiles\Python25\lib\site-packages\peppy-0.14.0-py2.5.egg\peppy\majormodematcher.py",
> line 350, in getFailsafeMetadata
> traceback.print_exc()
> File "C:\ProgramFiles\Python25\Lib\traceback.py", line 227, in print_exc
> print_exception(etype, value, tb, limit, file)
> File "C:\ProgramFiles\Python25\Lib\traceback.py", line 124, in
> print_exception
> _print(file, 'Traceback (most recent call last):')
> File "C:\ProgramFiles\Python25\Lib\traceback.py", line 13, in _print
> file.write(str+terminator)
> IOError: [Errno 9] Bad file descriptor

Any ideas?


Don

Rob McMullen

unread,
Apr 13, 2010, 10:19:13 PM4/13/10
to pepp...@googlegroups.com
On Tue, Apr 13, 2010 at 3:18 PM, Don Dwiggins <ddwi...@advpubtech.com> wrote:
> I just loaded a wxPthon .py file and tried to execute it with F5. I got the
> following traceback:

It looks like the traceback is not actually the error that we're
interested in, but an error caused by trying to print the real error.
I can't seem to duplicate it here -- when I try to run a wxpython
sample file using F5 it seems to work.

Can you try the latest svn? I made a change that should cause the
error to be printed in the errorlog sidebar. I realize you're on
Windows and so that may not be convenient... Soon when I get some
more Fortran 77 mode stuff done, I'll make a new release.

(Yes, I have the occasion to code in F77 for my job. Yuck.)

Rob

Don Dwiggins

unread,
Apr 14, 2010, 4:56:38 PM4/14/10
to pepp...@googlegroups.com
Rob McMullen wrote:
On Tue, Apr 13, 2010 at 3:18 PM, Don Dwiggins <ddwi...@advpubtech.com> wrote:
  
I just loaded a wxPthon .py file and tried to execute it with F5. I got the
following traceback:
    
It looks like the traceback is not actually the error that we're
interested in, but an error caused by trying to print the real error.
I can't seem to duplicate it here -- when I try to run a wxpython
sample file using F5 it seems to work.

Can you try the latest svn?  I made a change that should cause the
error to be printed in the errorlog sidebar.

Nothing shows up in the error log or the debug log.  (I've updated peppy to r2521 on the trunk.)


  I realize you're on
Windows and so that may not be convenient...  Soon when I get some
more Fortran 77 mode stuff done, I'll make a new release.

(Yes, I have the occasion to code in F77 for my job.  Yuck.)
  

Sympathies.  I thought I had it bad having to maintain a bunch of VB6 code.


Don

Rob McMullen

unread,
Apr 16, 2010, 12:05:40 AM4/16/10
to pepp...@googlegroups.com
On Wed, Apr 14, 2010 at 1:56 PM, Don Dwiggins <ddwi...@advpubtech.com> wrote:
> Nothing shows up in the error log or the debug log.  (I've updated peppy to
> r2521 on the trunk.)

Huh. I don't suppose you can send me the wxpython code that causes
the problem on your system?

> Sympathies.  I thought I had it bad having to maintain a bunch of VB6 code.

Never had the pleasure of using Visual Basic!

Rob

--
You received this message because you are subscribed to the Google Groups "peppy-dev" group.
To post to this group, send email to pepp...@googlegroups.com.
To unsubscribe from this group, send email to peppy-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/peppy-dev?hl=en.

Don Dwiggins

unread,
Apr 19, 2010, 12:32:59 PM4/19/10
to pepp...@googlegroups.com
Rob,
> Huh. I don't suppose you can send me the wxpython code that causes
> the problem on your system?
>
Actually, I can (and have). It's a first cut at an editor for .ini
files in the style of Michael Foord's ConfigObj. (It was written by a
junior colleague, and I haven't reviewed the code in any depth.)

I've looked a bit more deeply into what's happening, using Process
Explorer. A subprocess is started, then just hangs until I stop it. It
runs fine when I start it from the command line or Windows Explorer.


Don
ConfigEdit.pyw

Rob McMullen

unread,
Apr 21, 2010, 10:46:29 AM4/21/10
to pepp...@googlegroups.com
Don,

I will take a look at this soon. I've got a whole bunch of family
visiting for the week so it's been crazy busy and I haven't had any
time to even think about software.

Rob

On Apr 19, 2010, at 11:32, Don Dwiggins <ddwi...@advpubtech.com>
wrote:
> ##from wx import wxApp
> import wx
> import wx.richtext as rt
> import images
> import wx.aui
> from configobj import ConfigObj, ConfigObjError
> from validate import Validator
> import os,sys
>
> class MyFrame(wx.Frame):
> def __init__(self, parent, ID, title):
> wx.Frame.__init__(self, parent, ID, title,wx.DefaultPosition,
> wx.Size(800, 600),
> style=wx.DEFAULT_FRAME_STYLE |
> wx.NO_FULL_REPAINT_ON_RESIZE)
>
> pnl = wx.Panel(self, style=wx.WANTS_CHARS)
> self.pnl = pnl
>
> self.mgr = wx.aui.AuiManager()
> self.mgr.SetManagedWindow(pnl)
> self.Centre(wx.BOTH)
>
> self.MakeMenuBar()
> self.MakeToolBar()
> self.CreateStatusBar()
> self.SetStatusText("Welcome!")
>
> # Create a TreeCtrl
> leftPanel = wx.Panel(pnl, style=wx.TAB_TRAVERSAL|
> wx.CLIP_CHILDREN)
> self.tree = wx.TreeCtrl(leftPanel, -1, wx.DefaultPosition,
> wx.Size(200, 495), wx.TR_DEFAULT_STYLE | wx.NO_BORDER)
> self.root = self.tree.AddRoot("File")
> self.tree.SetPyData(self.root, None)
> self.tree.Bind(wx.EVT_TREE_SEL_CHANGED,
> self.OnActivatedTreeItem)
>
> leftBox = wx.BoxSizer(wx.VERTICAL)
> leftBox.Add(self.tree, 1, wx.EXPAND)
> leftPanel.SetSizer(leftBox)
>
> self.rtc = rt.RichTextCtrl(pnl, style=wx.VSCROLL|wx.HSCROLL|
> wx.NO_BORDER)
> self.errorlog = wx.TextCtrl(pnl, -1,style = wx.TE_MULTILINE|
> wx.TE_READONLY|wx.HSCROLL)
> self.errorlog.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
> #wx.CallAfter(self.rtc.SetFocus)
> self.rtc.Freeze()
> self.rtc.BeginSuppressUndo()
> self.rtc.BeginParagraphSpacing(0, 20)
>
> self.rtc.BeginAlignment(rt.TEXT_ALIGNMENT_CENTRE)
> self.rtc.BeginBold()
>
> self.rtc.BeginFontSize(14)
> self.rtc.WriteText("Welcome!")
> self.rtc.Newline()
> self.rtc.WriteText("Please select a Config file to edit ...")
> self.rtc.Newline()
> self.rtc.EndFontSize()
>
> self.rtc.EndBold()
> self.rtc.EndAlignment()
> self.rtc.EndParagraphSpacing()
> self.rtc.EndSuppressUndo()
> self.rtc.Thaw()
>
> self.mgr.AddPane(self.rtc, wx.aui.AuiPaneInfo().CenterPane
> ().Name("Notebook"))
> self.mgr.AddPane(leftPanel,
> wx.aui.AuiPaneInfo().
> Left().Layer(2).BestSize((240, -1)).
> MinSize((160, -1)).
> Floatable(False).FloatingSize((240, 700)).
> Caption("Config sections and keywords").
> CloseButton(False).
> Name("Tree"))
> self.mgr.AddPane(self.errorlog,
> wx.aui.AuiPaneInfo().
> Bottom().BestSize((-1, 150)).
> MinSize((-1, 60)).
> Floatable(False).FloatingSize((500, 160)).
> Caption("Error Log").
> CloseButton(False).
> Name("Log"))
> self.mgr.Update()
>
> def MakeMenuBar(self):
> def doBind(item, handler, updateUI=None):
> self.Bind(wx.EVT_MENU, handler, item)
> if updateUI is not None:
> self.Bind(wx.EVT_UPDATE_UI, updateUI, item)
>
> fileMenu = wx.Menu()
> doBind( fileMenu.Append(-1, "&Open\tCtrl+O", "Open a file"),
> self.OnFileOpen )
> doBind( fileMenu.Append(-1, "&Save\tCtrl+S", "Save a file"),
> self.OnFileSave )
> doBind( fileMenu.Append(-1, "&Save As...\tF12", "Save to a
> new file"),
> self.OnFileSaveAs )
> fileMenu.AppendSeparator()
> doBind( fileMenu.Append(-1, "E&xit\tCtrl+Q", "Quit this
> program"),
> self.OnFileExit )
>
> editMenu = wx.Menu()
> doBind( editMenu.Append(wx.ID_UNDO, "&Undo\tCtrl+Z"),
> self.ForwardEvent, self.ForwardEvent)
> doBind( editMenu.Append(wx.ID_REDO, "&Redo\tCtrl+Y"),
> self.ForwardEvent, self.ForwardEvent )
> editMenu.AppendSeparator()
> doBind( editMenu.Append(wx.ID_CUT, "Cu&t\tCtrl+X"),
> self.ForwardEvent, self.ForwardEvent )
> doBind( editMenu.Append(wx.ID_COPY, "&Copy\tCtrl+C"),
> self.ForwardEvent, self.ForwardEvent)
> doBind( editMenu.Append(wx.ID_PASTE, "&Paste\tCtrl+V"),
> self.ForwardEvent, self.ForwardEvent)
> doBind( editMenu.Append(wx.ID_CLEAR, "&Delete\tDel"),
> self.ForwardEvent, self.ForwardEvent)
> editMenu.AppendSeparator()
> doBind( editMenu.Append(wx.ID_SELECTALL, "Select A&ll\tCtrl
> +A"),
> self.ForwardEvent, self.ForwardEvent )
>
> mb = wx.MenuBar()
> mb.Append(fileMenu, "&File")
> mb.Append(editMenu, "&Edit")
> self.SetMenuBar(mb)
>
> def MakeToolBar(self):
> def doBind(item, handler, updateUI=None):
> self.Bind(wx.EVT_TOOL, handler, item)
> if updateUI is not None:
> self.Bind(wx.EVT_UPDATE_UI, updateUI, item)
>
> tbar = self.CreateToolBar()
> doBind( tbar.AddTool(-1, images._rt_open.GetBitmap(),
> shortHelpString="Open"), self.OnFileOpen)
> doBind( tbar.AddTool(-1, images._rt_save.GetBitmap(),
> shortHelpString="Save"), self.OnFileSave)
> tbar.AddSeparator()
> doBind( tbar.AddTool(wx.ID_CUT, images._rt_cut.GetBitmap(),
> shortHelpString="Cut"),
> self.ForwardEvent, self.ForwardEvent)
> doBind( tbar.AddTool(wx.ID_COPY, images._rt_copy.GetBitmap(),
> shortHelpString="Copy"),
> self.ForwardEvent, self.ForwardEvent)
> doBind( tbar.AddTool(wx.ID_PASTE, images._rt_paste.GetBitmap(),
> shortHelpString="Paste"),
> self.ForwardEvent, self.ForwardEvent)
> tbar.AddSeparator()
> doBind( tbar.AddTool(wx.ID_UNDO, images._rt_undo.GetBitmap(),
> shortHelpString="Undo"),
> self.ForwardEvent, self.ForwardEvent)
> doBind( tbar.AddTool(wx.ID_REDO, images._rt_redo.GetBitmap(),
> shortHelpString="Redo"),
> self.ForwardEvent, self.ForwardEvent)
> tbar.Realize()
>
> def SetTitle(self, filename):
> """Adds the filename to the title"""
> wx.Frame.SetTitle(self, filename)
>
> def OnLeftDown(self, evt):
> evt.Skip()
> # hit --> (result, col, row)
> hit = self.errorlog.HitTest(evt.GetPosition())
> wx.CallAfter(self.LeftDownAction, hit)
>
> def LeftDownAction(self, hit):
> #print evt.GetPosition()
> self.selection = hit
> line_number = hit[2]
> err_text = self.errorlog.GetLineText(line_number)
> if err_text.strip() != "" :
> err_text = err_text[err_text.rfind(" ")+1:len(err_text)]
> err_text = err_text.replace('"',"")
> err_text = err_text.replace('.',"")
> line_number = int(err_text)
> start = self.rtc.XYToPosition(0,line_number - 1)
> self.rtc.ShowPosition(start)
>
> def OnFileOpen(self, evt):
> # This gives us a string suitable for the file dialog based on
> # the file handlers that are loaded
> wildcard, types = rt.RichTextBuffer.GetExtWildcard(save=False)
> dlg = wx.FileDialog(self, "Choose a filename",
> wildcard="*.ini",
> style=wx.OPEN)
> if dlg.ShowModal() == wx.ID_OK:
> wildcard, types = rt.RichTextBuffer.GetExtWildcard
> (save=False)
> path = dlg.GetPath()
> if path:
> self.SetTitle(path)
> fileType = types[dlg.GetFilterIndex()]
> self.rtc.LoadFile(path, fileType)
> self.SetDefaultTextColour()
> self.ReadConfigFile(path)
> dlg.Destroy()
>
> def ConfigError (self, error):
> attr = rt.TextAttrEx()
> attr.SetFlags(rt.TEXT_ATTR_TEXT_COLOUR)
>
> self.SetDefaultTextColour()
>
> for e in error.errors :
> line_number = e.line_number
>
> attr.SetTextColour((255, 0, 0))
> start = self.rtc.XYToPosition(0,line_number-1)
> end = self.rtc.XYToPosition(len(self.rtc.GetLineText
> (line_number-1)),line_number-1)
> self.rtc.ShowPosition(start)
> self.rtc.SetSelection(start, end)
> r = self.rtc.GetSelectionRange()
> self.rtc.SetStyle(r, attr)
>
> self.rtc.SelectNone()
> self.errorlog.WriteText(e.message + "\n")
>
> def AppendItemToTree (self, parent, sections, line_number,
> rowCount):
> for el in sections :
> line_number = self.GetLineNumberConfig(el[0],
> line_number, rowCount)
> section = self.tree.AppendItem(parent, el[0])
> self.tree.SetPyData(section, line_number)
> if line_number>=self.rtc.GetNumberOfLines() :
> dlg = wx.MessageDialog(self, 'The section "' + el[0]
> + '" is missing.',
> 'Warning',
> wx.OK | wx.ICON_INFORMATION
> #wx.YES_NO | wx.NO_DEFAULT |
> wx.CANCEL | wx.ICON_INFORMATION
> )
> dlg.ShowModal()
> dlg.Destroy()
> #print "item : " + el[0] + " Line Number : " + str
> (line_number) + " Start : " + str(line_number)
> for j in range(1,len(el)) :
> if str(type(el[j]))!="<type 'str'>" and str(type(el
> [j]))!="<type 'list'>" and str(type(el[j]))!="<type 'int'>":
> subsections = [(k, v) for (k, v) in el
> [j].iteritems()]
> if len(subsections) >0 :
> line_number = self.AppendItemToTree(section,
> subsections, line_number+1, rowCount)
> return line_number + 1
>
> def validate_err(self,ErrorList,newKeyList, parent="") :
> for k,v in ErrorList.iteritems():
> if v is True:
> continue
> if isinstance(v,dict):
> self.validate_err(v, newKeyList,k)
> else :
> newKeyList.append(parent + "->" + k + "=" + str(v)[str
> (v).find('"')+1:str(v).rfind('"')])
> return newKeyList
>
> def ReadConfigFile (self, path):
> self.errorlog.Clear()
> self.tree.DeleteAllItems()
> self.root = self.tree.AddRoot(path)
> self.tree.SetPyData(self.root, None)
> try:
> if path[path.rfind("\\")+1:] == "DSMConfig.ini" :
> val = Validator()
> configspec = ConfigObj(os.path.realpath
> (os.path.dirname(sys.argv[0])) + "\configspec\configspec.ini",
> interpolation=False, list_values=False,
> _inspec=True)
> config = ConfigObj(path,
> file_error=True,configspec=configspec)
> validationResult = config.validate
> (val,preserve_errors=True)
> #print flatten_errors(config, ErrorList)
> invalidKeys=[]
> invalidKeys = self.validate_err
> (validationResult,invalidKeys)
> attr = rt.TextAttrEx()
> attr.SetFlags(rt.TEXT_ATTR_TEXT_COLOUR)
> self.SetDefaultTextColour()
> for key in invalidKeys:
> key1 = key.split("->")
> for j in range(0,self.rtc.GetNumberOfLines()) :
> pos = self.rtc.GetLineText(j).find(key1[0])
> if pos>=0 : break
> for i in range(j+1,self.rtc.GetNumberOfLines()) :
> key2 = key1[1].split("=")
> pos0 = self.rtc.GetLineText(i).find(key2[0])
> if key2[1]=="" :
> pos1 = -1
> else :
> pos1 = self.rtc.GetLineText(i).find(key2
> [1])
> pos2 = self.rtc.GetLineText(i).find("=")
> pos3 = self.rtc.GetLineText(i).find("#")
> if pos0 >= 0 and pos1>=0 and pos2>=0 and
> pos3<0 :
> start = self.rtc.XYToPosition(0,i)
> end = self.rtc.XYToPosition(len
> (self.rtc.GetLineText(i)),i)
> attr.SetTextColour((255, 0, 0))
> self.rtc.SetSelection(start, end)
> r = self.rtc.GetSelectionRange()
> self.rtc.SetStyle(r, attr)
> self.rtc.SelectNone()
> self.errorlog.WriteText('Invalid format
> for "' + key + '" at line ' + str(i+1) + '.\n')
> break
> else :
> config = ConfigObj(path, file_error=True)
> sections = [(k, v) for (k, v) in config.iteritems()]
> line_number = self.AppendItemToTree(self.root,sections,
> 0, self.rtc.GetNumberOfLines())
> self.tree.Expand(self.root)
> except (ConfigObjError, IOError), e:
> self.ConfigError(e)
>
> def OnFileSave(self, evt):
> if not self.rtc.GetFilename():
> self.OnFileSaveAs(evt)
> return
> self.rtc.SaveFile(self.rtc.GetFilename(),1)
> self.ReadConfigFile(self.rtc.GetFilename())
>
> def OnFileSaveAs(self, evt):
> wildcard, types = rt.RichTextBuffer.GetExtWildcard(save=False)
> dlg = wx.FileDialog(self, "Choose a filename",
> wildcard="*.ini",
> style=wx.SAVE)
> if dlg.ShowModal() == wx.ID_OK:
> wildcard, types = rt.RichTextBuffer.GetExtWildcard
> (save=False)
> path = dlg.GetPath()
> if path:
> fileType = types[dlg.GetFilterIndex()]
> self.rtc.SaveFile(path, fileType)
> self.ReadConfigFile(path)
> dlg.Destroy()
>
> def OnFileExit(self, evt):
> self.Close(True)
>
> def GetLineNumberConfig(self, key, startLine, endLine):
> for i in range(startLine,endLine) :
> text=""
> pos = self.rtc.GetLineText(i).find(key)
> if pos >= 0 :
> if self.rtc.GetLineText(i).find("[") >= 0 :
> text = self.rtc.GetLineText(i).replace("[","")
> text = text.replace("]","")
> elif self.rtc.GetLineText(i).find("=") >= 0 :
> text = self.rtc.GetLineText(i)
> [0:self.rtc.GetLineText(i).find("=")].strip()
> if text.strip() == key.strip() :
> return i
> return startLine
>
> def OnActivatedTreeItem(self, evt):
> item = evt.GetItem()
> if self.tree.GetPyData(item) != None :
> line_number = self.tree.GetPyData(item)
> if line_number<self.rtc.GetNumberOfLines() :
> attr = rt.TextAttrEx()
> attr.SetFlags(rt.TEXT_ATTR_TEXT_COLOUR)
>
> self.SetDefaultTextColour()
>
> attr.SetTextColour((0, 200, 0))
> start = self.rtc.XYToPosition(0,line_number)
> end = self.rtc.XYToPosition(len(self.rtc.GetLineText
> (line_number)),line_number)
> self.rtc.ShowPosition(start)
> self.rtc.SetSelection(start, end)
> r = self.rtc.GetSelectionRange()
> self.rtc.SetStyle(r, attr)
> self.rtc.SelectNone()
> else :
> dlg = wx.MessageDialog(self, 'This section is
> missing.',
> 'Warning',
> wx.OK | wx.ICON_INFORMATION
> #wx.YES_NO | wx.NO_DEFAULT |
> wx.CANCEL | wx.ICON_INFORMATION
> )
> dlg.ShowModal()
> dlg.Destroy()
>
> def ForwardEvent(self, evt):
> # The RichTextCtrl can handle menu and update events for undo,
> # redo, cut, copy, paste,

Don Dwiggins

unread,
Apr 21, 2010, 12:22:23 PM4/21/10
to pepp...@googlegroups.com
Rob McMullen wrote:
> Don,
>
> I will take a look at this soon. I've got a whole bunch of family
> visiting for the week so it's been crazy busy and I haven't had any
> time to even think about software.

Except of course the two-legged kind. ;-) OK, I'll be patient -- it's
not a pressing issue.


Don
>> wx.aui.AuiPaneInfo().CenterPane().Name("Notebook"))
>> doBind( editMenu.Append(wx.ID_SELECTALL, "Select A&ll\tCtrl+A"),
>> str(line_number) + " Start : " + str(line_number)
>> for j in range(1,len(el)) :
>> if str(type(el[j]))!="<type 'str'>" and
>> str(type(el[j]))!="<type 'list'>" and str(type(el[j]))!="<type 'int'>":
>> subsections = [(k, v) for (k, v) in
>> el[j].iteritems()]
>> if len(subsections) >0 :
>> line_number = self.AppendItemToTree(section,
>> subsections, line_number+1, rowCount)
>> return line_number + 1
>>
>> def validate_err(self,ErrorList,newKeyList, parent="") :
>> for k,v in ErrorList.iteritems():
>> if v is True:
>> continue
>> if isinstance(v,dict):
>> self.validate_err(v, newKeyList,k)
>> else :
>> newKeyList.append(parent + "->" + k + "=" +
>> str(v)[str(v).find('"')+1:str(v).rfind('"')])
>> return newKeyList
>>
>> def ReadConfigFile (self, path):
>> self.errorlog.Clear()
>> self.tree.DeleteAllItems()
>> self.root = self.tree.AddRoot(path)
>> self.tree.SetPyData(self.root, None)
>> try:
>> if path[path.rfind("\\")+1:] == "DSMConfig.ini" :
>> val = Validator()
>> configspec =
>> ConfigObj(os.path.realpath(os.path.dirname(sys.argv[0])) +

Rob McMullen

unread,
Apr 29, 2010, 4:59:32 PM4/29/10
to pepp...@googlegroups.com
Don,

On Wed, Apr 21, 2010 at 9:22 AM, Don Dwiggins <ddwi...@advpubtech.com> wrote:
> OK, I'll be patient -- it's not a pressing issue.

Sorry for the delay. Life is just starting to return to normal and I
was trying to look the sample file that you sent. It looks like it is
trying to import local modules:

images.py
configobj.py
validate.py

Can you send those files as well?

Thanks,

Rob

Rob McMullen

unread,
May 7, 2010, 12:43:22 AM5/7/10
to pepp...@googlegroups.com
Don,

I've had some time to try and debug this over the past week, and what
I think it boils down to is that there's a problem with
wx.Process/wx.Execute on windows. It seems that wxPython code freezes
somewhere in the app.MainLoop() and no amount of my hacking around or
googling could find a way around it.

It looks like I'll have to convert to using the python subprocess
module, as that doesn't appear to be affected by the problem. The
app.MainLoop() function works when started using subprocess.

Rob

Rob McMullen

unread,
May 7, 2010, 3:56:42 PM5/7/10
to pepp...@googlegroups.com
Don,

Give the current svn a shot. As it happens, I went down the road of
fixing the problem by trying to integrate some working code from
another project, when I discovered a workaround for the original
wx.Process/wx.Execute code.
Reply all
Reply to author
Forward
0 new messages