a/trunk/cforge/cforge/Package/CFORGE/Scripts/ui.py | b/trunk/cforge/cforge/Package/CFORGE/Scripts/ui.py | ||
---|---|---|---|
... |
... |
||
15 | 15 | ||
16 | GlobalResult = 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, Info=False, InfoText="", Message=False): |
20 | def __init__(self, Title, Config, Folder=False, Credentials=False, Info=False, InfoText="", Message=False, PkgName=False, PkgVendor=False, PkgCopyright=False, PkgDescription=False): |
21 | self.Config = Config |
21 | self.Config = Config |
22 | 22 | ||
23 | y = 0 |
23 | y = 0 |
24 | self.TitleLable = Label() |
24 | self.TitleLable = Label() |
25 | self.TitleLable.Text = Title |
25 | self.TitleLable.Text = Title |
26 | self.TitleLable.Parent = self |
26 | self.TitleLable.Parent = self |
27 | self.TitleLable.Height = 36 |
27 | self.TitleLable.Height = 36 |
28 | self.TitleLable.Font = Font("Arial", 24,FontStyle.Bold) |
28 | self.TitleLable.Font = Font("Arial", 24,FontStyle.Bold) |
29 | self.TitleLable.BackColor = Color.FromArgb(80,80,80) |
29 | self.TitleLable.BackColor = Color.FromArgb(80,80,80) |
30 | self.TitleLable.ForeColor = Color.FromArgb(255,255,255) |
30 | self.TitleLable.ForeColor = Color.FromArgb(255,255,255) |
31 | self.TitleLable.Dock = DockStyle.Top |
31 | self.TitleLable.Dock = DockStyle.Top |
32 | y += 42 |
32 | y += 42 |
33 | 33 | ||
34 | if Folder: |
34 | if Folder: |
35 | # Folder |
35 | # Folder |
36 | self.FolderLabel = Label() |
36 | self.FolderLabel = Label() |
37 | self.FolderLabel.Text = "Folder:" |
37 | self.FolderLabel.Text = "Folder:" |
38 | self.FolderLabel.Location = Point(0, y) |
38 | self.FolderLabel.Location = Point(0, y) |
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 | if "folder" in Config: |
44 | self.FolderBox.Enabled = True |
44 | self.FolderBox.Text = Config["folder"] |
45 | self.FolderBox.Location = Point(60, y) |
45 | self.FolderBox.Enabled = True |
46 | self.FolderBox.Parent = self |
46 | self.FolderBox.Location = Point(60, y) |
47 | self.FolderBox.Width = 300 |
47 | self.FolderBox.Parent = self |
48 | 48 | self.FolderBox.Width = 300 |
|
49 | self.FolderButton = Button() |
49 | |
50 | self.FolderButton.Click += self.OnClickBrowse |
50 | self.FolderButton = Button() |
51 | self.FolderButton.Text = "..." |
51 | self.FolderButton.Click += self.OnClickBrowse |
52 | self.FolderButton.Parent = self |
52 | self.FolderButton.Text = "..." |
53 | self.FolderButton.Location = Point(364, y) |
53 | self.FolderButton.Parent = self |
54 | y += 24 |
54 | self.FolderButton.Location = Point(364, y) |
55 | 55 | y += 24 |
|
56 | if Credentials: |
56 | |
57 | # Credentials |
57 | if Credentials: |
58 | self.UserLabel = Label() |
58 | # Credentials |
59 | self.UserLabel.Text = "Username:" |
59 | self.UserLabel = Label() |
60 | self.UserLabel.Location = Point(0, y) |
60 | self.UserLabel.Text = "Username:" |
61 | self.UserLabel.Width = 60 |
61 | self.UserLabel.Location = Point(0, y) |
62 | self.UserLabel.Parent = self |
62 | self.UserLabel.Width = 60 |
63 | 63 | self.UserLabel.Parent = self |
|
64 | self.UserBox = TextBox() |
64 | |
65 | self.UserBox.Text = Config["user"] |
65 | self.UserBox = TextBox() |
66 | self.UserBox.Enabled = True |
66 | if "user" in Config: |
67 | self.UserBox.Location = Point(60, y) |
67 | self.UserBox.Text = Config["user"] |
68 | self.UserBox.Parent = self |
68 | self.UserBox.Enabled = True |
69 | self.UserBox.Width = 300 |
69 | self.UserBox.Location = Point(60, y) |
70 | y += 24 |
70 | self.UserBox.Parent = self |
71 | 71 | self.UserBox.Width = 300 |
|
72 | self.PassLabel = Label() |
72 | y += 24 |
73 | self.PassLabel.Text = "Password:" |
73 | |
74 | self.PassLabel.Location = Point(0, y) |
74 | self.PassLabel = Label() |
75 | self.PassLabel.Width = 60 |
75 | self.PassLabel.Text = "Password:" |
76 | self.PassLabel.Parent = self |
76 | self.PassLabel.Location = Point(0, y) |
77 | 77 | self.PassLabel.Width = 60 |
|
78 | self.PassBox = TextBox() |
78 | self.PassLabel.Parent = self |
79 | self.PassBox.Text = Config["pass"] |
79 | |
80 | self.PassBox.Enabled = True |
80 | self.PassBox = TextBox() |
81 | self.PassBox.PasswordChar = "*" |
81 | if "pass" in Config: |
82 | self.PassBox.Location = Point(60, y) |
82 | self.PassBox.Text = Config["pass"] |
83 | self.PassBox.Parent = self |
83 | self.PassBox.Enabled = True |
84 | self.PassBox.Width = 300 |
84 | self.PassBox.PasswordChar = "*" |
85 | y += 24 |
85 | self.PassBox.Location = Point(60, y) |
86 | 86 | self.PassBox.Parent = self |
|
87 | if Info: |
87 | self.PassBox.Width = 300 |
88 | # Info Box |
88 | y += 24 |
89 | self.InfoLabel = Label() |
89 | |
90 | self.InfoLabel.Text = "Info:" |
90 | if Info: |
91 | self.InfoLabel.Location = Point(0, y) |
91 | # Info Box |
92 | self.InfoLabel.Width = 60 |
92 | self.InfoLabel = Label() |
93 | self.InfoLabel.Parent = self |
93 | self.InfoLabel.Text = "Info:" |
94 | y += 24 |
94 | self.InfoLabel.Location = Point(0, y) |
95 | 95 | self.InfoLabel.Width = 60 |
|
96 | self.InfoBox = TextBox() |
96 | self.InfoLabel.Parent = self |
97 | self.InfoBox.Text = InfoText |
97 | y += 24 |
98 | self.InfoBox.Enabled = False |
98 | |
99 | self.InfoBox.Location = Point(0, y) |
99 | self.InfoBox = TextBox() |
100 | self.InfoBox.Parent = self |
100 | self.InfoBox.Text = InfoText |
101 | self.InfoBox.WordWrap = False |
101 | self.InfoBox.Enabled = False |
102 | self.InfoBox.Multiline = True |
102 | self.InfoBox.Location = Point(0, y) |
103 | self.InfoBox.ScrollBars = ScrollBars.Horizontal | ScrollBars.Vertical |
103 | self.InfoBox.Parent = self |
104 | self.InfoBox.Width = 360 |
104 | self.InfoBox.WordWrap = False |
105 | self.InfoBox.Height = 260 |
105 | self.InfoBox.Multiline = True |
106 | y += 280 |
106 | self.InfoBox.ScrollBars = ScrollBars.Horizontal | ScrollBars.Vertical |
107 | 107 | self.InfoBox.Width = 360 |
|
108 | if Message: |
108 | self.InfoBox.Height = 260 |
109 | # Message |
109 | y += 280 |
110 | self.MessageLabel = Label() |
110 | |
111 | self.MessageLabel.Text = "Message:" |
111 | if Message: |
112 | self.MessageLabel.Location = Point(0, y) |
112 | # Message |
113 | self.MessageLabel.Width = 60 |
113 | self.MessageLabel = Label() |
114 | self.MessageLabel.Parent = self |
114 | self.MessageLabel.Text = "Message:" |
115 | y += 24 |
115 | self.MessageLabel.Location = Point(0, y) |
116 | 116 | self.MessageLabel.Width = 60 |
|
117 | self.MessageBox = TextBox() |
117 | self.MessageLabel.Parent = self |
118 | self.MessageBox.Text = "Enter Message..." |
118 | y += 24 |
119 | if Config["msg"] != "": |
119 | |
120 | self.MessageBox.Text = Config["msg"] |
120 | self.MessageBox = TextBox() |
121 | self.MessageBox.Enabled = True |
121 | self.MessageBox.Text = "Enter Message..." |
122 | self.MessageBox.Location = Point(0, y) |
122 | if "msg" in Config and Config["msg"] != "": |
123 | self.MessageBox.Parent = self |
123 | self.MessageBox.Text = Config["msg"] |
124 | self.MessageBox.WordWrap = False |
124 | self.MessageBox.Enabled = True |
125 | self.MessageBox.Multiline = True |
125 | self.MessageBox.Location = Point(0, y) |
126 | self.MessageBox.AcceptsReturn = True |
126 | self.MessageBox.Parent = self |
127 | self.MessageBox.ScrollBars = ScrollBars.Horizontal | ScrollBars.Vertical |
127 | self.MessageBox.WordWrap = False |
128 | self.MessageBox.Width = 360 |
128 | self.MessageBox.Multiline = True |
129 | self.MessageBox.Height = 160 |
129 | self.MessageBox.AcceptsReturn = True |
130 | y += 180 |
130 | self.MessageBox.ScrollBars = ScrollBars.Horizontal | ScrollBars.Vertical |
131 | 131 | self.MessageBox.Width = 360 |
|
132 | # OK / Cancel Button |
132 | self.MessageBox.Height = 160 |
133 | self.AcceptButton = Button() |
133 | y += 180 |
134 | self.AcceptButton.Click += self.OnClickOK |
134 | |
135 | self.AcceptButton.Text = "OK" |
135 | if PkgName: |
136 | self.AcceptButton.Parent = self |
136 | # Name |
137 | self.AcceptButton.Location = Point(364, y) |
137 | self.PkgNameLabel = Label() |
138 | self.AcceptButton.Select() |
138 | self.PkgNameLabel.Text = "Name:" |
139 | 139 | self.PkgNameLabel.Location = Point(0, y) |
|
140 | self.CancelButton = Button() |
140 | self.PkgNameLabel.Width = 60 |
141 | self.CancelButton.Click += self.OnClickCancel |
141 | self.PkgNameLabel.Parent = self |
142 | self.CancelButton.Text = "Cancel" |
142 | |
143 | self.CancelButton.Parent = self |
143 | self.PkgNameBox = TextBox() |
144 | self.CancelButton.Location = Point(0, y) |
144 | if "PkgName" in Config: |
145 | 145 | self.PkgNameBox.Text = Config["PkgName"] |
|
146 | y += 24 |
146 | self.PkgNameBox.Enabled = True |
147 | 147 | self.PkgNameBox.Location = Point(60, y) |
|
148 | # Self (Dialog) |
148 | self.PkgNameBox.Parent = self |
149 | self.Width = 458 |
149 | self.PkgNameBox.Width = 300 |
150 | self.Height = y + 50 |
150 | y += 24 |
151 | self.Text = "cforge - " + Title |
151 | |
152 | workingdir = os.path.dirname(sys.argv[0]) |
152 | if PkgVendor: |
153 | self.Icon = Icon(os.path.join(workingdir, "icon.ico")) |
153 | # Name |
154 | 154 | self.PkgVendorLabel = Label() |
|
155 | self.CenterToScreen() |
155 | self.PkgVendorLabel.Text = "Vendor:" |
156 | 156 | self.PkgVendorLabel.Location = Point(0, y) |
|
157 | def OnClickBrowse(self, sender, event): |
157 | self.PkgVendorLabel.Width = 60 |
158 | dialog = OpenFileDialog() |
158 | self.PkgVendorLabel.Parent = self |
159 | dialog.Filter = "all files (*.*) |*.*" |
159 | |
160 | dialog.ShowHelp = True |
160 | self.PkgVendorBox = TextBox() |
161 | dialog.ValidateNames = False; |
161 | self.PkgVendorBox.Text = "Open Source Software" |
162 | dialog.CheckFileExists = False; |
162 | if "PkgVendor" in Config and Config["PkgVendor"] != "": |
163 | dialog.CheckPathExists = False; |
163 | self.PkgVendorBox.Text = Config["PkgVendor"] |
164 | dialog.FileName = "Folder Selection" |
164 | self.PkgVendorBox.Enabled = True |
165 | 165 | self.PkgVendorBox.Location = Point(60, y) |
|
166 | if dialog.ShowDialog(self) == DialogResult.OK: |
166 | self.PkgVendorBox.Parent = self |
167 | folder, file = ntpath.split(dialog.FileName) |
167 | self.PkgVendorBox.Width = 300 |
168 | print (self.FolderBox) |
168 | y += 24 |
169 | self.FolderBox.Text = folder |
169 | |
170 | 170 | if PkgCopyright: |
|
171 | def OnClickOK(self, sender, event): |
171 | # Name |
172 | global GlobalResult |
172 | self.PkgCopyrightLabel = Label() |
173 | # Return content of form in config structure |
173 | self.PkgCopyrightLabel.Text = "Copyright:" |
174 | if hasattr(self, 'FolderBox'): |
174 | self.PkgCopyrightLabel.Location = Point(0, y) |
175 | self.Config["folder"] = self.FolderBox.Text |
175 | self.PkgCopyrightLabel.Width = 60 |
176 | if hasattr(self, 'UserBox'): |
176 | self.PkgCopyrightLabel.Parent = self |
177 | self.Config["user"] = self.UserBox.Text |
177 | |
178 | if hasattr(self, 'PassBox'): |
178 | self.PkgCopyrightBox = TextBox() |
179 | self.Config["pass"] = self.PassBox.Text |
179 | self.PkgCopyrightBox.Text = "all rights reserved" |
180 | if hasattr(self, 'MessageBox'): |
180 | if "PkgCopyright" in Config and Config["PkgCopyright"] != "": |
181 | self.Config["msg"] = self.MessageBox.Text |
181 | self.PkgCopyrightBox.Text = Config["PkgCopyright"] |
182 | GlobalResult = True |
182 | self.PkgCopyrightBox.Enabled = True |
183 | self.Dispose() |
183 | self.PkgCopyrightBox.Location = Point(60, y) |
184 | 184 | self.PkgCopyrightBox.Parent = self |
|
185 | def OnClickCancel(self, sender, event): |
185 | self.PkgCopyrightBox.Width = 300 |
186 | global GlobalResult |
186 | y += 24 |
187 | # Discard form data, don't return it |
187 | |
188 | GlobalResult = False |
188 | if PkgDescription: |
189 | self.Dispose() |
189 | # Name |
190 | 190 | self.PkgDescriptionLabel = Label() |
|
191 | 191 | self.PkgDescriptionLabel.Text = "Descr.:" |
|
192 | def GetSettings(): |
192 | self.PkgDescriptionLabel.Location = Point(0, y) |
193 | dirname = os.path.expanduser("~\\cforge") |
193 | self.PkgDescriptionLabel.Width = 60 |
194 | filename = dirname + "\\cache.json" |
194 | self.PkgDescriptionLabel.Parent = self |
195 | config = { 'folder' : dirname, 'user' : os.environ["USERNAME"], 'pass' : '', 'msg' : ''} |
195 | |
196 | if not os.path.isfile(filename): |
196 | self.PkgDescriptionBox = TextBox() |
197 | if not os.path.isdir(dirname): |
197 | if "PkgDescription" in Config: |
198 | os.mkdir(dirname) |
198 | self.PkgDescriptionBox.Text = Config["PkgDescription"] |
199 | with open(filename, "w") as f: |
199 | self.PkgDescriptionBox.Enabled = True |
200 | config = json.dump(config, f) |
200 | self.PkgDescriptionBox.Location = Point(60, y) |
201 | with open(filename) as f: |
201 | self.PkgDescriptionBox.Parent = self |
202 | config = json.load(f) |
202 | self.PkgDescriptionBox.Width = 300 |
203 | 203 | y += 24 |
|
204 | return config |
204 | |
205 | 205 | # OK / Cancel Button |
|
206 | def SaveSettings(config): |
206 | self.AcceptButton = Button() |
207 | dirname = os.path.expanduser("~\\cforge") |
207 | self.AcceptButton.Click += self.OnClickOK |
208 | filename = dirname + "\\cache.json" |
208 | self.AcceptButton.Text = "OK" |
209 | with open(filename, "w") as f: |
209 | self.AcceptButton.Parent = self |
210 | config = json.dump(config, f) |
210 | self.AcceptButton.Location = Point(364, y) |
211 | 211 | self.AcceptButton.Select() |
|
212 | def Dialog(Title, Folder=False, Credentials=False, DefaultFolder="", Info=False, InfoText="", Message=False): |
212 | |
213 | config = GetSettings() |
213 | self.CancelButton = Button() |
214 | 214 | self.CancelButton.Click += self.OnClickCancel |
|
215 | if DefaultFolder != "": |
215 | self.CancelButton.Text = "Cancel" |
216 | folder, file = ntpath.split(config['folder']) |
216 | self.CancelButton.Parent = self |
217 | config['folder'] = os.path.join(folder, DefaultFolder) |
217 | self.CancelButton.Location = Point(0, y) |
218 | 218 | ||
219 | Application.Run(IFormSettings(Title, Folder=Folder, Credentials=Credentials, Info=Info, InfoText=InfoText, Message=Message, Config=config)) |
219 | y += 24 |
220 | |||
221 | # Self (Dialog) |
||
222 | self.Width = 458 |
||
223 | self.Height = y + 50 |
||
224 | self.Text = "cforge - " + Title |
||
225 | workingdir = os.path.dirname(sys.argv[0]) |
||
226 | self.Icon = Icon(os.path.join(workingdir, "icon.ico")) |
||
227 | |||
228 | self.CenterToScreen() |
||
229 | |||
230 | def OnClickBrowse(self, sender, event): |
||
231 | dialog = OpenFileDialog() |
||
232 | dialog.Filter = "all files (*.*) |*.*" |
||
233 | dialog.ShowHelp = True |
||
234 | dialog.ValidateNames = False; |
||
235 | dialog.CheckFileExists = False; |
||
236 | dialog.CheckPathExists = False; |
||
237 | dialog.FileName = "Folder Selection" |
||
238 | |||
239 | if dialog.ShowDialog(self) == DialogResult.OK: |
||
240 | folder, file = ntpath.split(dialog.FileName) |
||
241 | print (self.FolderBox) |
||
242 | self.FolderBox.Text = folder |
||
243 | |||
244 | def OnClickOK(self, sender, event): |
||
245 | global GlobalResult |
||
246 | # Return content of form in config structure |
||
247 | if hasattr(self, 'FolderBox'): |
||
248 | self.Config["folder"] = self.FolderBox.Text |
||
249 | if hasattr(self, 'UserBox'): |
||
250 | self.Config["user"] = self.UserBox.Text |
||
251 | if hasattr(self, 'PassBox'): |
||
252 | self.Config["pass"] = self.PassBox.Text |
||
253 | if hasattr(self, 'MessageBox'): |
||
254 | self.Config["msg"] = self.MessageBox.Text |
||
255 | if hasattr(self, 'PkgNameBox'): |
||
256 | self.Config["PkgName"] = self.PkgNameBox.Text |
||
257 | if hasattr(self, 'PkgVendorBox'): |
||
258 | self.Config["PkgVendor"] = self.PkgVendorBox.Text |
||
259 | if hasattr(self, 'PkgCopyrightBox'): |
||
260 | self.Config["PkgCopyright"] = self.PkgCopyrightBox.Text |
||
261 | if hasattr(self, 'PkgDescriptionBox'): |
||
262 | self.Config["PkgDescription"] = self.PkgDescriptionBox.Text |
||
263 | GlobalResult = True |
||
264 | self.Dispose() |
||
265 | |||
266 | def OnClickCancel(self, sender, event): |
||
267 | global GlobalResult |
||
268 | # Discard form data, don't return it |
||
269 | GlobalResult = False |
||
270 | self.Dispose() |
||
271 | |||
272 | |||
273 | def GetSettings(): |
||
274 | dirname = os.path.expanduser("~\\cforge") |
||
275 | filename = dirname + "\\cache.json" |
||
276 | config = { 'folder' : dirname, 'user' : os.environ["USERNAME"], 'pass' : '', 'msg' : ''} |
||
277 | if not os.path.isfile(filename): |
||
278 | if not os.path.isdir(dirname): |
||
279 | os.mkdir(dirname) |
||
280 | with open(filename, "w") as f: |
||
281 | config = json.dump(config, f) |
||
282 | with open(filename) as f: |
||
283 | config = json.load(f) |
||
284 | |||
285 | return config |
||
286 | |||
287 | def SaveSettings(config): |
||
288 | dirname = os.path.expanduser("~\\cforge") |
||
289 | filename = dirname + "\\cache.json" |
||
290 | with open(filename, "w") as f: |
||
291 | config = json.dump(config, f) |
||
292 | |||
293 | def Dialog(Title, Folder=False, Credentials=False, DefaultFolder="", Info=False, InfoText="", Message=False, PkgName=False, PkgVendor=False, PkgCopyright=False, PkgDescription=False): |
||
294 | config = GetSettings() |
||
295 | |||
296 | if DefaultFolder != "": |
||
297 | folder, file = ntpath.split(config['folder']) |
||
298 | config['folder'] = os.path.join(folder, DefaultFolder) |
||
299 | |||
300 | Application.Run(IFormSettings(Title, Folder=Folder, Credentials=Credentials, Info=Info, InfoText=InfoText, Message=Message, Config=config, PkgName=PkgName, PkgVendor=PkgVendor, PkgCopyright=PkgCopyright, PkgDescription=PkgDescription)) |
||
220 | if GlobalResult: |
301 | if GlobalResult: |
221 | SaveSettings(config) |
302 | SaveSettings(config) |
222 | return config |
303 | return config |
223 | else: |
304 | else: |
224 | return None |
305 | return None |