Memory error in StyledTextCtrl.GotoLine

View: New views
12 Messages — Rating Filter:   Alert me  

Memory error in StyledTextCtrl.GotoLine

by Cristina Yenyxe González García :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello:

I'm implementing a simple interface for a debugger in wxPython and I
have decided to use the StyledTextCtrl to show the source code. I have
managed to change the file shown when the debugger moves from one to
another, but I can't use the GotoLine method to set the correct
position for the caret, because after some calls (not always the same)
it raises a memory error, not a Python's MemoryError (I can't catch it
with an except branch). I haven't found anything about this problem
surfing the Internet, so I don't know if it is exactly a bug.

The code I'm using is the following, and after removing the GotoLine
call it works perfectly:

    def set_editor_file(self, path, line):
        try:
            self.editor.LoadFile(path) # self.editor is the
StyledTextCtrl component
        except:
            text = "File in path " + path + " not available"
            self.editor.SetText(text)
        self.editor.MoveCaretInsideView()
        self.editor.GotoLine(line-1) # The minimum line in Python is
1, in C++ it is 0

I'm using Windows XP, Python 2.5 and wxWidgets 2.8.8.0 and 2.8.8.1.
Thanks in advance.
_______________________________________________
wx-users mailing list
wx-users@...
http://lists.wxwidgets.org/mailman/listinfo/wx-users

Re: Memory error in StyledTextCtrl.GotoLine

by Stef Mientki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Cristina Yenyxe González García wrote:
> Hello:
>
> I'm implementing a simple interface for a debugger in wxPython and I
> have decided to use the StyledTextCtrl to show the source code.
Well I'm doing exactly the same at this moment,
and use a slightly different syntax, which until now works perfect:

  # *********************************************************
  # Called by Debugger, when a new breakpoint is reached
  # *********************************************************
  def Callback_Load_Editor ( self, filename, lineno = -1 ) :
    ...select the right editor, I use multi-page/tab editor
    Edit[0].EnsureVisibleEnforcePolicy ( lineno )
    Edit[0].GotoLine ( lineno )

Interesting to know what debugger you use,
and maybe we can coöperate and / or exchange some ideas.
I'll put my notes until now on the web this evening.

cheers,
Stef

>  I have
> managed to change the file shown when the debugger moves from one to
> another, but I can't use the GotoLine method to set the correct
> position for the caret, because after some calls (not always the same)
> it raises a memory error, not a Python's MemoryError (I can't catch it
> with an except branch). I haven't found anything about this problem
> surfing the Internet, so I don't know if it is exactly a bug.
>
> The code I'm using is the following, and after removing the GotoLine
> call it works perfectly:
>
>     def set_editor_file(self, path, line):
>         try:
>             self.editor.LoadFile(path) # self.editor is the
> StyledTextCtrl component
>         except:
>             text = "File in path " + path + " not available"
>             self.editor.SetText(text)
>         self.editor.MoveCaretInsideView()
>         self.editor.GotoLine(line-1) # The minimum line in Python is
> 1, in C++ it is 0
>
> I'm using Windows XP, Python 2.5 and wxWidgets 2.8.8.0 and 2.8.8.1.
> Thanks in advance.
> _______________________________________________
> wx-users mailing list
> wx-users@...
> http://lists.wxwidgets.org/mailman/listinfo/wx-users
>
>
>  


Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629.
The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629.


_______________________________________________
wx-users mailing list
wx-users@...
http://lists.wxwidgets.org/mailman/listinfo/wx-users

Re: Memory error in StyledTextCtrl.GotoLine

by Cristina Yenyxe González García :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2008/9/2 Stef Mientki <s.mientki@...>:

>
>
> Well I'm doing exactly the same at this moment,
> and use a slightly different syntax, which until now works perfect:
>
>  # *********************************************************
>  # Called by Debugger, when a new breakpoint is reached
>  # *********************************************************
>  def Callback_Load_Editor ( self, filename, lineno = -1 ) :
>   ...select the right editor, I use multi-page/tab editor
>   Edit[0].EnsureVisibleEnforcePolicy ( lineno )
>   Edit[0].GotoLine ( lineno )
>
> Interesting to know what debugger you use,
> and maybe we can coöperate and / or exchange some ideas.
> I'll put my notes until now on the web this evening.
>

