All code after "if wxTextEntryDialog.ShowModal() == wx.ID_OK:" line will not run

Hey Guys, I’m hoping someone could shed some light on my little problem here :smiley:

I’ve been trying to create a wxTextEntryDialog() within this script here and for some reason I am not getting any return from the ShowModal() call. Although the dialog pops up just fine and when I press the Ok or Cancel button(s) it closes the dialog just fine, it seems that the dialog still does not exit properly as whenever the ShowModal() call is made, all code written afterwards will not run. Even code after the “if passdlg.ShowModal() == wx.ID_OK:” (and trailing else: line) will not run, which includes the “print temp” line, which is after the if/else statement so it should be run after the Ok or Cancel button have been pressed.

What is driving me nuts the most is that the same code for the TextEntryDialog() is used in another window for this application and it works just fine but within this script it just locks up like ShowModal() wont exit properly.

I have also tried to create my own custom dialog with wxDialog, using different ids for the Ok & Cancel buttons, incase there was an id confliction, but that didn’t seem to help at all either.

As well, no errors are generated from this code which leaves me little to go on and I am completely out of ideas.

Any suggestions would be appreciated as I am completely stuck atm and I REALLY need to get the dialog working properly!

import wx, os, sys, thread, random

from Resources import Variables as variables
from Resources.Modules import win32tests as kroll
from Resources.Controls import Services as svc
from Resources.Controls import Notebook1 as nb
from Resources.Controls import TaskBarIcon as tbi
from Resources.Controls import Dialog as dlg
from Resources.Controls import servicewindow as advsvc

ImageDir = variables.ImageDir

ids = [‘FILEEXIT’, ‘TOOLSDISFWALL’, ‘TOOLSBACKUP’, ‘TOOLSRESTORE’, ‘HELPABOUT’]
for a in ids: exec “ID_%s = wx.NewId()” % (a)

class Main(wx.Frame):

def __init__(self, parent):
    wx.Frame.__init__(self, parent, -1, "KHW Toolbox", wx.Point(171, 114), wx.Size(800, 600),
                      wx.DEFAULT_FRAME_STYLE | wx.FULL_REPAINT_ON_RESIZE)
    self.TrayIcon = tbi.TaskBarIcon(self, wx.Icon(ImageDir + '\\icon16.png', wx.BITMAP_TYPE_PNG), "KHW Toolbox")
    self.Split    = wx.SplitterWindow(self, -1, style=wx.SP_LIVE_UPDATE | wx.SP_3D)
    self.Split1   = wx.SplitterWindow(self.Split, -1, style=wx.SP_LIVE_UPDATE | wx.SP_3D)
    self.Panel1   = svc.Services(self.Split, -1)
    self.TextCtrl = wx.TextCtrl(self.Split1, -1, style=wx.RAISED_BORDER | wx.HSCROLL | wx.TE_MULTILINE | wx.TE_DONTWRAP | wx.TE_READONLY)
    self.Notebook = nb.Notebook(self.Split1, -1)

    self.Split.SetMinimumPaneSize(20)
    self.Split1.SetMinimumPaneSize(20)

    self.Split.SplitVertically(self.Panel1, self.Split1, 220)
    self.Split1.SplitHorizontally(self.TextCtrl, self.Notebook, -100)
    self.Split1.SetSashSize(4)

    self.TextCtrl.SetBackgroundColour("black")
    self.TextCtrl.SetForegroundColour("white")
    self.TextCtrl.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, False, 'Currier'))
    self.TextCtrl.ChangeValue(kroll.Win().WindowsInfo())

    self.SetIcon(wx.Icon(ImageDir + '\\icon32.png', wx.BITMAP_TYPE_PNG))
    self.Bind(wx.EVT_MENU, self.OnMenuSelected)

    self.DoMenuBar()
    self.DoStatusBar()

def OnMenuSelected(self, event):
    if event.GetId() == ID_TOOLSDISFWALL:
        # ID matches fine and runs the below code
        passdlg = wx.TextEntryDialog(self, 'Enter Password:', 'Administrative Login', '')

        # Dialog is called and pops up fine
        if passdlg.ShowModal() == wx.ID_OK:
            # "print 'working!'" line does not print when Ok is pressed and "temp" is not set

            print 'working!'
            temp = passdlg.GetValue()
        else:
            # "print 'BAHHHH!' line does not print when Cancel is pressed
            print 'BAHHHH!'

        passdlg.Destroy()
        # "print temp" does not print after Ok or Cancel print, no errors are generated
        print temp

def DoStatusBar(self):
    self.StatusBar = wx.StatusBar(self, -1)

    self.SetStatusBar(self.StatusBar)

