wxPython Error in Opening Files in Ubuntu












1















I'm working on this tutorial and I noticed that this code snippet has a problem with it:



def OnOpen(self, e):
"""To open d' files"""
self.dirname = ""
dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetFilename()
self.dirname = dlg.GetDirectory()
f = open(os.path.join(self.dirname, self.filename))
self.control.SetValue(f.read())
f.close()
dlg.Destroy()


I'm running the code in Ubuntu 11.10 and it works as intended as long as you don't attempt to pick a file from the search or recently opened file features. Apparently it isn't receiving the directory in those cases, as self.dirname is None. I'm wondering what is happening in GetFilename and how Linux is returning the file directories in the dialog when search or recently used files are selected.



Any insight on this would be appreciated. Also, if there is anyplace to find the specific code would be appreciated. I know that it is on my drive, but I have no idea what file its in.










share|improve this question




















  • 1





    Take a look in your site-packages directory. It's highly possible that the important bits are compiled C++ code, though.

    – Wayne Werner
    May 1 '12 at 19:42
















1















I'm working on this tutorial and I noticed that this code snippet has a problem with it:



def OnOpen(self, e):
"""To open d' files"""
self.dirname = ""
dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetFilename()
self.dirname = dlg.GetDirectory()
f = open(os.path.join(self.dirname, self.filename))
self.control.SetValue(f.read())
f.close()
dlg.Destroy()


I'm running the code in Ubuntu 11.10 and it works as intended as long as you don't attempt to pick a file from the search or recently opened file features. Apparently it isn't receiving the directory in those cases, as self.dirname is None. I'm wondering what is happening in GetFilename and how Linux is returning the file directories in the dialog when search or recently used files are selected.



Any insight on this would be appreciated. Also, if there is anyplace to find the specific code would be appreciated. I know that it is on my drive, but I have no idea what file its in.










share|improve this question




















  • 1





    Take a look in your site-packages directory. It's highly possible that the important bits are compiled C++ code, though.

    – Wayne Werner
    May 1 '12 at 19:42














1












1








1








I'm working on this tutorial and I noticed that this code snippet has a problem with it:



def OnOpen(self, e):
"""To open d' files"""
self.dirname = ""
dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetFilename()
self.dirname = dlg.GetDirectory()
f = open(os.path.join(self.dirname, self.filename))
self.control.SetValue(f.read())
f.close()
dlg.Destroy()


I'm running the code in Ubuntu 11.10 and it works as intended as long as you don't attempt to pick a file from the search or recently opened file features. Apparently it isn't receiving the directory in those cases, as self.dirname is None. I'm wondering what is happening in GetFilename and how Linux is returning the file directories in the dialog when search or recently used files are selected.



Any insight on this would be appreciated. Also, if there is anyplace to find the specific code would be appreciated. I know that it is on my drive, but I have no idea what file its in.










share|improve this question
















I'm working on this tutorial and I noticed that this code snippet has a problem with it:



def OnOpen(self, e):
"""To open d' files"""
self.dirname = ""
dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetFilename()
self.dirname = dlg.GetDirectory()
f = open(os.path.join(self.dirname, self.filename))
self.control.SetValue(f.read())
f.close()
dlg.Destroy()


I'm running the code in Ubuntu 11.10 and it works as intended as long as you don't attempt to pick a file from the search or recently opened file features. Apparently it isn't receiving the directory in those cases, as self.dirname is None. I'm wondering what is happening in GetFilename and how Linux is returning the file directories in the dialog when search or recently used files are selected.



Any insight on this would be appreciated. Also, if there is anyplace to find the specific code would be appreciated. I know that it is on my drive, but I have no idea what file its in.







python user-interface wxpython ubuntu-11.10






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 3:40









Cœur

18.6k9110150




18.6k9110150










asked May 1 '12 at 19:36









BrotherJackBrotherJack

214113




214113








  • 1





    Take a look in your site-packages directory. It's highly possible that the important bits are compiled C++ code, though.

    – Wayne Werner
    May 1 '12 at 19:42














  • 1





    Take a look in your site-packages directory. It's highly possible that the important bits are compiled C++ code, though.

    – Wayne Werner
    May 1 '12 at 19:42








1




1





Take a look in your site-packages directory. It's highly possible that the important bits are compiled C++ code, though.

– Wayne Werner
May 1 '12 at 19:42





Take a look in your site-packages directory. It's highly possible that the important bits are compiled C++ code, though.

– Wayne Werner
May 1 '12 at 19:42












1 Answer
1






active

oldest

votes


















3














Isn't GetPath the function you'd want to use to get the path and filename of the selected file?






share|improve this answer



















  • 1





    Yes, apparently so. I modified the code to use that function rather than GetFilename and GetDirectory. This seems simpler and it works better, I wonder why the author decided to use the method showed in my question.

    – BrotherJack
    May 1 '12 at 20:08











  • @BrotherJack I read through the Wiki entry and I'm not sure how their approach would work - seems like it depends on the FileDialog setting the default Filename and Directory to the user-selected file, which I'm not seeing in the FileDialog docs.

    – ChrisC
    May 1 '12 at 20:14











  • GetDirectory() has stopped working entirely for this purpose in Ubuntu Quantal. Now it just returns the user's home directory. But GetPath() still works correctly.

    – jab
    Dec 1 '12 at 5:09











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10403205%2fwxpython-error-in-opening-files-in-ubuntu%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Isn't GetPath the function you'd want to use to get the path and filename of the selected file?