Well, it's a Final Degree Project so I've made an implementation
myself, inspired on Pdb but redesigning things like the UI and
breakpoint or watchpoint checking, using AOP. Yeah, it's a bit strange
:) Anyway, I'll be glad to exchange ideas.

And about your code, now I'm getting this error message (which is
better than before, when it simply crashed):
runtime error R6025 - pure virtual function call

I'll take a look again and post the results in another mail.
Thank you!
_______________________________________________
wx-users mailing list
wx-users@...
http://lists.wxwidgets.org/mailman/listinfo/wx-users

Re: Memory error in StyledTextCtrl.GotoLine

by Robin Dunn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Cristina Yenyxe González García wrote:

> Hello:
>
> I'm implementing a simple interface for a debugger in wxPython and I
> have decided to use the StyledTextCtrl to show the source code. I have
> managed to change the file shown when the debugger moves from one to
> another, but I can't use the GotoLine method to set the correct
> position for the caret, because after some calls (not always the same)
> it raises a memory error, not a Python's MemoryError (I can't catch it
> with an except branch). I haven't found anything about this problem
> surfing the Internet, so I don't know if it is exactly a bug.
>
> The code I'm using is the following, and after removing the GotoLine
> call it works perfectly:
>
>     def set_editor_file(self, path, line):
>         try:
>             self.editor.LoadFile(path) # self.editor is the
> StyledTextCtrl component
>         except:
>             text = "File in path " + path + " not available"
>             self.editor.SetText(text)
>         self.editor.MoveCaretInsideView()
>         self.editor.GotoLine(line-1) # The minimum line in Python is
> 1, in C++ it is 0
>
> I'm using Windows XP, Python 2.5 and wxWidgets 2.8.8.0 and 2.8.8.1.

Please create a small runnable sample that demonstrates the problem.

http://wiki.wxpython.org/MakingSampleApps

--
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!

_______________________________________________
wx-users mailing list
wx-users@...
http://lists.wxwidgets.org/mailman/listinfo/wx-users

Re: Memory error in StyledTextCtrl.GotoLine

by Stef Mientki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Cristina Yenyxe González García wrote:

> 2008/9/2 Stef Mientki <s.mientki@...>:
>  
>> Well I'm doing exactly the same at this moment,
>> and use a slightly different syntax, which until now works perfect:
>>
>>  # *********************************************************
>>  # Called by Debugger, when a new breakpoint is reached
>>  # *********************************************************
>>  def Callback_Load_Editor ( self, filename, lineno = -1 ) :
>>   ...select the right editor, I use multi-page/tab editor
>>   Edit[0].EnsureVisibleEnforcePolicy ( lineno )
>>   Edit[0].GotoLine ( lineno )
>>
>> Interesting to know what debugger you use,
>> and maybe we can coöperate and / or exchange some ideas.
>> I'll put my notes until now on the web this evening.
>>
>>    
>
> Well, it's a Final Degree Project so I've made an implementation
> myself, inspired on Pdb but redesigning things like the UI and
> breakpoint or watchpoint checking, using AOP. Yeah, it's a bit strange
> :)
As it's your Final Degree Project, you must certainly create it yourself.
Never heard of AOP, but just looked it up, and it looks like an
interesting technique.
This is indeed one of the most tangled programs I've made, so I'm
curious how it will look with AOP.
> Anyway, I'll be glad to exchange ideas.
>  
Although you must use your own imagination
(this might be the last time you can think and act so freely ;-),
here are my notes
  http://oase.uci.kun.nl/~mientki/data_www/pylab_works/pw_debug.html
but I'm sure you can come up with more and better ideas.

good luck with your project,
cheers,
Stef

_______________________________________________
wx-users mailing list
wx-users@...
http://lists.wxwidgets.org/mailman/listinfo/wx-users

Re: Memory error in StyledTextCtrl.GotoLine

by Stef Mientki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Cristina Yenyxe González García wrote:
> 2008/9/2 Stef Mientki <s.mientki@...>:
>  
>>
>>    
>
> Well, it's a Final Degree Project so I've made an implementation
> myself, inspired on Pdb but redesigning things like the UI and
>  

