Is this the correct way to use threads (was Babel Fish translation) ?

hello,

For translation of selected text in a texteditor (Scintilla),
I use Babel Fish.
As it takes a while, before Babel Fish responds,
a normal call to Babel Fish, will freeze the wxPython application.
With the help of other Python users,
I implemented a thread construction,
which indeed seems to work as expected.

Now my question are:
  Is this the correct way to use threads in wxPython ?
  Should I kill or destroy the thread ?

Here is the essential code:

If the user moves to a piece of text that must be translated,
the event handler will start a thread

        self.Thread = threading.Thread ( target = self.Read_Bablefish,
                                         args = ( [ text ] ) )
        self.Thread.start()

The thread starts this procedure:
  # *************************************************************
  def Read_Bablefish ( self, text ) :
    BABLEFISH_URL = ‘http://babelfish.altavista.com/tr
    url = BABLEFISH_URL + ‘?’ +\
          urlencode ( { ‘trtext’ : text,
                        ‘lp’ : ‘en_’ + self.Language_Current.lower () } )
    page = lxml.html.parse(url)
    Babel_Result = []
    for div in page.iter ( ‘div’ ) :
      style = div.get ( ‘style’ )
      if ( style != None ) and ( ‘padding:0.6em;’ in style ) :
        Babel_Result.append(
          lxml.html.tostring ( div, method = “text” ) )

    # if a result is found, it's placed directly into a textwindow
    if Babel_Result :
      self.Editor_Babel.SetLabel ( Babel_Result[0] )
    else :
      self.Editor_Babel.SetLabel ( 'Babel Fish translation Failed' )

thanks,
Stef Mientki

Hi Stef,

hello,

For translation of selected text in a texteditor (Scintilla),

[…]

Now my question are:

Is this the correct way to use threads in wxPython ?

Should I kill or destroy the thread ?

No, you don’t have to do that.

Here is the essential code:

If the user moves to a piece of text that must be translated,

the event handler will start a thread

[…]

if a result is found, it’s placed directly into a textwindow

if Babel_Result :

 self.Editor_Babel.SetLabel ( Babel_Result[0] )

else :

 self.Editor_Babel.SetLabel ( 'Babel Fish translation Failed' )

Perhaps Scintilla is thread-safe, but the rule is that you should not make any wx-calls from a thread. The only things which are safe to call from a thread are:

  • wx.CallLater,
  • wx.CallAfter,
  • wx.Thread_IsMain.

This is how you use wx.CallLater:

wx.CallLater(self.Editor_Babel.SetLabel, Babel_Result[0] )

As you can see, it’s a small change to make :slight_smile:

Regards,

–Tim

···

On Fri, Jul 18, 2008 at 1:34 PM, Stef Mientki s.mientki@ru.nl wrote:

Stef Mientki wrote:

thanks Tim,

[..]

Perhaps Scintilla is thread-safe, but the rule is that you should not make any wx-calls from a thread. The only things which are safe to call from a thread are:

    * wx.CallLater,
    * wx.CallAfter,
    * wx.Thread_IsMain.

This is how you use wx.CallLater:

wx.CallLater(self.Editor_Babel.SetLabel, Babel_Result[0] )

As you can see, it's a small change to make :slight_smile:

Yes, it's a small change indeed,
but it has enormous consequences :wink:

<Tons of errors snipped>

cheers,
Stef

Perhaps Tim meant 'CallAfter' instead of 'CallLater'. I have used that from a thread before.

--John

Steve,

Steve Freedenburg wrote:

First off, I tried the Py2Exe mailing list, but have only seen 1 new e-mail since I left mine. So I
am guessing that mailing list isn't very active.

It is active, maybe just a bit slower then this list:) :wink: .

Ok the EXE, does "work" in the sense that the GUI loads, all the widgets load, and look correct.
Everything "works" except it seems that part of the program is getting skipped over. I've linked
the code that is getting skipped over. There are no traceback errors being reported at all in the
log file the EXE generates. I even fouled up the code to see if it would even generate a log of
errors and recompiled it. It does in fact report errors.

The script itself works, I've tested it for hours. You may remember me asking about, wx.Timers,
which is better, slice or split, and pretty much everything I've posted about is what is getting skipped.
Maybe skipped isn't what is happening, but that is what it looks like.

