Upgraded System, New Error Generated

You have a confusion between the two dialogs here. Here's basically
what you had:

    wd = wx.DirDialog(...)
    result = wd.ShowModal()
    if result == wx.ID_OK:
        wd.Destroy()
        dlg = wx.FileDialog( ... )
        result = dlg.ShowModal()
    dlg.Destroy()

If the result of the first dialog is not OK, you never destroy wd at
all, and you call Destroy() on dlg, which does not exist.

I *THINK* what you meant to do here is reuse the same variable. If you
changed "wd" to "dlg" in the 4 places it occurs, this would work just
fine. Otherwise, you need to destroy "dlg" inside the if, and destroy
"wd" outside the if.

···

On Wed, 17 Jan 2007 19:03:00 -0800 (PST), Rich Shepard <rshepard@appl-ecosys.com> wrote:

On Wed, 17 Jan 2007, Josiah Carlson wrote:

     self.SetTitle(('FuzzyEI-Assessor: - %s') % appData.projname)
   dlg.Destroy()

Indent that last line 2 more spaces so it lines up with the
"self.SetTitle..." line.

Josiah,

  Then do I need separate code to destroy the dialog if cancel is
selected?

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

Tim,

   You're right, but it worked OK before. I guess that I had not tested
"Cancel" on the directory dialog.

   What I now have is this:

def openFile(self, event):
   """ Open a project file."""
   wd = wx.DirDialog(None, "Choose a default directory:", defaultPath=".",
                         style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)
   result = wd.ShowModal()
   if result == wx.ID_OK:
     appData.dirname = wd.GetPath()
   wd.Destroy()
   wildcard = 'Project databases (*.db)|*.db|' \
              'All files (*.*)|*.*'
   dlg = wx.FileDialog(None, "Choose a project", appData.dirname,
                     wildcard=wildcard, style=wx.OPEN|wx.CHANGE_DIR)
   result = dlg.ShowModal()
   if result == wx.ID_OK:
     appData.projname=dlg.GetFilename()
     appData.dirname=dlg.GetDirectory()
     appData.dbFileName=dlg.GetFilename()
     titleStr = appData.projname[:-4]
     self.SetTitle(('FuzzyEI-Assessor: - %s') % appData.projname)
   dlg.Destroy()

   When 'wd,' the directory dialog is displayed, the [OK] button does
nothing. Clicking on [Cancel] closes that dialog and brings up the file
display dialog, 'dlg.' Then, when I double click on a file name, the dialog
is closed, the following error message is displayed on the console

(python:20823): Gtk-CRITICAL **: gtk_file_system_unix_get_folder: assertion
a_path_is_absolute (filename)' failed
Traceback (most recent call last):
   File "/data1/eikos/modelPage.py", line 201, in OnOpenMod
     pName = functions.openFile(self, event)
   File "/data1/eikos/functions.py", line 48, in openFile
     self.SetTitle(('FuzzyEI-Assessor: - %s') % appData.projname) AttributeError: 'modModel' object has no attribute 'SetTitle'

the window title _is_ set, but the file name and other data are no longer
loaded into the page's widgets.

Rich

···

On Thu, 18 Jan 2007, Tim Roberts wrote:

If the result of the first dialog is not OK, you never destroy wd at all,
and you call Destroy() on dlg, which does not exist.

I *THINK* what you meant to do here is reuse the same variable. If you
changed "wd" to "dlg" in the 4 places it occurs, this would work just
fine. Otherwise, you need to destroy "dlg" inside the if, and destroy
"wd" outside the if.

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

