Exemple #1
0
 def OnNewProject(self, event):
     if Core.getInstance().project:
         wx.MessageBox('There already is a project (%s)' % Core.getInstance().project.name, 'New project', wx.OK | wx.ICON_INFORMATION, self)
     else:
         Core.getInstance().project = Project()
         Core.getInstance().project.name = 'New project'
         self.__GetTree().Populate()
Exemple #2
0
 def OnClose(self, event):
     if Core.getInstance().project and Core.getInstance().project.modified:
         dlg = wx.MessageDialog(self,
                                '%s has been modified. Shall it be saved?' % Core.getInstance().project.name,
                                'Quitting' ,
                                wx.YES_NO | wx.YES_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION)
         ret = dlg.ShowModal()
         if ret == wx.ID_YES:
             self.OnSaveProject(None)
             self.Destroy()
         elif ret == wx.ID_NO:
             self.Destroy()
         else:
             pass
     else:
         self.Destroy()
Exemple #3
0
 def getHTML(self):
     global default_template
     parser = etree.XMLTreeBuilder()
     self.__addXhtmlEntitiesToParser(parser)
     template_path = self.__template_path
     if not template_path: template_path = Core.getInstance().project.xhtml_template
     if template_path and os.path.exists(template_path):
         fd = open(template_path, 'r')
         try:
             parser.feed(fd.read())
             fd.close()
         except:
             fd.close()
             raise
     else:
         parser.feed(default_template)
     html = parser.close()
     return etree.ElementTree(html)
Exemple #4
0
 def OnSaveProject(self, event):
     if not Core.getInstance().project:
         wx.MessageBox('Nothing to save', 'Save project', wx.OK | wx.ICON_INFORMATION, self)
     else:
         if not Core.getInstance().project.filename:
             dlg = wx.FileDialog(self,
                                 message="Choose a file",
                                 defaultDir=os.getcwd(),
                                 defaultFile="",
                                 wildcard="GalGen project file (*.ggp)|*.ggp|All files (*.*)|*.*",
                                 style=wx.SAVE | wx.CHANGE_DIR)
             if dlg.ShowModal() != wx.ID_OK: return
             Core.getInstance().project.filename = dlg.GetPath()
         self.__CreateBackup(Core.getInstance().project.filename)
         fd = codecs.open(Core.getInstance().project.filename, 'w', 'utf-8')
         Core.getInstance().project.save(fd)
         fd.close()
Exemple #5
0
 def OnOpenProject(self, event):
     if Core.getInstance().project and Core.getInstance().project.modified:
         wx.MessageBox('%s has changes - save or close it' % Core.getInstance().project.name, 'Open project', wx.OK | wx.ICON_ERROR, self)
     else:
         dlg = wx.FileDialog(self,
                             message="Choose a file",
                             defaultDir=os.getcwd(),
                             defaultFile="",
                             wildcard="GalGen project file (*.ggp)|*.ggp|All files (*.*)|*.*",
                             style=wx.OPEN | wx.CHANGE_DIR)
         if dlg.ShowModal() == wx.ID_OK:
             Core.getInstance().project = Project(dlg.GetPath())
             Core.getInstance().project.load()
             self.__GetTree().Populate()
Exemple #6
0
 def OnGenerateOutput(self, event):
     project = Core.getInstance().project
     if not project:
         wx.MessageBox('Nothing to generate', 'Save project', wx.OK | wx.ICON_INFORMATION, self)
     else:
         target_dir_path = self.__GetTargetDir()
         if target_dir_path: #and not os.listdir(target_dir_path):
             progress_dialog = GenerationProgressDialog(project.getPageCount(), self)
             try:
                 generated = project.generateOutput(target_dir_path, progress_dialog, 0)
                 if generated != project.getPageCount():
                     raise Exception, 'Unexpected: generated %d pages, while expected to generate %d' % (generated, project.getPageCount())
             except:
                 progress_dialog.destroy()
                 raise
         else:
             dlg = wx.MessageDialog(self, 'You have to select an empty target directory!',
                                    'Generate output',
                                    wx.OK | wx.ICON_ERROR)
             dlg.ShowModal()
Exemple #7
0
 def Populate(self, selected_element = None):
     if not selected_element:
         selection = self.GetSelection()
         if selection.IsOk():
             selected_element = self.GetItemPyData(selection).element
     if self.__root_id:
         self.__UnsubscribeObservers(self.__root_id)
     self.DeleteAllItems()
     project = Core.getInstance().project
     if project:
         self.__root_id = self.AddRoot(project.name)
         self.__object_to_id[project] = self.__root_id
         item = TreeItem(self, project, self.__root_id)
         self.SetItemPyData(self.__root_id, item)
         self.SetItemImage(self.__root_id, self.__folder_img, wx.TreeItemIcon_Normal)
         self.SetItemImage(self.__root_id, self.__folder_open_img, wx.TreeItemIcon_Expanded)
         self.__AddChildren(self.__root_id)
     self.__RestoreExpansionState(self.__root_id)
     if selected_element:
         self.SelectItem(self.__object_to_id[selected_element])
Exemple #8
0
def main(project_file):
    if project_file:
        project = Project(project_file)
        project.load()
        Core.getInstance().project = project
    startGui()