Maybe your .exe problem has to do with something not being in the same place then what you expect it to be? I.e. is it really finding your log file, or is it not finding the correct position in the log file or ........

As no exception is thrown and the program is not crashing I would guess that it is something in your code which prevents it to work correctly in py2exe'd form.

Maybe post your complete code on a site of yours, then someone might look at it and be able to help you.

Werner

I don't have a web site to hold the program, but here is what I did do.

I stripped the splash screen, all the bmp files, icons, and everything else that is "fluff."
So the file is just a python with no dependancies other than needing Python and wxPython
and whatever other modules and libraries are shipped with Python and wxPython.

The version information for Python, IDLE, and wxPython that I used to make it are:
Python 2.5.1
IDLE 1.2.1
wxPython 2.8.7.1

I will attach the py file, the configuration file that TopiView makes when the user
sets it up, so you can see that too, the "help" file which is as close to a __doc__
as could be, and a short wav file that will play when TopiView matches a
search string. Small files really, maybe 85kb.

IF those three files don't exist and you run the program as is, you'll have to make
one by setting TopiView up. (That's the name of my program if you hadn't figured
it out.) The help file won't cause the program to fail, and the sound won't either,
but it is as convenient as I could make it without removing a large amount of code.

Try it on any log file or make your own. You'll see it works. The program will read
the last saved line in a log file, and if that line contains the search string you set up in
the config it will output to the miniframe you set up.

So I don't buy that it's my program that has an error in it and that's why the EXE
doesn't work, the python file does., so why wouldn't the exe?

<salute>

Steve

TVConfig.SAV (1.37 KB)

soundfile.wav (1.52 KB)

TopiViewNoBMP.py (65.5 KB)

TV.hlp (12.5 KB)

Stef Mientki wrote:

now I already found out, I have to specify a time,
but that doesn't make it better :frowning:

     wx.CallLater ( 100, self.Editor_Babel.SetLabel, Babel_Result[0] )

Try wx.CallAfter instead.

···

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

1. Create a thread.
2. Have the thread call babelfish
3. Have the thread then call wx.CallAfter(...)

It's not magic.

- Josiah

···

On Fri, Jul 18, 2008 at 2:31 PM, Stef Mientki <s.mientki@ru.nl> wrote:

Robin Dunn wrote:

Stef Mientki wrote:

now I already found out, I have to specify a time,
but that doesn't make it better :frowning:

    wx.CallLater ( 100, self.Editor_Babel.SetLabel, Babel_Result[0] )

Try wx.CallAfter instead.

thanks Robin, but no luck,

CallAfter, waits also until the Babel Fish Translation is received :frowning:

cheers,
Stef
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Don't forget the second wx.CallAfter to set the label on failure.

And it's not really magic.

- Josiah

···

On Fri, Jul 18, 2008 at 4:39 PM, Stef Mientki <s.mientki@ru.nl> wrote:

Josiah Carlson wrote:

1. Create a thread.

                 # from the event routine
      self.Thread = threading.Thread ( target = self.Read_Bablefish,
                                       args = ( [ text ] ) )
      self.Thread.start()

2. Have the thread call babelfish

# *************************************************************
# *************************************************************
def Read_Bablefish ( self, text ) :
  BABLEFISH_URL = 'Yahooist Teil der Yahoo Markenfamilie
  url = BABLEFISH_URL + '?' +\
        urlencode ( { 'trtext' : text,
                      'lp' : 'en_' + self.Language_Current.lower () } )
  page = lxml.html.parse(url)
  Babel_Result =
  for div in page.iter ( 'div' ) :
    style = div.get ( 'style' )
    #if ( style != None ) and ( 'padding:10px;' in style ) :
    if ( style != None ) and ( 'padding:0.6em;' in style ) :
      Babel_Result.append(
        lxml.html.tostring ( div, method = "text" ) ) #, with_tail=False))