def DoMenuBar(self):
    self.File    = wx.Menu(title='')
    self.Tools   = wx.Menu(title='')
    self.View    = wx.Menu(title='')

    self.Help    = wx.Menu(title='')
    self.MenuBar = wx.MenuBar()

    self.File.Append(ID_FILEEXIT, 'E&xit', 'Exit KrollHW Toolbox', kind=wx.ITEM_NORMAL)
    self.Tools.Append(ID_TOOLSDISFWALL, '&Disable All Firewalls', 'Attempts to disable "Windows Firewall" service on selected computers found within the network', kind=wx.ITEM_NORMAL)

    self.Tools.Append(ID_TOOLSBACKUP, '&Backup Database', '', kind=wx.ITEM_NORMAL)
    self.Tools.Append(ID_TOOLSRESTORE, '&Restore Database', '', kind=wx.ITEM_NORMAL)

    self.Help.Append(ID_HELPABOUT, 'A&bout', 'Displays help information', kind=wx.ITEM_NORMAL)
    self.MenuBar.Append(menu=self.File,  title='&File')
    self.MenuBar.Append(menu=self.Tools, title='&Tools')

    self.MenuBar.Append(menu=self.Help,  title='&Help')
    self.SetMenuBar(self.MenuBar)

if name == ‘main’:
app = wx.PySimpleApp()
frame = Main(None)
frame.Show()

app.MainLoop()

Two things:

  1. Here’s how I usually handle a modal dialog:

             dlg = wx.MessageDialog(self, "The email file you specified doesn't exist (yet).  Should I create it?",
                         "Create a new file?", wx.YES_NO | wx.ICON_QUESTION)
    
             response = dlg.ShowModal()
             dlg.Destroy()
             if (response == wx.ID_NO): return
    

In other words, assign the dialog’s return value to a variable, destroy the dialog, THEN check what the return was. It may not be absolutely necessary - I’m a belt-and-suspenders kind of guy myself - but it definitely works.

  1. When you ask a question, pare your code down to the very minimum, and make sure it doesn’t have any dependencies. The code you posted won’t run without “Resources”; comment that out and it wants something called “tbi”… Not only do you save us a bunch of work trying to get your code to run on our machines, but 90% of the time the solution pops out at you while you’re editing.
···

On Sun, Dec 14, 2008 at 8:24 AM, A Wain awainb@gmail.com wrote:

Hey Guys, I’m hoping someone could shed some light on my little problem here :smiley:

I’ve been trying to create a wxTextEntryDialog() within this script here and for some reason I am not getting any return from the ShowModal() call.


www.fsrtechnologies.com

I will limit the code next time, didnt realize I copied most of it in :P. As well, I have tried your suggestion, assigning it to a variable, destroying the window, etc. it still has the exact same effect. I’ll give the example I tested with using your suggestion:

···

print ‘Setup TextEntryDialog’
passdlg = wx.TextEntryDialog(self, ‘message’, ‘caption’, ‘blah’)
print ‘Show TextEntryDialog with ShowModal(), Assigning it a variable name: result’
result = passdlg.ShowModal()
print ‘Destroying Dialog’
passdlg.Destroy()
print result, wx.ID_OK
if result == wx.ID_OK:
print ‘YEAH!!!’
else:
print ‘BAHHHH!!!’

(I added the print lines to see where the script it hanging, there is no difference whether they are present or not)

The result when it is run within my script is:

Setup TextEntryDialog
Show TextEntryDialog with ShowModal(), Assigning it a variable name: result

the rest of the code doesn’t seem to run after ShowModal() is opened, it exits back into the rest of the application without a hitch but it doesnt process any of the dialogs actions.

Thanks again for your response

On Sun, Dec 14, 2008 at 2:01 PM, Marc Tompkins marc.tompkins@gmail.com wrote:

On Sun, Dec 14, 2008 at 8:24 AM, A Wain awainb@gmail.com wrote:

Hey Guys, I’m hoping someone could shed some light on my little problem here :smiley:

I’ve been trying to create a wxTextEntryDialog() within this script here and for some reason I am not getting any return from the ShowModal() call.

Two things:

  1. Here’s how I usually handle a modal dialog:

             dlg = wx.MessageDialog(self, "The email file you specified doesn't exist (yet).  Should I create it?",
                         "Create a new file?", wx.YES_NO | wx.ICON_QUESTION)
    
    
             response = dlg.ShowModal()
             dlg.Destroy()
             if (response == wx.ID_NO): return
    

In other words, assign the dialog’s return value to a variable, destroy the dialog, THEN check what the return was. It may not be absolutely necessary - I’m a belt-and-suspenders kind of guy myself - but it definitely works.

  1. When you ask a question, pare your code down to the very minimum, and make sure it doesn’t have any dependencies. The code you posted won’t run without “Resources”; comment that out and it wants something called “tbi”… Not only do you save us a bunch of work trying to get your code to run on our machines, but 90% of the time the solution pops out at you while you’re editing.


www.fsrtechnologies.com


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