I've checked the new API docs for DirDialog and FileDialog and ensured
that I'm calling them correctly. But, the function is still not working.

   The latest changes:

   def openFile(self, event):
     wd = wx.DirDialog(None, "Choose a default directory:", defaultPath=".",
                           style=wx.DD_DEFAULT_STYLE)
     result = wd.ShowModal()
     if result == wx.ID_CANCEL:
             wd.Destroy()
     if result == wx.ID_OK:
       self.appData.dirname = wd.GetPath()
     wd.Destroy()
     wildcard = 'Project databases (*.db)|*.db|'
     dlg = wx.FileDialog(None, "Choose a project", self.appData.dirname,
                        wildcard=wildcard, style=wx.FD_OPEN|wx.FD_CHANGE_DIR)
     result = dlg.ShowModal()
     if result == wx.ID_CANCEL:
       dlg.Destroy()
     if result == wx.ID_OK:
       self.appData.projname=dlg.GetFilename()
       self.appData.dirname=dlg.GetDirectory()
       self.appData.dbFileName=dlg.GetFilename()
       titleStr = self.appData.projname[:-4]
       self.SetTitle(('FuzzyEI-Assessor: - %s') % self.appData.projname)
       dlg.Destroy()

   Now, as soon as the function is called, the console displays this message:

   (python:9274): Gtk-CRITICAL **: gtk_file_system_unix_get_folder:
   assertion `g_path_is_absolute (filename)' failed

   Pressing the "OK" button does nothing. Pressing the "Cancel" button closes
the dialog box and brings up the FileDialog. That seems backward to me.

   Regardless, when I then double-click on a file name, rather than
displaying that name in the appropriate widget and loading other data from
the database tables, the same error message as before is displayed; that is,

   Traceback (most recent call last):
   File "/data1/eikos/modelPage.py", line 201, in OnOpenMod
     pName = functions.openFile(self, event)
   File "/data1/eikos/functions.py", line 51, in openFile
     self.SetTitle(('FuzzyEI-Assessor: - %s') % self.appData.projname) AttributeError: 'modModel' object has no attribute 'SetTitle'

   As I wrote yesterday, this all worked just fine before all the upgrades.
I'd _really_ appreciate learning what I need to change so I can get this
working once again and get on to the rest of the application GUI.

TIA,

Rich

···

On Thu, 18 Jan 2007, Rich Shepard wrote:

What I now have is this:

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Rich Shepard wrote:

What I now have is this:

  I've checked the new API docs for DirDialog and FileDialog and ensured
that I'm calling them correctly. But, the function is still not working.

  The latest changes:

    def openFile(self, event):
      wd = wx.DirDialog(None, "Choose a default directory:", defaultPath=".",
                            style=wx.DD_DEFAULT_STYLE)

  Now, as soon as the function is called, the console displays this message:

    (python:9274): Gtk-CRITICAL **: gtk_file_system_unix_get_folder:
    assertion `g_path_is_absolute (filename)' failed

Just a guess based on the message, but try using defaultPath=os.getcwd() instead of '.'. Sounds to me like it is wanting a full pathname.

  Pressing the "OK" button does nothing. Pressing the "Cancel" button closes
the dialog box and brings up the FileDialog. That seems backward to me.

Not sure what's going on with the OK button, maybe it's a bug caused by the error above. However the way you have the code organized it is setup to go to the file dialog no matter what the result of the dir dialog is. A bit of reorg and simplification of the code will probably help it make more sense to you:

     def openFile(self, event):
         wd = wx.DirDialog(None, "Choose a default directory:",
                           defaultPath=".",
                           style=wx.DD_DEFAULT_STYLE)
         if wd.ShowModal() == wx.ID_OK:
             self.appData.dirname = wd.GetPath()
             wildcard = 'Project databases (*.db)|*.db|'
             dlg = wx.FileDialog(None, "Choose a project",
                                 self.appData.dirname,
                                 wildcard=wildcard,
                                 style=wx.FD_OPEN|wx.FD_CHANGE_DIR)
             if wd.ShowModal() == wx.ID_OK:
                 self.appData.projname=dlg.GetFilename()
                 self.appData.dirname=dlg.GetDirectory()
                 self.appData.dbFileName=dlg.GetFilename()
                 titleStr = self.appData.projname[:-4]
                 self.SetTitle(('FuzzyEI-Assessor: - %s') % self.appData.projname)
             dlg.Destroy()
         wd.Destroy()

  Regardless, when I then double-click on a file name, rather than