3. Have the thread then call wx.CallAfter(...)

  # last part of "Reaf_Bablefish"
  if Babel_Result :
    #self.Editor_Babel.SetLabel ( Babel_Result[0] )
    wx.CallAfter ( self.Editor_Babel.SetLabel, Babel_Result[0] )
    #wx.CallLater ( 100, self.Editor_Babel.SetLabel, Babel_Result[0] )
  else :
    self.Editor_Babel.SetLabel ( 'Babel Fish translation Failed' )
    #wx.CallLater ( 100, self.Editor_Babel.SetLabel, 'Babel Fish translation
Failed' )

like above you mean ?

It's not magic.

It's certainly magic to me !

cheers,
Stef

- Josiah

On Fri, Jul 18, 2008 at 2:31 PM, Stef Mientki <s.mientki@ru.nl> wrote:

Robin Dunn wrote:

Stef Mientki wrote:

now I already found out, I have to specify a time,
but that doesn't make it better :frowning:

   wx.CallLater ( 100, self.Editor_Babel.SetLabel, Babel_Result[0] )

Try wx.CallAfter instead.

thanks Robin, but no luck,

CallAfter, waits also until the Babel Fish Translation is received :frowning:

cheers,
Stef
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

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

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

This: http://entrian.com/goto/ is as close to magic as you will see in Python :wink:

Well, there was the shell script stuff that I once saw...

output = cStringIO.StringIO()
shellrun | 'ls -la' | 'grep py' > output

But we shall never speak of these things again :wink:

- Josiah

···

On Fri, Jul 18, 2008 at 5:25 PM, Josiah Carlson <josiah.carlson@gmail.com> wrote:

Don't forget the second wx.CallAfter to set the label on failure.

And it's not really magic.

- Josiah

On Fri, Jul 18, 2008 at 4:39 PM, Stef Mientki <s.mientki@ru.nl> wrote:

Josiah Carlson wrote:

1. Create a thread.

                 # from the event routine
      self.Thread = threading.Thread ( target = self.Read_Bablefish,
                                       args = ( [ text ] ) )
      self.Thread.start()

2. Have the thread call babelfish

# *************************************************************
# *************************************************************
def Read_Bablefish ( self, text ) :
  BABLEFISH_URL = 'Yahooist Teil der Yahoo Markenfamilie
  url = BABLEFISH_URL + '?' +\
        urlencode ( { 'trtext' : text,
                      'lp' : 'en_' + self.Language_Current.lower () } )
  page = lxml.html.parse(url)
  Babel_Result =
  for div in page.iter ( 'div' ) :
    style = div.get ( 'style' )
    #if ( style != None ) and ( 'padding:10px;' in style ) :
    if ( style != None ) and ( 'padding:0.6em;' in style ) :
      Babel_Result.append(
        lxml.html.tostring ( div, method = "text" ) ) #, with_tail=False))

3. Have the thread then call wx.CallAfter(...)

  # last part of "Reaf_Bablefish"
  if Babel_Result :
    #self.Editor_Babel.SetLabel ( Babel_Result[0] )
    wx.CallAfter ( self.Editor_Babel.SetLabel, Babel_Result[0] )
    #wx.CallLater ( 100, self.Editor_Babel.SetLabel, Babel_Result[0] )
  else :
    self.Editor_Babel.SetLabel ( 'Babel Fish translation Failed' )
    #wx.CallLater ( 100, self.Editor_Babel.SetLabel, 'Babel Fish translation
Failed' )

like above you mean ?

It's not magic.

It's certainly magic to me !

cheers,
Stef

- Josiah

On Fri, Jul 18, 2008 at 2:31 PM, Stef Mientki <s.mientki@ru.nl> wrote:

Robin Dunn wrote:

Stef Mientki wrote:

now I already found out, I have to specify a time,
but that doesn't make it better :frowning:

   wx.CallLater ( 100, self.Editor_Babel.SetLabel, Babel_Result[0] )

Try wx.CallAfter instead.

thanks Robin, but no luck,

CallAfter, waits also until the Babel Fish Translation is received :frowning:

cheers,
Stef
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

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

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

Maybe I edited down the wrong file or accidently took out too much code... I'll look at your observations with the intact file... Like I said, everything works for me, and I'm sure my version of Python isn't magically forgiving.
I appreciate your observations.

···

