~ubuntu-branches/ubuntu/trusty/drpython/trusty

« back to all changes in this revision

Viewing changes to drOpenImportedModuleDialog.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-07-03 22:11:49 UTC
  • mfrom: (0.1.3 upstream) (8 intrepid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20080703221149-puu681p4w33g3s3m
* New upstream release.
* Bump epoch due to new version numbering system.
* debian/control:
  - Adjust dependencies for wxwidgets2.8.
* debian/patches/15_output_redirection.dpatch:
  - Set standard output and error to valid UNIX locations.
* Adjust patches for new upstream release:
  - debian/patches/03_pythonfix.dpatch
* Drop patches, implemented upstream:
  - debian/patches/10_ctrl_q_to_exit_as_default_shortcut.dpatch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#       Programmer:     Daniel Pozmanter
2
 
#       E-mail:         drpython@bluebottle.com
3
 
#       Note:           You must reply to the verification e-mail to get through.
4
 
#
5
 
#       Copyright 2003-2005 Daniel Pozmanter
6
 
#
7
 
#       Distributed under the terms of the GPL (GNU Public License)
8
 
#
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.
13
 
#
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.
18
 
#
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
22
 
        
 
1
#   Programmer: Daniel Pozmanter
 
2
#   E-mail:     drpython@bluebottle.com
 
3
#   Note:       You must reply to the verification e-mail to get through.
 
4
#
 
5
#   Copyright 2003-2007 Daniel Pozmanter
 
6
#
 
7
#   Distributed under the terms of the GPL (GNU Public License)
 
8
#
 
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.
 
13
#
 
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.
 
18
#
 
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
 
22
 
23
23
#Open Imported Module Dialog
24
24
 
25
 
import os, os.path, sys, keyword
 
25
import os, sys, keyword
26
26
import wx
27
27
from drSingleChoiceDialog import drSingleChoiceDialog
28
28
 
31
31
#and getting the path for each module.
32
32
 
33
33
def GetModulePath(filepath, selmodule, platformiswin):
34
 
        moduletext = selmodule
35
 
        #Special Cases:
36
 
        if selmodule == 'os.path':
37
 
                if platformiswin:
38
 
                        selmodule = 'ntpath'
39
 
                elif os.name == 'mac':
40
 
                        selmodule = 'macpath'
41
 
                else:
42
 
                        selmodule = 'posixpath'
43
 
                        
44
 
        selectedmodule = '/' + selmodule.replace('.', '/') + '.py'
45
 
        #Handle cases like 'import wx' == import 'wx.__init__'
46
 
        selectedinitmodule = '/' + selmodule.replace('.', '/') + '/__init__.py'
47
 
        
48
 
        if os.path.exists(filepath + selectedmodule):
49
 
                return moduletext, (filepath + selectedmodule)
50
 
        if os.path.exists(filepath + selectedinitmodule):
51
 
                return moduletext, (filepath + selectedinitmodule)
52
 
        
53
 
        #Search for the file:
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
61
 
                                                
62
 
        return moduletext, None
 
34
    moduletext = selmodule
 
35
    #Special Cases:
 
36
    if selmodule == 'os.path':
 
37
        if platformiswin:
 
38
            selmodule = 'ntpath'
 
39
        elif os.name == 'mac':
 
40
            selmodule = 'macpath'
 
41
        else:
 
42
            selmodule = 'posixpath'
 
43
 
 
44
    selectedmodule = '/' + selmodule.replace('.', '/') + '.py'
 
45
    #Handle cases like 'import wx' == import 'wx.__init__'
 
46
    selectedinitmodule = '/' + selmodule.replace('.', '/') + '/__init__.py'
 
47
 
 
48
    if os.path.exists(filepath + selectedmodule):
 
49
        return moduletext, (filepath + selectedmodule)
 
50
    if os.path.exists(filepath + selectedinitmodule):
 
51
        return moduletext, (filepath + selectedinitmodule)
 
52
 
 
53
    #Search for the file:
 
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
 
61
 
 
62
    return moduletext, None
63
63
 
64
64
def ParseImportStatement(matches):
65
 
        targetarray = map(lambda x: x.strip().split(), matches)
66
 
        results = []
67
 
        for item in targetarray:                                                        
68
 
                x = 0
69
 
                isfrom = (item[0] == 'from')
70
 
                l = len(item)
71
 
                while x < l:
72
 
                        if item[x].find(',') > -1:
73
 
                                y = item.pop(x)
74
 
                                ya = y.split(',')
75
 
                                ly = len(ya)
76
 
                                counter = 0
77
 
                                while counter < ly:
78
 
                                        if len(ya[counter]) < 1:
79
 
                                                ya.pop(counter)
80
 
                                                ly -= 1
81
 
                                        else:
82
 
                                                counter += 1
83
 
                                item.extend(ya)
84
 
                                l = l + len(ya) - 1
85
 
                        elif item[x] == 'as':
86
 
                                item.pop(x)
87
 
                                try:
88
 
                                        item.pop(x)
89
 
                                        l -= 2
90
 
                                except:
91
 
                                        l -= 1
92
 
                        elif item[x] == '*':
93
 
                                item.pop(x)
94
 
                                l -= 1
95
 
                        elif item[x] in keyword.kwlist:
96
 
                                item.pop(x)
97
 
                                l -= 1
98
 
                        else:
99
 
                                if (x > 0) and isfrom:
100
 
                                        a = item.pop(x)
101
 
                                        item.insert(x, item[0] + '.' + a)
102
 
                                x += 1
103
 
                results.append(item)
104
 
        return results
 
65
    targetarray = map(lambda x: x.strip().split(), matches)
 
66
    results = []
 
67
    for item in targetarray:
 
68
        x = 0
 
69
        isfrom = (item[0] == 'from')
 
70
        l = len(item)
 
71
        while x < l:
 
72
            if item[x].find(',') > -1:
 
73
                y = item.pop(x)
 
74
                ya = y.split(',')
 
75
                ly = len(ya)
 
76
                counter = 0
 
77
                while counter < ly:
 
78
                    if not ya[counter]:
 
79
                        ya.pop(counter)
 
80
                        ly -= 1
 
81
                    else:
 
82
                        counter += 1
 
83
                item.extend(ya)
 
84
                l = l + len(ya) - 1
 
85
            elif item[x] == 'as':
 
86
                item.pop(x)
 
87
                try:
 
88
                    item.pop(x)
 
89
                    l -= 2
 
90
                except:
 
91
                    l -= 1
 
92
            elif item[x] == '*':
 
93
                item.pop(x)
 
94
                l -= 1
 
95
            elif item[x] in keyword.kwlist:
 
96
                item.pop(x)
 
97
                l -= 1
 
98
            else:
 
99
                if (x > 0) and isfrom:
 
100
                    a = item.pop(x)
 
101
                    item.insert(x, item[0] + '.' + a)
 
102
                x += 1
 
103
        results.append(item)
 
104
    return results
105
105
 
106
106
 
107
107
#*******************************************************************************************************
108
108
 
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)
112
 
                
113
 
                #Why is this needed?  Who knows.  But it is.