displaying that name in the appropriate widget and loading other data from
the database tables, the same error message as before is displayed; that is,

    Traceback (most recent call last):
  File "/data1/eikos/modelPage.py", line 201, in OnOpenMod
    pName = functions.openFile(self, event)
  File "/data1/eikos/functions.py", line 51, in openFile
    self.SetTitle(('FuzzyEI-Assessor: - %s') % self.appData.projname) AttributeError: 'modModel' object has no attribute 'SetTitle'

What is the type of self? Does that class have a SetTitle method?

···

On Thu, 18 Jan 2007, Rich Shepard wrote:

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

Hi Robin and Rich,

I think there is a little copy/paste error in the code, see below.

Robin Dunn wrote:

...
Not sure what's going on with the OK button, maybe it's a bug caused by the error above. However the way you have the code organized it is setup to go to the file dialog no matter what the result of the dir dialog is. A bit of reorg and simplification of the code will probably help it make more sense to you:

    def openFile(self, event):
        wd = wx.DirDialog(None, "Choose a default directory:",
                          defaultPath=".",
                          style=wx.DD_DEFAULT_STYLE)
        if wd.ShowModal() == wx.ID_OK:
            self.appData.dirname = wd.GetPath()
            wildcard = 'Project databases (*.db)|*.db|'
            dlg = wx.FileDialog(None, "Choose a project",
                                self.appData.dirname,
                                wildcard=wildcard,
                                style=wx.FD_OPEN|wx.FD_CHANGE_DIR)
            if wd.ShowModal() == wx.ID_OK:

I think above should use dlg and not wd:
            if dlg.ShowModal() == wx.ID_OK:

                self.appData.projname=dlg.GetFilename()
                self.appData.dirname=dlg.GetDirectory()
                self.appData.dbFileName=dlg.GetFilename()
                titleStr = self.appData.projname[:-4]
                self.SetTitle(('FuzzyEI-Assessor: - %s') % self.appData.projname)
            dlg.Destroy()
        wd.Destroy()

I use try/finally with dialogs to ensure that they always get destroyed, a habit I picked from Boa which generates the dialog code along these lines.

dlg = wx.FileDialog(self, 'Choose a file', '.', '', '*.*', wx.OPEN)
try:
    if dlg.ShowModal() == wx.ID_OK:
        filename = dlg.GetPath()
        # Your code
finally:
    dlg.Destroy()