----- Original Message ----- From: "claxo" <clazzt@arnet.com.ar>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Friday, 18 July, 2008 19:18
Subject: Re: [wxpython-users] Why does py work, but EXE not?

On Fri, 18 Jul 2008 12:37:34 -0400 Steve Freedenburg <stevefreedenburg@charter.net> wrote:

Ok the EXE, does "work" in the sense that the GUI loads, all the widgets
load, and look correct.
Everything "works" except it seems that part of the program is getting
skipped over. I've linked
the code that is getting skipped over. There are no traceback errors being
reported at all in the
log file the EXE generates. I even fouled up the code to see if it would
even generate a log of
errors and recompiled it. It does in fact report errors.

The script itself works, I've tested it for hours. You may remember me
asking about, wx.Timers,[...]

Well, the .py doenst work for me.
I have spoted some errors, and posted the code at
http://python.pastebin.com/m6b89fc2d

Modifications are marked with comments #@ , to make it easy to find.

1. The first problem I found was that configurations would not be remembered, a lot of globals fixed that

2. Stored configurattion would not load, you get
AttributeError: 'MenuItem' object has no attribute 'SetItemLabel'
My wxPython is version '2.8.4.2 (msw-unicode)

3. Missing global in method FLCplus1

4. You miss to Start() the timer

5. Missing global at class ContainerOneFrame method ContainerOneFrameReceive() ( and you copy & pasted this code to oteher containers without changing the '1')

I stopped there. Probably the best would be to follow another poster sugestion about eliminating the code repetitions, and later get rid of all globals.

hope it helps

--
claxo

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

claxo,

ok I looked at the code in detail, and maybe my code is hard to read, but what global did the class ContainerOneFrame, method ContainerOneFrameRecieve need? it's not changing any of the variables so
it doesn't need a global reference in the method. It's just looking at it. Am I wrong here? like I said, I
haven't been doing this long.

The start timer does exist, and when i run configuration using the py file i attched in a seperate folder with nothign else in it and it works just fine, saves, loads, and everything. You wouldn't be pulling my leg just for kicks would you? That wouldn't be very nice.

Anyhow, appreciate the attempt to help, but i'm not seeing what you're seein.

Steve

Ok I looked at the code, and

···

----- Original Message ----- From: "claxo" <clazzt@arnet.com.ar>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Friday, 18 July, 2008 19:18
Subject: Re: [wxpython-users] Why does py work, but EXE not?

On Fri, 18 Jul 2008 12:37:34 -0400 Steve Freedenburg <stevefreedenburg@charter.net> wrote:

Ok the EXE, does "work" in the sense that the GUI loads, all the widgets
load, and look correct.
Everything "works" except it seems that part of the program is getting
skipped over. I've linked
the code that is getting skipped over. There are no traceback errors being
reported at all in the
log file the EXE generates. I even fouled up the code to see if it would
even generate a log of
errors and recompiled it. It does in fact report errors.

The script itself works, I've tested it for hours. You may remember me
asking about, wx.Timers,[...]

Well, the .py doenst work for me.
I have spoted some errors, and posted the code at
http://python.pastebin.com/m6b89fc2d

Modifications are marked with comments #@ , to make it easy to find.

1. The first problem I found was that configurations would not be remembered, a lot of globals fixed that

2. Stored configurattion would not load, you get
AttributeError: 'MenuItem' object has no attribute 'SetItemLabel'
My wxPython is version '2.8.4.2 (msw-unicode)

3. Missing global in method FLCplus1

4. You miss to Start() the timer

5. Missing global at class ContainerOneFrame method ContainerOneFrameReceive() ( and you copy & pasted this code to oteher containers without changing the '1')

I stopped there. Probably the best would be to follow another poster sugestion about eliminating the code repetitions, and later get rid of all globals.

hope it helps

--
claxo

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

On a performance-realated note, as your log files grow, you probably
aren't going to be wanting to read the entire file at one time (hence
my use of os.stat a week ago).

- Josiah

···

On Fri, Jul 18, 2008 at 6:03 PM, Steve Freedenburg <stevefreedenburg@charter.net> wrote:

Maybe I edited down the wrong file or accidently took out too much code...
I'll look at your observations with the intact file... Like I said,
everything works for me, and I'm sure my version of Python isn't magically
forgiving.
I appreciate your observations.