114
 
                self.Move(point)
115
 
                
116
 
                self.Bind(wx.EVT_CLOSE, self.OnCloseW)
117
 
                
118
 
                self.parent.LoadDialogSizeAndPosition(self, 'openimportedmoduledialog.sizeandposition.dat')
119
 
        
120
 
        def GetSelectedModule(self):
121
 
                return self.GetStringSelection()
122
 
 
123
 
        def OnbtnCancel(self, event):
124
 
                self.OnCloseW(None)
125
 
                drSingleChoiceDialog.OnbtnCancel(self, event)
126
 
        
127
 
        def OnbtnOk(self, event):               
128
 
                self.OnCloseW(None)
129
 
                drSingleChoiceDialog.OnbtnOk(self, event)
130
 
        
131
 
        def OnCloseW(self, event):
132
 
                self.parent.SaveDialogSizeAndPosition(self, 'openimportedmoduledialog.sizeandposition.dat')
133
 
                if event is not None:
134
 
                        event.Skip()
 
110
    def __init__(self, parent, modulelist, point=wx.DefaultPosition, size=(250, 300)):
 
111
        drSingleChoiceDialog.__init__(self, parent, "Open Imported Module", modulelist, point, size)
 
112
 
 
113
        #Why is this needed?  Who knows.  But it is.
 
114
        self.Move(point)
 
115
 
 
116
        self.Bind(wx.EVT_CLOSE, self.OnCloseW)
 
117
 
 
118
        self.parent.LoadDialogSizeAndPosition(self, 'openimportedmoduledialog.sizeandposition.dat')
 
119
 
 
120
    def GetSelectedModule(self):
 
121
        return self.GetStringSelection()
 
122
 
 
123
    def OnbtnCancel(self, event):
 
124
        self.OnCloseW(None)
 
125
        drSingleChoiceDialog.OnbtnCancel(self, event)
 
126
 
 
127
    def OnbtnOk(self, event):
 
128
        self.OnCloseW(None)
 
129
        drSingleChoiceDialog.OnbtnOk(self, event)
 
130
 
 
131
    def OnCloseW(self, event):
 
132
        self.parent.SaveDialogSizeAndPosition(self, 'openimportedmoduledialog.sizeandposition.dat')
 
133
        if event is not None:
 
134
            event.Skip()