hi Cristina,
Although I thought I had my program almost finished,
I yesterday discovered some really annoyances with rpdb2,
(illegal memory reads, doesn't work with utorrent)
so I seriously consider to move to the standard pdb for internal debugging.

So I'm greatly interested in your interface with pdb, to quickly find
out if pdb is a better choice for me.
I'm specially interested in the following issues:
- how do you launch pdb from within your program (I'm not a programmer
and don't understand much of pipes)
- how do you communicate between pdb and your textctrl

thanks,
Stef Mientki



Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629.
The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629.


_______________________________________________
wx-users mailing list
wx-users@...
http://lists.wxwidgets.org/mailman/listinfo/wx-users

Re: Memory error in StyledTextCtrl.GotoLine

by Cristina Yenyxe González García :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2008/9/3 Stef Mientki <s.mientki@...>:

>
> hi Cristina,
> Although I thought I had my program almost finished,
> I yesterday discovered some really annoyances with rpdb2,
> (illegal memory reads, doesn't work with utorrent)
> so I seriously consider to move to the standard pdb for internal debugging.
>
> So I'm greatly interested in your interface with pdb, to quickly find out if
> pdb is a better choice for me.
> I'm specially interested in the following issues:
> - how do you launch pdb from within your program (I'm not a programmer and
> don't understand much of pipes)
> - how do you communicate between pdb and your textctrl
>

To start the debugger, you only need to call its 'run' method, like
the Python tutorial explains:
http://docs.python.org/lib/module-pdb.html
Feel free to ask me if you have any problem with that ;)

If you don't bother about separating debugging and user I/O in the
design, it is really simple to communicate between pdb and the rest of
your application. I think you should rewrite the user_line, user_call,
user_return, user_exception and interaction methods. These ones
perform some actions when the debugger traces an event, and if you
take a look at the code you see they make some "prints" to sys.stdout
and read and write the different commands from/to console, so you'll
simply need to put the sentences to write in your textctrl.

Robin, I'll try to have the sample app this week, but I have a lot of
oh-so-wonderful documentation to write that I don't know if I'll
finally have time to include this feature :(
_______________________________________________
wx-users mailing list
wx-users@...
http://lists.wxwidgets.org/mailman/listinfo/wx-users

Re: Memory error in StyledTextCtrl.GotoLine

by Stef Mientki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Cristina Yenyxe González García wrote:

> 2008/9/3 Stef Mientki <s.mientki@...>:
>  
>> hi Cristina,
>> Although I thought I had my program almost finished,
>> I yesterday discovered some really annoyances with rpdb2,
>> (illegal memory reads, doesn't work with utorrent)
>> so I seriously consider to move to the standard pdb for internal debugging.
>>
>> So I'm greatly interested in your interface with pdb, to quickly find out if
>> pdb is a better choice for me.
>> I'm specially interested in the following issues:
>> - how do you launch pdb from within your program (I'm not a programmer and
>> don't understand much of pipes)
>> - how do you communicate between pdb and your textctrl
>>
>>    
>
> To start the debugger, you only need to call its 'run' method, like
> the Python tutorial explains:
> http://docs.python.org/lib/module-pdb.html
> Feel free to ask me if you have any problem with that ;)
>  
Well indeed I can't get that to work: if I start the debugger the
wxPython GUI hangs completely.
I've put the main code at the bottom of this message,
so if you've any hints, please ...
> If you don't bother about separating debugging and user I/O in the
> design, it is really simple to communicate between pdb and the rest of
> your application. I think you should rewrite the user_line, user_call,
> user_return, user_exception and interaction methods. These ones
> perform some actions when the debugger traces an event, and if you
> take a look at the code you see they make some "prints" to sys.stdout
> and read and write the different commands from/to console, so you'll
> simply need to put the sentences to write in your textctrl.
>  
Interesting thought,
I Never thought of hacking pdb ( I try to avoid changing standard libs ;-)
but why should you, the Pdb class already has a stdin/stdout as an
argument ?

thanks,
Stef

# ***********************************************************************
class Simple_Test_Form ( wx.MiniFrame ):
  def __init__ ( self ):
    wx.MiniFrame.__init__( self, None, style = wx.DEFAULT_FRAME_STYLE  )

    GUI = """
    self.Splitter_Plots    ,SplitterVer
      Panel1        ,PanelVer, 01  ,name  = "Hello"
        Button_1    ,wx.Button     ,label = "Test"
        self.KeyB   ,wx.TextCtrl   ,style = wx.TE_MULTILINE |
wx.TE_PROCESS_ENTER
      Panel2        ,PanelVer, 11  ,name  = "Page2"
        self.Log    ,wx.TextCtrl   ,style = wx.TE_MULTILINE |
wx.TE_PROCESS_ENTER
    """
    exec ( Create_wxGUI ( GUI ) )

    import Queue
    self.m_queue = Queue.Queue()
    self.Log.flush = self.flush
    self.KeyB.readline = self.readline

    self.Log.Bind ( wx.EVT_TEXT_ENTER, self.On_Enter_Key )
    self.Bind ( wx.EVT_BUTTON, self.B )
   
  def On_Enter_Key ( self, event ) :
    self.m_queue.put ( event.GetString() + '\n' )

  def B ( self, event ):
    import pdb
    import test_IDE
    aap = pdb.Pdb ( stdin = self.KeyB ,stdout  = self.Log )
    #aap.run('test_IDE')
    wx.CallAfter ( aap.run, 'test_IDE' )
   
  def readline ( self ) :
    _str = self.m_queue.get()
    import time
    time.sleep(0.02)
    self.ProcessIdle()
    return _str

  def flush ( self  ):
    pass

_______________________________________________
wx-users mailing list
wx-users@...
http://lists.wxwidgets.org/mailman/listinfo/wx-users

Re: Memory error in StyledTextCtrl.GotoLine

by Cristina Yenyxe González García :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry about the confusion with the streams, I had to change them in my
effort to separate completely the user interface and didn't remember
the arguments of the Pdb's constructor :)

But I think we should start a new thread in the list to talk about
this topic, don't you think so? :) If you can't find a solution I'll
prepare my answer for tomorrow morning, because I had the same problem
some time ago. A good point would be executing app.run in a new
thread, so the wx interface and the debugger would be in different
threads, and this way is a lot easier to avoid GUI blocking. You can
also use the threading.Event objects from the Python's API to wait for
the user response (I think wx has something to wait for GUI events,
though).

So may I suppose that wx always runs in the same thread than the rest
of the application? In other graphic libraries like Swing I think they
are internally separated by the virtual machine and that makes thing
easier, but I have to admit that is not a wx issue.
_______________________________________________
wx-users mailing list
wx-users@...
http://lists.wxwidgets.org/mailman/listinfo/wx-users

Re: Memory error in StyledTextCtrl.GotoLine

by Stef Mientki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

ok, got it running now, using wx.Process and wx.Execute with the -u switch.

thnaks anyway,
cheers,
Stef

Stef Mientki wrote:

>
>
> Cristina Yenyxe González García wrote:
>> 2008/9/3 Stef Mientki <s.mientki@...>:
>>  
>>> hi Cristina,
>>> Although I thought I had my program almost finished,
>>> I yesterday discovered some really annoyances with rpdb2,
>>> (illegal memory reads, doesn't work with utorrent)
>>> so I seriously consider to move to the standard pdb for internal
>>> debugging.
>>>
>>> So I'm greatly interested in your interface with pdb, to quickly
>>> find out if
>>> pdb is a better choice for me.
>>> I'm specially interested in the following issues:
>>> - how do you launch pdb from within your program (I'm not a
>>> programmer and
>>> don't understand much of pipes)
>>> - how do you communicate between pdb and your textctrl
>>>
>>>    
>>
>> To start the debugger, you only need to call its 'run' method, like
>> the Python tutorial explains:
>> http://docs.python.org/lib/module-pdb.html
>> Feel free to ask me if you have any problem with that ;)
>>  
> Well indeed I can't get that to work: if I start the debugger the
> wxPython GUI hangs completely.
> I've put the main code at the bottom of this message,
> so if you've any hints, please ...
>> If you don't bother about separating debugging and user I/O in the
>> design, it is really simple to communicate between pdb and the rest of
>> your application. I think you should rewrite the user_line, user_call,
>> user_return, user_exception and interaction methods. These ones
>> perform some actions when the debugger traces an event, and if you
>> take a look at the code you see they make some "prints" to sys.stdout
>> and read and write the different commands from/to console, so you'll
>> simply need to put the sentences to write in your textctrl.
>>  
> Interesting thought,
> I Never thought of hacking pdb ( I try to avoid changing standard libs
> ;-)
> but why should you, the Pdb class already has a stdin/stdout as an
> argument ?
>
> thanks,
> Stef
>
> # ***********************************************************************
> class Simple_Test_Form ( wx.MiniFrame ):
>  def __init__ ( self ):
>    wx.MiniFrame.__init__( self, None, style = wx.DEFAULT_FRAME_STYLE  )
>
>    GUI = """
>    self.Splitter_Plots    ,SplitterVer
>      Panel1        ,PanelVer, 01  ,name  = "Hello"
>        Button_1    ,wx.Button     ,label = "Test"
>        self.KeyB   ,wx.TextCtrl   ,style = wx.TE_MULTILINE |
> wx.TE_PROCESS_ENTER
>      Panel2        ,PanelVer, 11  ,name  = "Page2"
>        self.Log    ,wx.TextCtrl   ,style = wx.TE_MULTILINE |
> wx.TE_PROCESS_ENTER
>    """
>    exec ( Create_wxGUI ( GUI ) )
>
>    import Queue
>    self.m_queue = Queue.Queue()
>    self.Log.flush = self.flush
>    self.KeyB.readline = self.readline
>
>    self.Log.Bind ( wx.EVT_TEXT_ENTER, self.On_Enter_Key )
>    self.Bind ( wx.EVT_BUTTON, self.B )
>    def On_Enter_Key ( self, event ) :
>    self.m_queue.put ( event.GetString() + '\n' )
>
>  def B ( self, event ):
>    import pdb
>    import test_IDE
>    aap = pdb.Pdb ( stdin = self.KeyB ,stdout  = self.Log )
>    #aap.run('test_IDE')
>    wx.CallAfter ( aap.run, 'test_IDE' )
>    def readline ( self ) :
>    _str = self.m_queue.get()
>    import time
>    time.sleep(0.02)
>    self.ProcessIdle()
>    return _str
>
>  def flush ( self  ):
>    pass
>
> _______________________________________________
> wx-users mailing list
> wx-users@...
> http://lists.wxwidgets.org/mailman/listinfo/wx-users
>
>
_______________________________________________
wx-users mailing list
wx-users@...
http://lists.wxwidgets.org/mailman/listinfo/wx-users

Re: Memory error in StyledTextCtrl.GotoLine

by Stef Mientki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hello Cristina,
our mails just crossed, I found a solution (and will probably use your
suggestion to change user_...),
and now you can/should concentrate further upon your "oh-so-wonderful
documentation" ;-)
thanks for the help,
and I really love to see your final product.
cheers,
Stef



Cristina Yenyxe González García wrote:

> Sorry about the confusion with the streams, I had to change them in my
> effort to separate completely the user interface and didn't remember
> the arguments of the Pdb's constructor :)
>
> But I think we should start a new thread in the list to talk about
> this topic, don't you think so? :) If you can't find a solution I'll
> prepare my answer for tomorrow morning, because I had the same problem
> some time ago. A good point would be executing app.run in a new
> thread, so the wx interface and the debugger would be in different
> threads, and this way is a lot easier to avoid GUI blocking. You can
> also use the threading.Event objects from the Python's API to wait for
> the user response (I think wx has something to wait for GUI events,
> though).
>
> So may I suppose that wx always runs in the same thread than the rest
> of the application? In other graphic libraries like Swing I think they
> are internally separated by the virtual machine and that makes thing
> easier, but I have to admit that is not a wx issue.
> _______________________________________________
> wx-users mailing list
> wx-users@...
> http://lists.wxwidgets.org/mailman/listinfo/wx-users
>
>
>  
_______________________________________________
wx-users mailing list
wx-users@...
http://lists.wxwidgets.org/mailman/listinfo/wx-users

Re: Memory error in StyledTextCtrl.GotoLine

by Cristina Yenyxe González García :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Finally, I didn't manage to reproduce the error in a sample app, so I
searched on the Internet and I think I found out why this could have
happened, thanks to this post in the mailing list archive:
http://lists.wxwidgets.org/pipermail/wxpython-users/2000-January/000957.html

It seems the problem was that I was trying to refresh the component
from another thread instead of the GUI's, so I simply put the sentence
in another place of the code and it works pretty well!

Thank you anyway :)
_______________________________________________
wx-users mailing list
wx-users@...
http://lists.wxwidgets.org/mailman/listinfo/wx-users
LightInTheBox - Buy quality products at wholesale price!