----- Original Message ----- From: "claxo" <clazzt@arnet.com.ar>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Friday, 18 July, 2008 19:18
Subject: Re: [wxpython-users] Why does py work, but EXE not?

On Fri, 18 Jul 2008 12:37:34 -0400 Steve Freedenburg > <stevefreedenburg@charter.net> wrote:

Ok the EXE, does "work" in the sense that the GUI loads, all the widgets
load, and look correct.
Everything "works" except it seems that part of the program is getting
skipped over. I've linked
the code that is getting skipped over. There are no traceback errors
being
reported at all in the
log file the EXE generates. I even fouled up the code to see if it would
even generate a log of
errors and recompiled it. It does in fact report errors.

The script itself works, I've tested it for hours. You may remember me
asking about, wx.Timers,[...]

Well, the .py doenst work for me.
I have spoted some errors, and posted the code at
http://python.pastebin.com/m6b89fc2d

Modifications are marked with comments #@ , to make it easy to find.

1. The first problem I found was that configurations would not be
remembered, a lot of globals fixed that

2. Stored configurattion would not load, you get
AttributeError: 'MenuItem' object has no attribute 'SetItemLabel'
My wxPython is version '2.8.4.2 (msw-unicode)

3. Missing global in method FLCplus1

4. You miss to Start() the timer

5. Missing global at class ContainerOneFrame method
ContainerOneFrameReceive() ( and you copy & pasted this code to oteher
containers without changing the '1')

I stopped there. Probably the best would be to follow another poster
sugestion about eliminating the code repetitions, and later get rid of all
globals.

hope it helps

--
claxo

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

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

Stef Mientki wrote:

like above you mean ?

It's not magic.
  

It's certainly magic to me !

It's only about a dozen lines of code. See wxTrac has been migrated to GitHub Issues - wxWidgets

···

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

I don't really know if I'm saving the config to a py file. What i'm doing is taking all the
diferent user settings (fonts, colors, sounds, directories etc) using GetValue from it's
respective dialog or text control widget or file browse widget and pickling them in a file
I call TVConfig.SAV So if that is a py file, then yes... I'm using a py file to save config
data.

I set up TopiView to look for TVConfig.SAV ... if it's there unpickle all the data, and
place that data in it's respective variable which is global so other methods and classes
can use them... (Sidenote: I read the tips and tricks that may increase Python performance
and it sure sounds like globals are the dark side of the force with regard to defining
variables. But like I said before, it's what I know how to do even though you guys have
been telling me in no uncertain terms to get rid of them... I think I will get rid of them!!!)
If the file isn't there, the user configures TopiView to his/her liking and clicks "Save" in the
frame I set up for config, and POW new TVConfig.SAV...

And yes I would like to distribute a fully functional EXE to who ever may find benefit from
the program. Particularly the people I play EQ with, some people have multiple monitors,
and play multiple accounts at the same time, and would like to have what's going on in the
game on another monitor, while not having the game in the foreground sucking up resources.
I started writting it for EverQuest (a slightly dated, but still popular MMORPG) but I tried
to make it versatile enough for anyone to use for any reason they may find.

No delusions about making money on this gig. I just want to be able say "I published
functioning software that has value to atleast two people (myself, and atleast one other
person in the world...)

Custom frame labels, search strings, colors fore and back, fontground, optional playing of
wave file if search string is found in text. The option to slive a line entries up to point X
(assuming the user wants to get rid of the time/date stamp, and it's at the beginning of the
leg entry.) I tried to think of it all, and do what I knew I could do.

So, at the end of the day, I have a program that works as a Py, and everything BUT what
I want TopiView to do works when it's an EXE.

···

----- Original Message ----- From: "Josiah Carlson" <josiah.carlson@gmail.com>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Friday, 18 July, 2008 22:58
Subject: Re: [wxpython-users] Why does py work, but EXE not?

range and xrange are builtins.

Based on your previous posts, it seems as though you are writing
configuration to a .py file. You then import that .py file and use
those values, correct? py2exe looks at all of the files you import,
and will discover those files that you import (including the ones you
currently use for configuration), and include them. So when you are
saving configuration, it won't actually be able to re-include them,
because the configuration is already included with py2exe.

