Diff of /trunk/cforge/cforge/Package/CFORGE/Scripts/ui.py [r42] .. [r43]  Maximize  Restore

Switch to unified view

a/trunk/cforge/cforge/Package/CFORGE/Scripts/ui.py b/trunk/cforge/cforge/Package/CFORGE/Scripts/ui.py
...
...
11
import sys
11
import sys
12
import os
12
import os
13
import json
13
import json
14
import ntpath
14
import ntpath
15
15
16
DialogResult = False
16
GlobalResult = False
17
17
18
class IFormSettings(Form):
18
class IFormSettings(Form):
19
19
20
    def __init__(self, Title, Config, Folder=False, Credentials=False):
20
    def __init__(self, Title, Config, Folder=False, Credentials=False):
21
        self.Config = Config
21
        self.Config = Config
...
...
39
            self.FolderLabel.Width = 60
39
            self.FolderLabel.Width = 60
40
            self.FolderLabel.Parent = self
40
            self.FolderLabel.Parent = self
41
            
41
            
42
            self.FolderBox = TextBox()
42
            self.FolderBox = TextBox()
43
            self.FolderBox.Text = Config["folder"]
43
            self.FolderBox.Text = Config["folder"]
44
            self.FolderBox.Enabled = False
44
            self.FolderBox.Enabled = True
45
            self.FolderBox.Location = Point(60, y)
45
            self.FolderBox.Location = Point(60, y)
46
            self.FolderBox.Parent = self
46
            self.FolderBox.Parent = self
47
            self.FolderBox.Width = 300
47
            self.FolderBox.Width = 300
48
            
48
            
49
            self.FolderButton = Button()
49
            self.FolderButton = Button()
...
...
113
        dialog = OpenFileDialog()
113
        dialog = OpenFileDialog()
114
        dialog.Filter = "all files (*.*) |*.*"
114
        dialog.Filter = "all files (*.*) |*.*"
115
        dialog.ShowHelp = True
115
        dialog.ShowHelp = True
116
        dialog.ValidateNames = False;
116
        dialog.ValidateNames = False;
117
        dialog.CheckFileExists = False;
117
        dialog.CheckFileExists = False;
118
        dialog.CheckPathExists = True;
118
        dialog.CheckPathExists = False;
119
        dialog.FileName = "Folder Selection"
119
        dialog.FileName = "Folder Selection"
120
120
121
        if dialog.ShowDialog(self) == DialogResult.OK:
121
        if dialog.ShowDialog(self) == DialogResult.OK:
122
            folder, file = ntpath.split(dialog.FileName)
122
            folder, file = ntpath.split(dialog.FileName)
123
            print (self.FolderBox)
123
            self.FolderBox.Text = folder
124
            self.FolderBox.Text = folder
124
125
125
    def OnClickOK(self, sender, event):
126
    def OnClickOK(self, sender, event):
126
        global DialogResult
127
        global GlobalResult
127
        # Return content of form in config structure
128
        # Return content of form in config structure
128
        self.Config["folder"] = self.FolderBox.Text
129
        if hasattr(self, 'FolderBox'):
130
            self.Config["folder"] = self.FolderBox.Text
129
        self.Config["user"] = self.UserBox.Text
131
        if hasattr(self, 'UserBox'):
132
            self.Config["user"] = self.UserBox.Text
130
        self.Config["pass"] = self.PassBox.Text
133
        if hasattr(self, 'PassBox'):
134
            self.Config["pass"] = self.PassBox.Text
131
        DialogResult = True
135
        GlobalResult = True
132
        self.Dispose()
136
        self.Dispose()
133
137
134
    def OnClickCancel(self, sender, event):
138
    def OnClickCancel(self, sender, event):
135
        global DialogResult
139
        global GlobalResult
136
        # Discard form data, don't return it
140
        # Discard form data, don't return it
137
        DialogResult = False
141
        GlobalResult = False
138
        self.Dispose()
142
        self.Dispose()
139
        
143
        
140
       
144
       
141
def GetSettings():            
145
def GetSettings():            
142
    dirname = os.path.expanduser("~\\cforge")
146
    dirname = os.path.expanduser("~\\cforge")
...
...
156
    dirname = os.path.expanduser("~\\cforge")
160
    dirname = os.path.expanduser("~\\cforge")
157
    filename = dirname + "\\cache.json"
161
    filename = dirname + "\\cache.json"
158
    with open(filename, "w") as f:
162
    with open(filename, "w") as f:
159
        config = json.dump(config, f)
163
        config = json.dump(config, f)
160
    
164
    
161
def Dialog(Title, Folder=True, Credentials=True, DefaultFolder=""):            
165
def Dialog(Title, Folder=False, Credentials=False, DefaultFolder=""):            
162
    config = GetSettings()
166
    config = GetSettings()
163
        
167
        
164
    if DefaultFolder != "":
168
    if DefaultFolder != "":
165
        folder, file = ntpath.split(config['folder'])
169
        folder, file = ntpath.split(config['folder'])
166
        config['folder'] = os.path.join(folder, DefaultFolder)
170
        config['folder'] = os.path.join(folder, DefaultFolder)
167
171
168
    Application.Run(IFormSettings("Checkout", Folder=Folder, Credentials=Credentials, Config=config))
172
    Application.Run(IFormSettings(Title, Folder=Folder, Credentials=Credentials, Config=config))
169
    if DialogResult:
173
    if GlobalResult:
170
        SaveSettings(config)
174
        SaveSettings(config)
171
        return config
175
        return config
172
    else:
176
    else:
173
        return None
177
        return None
174
    
178