Werner

    (python:9274): Gtk-CRITICAL **: gtk_file_system_unix_get_folder:
    assertion `g_path_is_absolute (filename)' failed

Just a guess based on the message, but try using defaultPath=os.getcwd() instead of '.'. Sounds to me like it is wanting a full pathname.

Robin, et al.:

   Changing the '.' to 'os.getcwd()' makes no difference at all.

  Pressing the "OK" button does nothing. Pressing the "Cancel" button
closes the dialog box and brings up the FileDialog. That seems backward
to me.

Not sure what's going on with the OK button, maybe it's a bug caused by the error above. However the way you have the code organized it is setup to go to the file dialog no matter what the result of the dir dialog is. A bit of reorg and simplification of the code will probably help it make more sense to you:

   Trying to isolate the problem, I've commented out everything after the
test whether the dialog's OK button was pressed, except a line to print the
pwd. Nothing's printed. Here's the truncated version:

def openFile(self, event):
     wd = wx.DirDialog(None, "Choose a default directory:", defaultPath="os.getcwd()",
                              style=wx.DD_DEFAULT_STYLE)
     if wd.ShowModal() == wx.ID_OK:
         print os.getcwd()
     wd.Destroy()

   What might have happened during the upgrade to break this so badly?
Despite the poor structure, this function worked over the past six or so
months since I first wrote it. Now a call to wx.DirDialog() won't work at
all for me. Is this related to wxGTK? Which library may be involved?

   This is obviously both a critical function and a major source of delay.
I'd greatly appreciate some suggestions on how to get it all working as
intended once again.

Thanks,

Rich

···

On Thu, 18 Jan 2007, Robin Dunn wrote:

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Werner F. Bruhin wrote:

Hi Robin and Rich,

I think there is a little copy/paste error in the code, see below.

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

I think above should use dlg and not wd:

Yep, you are right.

···

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

Rich Shepard wrote:

  Trying to isolate the problem, I've commented out everything after the
test whether the dialog's OK button was pressed, except a line to print the
pwd. Nothing's printed. Here's the truncated version:

def openFile(self, event):
    wd = wx.DirDialog(None, "Choose a default directory:", defaultPath="os.getcwd()",
                             style=wx.DD_DEFAULT_STYLE)
    if wd.ShowModal() == wx.ID_OK:
        print os.getcwd()
    wd.Destroy()

You want to *call* os.getcwd(), not pass it as a string.

BTW, you could probably solve a lot of your problems if you take the time to experiment in a PyShell. It's much easier to try things out, along with lots of variations, etc. until you understand what is going on. For example:

  >>> import wx, os
  >>> dlg = wx.DirDialog(None, "hello", defaultPath=os.getcwd())
  >>> dlg.ShowModal()
  5100
  >>> dlg.GetPath()
  u'/home/robind/Documents/wxPython'
  >>>

BTW, your issue with the Open button (or the wx.ID_OK one) not doing anything is probably due to a quirk in the GTK dialog. You don't want to drill down all the way *into* the dialog you are selecting, but instead just drill down into the parent, and then select (without double clicking) the dir you want. In the example above I drilled down into /home/robind/Documents and then clicked once on the wxPython folder and then pressed the Open button. The Open button only does something if there is data in the Name field at the top of the dialog.

  What might have happened during the upgrade to break this so badly?

You were apparently using the generic dialog before, probably because of a very old libgtk that doesn't have the new version of the native common dialogs. The generic one somewhat emulated the native dialog on Windows, and so it behaved somewhat differently, had different limitations, etc.

Despite the poor structure, this function worked over the past six or so
months since I first wrote it. Now a call to wx.DirDialog() won't work at
all for me.

I expect it is just because of drilling down too far, as I described above.

···

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

You want to *call* os.getcwd(), not pass it as a string.

Robin,

   Yes, I changed that after posting the message.

BTW, you could probably solve a lot of your problems if you take the time to experiment in a PyShell. It's much easier to try things out, along with lots of variations, etc. until you understand what is going on. For example:

   Excellent advice. I'll do this.

BTW, your issue with the Open button (or the wx.ID_OK one) not doing anything is probably due to a quirk in the GTK dialog. You don't want to drill down all the way *into* the dialog you are selecting, but instead just drill down into the parent, and then select (without double clicking) the dir you want. In the example above I drilled down into /home/robind/Documents and then clicked once on the wxPython folder and then pressed the Open button. The Open button only does something if there is data in the Name field at the top of the dialog.

You were apparently using the generic dialog before, probably because of a
very old libgtk that doesn't have the new version of the native common
dialogs. The generic one somewhat emulated the native dialog on Windows,
and so it behaved somewhat differently, had different limitations, etc.

   This is exactly the issue. The previous display had the current working
directory highlighted, so pressing the OK button accepted that as the
default. I now see that the new version requires the explicit entry of the
directory string into the name window. I missed that completely. When I take
the extra steps of backing up one directory, then clicking on the one I
want, it works.

   Now I'm on to fixing the wx.FileDialog(). It may be a similar issue.

Many thanks,

Rich

···

On Fri, 19 Jan 2007, Robin Dunn wrote:

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

>>> import wx, os
>>> dlg = wx.DirDialog(None, "hello", defaultPath=os.getcwd())
>>> dlg.ShowModal()
5100
>>> dlg.GetPath()
u'/home/robind/Documents/wxPython'
>>>

Robin,

   Not to beat on a dead horse, but I could not replicate the above on my
system. See attached screenshot.

BTW, your issue with the Open button (or the wx.ID_OK one) not doing anything is probably due to a quirk in the GTK dialog. You don't want to drill down all the way *into* the dialog you are selecting, but instead just drill down into the parent, and then select (without double clicking) the dir you want.

   So, if I invoke the application from within the project directory I have
to use the dialog box to back up one directory, then select the current one?
No wonder I didn't realize that the 'name' field referred to the directory I
want, not a filename.

I expect it is just because of drilling down too far, as I described above.

   This is probably part of the situation: I'm not drilling at all. I suppose
that when we have the application finished we'll launch it from the Xfce
panel so we'll have to explicitly select the directory to use.

   Hope you weren't inconvenienced by the snow and ice this week.

Many thanks!

Rich

···

On Fri, 19 Jan 2007, Robin Dunn wrote:

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Rich Shepard schrieb:

···

On Fri, 19 Jan 2007, Robin Dunn wrote:

>>> import wx, os
>>> dlg = wx.DirDialog(None, "hello", defaultPath=os.getcwd())
>>> dlg.ShowModal()
5100
>>> dlg.GetPath()
u'/home/robind/Documents/wxPython'

I could not replicate the above on my system.

Hi Rich!

I think, you´ve forgotten ``dlg.ShowModal()``.

regards,
Gerold
:slight_smile:

--
________________________________________________________________________
Gerold Penz - bcom - Programmierung
     gerold.penz@tirol.utanet.at | http://gerold.bcom.at | http://sw3.at
Ehrliche, herzliche Begeisterung ist einer der
     wirksamsten Erfolgsfaktoren. Dale Carnegie

Gerold,

   I'm sure that you're correct. It's been that sort of a week here.

Thanks,

Rich

···

On Fri, 19 Jan 2007, Gerold Penz wrote:

Hi Rich!

I think, you´ve forgotten ``dlg.ShowModal()``.

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

I think, you´ve forgotten ``dlg.ShowModal()``.

   No, I didn't:

PyShell 0.9.5 - The Flakiest Python Shell
Python 2.4.3 (#1, Jul 26 2006, 20:13:39) [GCC 3.4.6] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import wx, os
dlg = wx.DirDialog(None, "hello", defaultPath=os.getcwd())
dlg.ShowModal()

5101

dlg.GetPath()

u''

Rich

···

On Fri, 19 Jan 2007, Rich Shepard wrote:

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Robin,

   When I stood up and looked over the edge of the rut I had dug myself into,
I realized that I don't need the directory dialog with the new GTK+ file
dialog. That allows the user to change directories so the wx.DirDialog() is
superfluous.

   It appears that the wx.TreeCtrl() has also changed. The constructor is:

   self.polTree = wx.TreeCtrl(self, wx.ID_ANY, size=wx.Size(220, 225),
            style=wx.RAISED_BORDER|wx.TR_EDIT_LABELS|wx.TR_HAS_BUTTONS)

but there are no lines connecting elements on the tree. The triangles are at
the left of each node, but that's it.

   I don't see any style choices on the API for TreeCtrl or its parent,
Control. Have these changed between 2.6 and 2.8?

Thanks,

Rich

···

On Fri, 19 Jan 2007, Robin Dunn wrote:

BTW, your issue with the Open button (or the wx.ID_OK one) not doing anything is probably due to a quirk in the GTK dialog.

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Rich Shepard wrote:

···

On Fri, 19 Jan 2007, Rich Shepard wrote:

I think, you´ve forgotten ``dlg.ShowModal()``.

  No, I didn't:

PyShell 0.9.5 - The Flakiest Python Shell
Python 2.4.3 (#1, Jul 26 2006, 20:13:39) [GCC 3.4.6] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import wx, os
dlg = wx.DirDialog(None, "hello", defaultPath=os.getcwd())
dlg.ShowModal()

5101

dlg.GetPath()

u''

5101 is wx.ID_CANCEL, so you didn't really select anything, so a '' makes sense.

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

That's because there's no action when I pressed "OK."

   Regardless, this has been mooted by my realization that I no longer need
the wx.DirDialog() because the wx.FileDialog() permits directory changes.

   What's left for me to fix is figuring out why only some of the fields
extracted from the database are placed in the widgets. That's my assignment
for tomorrow.

Rich

···

On Sat, 20 Jan 2007, Robin Dunn wrote:

import wx, os
dlg = wx.DirDialog(None, "hello", defaultPath=os.getcwd())
dlg.ShowModal()

5101

dlg.GetPath()

u''

5101 is wx.ID_CANCEL, so you didn't really select anything, so a '' makes sense.

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863