If you are sneaky, you can use the __import__() function to do a lot
of that for you, and your configuration might not be included.
Alternatively, I think there's a setting with py2exe which will allow
you to include files as "data", and you can specify your config file
as data rather than code to be included with the binary.

Out of curiosity, why are you using py2exe? Aside from a minor
speedup (related to only needing to search the zipfile rather than the
filesystem), what do you hope to gain? Are you going to be giving it
to your friends?

- Josiah

On Fri, Jul 18, 2008 at 7:15 PM, Steve Freedenburg > <stevefreedenburg@charter.net> wrote:

That's an important thing to consider... The log file can get quite large,
other log parsers i've tried then to get
sluggish as the log grows, and they recommend trimming it from time to time.
The code you gave me, which
I printed out, and used parts of the (xrange part) was a cryptic to me, I
wasn't 100% sure how to use it all.

Once I figure out what that for loop is getting skipped in the EXE I'll go
back and re evaluate the entire Py.
It is a rather large program, atleast in my experience, heck anything larger
than 100 lines is huge to me.

does xrange or range rely on any imports that may be impied in Python, but
require an import in Py2Exe?

btw, I really appreciate your help Josiah with this whole thing.

Steve
----- Original Message ----- From: "Josiah Carlson"
<josiah.carlson@gmail.com>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Friday, 18 July, 2008 21:45
Subject: Re: [wxpython-users] Why does py work, but EXE not?

On a performance-realated note, as your log files grow, you probably
aren't going to be wanting to read the entire file at one time (hence
my use of os.stat a week ago).

- Josiah

On Fri, Jul 18, 2008 at 6:03 PM, Steve Freedenburg >>> <stevefreedenburg@charter.net> wrote:

Maybe I edited down the wrong file or accidently took out too much
code...
I'll look at your observations with the intact file... Like I said,
everything works for me, and I'm sure my version of Python isn't
magically
forgiving.
I appreciate your observations.

----- Original Message ----- From: "claxo" <clazzt@arnet.com.ar>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Friday, 18 July, 2008 19:18
Subject: Re: [wxpython-users] Why does py work, but EXE not?

On Fri, 18 Jul 2008 12:37:34 -0400 Steve Freedenburg >>>> <stevefreedenburg@charter.net> wrote:

Ok the EXE, does "work" in the sense that the GUI loads, all the widgets
load, and look correct.
Everything "works" except it seems that part of the program is getting
skipped over. I've linked
the code that is getting skipped over. There are no traceback errors
being
reported at all in the
log file the EXE generates. I even fouled up the code to see if it
would
even generate a log of
errors and recompiled it. It does in fact report errors.

The script itself works, I've tested it for hours. You may remember me
asking about, wx.Timers,[...]

Well, the .py doenst work for me.
I have spoted some errors, and posted the code at
http://python.pastebin.com/m6b89fc2d

Modifications are marked with comments #@ , to make it easy to find.

1. The first problem I found was that configurations would not be
remembered, a lot of globals fixed that

2. Stored configurattion would not load, you get
AttributeError: 'MenuItem' object has no attribute 'SetItemLabel'
My wxPython is version '2.8.4.2 (msw-unicode)

3. Missing global in method FLCplus1

4. You miss to Start() the timer

5. Missing global at class ContainerOneFrame method
ContainerOneFrameReceive() ( and you copy & pasted this code to oteher
containers without changing the '1')

I stopped there. Probably the best would be to follow another poster
sugestion about eliminating the code repetitions, and later get rid of
all
globals.

hope it helps

--
claxo

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

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

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

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

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

Ok Tim,

    I think I'm getting it. What you have there is a list, and in that list are x amount of dictionairies.
x = the number of chat containers I have, in my case it's 6... could be 10, or 50....

    and the way you have the dictionairies set up, would help in creating the instance in a given
frame. One class or method that creates 6 frames.... instead of 6 classes that create a frame each, and the
construction of the frames is pretty much identical.

    And how this gets rid of global variables is by creating those lists with the self.List in a given method
