1
# Programmer: Daniel Pozmanter
2
# E-mail: drpython@bluebottle.com
3
# Note: You must reply to the verification e-mail to get through.
5
# Copyright 2003-2005 Daniel Pozmanter
7
# Distributed under the terms of the GPL (GNU Public License)
9
# DrPython is free software; you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation; either version 2 of the License, or
12
# (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program; if not, write to the Free Software
21
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1
# Programmer: Daniel Pozmanter
2
# E-mail: drpython@bluebottle.com
3
# Note: You must reply to the verification e-mail to get through.
5
# Copyright 2003-2007 Daniel Pozmanter
7
# Distributed under the terms of the GPL (GNU Public License)
9
# DrPython is free software; you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation; either version 2 of the License, or
12
# (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program; if not, write to the Free Software
21
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
23
#Open Imported Module Dialog
25
import os, os.path, sys, keyword
25
import os, sys, keyword
27
27
from drSingleChoiceDialog import drSingleChoiceDialog
31
31
#and getting the path for each module.
33
33
def GetModulePath(filepath, selmodule, platformiswin):
34
moduletext = selmodule
36
if selmodule == 'os.path':
39
elif os.name == 'mac':
42
selmodule = 'posixpath'
44
selectedmodule = '/' + selmodule.replace('.', '/') + '.py'
45
#Handle cases like 'import wx' == import 'wx.__init__'
46
selectedinitmodule = '/' + selmodule.replace('.', '/') + '/__init__.py'
48
if os.path.exists(filepath + selectedmodule):
49
return moduletext, (filepath + selectedmodule)
50
if os.path.exists(filepath + selectedinitmodule):
51
return moduletext, (filepath + selectedinitmodule)
54
for somepath in sys.path:
55
modulefile = somepath.replace('\\', '/') + selectedmodule
56
initfile = somepath.replace('\\', '/') + selectedinitmodule
57
if os.path.exists(modulefile):
58
return moduletext, modulefile
59
elif os.path.exists(initfile):
60
return moduletext, initfile
62
return moduletext, None
34
moduletext = selmodule
36
if selmodule == 'os.path':
39
elif os.name == 'mac':
42
selmodule = 'posixpath'
44
selectedmodule = '/' + selmodule.replace('.', '/') + '.py'
45
#Handle cases like 'import wx' == import 'wx.__init__'
46
selectedinitmodule = '/' + selmodule.replace('.', '/') + '/__init__.py'
48
if os.path.exists(filepath + selectedmodule):
49
return moduletext, (filepath + selectedmodule)
50
if os.path.exists(filepath + selectedinitmodule):
51
return moduletext, (filepath + selectedinitmodule)
54
for somepath in sys.path:
55
modulefile = somepath.replace('\\', '/') + selectedmodule
56
initfile = somepath.replace('\\', '/') + selectedinitmodule
57
if os.path.exists(modulefile):
58
return moduletext, modulefile
59
elif os.path.exists(initfile):
60
return moduletext, initfile
62
return moduletext, None
64
64
def ParseImportStatement(matches):
65
targetarray = map(lambda x: x.strip().split(), matches)
67
for item in targetarray:
69
isfrom = (item[0] == 'from')
72
if item[x].find(',') > -1:
78
if len(ya[counter]) < 1:
95
elif item[x] in keyword.kwlist:
99
if (x > 0) and isfrom:
101
item.insert(x, item[0] + '.' + a)
65
targetarray = map(lambda x: x.strip().split(), matches)
67
for item in targetarray:
69
isfrom = (item[0] == 'from')
72
if item[x].find(',') > -1:
95
elif item[x] in keyword.kwlist:
99
if (x > 0) and isfrom:
101
item.insert(x, item[0] + '.' + a)
107
107
#*******************************************************************************************************
109
109
class drOpenImportedModuleDialog(drSingleChoiceDialog):
110
def __init__(self, parent, modulelist, point=wx.DefaultPosition, size=(250, 300)):
111
drSingleChoiceDialog.__init__(self, parent, "Open Imported Module", modulelist, point, size)
113
#Why is this needed? Who knows. But it is.
116
self.Bind(wx.EVT_CLOSE, self.OnCloseW)
118
self.parent.LoadDialogSizeAndPosition(self, 'openimportedmoduledialog.sizeandposition.dat')
120
def GetSelectedModule(self):
121
return self.GetStringSelection()
123
def OnbtnCancel(self, event):
125
drSingleChoiceDialog.OnbtnCancel(self, event)
127
def OnbtnOk(self, event):
129
drSingleChoiceDialog.OnbtnOk(self, event)
131
def OnCloseW(self, event):
132
self.parent.SaveDialogSizeAndPosition(self, 'openimportedmoduledialog.sizeandposition.dat')
133
if event is not None:
110
def __init__(self, parent, modulelist, point=wx.DefaultPosition, size=(250, 300)):
111
drSingleChoiceDialog.__init__(self, parent, "Open Imported Module", modulelist, point, size)
113
#Why is this needed? Who knows. But it is.
116
self.Bind(wx.EVT_CLOSE, self.OnCloseW)
118
self.parent.LoadDialogSizeAndPosition(self, 'openimportedmoduledialog.sizeandposition.dat')
120
def GetSelectedModule(self):
121
return self.GetStringSelection()
123
def OnbtnCancel(self, event):
125
drSingleChoiceDialog.OnbtnCancel(self, event)
127
def OnbtnOk(self, event):
129
drSingleChoiceDialog.OnbtnOk(self, event)
131
def OnCloseW(self, event):
132
self.parent.SaveDialogSizeAndPosition(self, 'openimportedmoduledialog.sizeandposition.dat')
133
if event is not None: