ProjectFlask/Project.py

changeset 13
ed33cdfca13d
parent 12
68ee221cd0cb
child 14
d2da14b2a233
equal deleted inserted replaced
12:68ee221cd0cb 13:ed33cdfca13d
10 import os 10 import os
11 11
12 from PyQt5.QtCore import ( 12 from PyQt5.QtCore import (
13 pyqtSlot, QObject, QProcess, QProcessEnvironment, QTimer 13 pyqtSlot, QObject, QProcess, QProcessEnvironment, QTimer
14 ) 14 )
15 from PyQt5.QtWidgets import QMenu 15 from PyQt5.QtWidgets import QMenu, QDialog
16 16
17 from E5Gui import E5MessageBox 17 from E5Gui import E5MessageBox
18 from E5Gui.E5Action import E5Action 18 from E5Gui.E5Action import E5Action
19 from E5Gui.E5Application import e5App 19 from E5Gui.E5Application import e5App
20 20
21 from Globals import isWindowsPlatform 21 from Globals import isWindowsPlatform
22 22
23 import UI.PixmapCache 23 import UI.PixmapCache
24 import Utilities 24 import Utilities
25
26 from .RunServerDialog import RunServerDialog
27 from .RoutesDialog import RoutesDialog
28 from .FlaskCommandDialog import FlaskCommandDialog
29 25
30 26
31 class Project(QObject): 27 class Project(QObject):
32 """ 28 """
33 Class implementing the Flask project support. 29 Class implementing the Flask project support.
178 )) 174 ))
179 self.initDatabaseAct.triggered.connect(self.__initDatabase) 175 self.initDatabaseAct.triggered.connect(self.__initDatabase)
180 self.actions.append(self.initDatabaseAct) 176 self.actions.append(self.initDatabaseAct)
181 177
182 ################################## 178 ##################################
179 ## database action below ##
180 ##################################
181
182 self.pybabelConfigAct = E5Action(
183 self.tr('Configure PyBabel'),
184 self.tr('Configure Py&Babel'),
185 0, 0,
186 self, 'flask_config_pybabel')
187 self.pybabelConfigAct.setStatusTip(self.tr(
188 'Shows a dialog to edit the configuration for pybabel'))
189 self.pybabelConfigAct.setWhatsThis(self.tr(
190 """<b>Configure PyBabel</b>"""
191 """<p>Shows a dialog to edit the configuration for pybabel.</p>"""
192 ))
193 self.pybabelConfigAct.triggered.connect(self.__configurePybabel)
194 self.actions.append(self.pybabelConfigAct)
195
196 ##################################
183 ## documentation action below ## 197 ## documentation action below ##
184 ################################## 198 ##################################
185 199
186 self.documentationAct = E5Action( 200 self.documentationAct = E5Action(
187 self.tr('Documentation'), 201 self.tr('Documentation'),
235 menu.addAction(self.runPythonShellAct) 249 menu.addAction(self.runPythonShellAct)
236 menu.addSection("flask routes") 250 menu.addSection("flask routes")
237 menu.addAction(self.showRoutesAct) 251 menu.addAction(self.showRoutesAct)
238 menu.addSection("flask init-db") 252 menu.addSection("flask init-db")
239 menu.addAction(self.initDatabaseAct) 253 menu.addAction(self.initDatabaseAct)
254 menu.addSection(self.tr("Translations"))
255 menu.addAction(self.pybabelConfigAct)
240 menu.addSection(self.tr("Various")) 256 menu.addSection(self.tr("Various"))
241 menu.addAction(self.documentationAct) 257 menu.addAction(self.documentationAct)
242 menu.addSeparator() 258 menu.addSeparator()
243 menu.addAction(self.aboutFlaskAct) 259 menu.addAction(self.aboutFlaskAct)
244 260
579 "PROJECTTYPESPECIFICDATA", category) 595 "PROJECTTYPESPECIFICDATA", category)
580 if data is not None: 596 if data is not None:
581 self.__projectData[category] = data 597 self.__projectData[category] = data
582 598
583 data = self.__projectData[category] 599 data = self.__projectData[category]
584 if key in data: 600 if not key:
601 # return complete category dictionary
602 return data
603 elif key in data:
604 # return individual entry
585 return data[key] 605 return data[key]
586 else: 606 else:
607 # failure
587 return None 608 return None
588 609
589 def setData(self, category, key, value): 610 def setData(self, category, key, value):
590 """ 611 """
591 Public method to store data in the project store. 612 Public method to store data in the project store.
604 data = self.__e5project.getData( 625 data = self.__e5project.getData(
605 "PROJECTTYPESPECIFICDATA", category) 626 "PROJECTTYPESPECIFICDATA", category)
606 if data is not None: 627 if data is not None:
607 self.__projectData[category] = data 628 self.__projectData[category] = data
608 629
609 self.__projectData[category][key] = value 630 if not key:
631 # update the complete category
632 self.__projectData[category] = value
633 else:
634 # update individual entry
635 self.__projectData[category][key] = value
610 636
611 self.__e5project.setData( 637 self.__e5project.setData(
612 "PROJECTTYPESPECIFICDATA", category, self.__projectData[category]) 638 "PROJECTTYPESPECIFICDATA", category, self.__projectData[category])
613 639
614 ################################################################## 640 ##################################################################
632 Private slot to start the Flask Web server. 658 Private slot to start the Flask Web server.
633 659
634 @param development flag indicating development mode 660 @param development flag indicating development mode
635 @type bool 661 @type bool
636 """ 662 """
663 from .RunServerDialog import RunServerDialog
664
637 if self.__serverDialog is not None: 665 if self.__serverDialog is not None:
638 self.__serverDialog.close() 666 self.__serverDialog.close()
639 667
640 askForOptions = self.askForServerOptionsAct.isChecked() 668 askForOptions = self.askForServerOptionsAct.isChecked()
641 dlg = RunServerDialog(self.__plugin, self) 669 dlg = RunServerDialog(self.__plugin, self)
707 @pyqtSlot() 735 @pyqtSlot()
708 def __showRoutes(self): 736 def __showRoutes(self):
709 """ 737 """
710 Private slot showing all URL dispatch routes. 738 Private slot showing all URL dispatch routes.
711 """ 739 """
740 from .RoutesDialog import RoutesDialog
741
712 if self.__routesDialog is not None: 742 if self.__routesDialog is not None:
713 self.__routesDialog.close() 743 self.__routesDialog.close()
714 744
715 dlg = RoutesDialog(self) 745 dlg = RoutesDialog(self)
716 if dlg.showRoutes(): 746 if dlg.showRoutes():
720 @pyqtSlot() 750 @pyqtSlot()
721 def __initDatabase(self): 751 def __initDatabase(self):
722 """ 752 """
723 Private slot showing the result of the database creation. 753 Private slot showing the result of the database creation.
724 """ 754 """
755 from .FlaskCommandDialog import FlaskCommandDialog
756
725 dlg = FlaskCommandDialog(self) 757 dlg = FlaskCommandDialog(self)
726 if dlg.startCommand("init-db"): 758 if dlg.startCommand("init-db"):
727 dlg.exec() 759 dlg.exec()
728 760
729 ################################################################## 761 ##################################################################
750 if finished and proc.exitCode() == 0: 782 if finished and proc.exitCode() == 0:
751 return True 783 return True
752 784
753 return False 785 return False
754 786
787 @pyqtSlot()
788 def __configurePybabel(self):
789 """
790 Private slot to show a dialog to edit the pybabel configuration.
791 """
792 # TODO: implement this
793 from .PyBabelConfigDialog import PyBabelConfigDialog
794
795 config = self.getData("pybabel", "")
796 dlg = PyBabelConfigDialog(config)
797 if dlg.exec() == QDialog.Accepted:
798 config = dlg.getConfiguration()
799 self.setData("pybabel", "", config)
800
801 if not os.path.exists(config["configFile"]):
802 self.__createBabelCfg(config["configFile"])
803
804 def __createBabelCfg(self, configFile):
805 """
806 Private method to create a template pybabel configuration file.
807 """
808 template = (
809 "[python: {0}/**.py]\n"
810 "[jinja2: {0}/templates/**.html]\n"
811 "extensions=jinja2.ext.autoescape,jinja2.ext.with_\n"
812 )
813 # TODO: determine app name and write file
814
755 def __projectLanguageAdded(self, code): 815 def __projectLanguageAdded(self, code):
756 # TODO: implement this with pybabel ... 816 # TODO: implement this with pybabel ...
757 pass 817 pass
758 818
759 def openPOEditor(self): 819 def openPOEditor(self):

eric ide

mercurial