in a given class, this list can be accessed from anywhere in the class. As far as how to access a list from another
class I'm not 100% on, however if the class is called MyClass, then I can access that class from another class
by defining it as self.MyClass = MyClass(class specific attribs here if any) so something like this:

Class X()
    self.ClassY = ClassY()

ClassY()
    self.searchstringtuple = ['x', 'y', 'z']

with something like that, anything defined as self in ClassY is also available in ClassX because ClassY is defined as self there too?

Wow... I hope I'm not wrong because THAT there is what is holding me back in Python. My "understanding"
of inheritance (right? inheritance) is slanted. Not so much I couldn't get around in

···

----- Original Message ----- From: "Tim Roberts" <timr@probo.com>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Friday, 18 July, 2008 14:16
Subject: Re: [wxpython-users] Py works, EXE doesn't here is stripped program, someone else verify please.

Steve Freedenburg wrote:

I will attach the py file, the configuration file that TopiView makes when the user
sets it up, so you can see that too, the "help" file which is as close to a __doc__
as could be, and a short wav file that will play when TopiView matches a
search string. Small files really, maybe 85kb.

But, can't you see how wasteful this code is? If you want to add a 7th string, you have to make modifications ALL over the file. Wouldn't it be obviously better to make this all a data structure:

SearchStuff = [
   {
       'font': '0;-13;0;0;0;400;0;0;0;0;3;2;1;34;Arial',
       'color': wx.BLACK,
       'label': 'Your Label Here',
       'search': 'Search String',
       'soundpath': 'Not specified',
       'soundfile': Not specified
   },
   {
       'font': '0;-13;0;0;0;400;0;0;0;0;3;2;1;34;Arial',
       'color': wx.BLACK,
       'label': 'Your Label Here',
       'search': 'Search String',
       'soundpath': 'Not specified',
       'soundfile': Not specified
   },
   ...
]

Now, instead of doing everything 6 times, you can do things once, in a loop:
   for stuff in SearchStuff:
       stuff['container'] = wx.MenuItem( Containers, -1, stuff['name'], 'View or hide', wx.ITEM_CHECK );
       Containers.AppendItem( stuff['container'] )

and so on.

If it were me, I would actually create a new class to hold all of this information, and create six instances of the class. That would make it even cleaner.

ANY time you find yourself writing the same code more than once, you need to think about how a data structure could help that.

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

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

I don't know what to tell you. I've been using that three-step method
(doing stuff other than calling babelfish) for the last 5 years in
wxPython and have never had a problem. I've had socket servers
running in that secondary thread, I currently have a parser (for
Python), and an event queue running in a secondary thread right now.
That it doesn't work for you makes me wonder what platform you are
using, and if 'import threading' actually imports the dummy_threading
module under the covers.

- Josiah

···

On Sat, Jul 19, 2008 at 2:21 AM, Stef Mientki <s.mientki@ru.nl> wrote:

Josiah Carlson wrote:

Don't forget the second wx.CallAfter to set the label on failure.