That fragment doesn't run on its own - it needs to be inside at least
a Frame, or some container for "self" to refer to - so to keep things
easy I opened up the wxPython demo (which is an excellent resource for
questions of this type - there's more good info in it than in a whole
bookshelf of reference books!) and modified the TextEntryDialog demo
thusly:
(Note that "print" needs to be changed to "self.log.WriteText()" when
working with the demo. It's not a bad habit to get into anyway.)
    def OnButton(self, evt):
        self.log.WriteText( 'Setup TextEntryDialog')
        passdlg = wx.TextEntryDialog(self, 'message', 'caption', 'blah')

        self.log.WriteText('Show TextEntryDialog with ShowModal(),
Assigning it a variable name: result')

        if passdlg.ShowModal() == wx.ID_OK:
            self.log.WriteText('YEAH!!!')
        else:
            self.log.WriteText('BAHHHH!!!')

It works just fine (says YEAH! every time).

I've learned that it's not necessary to assign to a variable first,
which is a good thing to know. I still don't know what the problem is
at your end, but I hope this helps you find it...

···

On Sun, Dec 14, 2008 at 11:19 AM, A Wain <awainb@gmail.com> wrote:

I will limit the code next time, didnt realize I copied most of it in :P. As
well, I have tried your suggestion, assigning it to a variable, destroying
the window, etc. it still has the exact same effect. I'll give the example I
tested with using your suggestion:

-------------------------------------------------------------------------------------------------------------------------------
print 'Setup TextEntryDialog'
passdlg = wx.TextEntryDialog(self, 'message', 'caption', 'blah')
print 'Show TextEntryDialog with ShowModal(), Assigning it a variable name:
result'
result = passdlg.ShowModal()
print 'Destroying Dialog'
passdlg.Destroy()
print result, wx.ID_OK
if result == wx.ID_OK:
    print 'YEAH!!!'
else:
    print 'BAHHHH!!!'
-------------------------------------------------------------------------------------------------------------------------------

--
www.fsrtechnologies.com

Yeah, the dialog’s parent, self, is the main frame of the application. The messed up part is that I know the code “shoud” work as-is, I use the same code in other scripts and it runs fine, in fact when I had first added this dialog into this script it was a direct copy from another “working” one, which in turn was copied and modified from the demo itself. Even with what you have supplied me for an example my script doesnt even let it get to the WriteText() line(s), nor does it return anything when I set ShowModal() to a variable. This is wehre I am at a complete loss. I cannot even verify if the ShowModal() returned the same id as wx.ID_OK. in Resources.Controls.ServicePanel I use the same code, also within a MenuEvent and it works just fine but within this one script all attempts to create a dialog and have it return a value fail. This goes for MessageDialog, a custom wxDialog, etc.

Another odd point is that after I click Ok/Cancel the dialog closes and goes back into the main window of the app, if I call the dialog again it pops up again and does the same thing. if there was an error in the code then it should have failed, not allowed the same dialog to be recreated over and over.

Cheers

···

On Sun, Dec 14, 2008 at 3:18 PM, Marc Tompkins marc.tompkins@gmail.com wrote:

On Sun, Dec 14, 2008 at 11:19 AM, A Wain awainb@gmail.com wrote:

I will limit the code next time, didnt realize I copied most of it in :P. As

well, I have tried your suggestion, assigning it to a variable, destroying

the window, etc. it still has the exact same effect. I’ll give the example I

tested with using your suggestion:


print ‘Setup TextEntryDialog’

passdlg = wx.TextEntryDialog(self, ‘message’, ‘caption’, ‘blah’)

print 'Show TextEntryDialog with ShowModal(), Assigning it a variable name:

result’

result = passdlg.ShowModal()

print ‘Destroying Dialog’

passdlg.Destroy()

print result, wx.ID_OK

if result == wx.ID_OK:

print 'YEAH!!!'

else:

print 'BAHHHH!!!'

That fragment doesn’t run on its own - it needs to be inside at least

a Frame, or some container for “self” to refer to - so to keep things

easy I opened up the wxPython demo (which is an excellent resource for

questions of this type - there’s more good info in it than in a whole

bookshelf of reference books!) and modified the TextEntryDialog demo

thusly:

(Note that “print” needs to be changed to “self.log.WriteText()” when

working with the demo. It’s not a bad habit to get into anyway.)

def OnButton(self, evt):

    self.log.WriteText( 'Setup TextEntryDialog')

passdlg = wx.TextEntryDialog(self, ‘message’, ‘caption’, ‘blah’)

self.log.WriteText('Show TextEntryDialog with ShowModal(),

Assigning it a variable name: result’)

    if passdlg.ShowModal() == wx.ID_OK:

self.log.WriteText(‘YEAH!!!’)

    else:

        self.log.WriteText('BAHHHH!!!')

It works just fine (says YEAH! every time).

I’ve learned that it’s not necessary to assign to a variable first,

which is a good thing to know. I still don’t know what the problem is

at your end, but I hope this helps you find it…

www.fsrtechnologies.com


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

A Wain wrote:

Hey Guys, I'm hoping someone could shed some light on my little problem here :smiley:

I've been trying to create a wxTextEntryDialog() within this script here and for some reason I am not getting any return from the ShowModal() call. Although the dialog pops up just fine and when I press the Ok or Cancel button(s) it closes the dialog just fine, it seems that the dialog still does not exit properly as whenever the ShowModal() call is made, all code written afterwards will not run. Even code after the "if passdlg.ShowModal() == wx.ID_OK:" (and trailing else: line) will not run, which includes the "print temp" line, which is after the if/else statement so it should be run after the Ok or Cancel button have been pressed.

Platform and version? Can you make a small standalone runnable sample that shows the problem so we can run it?

···

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