ProjectDjango/Project.py

branch
eric7
changeset 202
b06794ae2a92
parent 197
2667e16a3379
child 203
07abb6af9048
equal deleted inserted replaced
201:9407d05d4109 202:b06794ae2a92
31 from UI import PixmapCache as EricPixmapCache 31 from UI import PixmapCache as EricPixmapCache
32 32
33 from eric7.EricGui.EricAction import EricAction 33 from eric7.EricGui.EricAction import EricAction
34 from eric7.EricWidgets import EricFileDialog, EricMessageBox 34 from eric7.EricWidgets import EricFileDialog, EricMessageBox
35 from eric7.EricWidgets.EricApplication import ericApp 35 from eric7.EricWidgets.EricApplication import ericApp
36 from eric7.EricWidgets.EricComboSelectionDialog import EricComboSelectionDialog
36 37
37 try: 38 try:
38 from eric7.SystemUtilities.OSUtilities import isWindowsPlatform 39 from eric7.SystemUtilities.OSUtilities import isWindowsPlatform
39 except ImportError: 40 except ImportError:
40 # imports for eric < 23.1 41 # imports for eric < 23.1
1261 None, 1262 None,
1262 EricFileDialog.DontConfirmOverwrite, 1263 EricFileDialog.DontConfirmOverwrite,
1263 ) 1264 )
1264 1265
1265 if not fname: 1266 if not fname:
1266 # user aborted or didn't enter a filename 1267 # user aborted or did not enter a filename
1267 return 1268 return
1268 1269
1269 ext = QFileInfo(fname).suffix() 1270 ext = QFileInfo(fname).suffix()
1270 if not ext: 1271 if not ext:
1271 ex = selectedFilter.split("(*")[1].split(")")[0] 1272 ex = selectedFilter.split("(*")[1].split(")")[0]
1282 1283
1283 if not res: 1284 if not res:
1284 # user selected to not overwrite 1285 # user selected to not overwrite
1285 return 1286 return
1286 1287
1287 try: 1288 templateTypes = [
1288 with open(fname, "w") as f: 1289 (self.tr("Base Template"), "base"),
1289 f.write("<!DOCTYPE html>") 1290 (self.tr("Extending Template"), "extend"),
1290 f.write("<html>\n") 1291 (self.tr("Standalone Template"), "standalone"),
1291 f.write(" <head>\n") 1292 (self.tr("Empty Template"), "empty"),
1292 f.write(' <meta content="" />\n') 1293 ]
1293 f.write(" <title></title>\n") 1294 dlg = EricComboSelectionDialog(
1294 f.write(' <link rel="stylesheet" type="text/css" href="style.css"/>') 1295 templateTypes,
1295 f.write(" <!--[if lte IE 7]>") 1296 title=self.tr("New Form"),
1296 f.write(' <link rel="stylesheet" type="text/css" href="ie.css"/>') 1297 message=self.tr("Select a template type:"),
1297 f.write(" <![endif]-->") 1298 parent=self.__ui,
1298 f.write(" </head>\n") 1299 )
1299 f.write("\n") 1300 if dlg.exec() == QDialog.DialogCode.Accepted:
1300 f.write(' <body class="bodyclass">\n') 1301 selectedType = dlg.getSelection()[1] # only the type is needed
1301 f.write(' <div id="container">') 1302
1302 f.write(" </div>") 1303 try:
1303 f.write(" </body>\n") 1304 with open(fname, "w") as f:
1304 f.close() 1305 if selectedType == "base":
1305 f.write("</html>\n") 1306 f.write(
1306 except OSError as e: 1307 """{% load static %}
1307 EricMessageBox.critical( 1308
1308 self.__ui, 1309 <!DOCTYPE html>
1309 self.tr("New Form"), 1310 <html>
1310 self.tr( 1311 <head>
1311 "<p>The new form file <b>{0}</b> could not be" 1312 <title>{% block title %}{% endblock %}</title>
1312 " created.<br> Problem: {1}</p>" 1313 <link href="{% static "css/style.css" %}" rel="stylesheet" type="text/css" />
1313 ).format(fname, str(e)), 1314 </head>
1314 ) 1315
1315 return 1316 <body class="bodyclass">
1316 1317 <div id="content">
1317 self.__ericProject.appendFile(fname) 1318 {% block content %}
1318 self.__formsBrowser.sourceFile.emit(fname) 1319 {% endblock %}
1320 </div>
1321 <div id="sidebar">
1322 </div>
1323 </body>
1324 </html>
1325 """
1326 )
1327
1328 elif selectedType == "extend":
1329 f.write(
1330 """{% extends "base.html" %}
1331
1332 {% block title %}{% endblock %}
1333
1334 {% block content %}
1335 {% endblock %}
1336 """
1337 )
1338
1339 elif selectedType == "standalone":
1340 f.write(
1341 """<!DOCTYPE html>
1342 <html>
1343 <head>
1344 <meta content="" />
1345 <title></title>
1346 <link href="style.css" rel="stylesheet" type="text/css" />
1347 </head>
1348
1349 <body class="bodyclass">
1350 <div id="content">
1351 </div>
1352 </body>
1353 </html>
1354 """
1355 )
1356 elif selectedType == "empty":
1357 f.write("\n")
1358 except OSError as e:
1359 EricMessageBox.critical(
1360 self.__ui,
1361 self.tr("New Form"),
1362 self.tr(
1363 "<p>The new form file <b>{0}</b> could not be"
1364 " created.<br> Problem: {1}</p>"
1365 ).format(fname, str(e)),
1366 )
1367 return
1368
1369 self.__ericProject.appendFile(fname)
1370 self.__formsBrowser.sourceFile.emit(fname)
1319 1371
1320 ################################################################## 1372 ##################################################################
1321 ## slots below implement general functionality 1373 ## slots below implement general functionality
1322 ################################################################## 1374 ##################################################################
1323 1375

eric ide

mercurial