def _buildHtml(self): def getTextFromWord(word): return self.wikiDocument.getWikiPage(word).getLiveText() exporterInstance = PluginManager.getExporterTypeDict( self.mainControl, False)[u"html_single"][0](self.mainControl) # TODO Progress handler # TODO Set additional options exporterInstance.setJobData(self.wikiDocument, self.wordList, u"html_previewWK", None, False, exporterInstance.getAddOpt(None), progressHandler=None) self.tempFileSet = TempFileSet() exporterInstance.tempFileSet = self.tempFileSet exporterInstance.styleSheet = u"" htpath = self.tempFileSet.createTempFile( u"", ".html", relativeTo="").decode("latin-1") realfp = StringIO.StringIO() with open(htpath, "w") as realfp: exporterInstance.exportHtmlMultiFile(realfp=realfp, tocMode=0) return htpath # realfp.getvalue().decode("utf-8")
def _buildHtml(self): def getTextFromWord(word): return self.wikiDocument.getWikiPage(word).getLiveText() exporterInstance = PluginManager.getExporterTypeDict( self.mainControl, False)["html_single"][0](self.mainControl) # TODO Progress handler # TODO Set additional options exporterInstance.setJobData(self.wikiDocument, self.wordList, "html_previewWX", None, False, exporterInstance.getAddOpt(None), progressHandler=None) self.tempFileSet = TempFileSet() exporterInstance.tempFileSet = self.tempFileSet exporterInstance.styleSheet = "" realfp = BytesIO() exporterInstance.exportHtmlMultiFile(realfp=realfp, tocMode=0) return realfp.getvalue().decode("utf-8")
def __init__(self, presenter, parent, ID, mode="relation graph/dot"): wx.html.HtmlWindow.__init__(self, parent, ID) self.presenter = presenter self.graphDotHandler = DotHandler(wx.GetApp()) self.graphDotHandler.findExe() self.visible = False self.outOfSync = True self.tempFileSet = TempFileSet() self._updateTempFilePrefPath() self.mode = mode wx.EVT_MENU(self, GUI_ID.CMD_CLIPBOARD_COPY, self.OnClipboardCopy)
def _buildHtml(self): def getTextFromWord(word): return self.wikiDocument.getWikiPage(word).getLiveText() exporterInstance = PluginManager.getExporterTypeDict( self.mainControl, False)["html_single"][0](self.mainControl) # TODO Progress handler # TODO Set additional options exporterInstance.setJobData(self.wikiDocument, self.wordList, "html_previewWK", None, False, exporterInstance.getAddOpt(None), progressHandler=None) self.tempFileSet = TempFileSet() exporterInstance.tempFileSet = self.tempFileSet exporterInstance.styleSheet = "" htpath = self.tempFileSet.createTempFile( "", ".html", relativeTo="") # realfp = StringIO.StringIO() with open(htpath, "wb") as realfp: exporterInstance.exportHtmlMultiFile(realfp=realfp, tocMode=0) return htpath # realfp.getvalue().decode("utf-8")
def __init__(self, presenter, parent, ID, mode="relation graph/dot"): wx.html.HtmlWindow.__init__(self, parent, ID) self.presenter = presenter self.graphDotHandler = DotHandler(wx.GetApp()) self.graphDotHandler.findExe() self.visible = False self.outOfSync = True self.tempFileSet = TempFileSet() self._updateTempFilePrefPath() self.mode = mode self.Bind(wx.EVT_MENU, self.OnClipboardCopy, id=GUI_ID.CMD_CLIPBOARD_COPY)
class GraphView(wx.html.HtmlWindow): def __init__(self, presenter, parent, ID, mode="relation graph/dot"): wx.html.HtmlWindow.__init__(self, parent, ID) self.presenter = presenter self.graphDotHandler = DotHandler(wx.GetApp()) self.graphDotHandler.findExe() self.visible = False self.outOfSync = True self.tempFileSet = TempFileSet() self._updateTempFilePrefPath() self.mode = mode self.Bind(wx.EVT_MENU, self.OnClipboardCopy, id=GUI_ID.CMD_CLIPBOARD_COPY) def _updateTempFilePrefPath(self): # wikiDoc = self.presenter.getWikiDocument() # # if wikiDoc is not None: # self.tempFileSet.setPreferredPath(wikiDoc.getWikiTempDir()) # else: self.tempFileSet.setPreferredPath(None) def close(self): self.tempFileSet.clear() # self.Unbind(wx.EVT_SET_FOCUS) # self.setLayerVisible(False) # self.presenterListener.disconnect() # self.__sinkApp.disconnect() # self.__sinkDocPage.disconnect() def setLayerVisible(self, vis, scName=""): """ Informs the widget if it is really visible on the screen or not """ if not self.visible and vis: self.outOfSync = True # Just to be sure self.refresh() if not vis: self.tempFileSet.clear() self.visible = vis def setMode(self, mode): if self.mode == mode: return self.mode = mode self.outOfSync = True # Just to be sure self.refresh() def refresh(self): if self.outOfSync: self.graphDotHandler.findExe() wikiPage = self.presenter.getDocPage() if wikiPage is None: return # TODO Do anything else here? word = wikiPage.getWikiWord() if word is None: return # TODO Do anything else here? # Remove previously used temporary files self.tempFileSet.clear() if self.mode.startswith("relation graph/"): source = buildRelationGraphSource( self.presenter.getWikiDocument(), word, self.presenter.getMainControl().getConfig()) else: # self.mode.startswith("child graph/"): source = buildChildGraphSource( self.presenter.getWikiDocument(), word, self.presenter.getMainControl().getConfig()) if self.mode.endswith("/dot"): response, url = self.graphDotHandler.createImage(self.tempFileSet, "html_previewWX", source, []) if response: self.presenter.displayErrorMessage(response) self.outOfSync = False return self.SetPage('<img src="%s" border="0" align="top" alt="relation" />' % url) else: # self.mode.endswith("/dot/source"): if self.graphDotHandler.extAppExe == "": # No path to executable -> show message warning = "To see the graph, you must install GraphViz executable\n"\ "and set the path to it in options\n\n" else: warning = "" self.SetPage('<pre>%s%s</pre>' % (escapeHtmlNoBreaks(warning), escapeHtmlNoBreaks(source))) self.outOfSync = False def OnClipboardCopy(self, evt): copyTextToClipboard(self.SelectionToText())
class HtmlWKPrint(HtmlPrint): @staticmethod def getPrintTypes(mainControl): if WKHtmlWindow: return (("html_webkit", u'HTML (Webkit)'), ) else: return () def _buildHtml(self): def getTextFromWord(word): return self.wikiDocument.getWikiPage(word).getLiveText() exporterInstance = PluginManager.getExporterTypeDict( self.mainControl, False)[u"html_single"][0](self.mainControl) # TODO Progress handler # TODO Set additional options exporterInstance.setJobData(self.wikiDocument, self.wordList, u"html_previewWK", None, False, exporterInstance.getAddOpt(None), progressHandler=None) self.tempFileSet = TempFileSet() exporterInstance.tempFileSet = self.tempFileSet exporterInstance.styleSheet = u"" htpath = self.tempFileSet.createTempFile( u"", ".html", relativeTo="").decode("latin-1") realfp = StringIO.StringIO() with open(htpath, "w") as realfp: exporterInstance.exportHtmlMultiFile(realfp=realfp, tocMode=0) return htpath # realfp.getvalue().decode("utf-8") def doPrint(self, printer, wikiDocument, wordList, printType, addopt, doPreview=False): """ To print with webkit we load the pages into a temporary frame that contains a WKHtmlWindow and use webkits print function. The frame does not need to be shown as a preview is builtin """ self.setContext(printer, wikiDocument, wordList, printType, addopt) if self.checkWebkit(): import gtk htpath = self._buildHtml() frame = None try: # Get page setup dialog data (wxPython) and translate to pyGTK psddata = self.printer.getPageSetupDialogData() tl = psddata.GetMarginTopLeft() br = psddata.GetMarginBottomRight() print_op = gtk.PrintOperation() page_setup = gtk.PageSetup() page_setup.set_top_margin(tl.y, gtk.UNIT_MM) page_setup.set_left_margin(tl.x, gtk.UNIT_MM) page_setup.set_right_margin(br.x, gtk.UNIT_MM) page_setup.set_bottom_margin(br.y, gtk.UNIT_MM) print_op.set_default_page_setup(page_setup) frame = WKPrintFrame(htpath) if doPreview: opCode = gtk.PRINT_OPERATION_ACTION_PREVIEW frame.print_full(print_op, opCode) return False else: opCode = gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG result = frame.print_full(print_op, opCode) return result in (gtk.PRINT_OPERATION_RESULT_APPLY, gtk.PRINT_OPERATION_RESULT_IN_PROGRESS) finally: if frame: frame.Destroy() self._freeHtml() def doPreview(self, printer, wikiDocument, wordList, printType, addopt): """Preview is built into the print function""" self.doPrint(printer, wikiDocument, wordList, printType, addopt, doPreview=True) def checkWebkit(self): # NOTE: It would be better to check this earlier but I don't # know how to have conditions in XrcControls -- Ross if WKHtmlWindow: return True else: dlg = wx.MessageDialog(None, \ _('Error loading Webkit: try a different export format)'), \ _('Error'), wx.OK | wx.ICON_ERROR) dlg.ShowModal() return False
class HtmlPrint: def __init__(self, mainControl): self.mainControl = mainControl self.tempFileSet = None @staticmethod def getPrintTypes(mainControl): return (("html_simple", u'HTML'), ) def getAddOptPanelsForTypes(self, guiparent, printTypes): return () # if not u"html_multi" in exportTypes and \ # not u"html_single" in exportTypes: # return () # # res = wx.xrc.XmlResource.Get() # htmlPanel = res.LoadPanel(guiparent, "ExportSubHtml") # ctrls = XrcControls(htmlPanel) # config = self.mainControl.getConfig() # # ctrls.cbPicsAsLinks.SetValue(config.getboolean("main", # "html_export_pics_as_links")) # ctrls.chTableOfContents.SetSelection(config.getint("main", # "export_table_of_contents")) # ctrls.tfHtmlTocTitle.SetValue(config.get("main", # "html_toc_title")) # # return ( # (u"html_multi", htmlPanel), # (u"html_single", htmlPanel) # ) def getAddOptVersion(self): return 0 def getAddOpt(self, addoptpanel): return () # if addoptpanel is None: # # Return default set in options # config = self.mainControl.getConfig() # # return ( boolToInt(config.getboolean("main", # "html_export_pics_as_links")), # config.getint("main", "export_table_of_contents"), # config.get("main", "html_toc_title"), # u"volatile" # ) # else: # ctrls = XrcControls(addoptpanel) # # picsAsLinks = boolToInt(ctrls.cbPicsAsLinks.GetValue()) # tableOfContents = ctrls.chTableOfContents.GetSelection() # tocTitle = ctrls.tfHtmlTocTitle.GetValue() # # return (picsAsLinks, tableOfContents, tocTitle, u"volatile") def setAddOpt(self, addOpt, addoptpanel): pass # picsAsLinks, tableOfContents, tocTitle, volatileDir = \ # addOpt[:4] # # # volatileDir is currently ignored # # ctrls = XrcControls(addoptpanel) # # ctrls.cbPicsAsLinks.SetValue(picsAsLinks != 0) # ctrls.chTableOfContents.SetSelection(tableOfContents) # ctrls.tfHtmlTocTitle.SetValue(tocTitle) def _buildHtml(self): def getTextFromWord(word): return self.wikiDocument.getWikiPage(word).getLiveText() exporterInstance = PluginManager.getExporterTypeDict( self.mainControl, False)[u"html_single"][0](self.mainControl) # TODO Progress handler # TODO Set additional options exporterInstance.setJobData(self.wikiDocument, self.wordList, u"html_previewWX", None, False, exporterInstance.getAddOpt(None), progressHandler=None) self.tempFileSet = TempFileSet() exporterInstance.tempFileSet = self.tempFileSet exporterInstance.styleSheet = u"" realfp = StringIO.StringIO() exporterInstance.exportHtmlMultiFile(realfp=realfp, tocMode=0) return realfp.getvalue().decode("utf-8") def _freeHtml(self): self.tempFileSet.clear() self.tempFileSet = None def setContext(self, printer, wikiDocument, wordList, printType, addopt): self.wikiDocument = wikiDocument self.wordList = wordList self.printer = printer def doPrint(self, printer, wikiDocument, wordList, printType, addopt): self.setContext(printer, wikiDocument, wordList, printType, addopt) text = self._buildHtml() try: printout = HtmlPrintout(text, self.printer) pData = wx.PrintDialogData(self.printer.getPrintData()) printer = wx.Printer(pData) return printer.Print(self.mainControl, printout, True) finally: self._freeHtml() def doPreview(self, printer, wikiDocument, wordList, printType, addopt): self.setContext(printer, wikiDocument, wordList, printType, addopt) text = self._buildHtml() try: pddata = wx.PrintDialogData(self.printer.getPrintData()) printout = HtmlPrintout(text, self.printer) printout2 = HtmlPrintout(text, self.printer) preview = wx.PrintPreview(printout, printout2, pddata) frame = wx.PreviewFrame(preview, self.mainControl, _(u"Print Preview"), style=wx.DEFAULT_FRAME_STYLE | wx.FRAME_FLOAT_ON_PARENT) frame.Initialize() frame.SetPosition(self.mainControl.GetPosition()) frame.SetSize(self.mainControl.GetSize()) frame.Show(True) finally: self._freeHtml()
class HtmlWKPrint(HtmlPrint): @staticmethod def getPrintTypes(mainControl): if WKHtmlWindow: return ( ("html_webkit", 'HTML (Webkit)'), ) else: return () def _buildHtml(self): def getTextFromWord(word): return self.wikiDocument.getWikiPage(word).getLiveText() exporterInstance = PluginManager.getExporterTypeDict( self.mainControl, False)["html_single"][0](self.mainControl) # TODO Progress handler # TODO Set additional options exporterInstance.setJobData(self.wikiDocument, self.wordList, "html_previewWK", None, False, exporterInstance.getAddOpt(None), progressHandler=None) self.tempFileSet = TempFileSet() exporterInstance.tempFileSet = self.tempFileSet exporterInstance.styleSheet = "" htpath = self.tempFileSet.createTempFile( "", ".html", relativeTo="") # realfp = StringIO.StringIO() with open(htpath, "wb") as realfp: exporterInstance.exportHtmlMultiFile(realfp=realfp, tocMode=0) return htpath # realfp.getvalue().decode("utf-8") def doPrint(self, printer, wikiDocument, wordList, printType, addopt, doPreview=False): """ To print with webkit we load the pages into a temporary frame that contains a WKHtmlWindow and use webkits print function. The frame does not need to be shown as a preview is builtin """ self.setContext(printer, wikiDocument, wordList, printType, addopt) if self.checkWebkit(): import gtk htpath = self._buildHtml() frame = None try: # Get page setup dialog data (wxPython) and translate to pyGTK psddata = self.printer.getPageSetupDialogData() tl = psddata.GetMarginTopLeft() br = psddata.GetMarginBottomRight() print_op = gtk.PrintOperation() page_setup = gtk.PageSetup() page_setup.set_top_margin(tl.y, gtk.UNIT_MM) page_setup.set_left_margin(tl.x, gtk.UNIT_MM) page_setup.set_right_margin(br.x, gtk.UNIT_MM) page_setup.set_bottom_margin(br.y, gtk.UNIT_MM) print_op.set_default_page_setup(page_setup) frame = WKPrintFrame(htpath) if doPreview: opCode = gtk.PRINT_OPERATION_ACTION_PREVIEW frame.print_full(print_op, opCode) return False else: opCode = gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG result = frame.print_full(print_op, opCode) return result in (gtk.PRINT_OPERATION_RESULT_APPLY, gtk.PRINT_OPERATION_RESULT_IN_PROGRESS) finally: if frame: frame.Destroy() self._freeHtml() def doPreview(self, printer, wikiDocument, wordList, printType, addopt): """Preview is built into the print function""" self.doPrint(printer, wikiDocument, wordList, printType, addopt, doPreview=True) def checkWebkit(self): # NOTE: It would be better to check this earlier but I don't # know how to have conditions in XrcControls -- Ross if WKHtmlWindow: return True else: dlg = wx.MessageDialog(None, \ _('Error loading Webkit: try a different export format)'), \ _('Error'), wx.OK | wx.ICON_ERROR) dlg.ShowModal() return False
class HtmlPrint: def __init__(self, mainControl): self.mainControl = mainControl self.tempFileSet = None @staticmethod def getPrintTypes(mainControl): return ( ("html_simple", 'HTML'), ) def getAddOptPanelsForTypes(self, guiparent, printTypes): return () # if not u"html_multi" in exportTypes and \ # not u"html_single" in exportTypes: # return () # # res = wx.xrc.XmlResource.Get() # htmlPanel = res.LoadPanel(guiparent, "ExportSubHtml") # ctrls = XrcControls(htmlPanel) # config = self.mainControl.getConfig() # # ctrls.cbPicsAsLinks.SetValue(config.getboolean("main", # "html_export_pics_as_links")) # ctrls.chTableOfContents.SetSelection(config.getint("main", # "export_table_of_contents")) # ctrls.tfHtmlTocTitle.SetValue(config.get("main", # "html_toc_title")) # # return ( # (u"html_multi", htmlPanel), # (u"html_single", htmlPanel) # ) def getAddOptVersion(self): return 0 def getAddOpt(self, addoptpanel): return () # if addoptpanel is None: # # Return default set in options # config = self.mainControl.getConfig() # # return ( boolToInt(config.getboolean("main", # "html_export_pics_as_links")), # config.getint("main", "export_table_of_contents"), # config.get("main", "html_toc_title"), # u"volatile" # ) # else: # ctrls = XrcControls(addoptpanel) # # picsAsLinks = boolToInt(ctrls.cbPicsAsLinks.GetValue()) # tableOfContents = ctrls.chTableOfContents.GetSelection() # tocTitle = ctrls.tfHtmlTocTitle.GetValue() # # return (picsAsLinks, tableOfContents, tocTitle, u"volatile") def setAddOpt(self, addOpt, addoptpanel): pass # picsAsLinks, tableOfContents, tocTitle, volatileDir = \ # addOpt[:4] # # # volatileDir is currently ignored # # ctrls = XrcControls(addoptpanel) # # ctrls.cbPicsAsLinks.SetValue(picsAsLinks != 0) # ctrls.chTableOfContents.SetSelection(tableOfContents) # ctrls.tfHtmlTocTitle.SetValue(tocTitle) def _buildHtml(self): def getTextFromWord(word): return self.wikiDocument.getWikiPage(word).getLiveText() exporterInstance = PluginManager.getExporterTypeDict( self.mainControl, False)["html_single"][0](self.mainControl) # TODO Progress handler # TODO Set additional options exporterInstance.setJobData(self.wikiDocument, self.wordList, "html_previewWX", None, False, exporterInstance.getAddOpt(None), progressHandler=None) self.tempFileSet = TempFileSet() exporterInstance.tempFileSet = self.tempFileSet exporterInstance.styleSheet = "" realfp = BytesIO() exporterInstance.exportHtmlMultiFile(realfp=realfp, tocMode=0) return realfp.getvalue().decode("utf-8") def _freeHtml(self): self.tempFileSet.clear() self.tempFileSet = None def setContext(self, printer, wikiDocument, wordList, printType, addopt): self.wikiDocument = wikiDocument self.wordList = wordList self.printer = printer def doPrint(self, printer, wikiDocument, wordList, printType, addopt): self.setContext(printer, wikiDocument, wordList, printType, addopt) text = self._buildHtml() try: printout = HtmlPrintout(text, self.printer) pData = wx.PrintDialogData(self.printer.getPrintData()) printer = wx.Printer(pData) return printer.Print(self.mainControl, printout, True) finally: self._freeHtml() def doPreview(self, printer, wikiDocument, wordList, printType, addopt): self.setContext(printer, wikiDocument, wordList, printType, addopt) text = self._buildHtml() try: pddata = wx.PrintDialogData(self.printer.getPrintData()) printout = HtmlPrintout(text, self.printer) printout2 = HtmlPrintout(text, self.printer) preview = wx.PrintPreview(printout, printout2, pddata) frame = wx.PreviewFrame(preview, self.mainControl, _("Print Preview"), style=wx.DEFAULT_FRAME_STYLE | wx.FRAME_FLOAT_ON_PARENT) frame.Initialize() frame.SetPosition(self.mainControl.GetPosition()) frame.SetSize(self.mainControl.GetSize()) frame.Show(True) finally: self._freeHtml()
class GraphView(wx.html.HtmlWindow): def __init__(self, presenter, parent, ID, mode="relation graph/dot"): wx.html.HtmlWindow.__init__(self, parent, ID) self.presenter = presenter self.graphDotHandler = DotHandler(wx.GetApp()) self.graphDotHandler.findExe() self.visible = False self.outOfSync = True self.tempFileSet = TempFileSet() self._updateTempFilePrefPath() self.mode = mode wx.EVT_MENU(self, GUI_ID.CMD_CLIPBOARD_COPY, self.OnClipboardCopy) def _updateTempFilePrefPath(self): # wikiDoc = self.presenter.getWikiDocument() # # if wikiDoc is not None: # self.tempFileSet.setPreferredPath(wikiDoc.getWikiTempDir()) # else: self.tempFileSet.setPreferredPath(None) def close(self): self.tempFileSet.clear() # self.Unbind(wx.EVT_SET_FOCUS) # self.setLayerVisible(False) # self.presenterListener.disconnect() # self.__sinkApp.disconnect() # self.__sinkDocPage.disconnect() def setLayerVisible(self, vis, scName=""): """ Informs the widget if it is really visible on the screen or not """ if not self.visible and vis: self.outOfSync = True # Just to be sure self.refresh() if not vis: self.tempFileSet.clear() self.visible = vis def setMode(self, mode): if self.mode == mode: return self.mode = mode self.outOfSync = True # Just to be sure self.refresh() def refresh(self): if self.outOfSync: self.graphDotHandler.findExe() wikiPage = self.presenter.getDocPage() if wikiPage is None: return # TODO Do anything else here? word = wikiPage.getWikiWord() if word is None: return # TODO Do anything else here? # Remove previously used temporary files self.tempFileSet.clear() if self.mode.startswith("relation graph/"): source = buildRelationGraphSource( self.presenter.getWikiDocument(), word, self.presenter.getMainControl().getConfig()) else: # self.mode.startswith("child graph/"): source = buildChildGraphSource( self.presenter.getWikiDocument(), word, self.presenter.getMainControl().getConfig()) if self.mode.endswith("/dot"): response, url = self.graphDotHandler.createImage( self.tempFileSet, "html_previewWX", source, []) if response: self.presenter.displayErrorMessage(response) self.outOfSync = False return self.SetPage( uniToGui( u'<img src="%s" border="0" align="top" alt="relation" />' % url)) else: # self.mode.endswith("/dot/source"): if self.graphDotHandler.extAppExe == "": # No path to executable -> show message warning = u"To see the graph, you must install GraphViz executable\n"\ u"and set the path to it in options\n\n" else: warning = u"" self.SetPage( uniToGui(u'<pre>%s%s</pre>' % (escapeHtmlNoBreaks(warning), escapeHtmlNoBreaks(source)))) self.outOfSync = False def OnClipboardCopy(self, evt): copyTextToClipboard(self.SelectionToText())