Well that's because the CallAfter doesn't work at all,
it blocks the GUI while babelfish is active ;-(
So it's not magic only for me :wink:

cheers,
Stef

Steve,

Steve Freedenburg wrote:

Werner,

...
So to solve your "config" problem, just delete the TVConfig.SAV file, and run TopiView. I should
have not sent it to begin with, I didn't think about any confusion that it woudl cause. The config file
is just a pickle of all the global variables used in TopiView to set user options.

I think you should still check that the path is valid, and if it is not valid then asked the user to point the program to a valid folder.

- I put the new version into a folder and run it.
- Created a configuration, it asks for a file name, which I can enter but it is being ignored. I.e. the file is always called TVConfig.SAV, no problem with that but why ask for a file name in the first place. Do you want to ask for a folder name?
- Save configuration and close the program
- Restart the program and I get this exception:
Traceback (most recent call last):
  File "TopiView_nobmp.py", line 1309, in <module>
    app = TopiViewApp(0)
  File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7912, in __init__
    self._BootstrapApp()
  File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7487, in _BootstrapApp
    return _core_.PyApp__BootstrapApp(*args, **kwargs)
  File "TopiView_nobmp.py", line 1305, in OnInit
    TVMainFrame = TopiViewMainFrame(None, wx.ID_ANY, 'TopiView v1.0') File "TopiView_nobmp.py", line 169, in __init__
    self.LoadConfigurationData()
  File "TopiView_nobmp.py", line 593, in LoadConfigurationData
    C1SoundData = open(C1SoundPathFile, 'rb').read()
IOError: [Errno 2] No such file or directory: 'Not Specified\\Not Specified'

- Delete the .sav file and started again, after adding my file encoding and forcing it to run with the wxPython ANSI version instead of my default Unicode
- Create the configuration again
- Close and reopen, same exception as above
- The first entry in the SAV file is: S'C:\\Dev\\BoaTest04\\SteveFreedenburg\\'
- So I guessed it might have to be like this: S'C:\\Dev\\BoaTest04\\SteveFreedenburg\\TVConfig.SAV', but still same problem.

I will not try to build an exe until I can run the program within my IDE (Boa and not Idle).

Werner

Where is the program asking you for a filename? Try this out:
- Delete the TVConfig.SAV.
- Start TopiView.
- You should get a warning saying the TVConfig.SAV doesn't exist
- Go the the configuration frame (The TopiView menu, Configure Containers
    menu item.)
- Configure TopiView as you want, the top filebrowse textctrl and browse
    button is for the log file you want to sort.
- The textctrl to the right of it, is the chars you want to slice from each log
    entry.
- Each Container can have a custom foreground / background color, a label
    of your choosing, a search string of your choosing, font of your choosing
    and a sound file of your choosing.
- If anything is going to foul up, it will probably be the sound files, I'm not
    sure if I got the try: / except: right on those. so any wave file will do.

After that click the "Save" button whichs does a slew of "GetValue()" from
the various widgets and assigns them to a variable, and then pickles them
in a file it creates. The "TVConfig.SAV" file.

After that, click "Close" and that frame should go away. After that.
click the TopiView menu, Load Configuration. This will then open the
TVConfig.SAV file and unpickle all the settings as the correct variables for
the various things in TopiView.

I think that should work if it's not what you're already doing.

···

----- Original Message ----- From: "Werner F. Bruhin" <werner.bruhin@free.fr>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Sunday, 20 July, 2008 10:34
Subject: Re: [wxpython-users] Py works, EXE doesn't here is stripped program, someone else verify please.

Steve,

Steve Freedenburg wrote:

Werner,

...
So to solve your "config" problem, just delete the TVConfig.SAV file, and run TopiView. I should
have not sent it to begin with, I didn't think about any confusion that it woudl cause. The config file
is just a pickle of all the global variables used in TopiView to set user options.

I think you should still check that the path is valid, and if it is not valid then asked the user to point the program to a valid folder.

- I put the new version into a folder and run it.
- Created a configuration, it asks for a file name, which I can enter but it is being ignored. I.e. the file is always called TVConfig.SAV, no problem with that but why ask for a file name in the first place. Do you want to ask for a folder name?
- Save configuration and close the program
- Restart the program and I get this exception:
Traceback (most recent call last):
File "TopiView_nobmp.py", line 1309, in <module>
   app = TopiViewApp(0)
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7912, in __init__
   self._BootstrapApp()
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7487, in _BootstrapApp
   return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "TopiView_nobmp.py", line 1305, in OnInit
   TVMainFrame = TopiViewMainFrame(None, wx.ID_ANY, 'TopiView v1.0') File "TopiView_nobmp.py", line 169, in __init__
   self.LoadConfigurationData()
File "TopiView_nobmp.py", line 593, in LoadConfigurationData
   C1SoundData = open(C1SoundPathFile, 'rb').read()
IOError: [Errno 2] No such file or directory: 'Not Specified\\Not Specified'

- Delete the .sav file and started again, after adding my file encoding and forcing it to run with the wxPython ANSI version instead of my default Unicode
- Create the configuration again
- Close and reopen, same exception as above
- The first entry in the SAV file is: S'C:\\Dev\\BoaTest04\\SteveFreedenburg\\'
- So I guessed it might have to be like this: S'C:\\Dev\\BoaTest04\\SteveFreedenburg\\TVConfig.SAV', but still same problem.

I will not try to build an exe until I can run the program within my IDE (Boa and not Idle).

Werner

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