share|improve this answer



















  • 1





    Yes, apparently so. I modified the code to use that function rather than GetFilename and GetDirectory. This seems simpler and it works better, I wonder why the author decided to use the method showed in my question.

    – BrotherJack
    May 1 '12 at 20:08











  • @BrotherJack I read through the Wiki entry and I'm not sure how their approach would work - seems like it depends on the FileDialog setting the default Filename and Directory to the user-selected file, which I'm not seeing in the FileDialog docs.

    – ChrisC
    May 1 '12 at 20:14











  • GetDirectory() has stopped working entirely for this purpose in Ubuntu Quantal. Now it just returns the user's home directory. But GetPath() still works correctly.

    – jab
    Dec 1 '12 at 5:09
















3














Isn't GetPath the function you'd want to use to get the path and filename of the selected file?






share|improve this answer



















  • 1





    Yes, apparently so. I modified the code to use that function rather than GetFilename and GetDirectory. This seems simpler and it works better, I wonder why the author decided to use the method showed in my question.

    – BrotherJack
    May 1 '12 at 20:08











  • @BrotherJack I read through the Wiki entry and I'm not sure how their approach would work - seems like it depends on the FileDialog setting the default Filename and Directory to the user-selected file, which I'm not seeing in the FileDialog docs.

    – ChrisC
    May 1 '12 at 20:14











  • GetDirectory() has stopped working entirely for this purpose in Ubuntu Quantal. Now it just returns the user's home directory. But GetPath() still works correctly.

    – jab
    Dec 1 '12 at 5:09














3












3








3







Isn't GetPath the function you'd want to use to get the path and filename of the selected file?






share|improve this answer













Isn't GetPath the function you'd want to use to get the path and filename of the selected file?







share|improve this answer












share|improve this answer



share|improve this answer










answered May 1 '12 at 19:54









ChrisCChrisC

1,18677




1,18677








  • 1





    Yes, apparently so. I modified the code to use that function rather than GetFilename and GetDirectory. This seems simpler and it works better, I wonder why the author decided to use the method showed in my question.

    – BrotherJack
    May 1 '12 at 20:08











  • @BrotherJack I read through the Wiki entry and I'm not sure how their approach would work - seems like it depends on the FileDialog setting the default Filename and Directory to the user-selected file, which I'm not seeing in the FileDialog docs.

    – ChrisC
    May 1 '12 at 20:14











  • GetDirectory() has stopped working entirely for this purpose in Ubuntu Quantal. Now it just returns the user's home directory. But GetPath() still works correctly.

    – jab
    Dec 1 '12 at 5:09














  • 1





    Yes, apparently so. I modified the code to use that function rather than GetFilename and GetDirectory. This seems simpler and it works better, I wonder why the author decided to use the method showed in my question.

    – BrotherJack
    May 1 '12 at 20:08











  • @BrotherJack I read through the Wiki entry and I'm not sure how their approach would work - seems like it depends on the FileDialog setting the default Filename and Directory to the user-selected file, which I'm not seeing in the FileDialog docs.

    – ChrisC
    May 1 '12 at 20:14











  • GetDirectory() has stopped working entirely for this purpose in Ubuntu Quantal. Now it just returns the user's home directory. But GetPath() still works correctly.

    – jab
    Dec 1 '12 at 5:09








1




1





Yes, apparently so. I modified the code to use that function rather than GetFilename and GetDirectory. This seems simpler and it works better, I wonder why the author decided to use the method showed in my question.

– BrotherJack
May 1 '12 at 20:08





Yes, apparently so. I modified the code to use that function rather than GetFilename and GetDirectory. This seems simpler and it works better, I wonder why the author decided to use the method showed in my question.

– BrotherJack
May 1 '12 at 20:08













@BrotherJack I read through the Wiki entry and I'm not sure how their approach would work - seems like it depends on the FileDialog setting the default Filename and Directory to the user-selected file, which I'm not seeing in the FileDialog docs.

– ChrisC
May 1 '12 at 20:14





@BrotherJack I read through the Wiki entry and I'm not sure how their approach would work - seems like it depends on the FileDialog setting the default Filename and Directory to the user-selected file, which I'm not seeing in the FileDialog docs.

– ChrisC
May 1 '12 at 20:14













GetDirectory() has stopped working entirely for this purpose in Ubuntu Quantal. Now it just returns the user's home directory. But GetPath() still works correctly.

– jab
Dec 1 '12 at 5:09





GetDirectory() has stopped working entirely for this purpose in Ubuntu Quantal. Now it just returns the user's home directory. But GetPath() still works correctly.

– jab
Dec 1 '12 at 5:09




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10403205%2fwxpython-error-in-opening-files-in-ubuntu%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Mossoró

Error while reading .h5 file using the rhdf5 package in R

Pushsharp Apns notification error: 'InvalidToken'