def createPageWithDialog(parentwnd, parentpage): """ Показать диалог настроек и создать страницу """ assert parentpage is not None if parentpage.readonly: raise outwiker.core.exceptions.ReadonlyException page = None with CreatePageDialog(parentwnd, parentpage, Application) as dlg: if dlg.ShowModal() == wx.ID_OK: factory = dlg.selectedFactory alias = dlg.pageTitle order_calculator = dlg.orderCalculator tags = [] try: page = factory.create(parentpage, alias, tags, order_calculator) except OSError: showError(Application.mainWindow, _(u"Can't create page")) return None assert page is not None if not dlg.setPageProperties(page): return None page.root.selectedPage = page return page
def sortChildren(self): if self._application.wikiroot is None: showError(self._application.mainWindow, _(u"Wiki is not open")) return if self._application.wikiroot.selectedPage is not None: self._application.wikiroot.selectedPage.parent.sortChildrenAlphabetical()
def _openGlobalSearch(self): if self._application.wikiroot is not None: try: GlobalSearch.create(self._application.wikiroot) except IOError: showError(self._application.mainWindow, _(u"Can't create page"))
def Save(self): """ Сохранить текущую страницу """ if self.__saveProcessing: return if (self.__pageView is not None and self._application.selectedPage is not None): if not pageExists(self._application.selectedPage.root): # Нет папки с деревом self.__saveProcessing = True showError(self._application.mainWindow, _(u"Can't save page. Wiki folder not exists. Wiki will be closed.")) self.__saveProcessing = False self._application.wikiroot = None return if not pageExists(self._application.selectedPage): # Похоже, страница удалена вручную, перезагрузим вики self.__saveProcessing = True showError(self._application.mainWindow, _(u"Can't save page. Page folder not exists. Wiki will be reloaded.")) self.__saveProcessing = False try: self.__reloadWiki() except OSError: self._application.wikiroot = None return self.__pageView.Save()
def Save(self): """ Сохранить текущую страницу """ if self.__saveProcessing: return if self.__pageView is not None: if not pageExists(self._application.selectedPage.root): # Нет папки с деревом self.__saveProcessing = True showError(self._application.mainWindow, _(u"Can't save page. Wiki folder not exists. Wiki will be closed.")) self.__saveProcessing = False self._application.wikiroot = None return if not pageExists(self._application.selectedPage): # Похоже, страница удалена вручную, перезагрузим вики self.__saveProcessing = True showError(self._application.mainWindow, _(u"Can't save page. Page folder not exists. Wiki will be reloaded.")) self.__saveProcessing = False try: self.__reloadWiki() except OSError: self._application.wikiroot = None return self.__pageView.Save()
def createPageWithDialog(parentwnd, parentpage): """ Показать диалог настроек и создать страницу """ assert parentpage is not None if parentpage.readonly: raise outwiker.core.exceptions.ReadonlyException page = None with CreatePageDialog(parentwnd, parentpage, Application) as dlg: if dlg.ShowModal() == wx.ID_OK: factory = dlg.selectedFactory alias = dlg.pageTitle siblings = [child_page.title for child_page in parentpage.children] title = getAlternativeTitle(alias, siblings) try: page = factory.create(parentpage, title, []) if title != alias: page.alias = alias except EnvironmentError: showError(Application.mainWindow, _(u"Can't create page")) return None assert page is not None if not dlg.setPageProperties(page): return None page.root.selectedPage = page return page
def run(self, params): if self._application.selectedPage is not None: folder = Attachment( self._application.selectedPage).getAttachPath(create=True) try: getOS().startFile(folder) except OSError: text = _(u"Can't open folder '{}'".format(folder)) showError(self._application.mainWindow, text)
def run(self, params): # 0 - папка рядом с запускаемым файлом, # затем идут другие папки, если они есть pluginsDir = getPluginsDirList()[-1] try: getOS().startFile(pluginsDir) except OSError: text = _(u"Can't open folder '{}'".format(pluginsDir)) showError(self._application.mainWindow, text)
def run(self, params): attachPanel = self._application.mainWindow.attachPanel.panel files = attachPanel.getSelectedFiles() if len(files) == 0: showError(self._application.mainWindow, _("You did not select any attached file")) return self._application.onAttachmentPaste(files)
def __pasteLink(self): """ Сгенерировать сообщение о том, что пользователь хочет вставить ссылку на приаттаченные файлы """ files = self.__getSelectedFiles() if len(files) == 0: showError(self._application.mainWindow, _(u"You did not select a file to paste")) return self._application.onAttachmentPaste(files)
def __onPageSelect(self, page): """ Событие при выборе страницы """ if page is not None and not pageExists(page): showError(self._application.mainWindow, _(u"Can't open page. Page folder not exists")) self.__reloadWiki() return self.__updatePageView(page) self.__updatePageInfo(page) self.bookmarkButton.Enable(page is not None)
def __toggleMarkTag(self, tagname): selectedPage = self.__application.selectedPage if selectedPage is None: return if selectedPage.readonly: showError(self.__application.mainWindow, _('Page is opened as read-only')) return if tagname in selectedPage.tags: removeTag(selectedPage, tagname) else: appendTag(selectedPage, tagname)
def _updateHtmlCode(self): if self.htmlcodePageIndex == -1: # Нет вкладки с кодом HTML. Ничего не делаем return try: path = self._currentpage.getHtmlPath() html = readTextFile(path) self.htmlCodeWindow.SetReadOnly(False) self.htmlCodeWindow.SetText(html) self.htmlCodeWindow.SetReadOnly(True) except IOError as e: showError(self._application.mainWindow, _(u"Can't load file %s") % (unicode(e.filename)))
def moveCurrentPageDown(self): """ Переместить текущую страницу на одну позицию вниз """ if self._application.wikiroot is None: showError(self._application.mainWindow, _(u"Wiki is not open")) return if self._application.wikiroot.selectedPage is not None: tree = self._application.mainWindow.treePanel.panel.treeCtrl tree.Freeze() scrollPos = tree.GetScrollPos(wx.VERTICAL) self._application.wikiroot.selectedPage.order += 1 tree.SetScrollPos(wx.VERTICAL, scrollPos) tree.Thaw()
def __executeFile(self): if self._application.selectedPage is not None: files = self.__getSelectedFiles() if len(files) == 0: showError(self._application.mainWindow, _(u"You did not select a file to execute")) return for file in files: fullpath = os.path.join(Attachment(self._application.selectedPage).getAttachPath(), file) try: getOS().startFile(fullpath) except OSError: text = _(u"Can't execute file '%s'") % file showError(self._application.mainWindow, text)
def run(self, params): assert self._application.mainWindow is not None assert self._application.mainWindow.pagePanel is not None if len(Attachment(self._application.selectedPage).attachmentFull) == 0: showError(self._application.mainWindow, _(u"Current page does not have any attachments")) return with IncludeDialog(self._application.mainWindow) as dlg: controller = IncludeDialogController( dlg, self._application.selectedPage) text = controller.getDialogResult() if text is not None: self._application.mainWindow.pagePanel.pageView.codeEditor.replaceText( text)
def beginRename(self, page=None): """ Начать переименование страницы в дереве. Если page is None, то начать переименование текущей страницы """ pageToRename = page if page is not None else self._application.selectedPage if pageToRename is None or pageToRename.parent is None: mainWindow = self._application.mainWindow showError(mainWindow, _(u"You can't rename the root element")) return selectedItem = self._pageCache[pageToRename] if not selectedItem.IsOk(): return self.treeCtrl.EditLabel(selectedItem)
def beginRename(self, page=None): """ Начать переименование страницы в дереве. Если page is None, то начать переименование текущей страницы """ pageToRename = page if page is not None else self._application.selectedPage if pageToRename is None or pageToRename.parent is None: mainWindow = self._application.mainWindow showError(mainWindow, _("You can't rename the root element")) return selectedItem = self.treeCtrl.getTreeItem(pageToRename) if not selectedItem.IsOk(): return self.treeCtrl.EditLabel(selectedItem)
def __saveTabs(self): if self._application.wikiroot is not None: try: pageSubpathList = [page.subpath if page is not None else '' for page in self._tabsCtrl.GetPages()] self.__createStringListConfig( self._application.wikiroot.params).value = pageSubpathList selectedTab = self._tabsCtrl.GetSelection() self._application.wikiroot.params.set( self._tabSelectedSection, self._tabSelectedOption, str(selectedTab)) except IOError as e: showError(self._application.mainWindow, _(u"Can't save file %s") % (str(e.filename)))
def __executeFile(self): if self._application.selectedPage is not None: files = self.__getSelectedFiles() if len(files) == 0: showError(self._application.mainWindow, _(u"You did not select a file to execute")) return for file in files: fullpath = os.path.join( Attachment(self._application.selectedPage).getAttachPath(), file) try: getOS().startFile(fullpath) except OSError: text = _(u"Can't execute file '%s'") % file showError(self._application.mainWindow, text)
def __saveTabs(self): if self._application.wikiroot is not None: try: pageSubpathList = [ page.subpath for page in self._tabsCtrl.GetPages() if page is not None ] self.__createStringListConfig( self._application.wikiroot.params).value = pageSubpathList selectedTab = self._tabsCtrl.GetSelection() self._application.wikiroot.params.set(self._tabSelectedSection, self._tabSelectedOption, str(selectedTab)) except IOError as e: showError(self._application.mainWindow, _(u"Can't save file %s") % (str(e.filename)))
def __onRemove(self, _event): if self._application.selectedPage is not None: files = self.__getSelectedFiles() if len(files) == 0: showError(self._application.mainWindow, _(u"You did not select a file to remove")) return if MessageBox(_(u"Remove selected files?"), _(u"Remove files?"), wx.YES_NO | wx.ICON_QUESTION) == wx.YES: try: Attachment( self._application.selectedPage).removeAttach(files) except IOError as e: showError(self._application.mainWindow, str(e)) self.updateAttachments()
def __onRemove(self, event): if self._application.selectedPage is not None: files = self.__getSelectedFiles() if len(files) == 0: showError(self._application.mainWindow, _(u"You did not select a file to remove")) return if MessageBox(_(u"Remove selected files?"), _(u"Remove files?"), wx.YES_NO | wx.ICON_QUESTION) == wx.YES: try: Attachment(self._application.selectedPage).removeAttach(files) except IOError as e: showError(self._application.mainWindow, str(e)) self.updateAttachments()
def editPage(parentWnd, currentPage): """ Вызвать диалог для редактирования страницы parentWnd - родительское окно currentPage - страница для редактирования """ if currentPage.readonly: raise outwiker.core.exceptions.ReadonlyException if not pageExists(currentPage): showError(Application.mainWindow, _(u'Page "%s" not found') % currentPage.display_title) return with EditPageDialog(parentWnd, currentPage, Application) as dlg: if dlg.ShowModal() == wx.ID_OK: renamePage(currentPage, dlg.pageTitle) if not dlg.setPageProperties(currentPage): return None
def _savePageContent(self, page): """ Сохранение содержимого страницы """ if page is None or page.isRemoved or page.readonly: return reg = page.root.registry.get_page_registry(page) try: reg.set(REGISTRY_PAGE_CURSOR_POSITION, self.GetCursorPosition()) except KeyError: logger.error("Registry. Can't set cursor position") newContent = self.GetContentFromGui() if self.__stringsAreEqual(page.content, newContent): return try: page.content = newContent except IOError as e: # TODO: Проверить под Windows showError(self._application.mainWindow, _(u"Can't save file %s") % (str(e.filename)))
def _saveParams(self): """ Сохранить параметры в конфиг """ self._updateRealSize() try: if not self.IsIconized(): self.mainWindowConfig.fullscreen.value = self.IsFullScreen() self.__panesController.savePanesParams() if self._realSize: (width, height) = self._realSize self.mainWindowConfig.width.value = width self.mainWindowConfig.height.value = height if self._realPosition: (xpos, ypos) = self._realPosition self.mainWindowConfig.xPos.value = xpos self.mainWindowConfig.yPos.value = ypos self.mainWindowConfig.maximized.value = self._realMaximized except Exception as e: showError(self, _(u"Can't save config\n%s") % (str(e)))