File: RemoteDialog.py

package info (click to toggle)
boa-constructor 0.3.0-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,188 kB
  • ctags: 8,857
  • sloc: python: 54,163; sh: 66; makefile: 36
file content (224 lines) | stat: -rw-r--r-- 8,309 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#Boa:Dialog:AttachDlg

import pprint

from wxPython.wx import *
from wxPython.grid import *

from PathsPanel import PathsPanel

def create(parent):
    return AttachDlg(parent)

[wxID_ATTACHDLG, wxID_ATTACHDLGCANCEL_BUTTON, wxID_ATTACHDLGHELP_BUTTON, 
 wxID_ATTACHDLGHOST_CTRL, wxID_ATTACHDLGOK_BUTTON, 
 wxID_ATTACHDLGPASSWORD_CTRL, wxID_ATTACHDLGPATHSPANEL, 
 wxID_ATTACHDLGPORT_CTRL, wxID_ATTACHDLGREM_PASS_CTRL, 
 wxID_ATTACHDLGSTATICTEXT1, wxID_ATTACHDLGSTATICTEXT2, 
 wxID_ATTACHDLGSTATICTEXT3, wxID_ATTACHDLGSTATICTEXT4, 
 wxID_ATTACHDLGUSERNAME_CTRL, 
] = map(lambda _init_ctrls: wxNewId(), range(14))

class AttachDlg(wxDialog):
    _custom_classes = {'wxPanel': ['PathsPanel']}

    rem_host = None
    rem_port = None
    rem_user = None
    rem_pass = None
    rem_pths = None
    
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wxDialog.__init__(self, id=wxID_ATTACHDLG, name='AttachDlg',
              parent=prnt, pos=wxPoint(270, 335), size=wxSize(527, 391),
              style=wxDEFAULT_DIALOG_STYLE, title='Attach to debugger')
        self.SetClientSize(wxSize(519, 364))
        EVT_CLOSE(self, self.OnCloseWindow)

        self.staticText1 = wxStaticText(id=wxID_ATTACHDLGSTATICTEXT1,
              label='Host', name='staticText1', parent=self, pos=wxPoint(16,
              24), size=wxSize(56, 16), style=0)

        self.staticText2 = wxStaticText(id=wxID_ATTACHDLGSTATICTEXT2,
              label='Port', name='staticText2', parent=self, pos=wxPoint(16,
              56), size=wxSize(56, 16), style=0)

        self.staticText3 = wxStaticText(id=wxID_ATTACHDLGSTATICTEXT3,
              label='Username', name='staticText3', parent=self, pos=wxPoint(16,
              88), size=wxSize(56, 16), style=0)

        self.staticText4 = wxStaticText(id=wxID_ATTACHDLGSTATICTEXT4,
              label='Password', name='staticText4', parent=self, pos=wxPoint(16,
              120), size=wxSize(56, 16), style=0)

        self.host_ctrl = wxTextCtrl(id=wxID_ATTACHDLGHOST_CTRL,
              name='host_ctrl', parent=self, pos=wxPoint(80, 16),
              size=wxSize(160, 24), style=0, value=self.host)

        self.port_ctrl = wxTextCtrl(id=wxID_ATTACHDLGPORT_CTRL,
              name='port_ctrl', parent=self, pos=wxPoint(80, 48),
              size=wxSize(48, 24), style=0, value=self.port)

        self.username_ctrl = wxTextCtrl(id=wxID_ATTACHDLGUSERNAME_CTRL,
              name='username_ctrl', parent=self, pos=wxPoint(80, 80),
              size=wxSize(96, 24), style=0, value=self.user)

        self.password_ctrl = wxTextCtrl(id=wxID_ATTACHDLGPASSWORD_CTRL,
              name='password_ctrl', parent=self, pos=wxPoint(80, 112),
              size=wxSize(96, 24), style=wxTE_PASSWORD, value=self.pwd)

        self.ok_button = wxButton(id=wxID_ATTACHDLGOK_BUTTON, label='Ok',
              name='ok_button', parent=self, pos=wxPoint(266, 323),
              size=wxSize(72, 24), style=0)
        EVT_BUTTON(self.ok_button, wxID_ATTACHDLGOK_BUTTON, self.OnOkButton)

        self.cancel_button = wxButton(id=wxID_CANCEL,
              label='Cancel', name='cancel_button', parent=self,
              pos=wxPoint(346, 323), size=wxSize(72, 24), style=0)

        self.help_button = wxButton(id=wxID_ATTACHDLGHELP_BUTTON, label='Help',
              name='help_button', parent=self, pos=wxPoint(426, 323),
              size=wxSize(72, 24), style=0)
        EVT_BUTTON(self.help_button, wxID_ATTACHDLGHELP_BUTTON,
              self.OnHelpButton)

        self.rem_pass_ctrl = wxCheckBox(id=wxID_ATTACHDLGREM_PASS_CTRL,
              label='Remember', name='rem_pass_ctrl', parent=self,
              pos=wxPoint(184, 120), size=wxSize(73, 13), style=0)
        self.rem_pass_ctrl.SetValue(False)

        self.pathsPanel = PathsPanel(id=wxID_ATTACHDLGPATHSPANEL,
              name='pathsPanel', parent=self, pos=wxPoint(8, 144),
              size=wxSize(504, 168), style=wxTAB_TRAVERSAL)

    def __init__(self, editor):
        import Utils
        conf = Utils.createAndReadConfig('Explorer')
        self.writeConfig = Utils.writeConfig

        if conf and conf.has_section('debugger.remote'):
            host = conf.get('debugger.remote', 'host')
            port = conf.get('debugger.remote', 'port')
            user = conf.get('debugger.remote', 'user')
            pwd = eval(conf.get('debugger.remote', 'passwd'))
            if pwd is not None:
                from Explorers import scrm
                pwd = scrm.scramble(pwd)
            paths = eval(conf.get('debugger.remote', 'paths'))
        else:
            host, port, user, pwd, paths = self.rem_host, self.rem_port, \
                  self.rem_user, self.rem_pass, self.rem_pths
        self.conf = conf

        self.host = '127.0.0.1'
        if host is not None: self.host = host

        self.port = '26200'
        if port is not None: self.port = port
        
        self.user = ''
        if user is not None: self.user = user
        
        self.pwd = ''
        if pwd is not None: self.pwd = pwd

        self.paths = []
        if paths is not None: self.paths[:] = paths
        
        self._init_ctrls(editor)
        self.editor = editor
        
        self.pathsPanel.init_paths(self.paths)
        
        try:
            from Preferences import IS
            self.SetIcon(IS.load('Images/Icons/Debug.ico'))
        except Exception:#ImportError: # for testing standalone
            pass

    def OnOkButton(self, event):
        paths = self.pathsPanel.read_paths()

        host = self.host_ctrl.GetValue()
        port = self.port_ctrl.GetValue()
        user = self.username_ctrl.GetValue()
        pw = self.password_ctrl.GetValue()

        if __name__ == '__main__': 
            self.EndModal(wxOK)
            return

        if self.conf:
            if not self.conf.has_section('debugger.remote'):
                self.conf.add_section('debugger.remote')
            self.conf.set('debugger.remote', 'host', host)
            self.conf.set('debugger.remote', 'port', port)
            self.conf.set('debugger.remote', 'user', user)
            if self.rem_pass_ctrl.GetValue():
                from Explorers import scrm
                self.conf.set('debugger.remote', 'passwd', repr(scrm.scramble(pw)))
            else:
                self.conf.set('debugger.remote', 'passwd', 'None')
            self.conf.set('debugger.remote', 'paths', pprint.pformat(paths))
            
            self.writeConfig(self.conf)
        else:
            AttachDlg.rem_host = host
            AttachDlg.rem_port = port
            AttachDlg.rem_user = user
            if self.rem_pass_ctrl.GetValue():
                AttachDlg.rem_pass = pw
            else:
                AttachDlg.rem_pass = None
            AttachDlg.rem_pths = paths
                
        from Debugger import DebuggerFrame
        from RemoteClient import RemoteClient

        debugger = DebuggerFrame(self.editor, slave_mode=0)
        client = RemoteClient(debugger, host, port, user, pw)
        debugger.setDebugClient(client)
        debugger.setServerClientPaths(paths)
        if user:
            debugger.setTitleInfo('%s@%s:%s' % (user, host, port))
        else:
            debugger.setTitleInfo('%s:%s' % (host, port))

        self.editor.debugger = debugger
        debugger.doDebugStep()
        debugger.Show(true)

        self.EndModal(wxOK)

    def OnHelpButton(self, event):
        pass

    def OnCloseWindow(self, event):
        self.editor = None
        self.Destroy()
        event.Skip()

#-------------------------------------------------------------------------------

if __name__ == '__main__':
    import sys; sys.path.append('..')
    app = wxPySimpleApp()
    wxInitAllImageHandlers()
    dlg = create(None)
    try:
        dlg.ShowModal()
        print dlg.pathsPanel.read_paths()
    finally:
        dlg.Destroy()

    app.MainLoop()

    dlg = create(None)
    try:
        dlg.ShowModal()
        print dlg.pathsPanel.read_paths()
    finally:
        dlg.Destroy()

    app.MainLoop()