def LoadState(self): self.columnsCountConfigElement = IntegerElement( self._config.columnsCount, self.columns, 0, self._config.COLUMNS_COUNT_MAX) self.thumbSizeConfigElement = IntegerElement( self._config.thumbSize, self.thumbSizeCtrl, 0, self._config.THUMB_SIZE_MAX)
class PrefPanelController(object): """ Контроллер для панели настроек """ def __init__(self, owner, config): self.MIN_TAB_WIDTH = 1 self.MAX_TAB_WIDTH = 50 self._langList = LangList(get_()) self._owner = owner self._config = SourceConfig(config) self._owner.selectAllButton.Bind(wx.EVT_BUTTON, self._onSelectAll) self._owner.clearButton.Bind(wx.EVT_BUTTON, self._onClear) def loadState(self): self._tabWidthOption = IntegerElement(self._config.tabWidth, self._owner.tabWidthSpin, self.MIN_TAB_WIDTH, self.MAX_TAB_WIDTH) fillStyleComboBox(self._config, self._owner.styleComboBox, self._config.defaultStyle.value.strip()) allLanguages = self._getAllLanguages() self._owner.langList.Clear() self._owner.langList.AppendItems(allLanguages) selectedLanguages = [ self._langList.getLangName(designation) for designation in self._config.languageList.value ] self._owner.langList.SetCheckedStrings(selectedLanguages) def save(self): self._tabWidthOption.save() self._config.defaultStyle.value = self._owner.styleComboBox.GetValue() designations = [ self._langList.getDesignation(name) for name in self._owner.langList.GetCheckedStrings() ] self._config.languageList.value = designations def _onSelectAll(self, event): self._owner.langList.SetChecked(range(self._owner.langList.GetCount())) def _onClear(self, event): self._owner.langList.SetChecked([]) def _getAllLanguages(self): """ Получить список всех языков, о которых знает pygments """ return sorted(self._langList.allNames())
def LoadState(self): self.columnsCountConfigElement = IntegerElement (self._config.columnsCount, self.columns, 0, self._config.COLUMNS_COUNT_MAX) self.thumbSizeConfigElement = IntegerElement (self._config.thumbSize, self.thumbSizeCtrl, 0, self._config.THUMB_SIZE_MAX)
def loadState(self): self._tabWidthOption = IntegerElement(self._config.tabWidth, self._owner.tabWidthSpin, self.MIN_TAB_WIDTH, self.MAX_TAB_WIDTH) fillStyleComboBox(self._config, self._owner.styleComboBox, self._config.defaultStyle.value.strip()) allLanguages = self._getAllLanguages() self._owner.langList.Clear() self._owner.langList.AppendItems(allLanguages) selectedLanguages = [ self._langList.getLangName(designation) for designation in self._config.languageList.value ] self._owner.langList.SetCheckedStrings(selectedLanguages)
def LoadState(self): # Показывать ли вкладку с кодом HTML self.showHtmlCodeOption = BooleanElement( self.config.showHtmlCodeOptions, self.htmlCodeCheckbox) self.colorizeWiki.SetValue(self.config.colorizeSyntax.value) # Размер превьюшек по умолчанию self.thumbSizeOption = IntegerElement(self.config.thumbSizeOptions, self.thumbSize, 1, 10000) # Шаблон для пустых страниц emptycontent = EmptyContent(Application.config) self.emptyTplTextCtrl.SetValue(emptycontent.content) # Стиль ссылок по умолчанию linkStyle = self.config.linkStyleOptions.value self.linkStyleCombo.SetSelection( linkStyle if linkStyle >= 0 and linkStyle < self.linkStyleCombo.GetCount() else 0)
def loadState(self): self._tabWidthOption = IntegerElement(self.__config.tabWidth, self.__owner.tabWidthSpin, self.MIN_TAB_WIDTH, self.MAX_TAB_WIDTH) fillStyleComboBox(self.__config, self.__owner.styleComboBox, self.__config.defaultStyle.value.strip()) allLanguages = self._getAllLanguages() self.__owner.langList.Clear() self.__owner.langList.AppendItems(allLanguages) # Уберем языки, которых нет в списке selectedLanguages = [ item for item in self.__config.languageList.value if item in allLanguages ] self.__owner.langList.SetCheckedStrings(selectedLanguages)
def loadState(self): self._tabWidthOption = IntegerElement( self.__config.tabWidth, self.__owner.tabWidthSpin, self.MIN_TAB_WIDTH, self.MAX_TAB_WIDTH ) fillStyleComboBox(self.__config, self.__owner.styleComboBox, self.__config.defaultStyle.value.strip()) allLanguages = self._getAllLanguages() self.__owner.langList.Clear() self.__owner.langList.AppendItems(allLanguages) # Уберем языки, которых нет в списке selectedLanguages = [item for item in self.__config.languageList.value if item in allLanguages] self.__owner.langList.SetCheckedStrings(selectedLanguages)
def LoadState(self): # Показывать ли вкладку с кодом HTML self.showHtmlCodeOption = BooleanElement (self.config.showHtmlCodeOptions, self.htmlCodeCheckbox) # Размер превьюшек по умолчанию self.thumbSizeOption = IntegerElement (self.config.thumbSizeOptions, self.thumbSize, 1, 10000) # Шаблон для пустых страниц emptycontent = EmptyContent (Application.config) self.emptyTplTextCtrl.SetValue (emptycontent.content) # Стиль ссылок по умолчанию linkStyle = self.config.linkStyleOptions.value self.linkStyleCombo.SetSelection ( linkStyle if linkStyle >= 0 and linkStyle < self.linkStyleCombo.GetCount() else 0)
class WikiPrefGeneralPanel(BasePrefPanel): def __init__(self, parent): super(WikiPrefGeneralPanel, self).__init__(parent) self.__createGui() self.config = WikiConfig(Application.config) def __createGui(self): # Показывать ли результирующий HTML? self.htmlCodeCheckbox = wx.CheckBox(self, -1, _(u"Show HTML Code Tab")) # Highlight the wiki notation? self.colorizeWiki = wx.CheckBox(self, -1, _(u"Highlight the Wiki Notation")) # Размер миниатюр self.thumbSizeLabel = wx.StaticText(self, -1, _(u"Thumbnail Size")) self.thumbSize = wx.SpinCtrl(self, -1, "250", min=1, max=10000) # Шаблон для пустых страниц self.emptyTplLabel = wx.StaticText(self, -1, _(u"Template for empty page")) self.emptyTplTextCtrl = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE | wx.HSCROLL | wx.TE_WORDWRAP) # Стиль ссылок по умолчанию (при создании через диалог) self.linkStyleLabel = wx.StaticText(self, label=_(u"Default link style")) self.linkStyleCombo = wx.ComboBox(self, -1, style=wx.CB_DROPDOWN | wx.CB_READONLY) self.linkStyleCombo.AppendItems( [_(u"[[comment -> link]]"), _(u"[[link | comment]]")]) self.linkStyleCombo.SetSelection(0) self.__do_layout() def __do_layout(self): mainSizer = wx.FlexGridSizer(cols=1) mainSizer.AddGrowableRow(5) mainSizer.AddGrowableCol(0) # Показывать ли результирующий HTML? mainSizer.Add(self.htmlCodeCheckbox, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2) # Highlight the wiki notation? mainSizer.Add(self.colorizeWiki, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2) # Размер миниатюр thumbSizer = wx.FlexGridSizer(1, 2, 0, 0) thumbSizer.AddGrowableCol(0) thumbSizer.AddGrowableCol(1) thumbSizer.Add(self.thumbSizeLabel, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2) thumbSizer.Add(self.thumbSize, 0, wx.ALL | wx.ALIGN_RIGHT, 2) mainSizer.Add(thumbSizer, 1, wx.EXPAND, 0) # Стиль ссылок по умолчанию (при создании через диалог) linkStyleSizer = wx.FlexGridSizer(1, 2, 0, 0) linkStyleSizer.AddGrowableCol(0) linkStyleSizer.AddGrowableCol(1) linkStyleSizer.Add(self.linkStyleLabel, 0, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=2) linkStyleSizer.Add(self.linkStyleCombo, 0, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=2) mainSizer.Add(linkStyleSizer, 1, wx.EXPAND, 0) # Шаблон для пустых страниц mainSizer.Add(self.emptyTplLabel, 0, wx.ALL, 4) mainSizer.Add(self.emptyTplTextCtrl, 0, wx.ALL | wx.EXPAND, 4) self.SetSizer(mainSizer) self.Layout() def LoadState(self): # Показывать ли вкладку с кодом HTML self.showHtmlCodeOption = BooleanElement( self.config.showHtmlCodeOptions, self.htmlCodeCheckbox) self.colorizeWiki.SetValue(self.config.colorizeSyntax.value) # Размер превьюшек по умолчанию self.thumbSizeOption = IntegerElement(self.config.thumbSizeOptions, self.thumbSize, 1, 10000) # Шаблон для пустых страниц emptycontent = EmptyContent(Application.config) self.emptyTplTextCtrl.SetValue(emptycontent.content) # Стиль ссылок по умолчанию linkStyle = self.config.linkStyleOptions.value self.linkStyleCombo.SetSelection( linkStyle if linkStyle >= 0 and linkStyle < self.linkStyleCombo.GetCount() else 0) def Save(self): changed = (self.showHtmlCodeOption.isValueChanged() or self.thumbSizeOption.isValueChanged()) self.showHtmlCodeOption.save() self.thumbSizeOption.save() self.config.colorizeSyntax.value = self.colorizeWiki.GetValue() emptycontent = EmptyContent(Application.config) emptycontent.content = self.emptyTplTextCtrl.GetValue() self.config.linkStyleOptions.value = self.linkStyleCombo.GetSelection() if changed: currpage = Application.wikiroot.selectedPage Application.wikiroot.selectedPage = None Application.wikiroot.selectedPage = currpage
class ThumbDialog (wx.Dialog): def __init__ (self, parent, page, lang, application): super (ThumbDialog, self).__init__ (parent, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.THICK_FRAME) global _ _ = lang self._page = page self._config = ThumbConfig (application.config) self.SetTitle (_(u"Gallery")) self.Center(wx.CENTRE_ON_SCREEN) self.ALL_BUTTON = wx.NewId() self.CLEAR_BUTTON = wx.NewId() # Контролы для выбора количества столбцов self.columnsLabel = wx.StaticText (self, -1, _(u"Columns count (0 - without table)")) self.columns = wx.SpinCtrl (self, min=0, max=self._config.COLUMNS_COUNT_MAX) self.columns.SetMinSize ((150, -1)) # Контролы для указания размера превьюшек self.thumbSizeLabel = wx.StaticText (self, -1, _(u"Thumbnails size (0 - default size)")) self.thumbSizeCtrl = wx.SpinCtrl (self, min=0, max=self._config.THUMB_SIZE_MAX) self.thumbSizeCtrl.SetMinSize ((150, -1)) # Контролы для выбора прикрепленных файлов self.attachFiles = wx.CheckListBox (self) self.attachFiles.SetMinSize ((-1, 100)) self.allFilesButton = wx.Button (self, self.ALL_BUTTON, _(u"All Images")) self.clearFilesButton = wx.Button (self, self.CLEAR_BUTTON, _(u"Clear")) self.Bind (wx.EVT_BUTTON, self._onAll, id=self.ALL_BUTTON) self.Bind (wx.EVT_BUTTON, self._onClear, id=self.CLEAR_BUTTON) self.Bind (wx.EVT_BUTTON, self.onOk, id=wx.ID_OK) self._fillAttaches() self.columns.SetFocus() # Используем золотое сечение dlgWidth = 500 dlgHeight = int (500 / 1.61803399) self.SetMinSize ((dlgWidth, dlgHeight)) self._layout () self.LoadState() def _onAll (self, event): self.attachFiles.SetChecked (range (self.attachFiles.GetCount())) def _onClear (self, event): self.attachFiles.SetChecked ([]) def _fillAttaches (self): attach = Attachment (self._page) allFiles = attach.getAttachRelative() imagesFiles = [fname for fname in allFiles if isImage (fname)] imagesFiles.sort(Attachment.sortByName) self.attachFiles.Clear() self.attachFiles.AppendItems (imagesFiles) def _getAttachSizer (self): buttonsSizer = wx.FlexGridSizer (1, 2) buttonsSizer.AddGrowableCol (0) buttonsSizer.AddGrowableCol (1) buttonsSizer.Add (self.allFilesButton, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 2) buttonsSizer.Add (self.clearFilesButton, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 2) attachSizer = wx.FlexGridSizer (cols=1) attachSizer.AddGrowableCol (0) attachSizer.AddGrowableRow (0) attachSizer.Add (self.attachFiles, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border = 2) attachSizer.Add (buttonsSizer, flag = wx.EXPAND | wx.BOTTOM, border = 2) return attachSizer def _getColumsSizer (self): # Строка для выбора количества столбцов columnsSizer = wx.FlexGridSizer (1, 2) columnsSizer.AddGrowableCol (0) columnsSizer.AddGrowableCol (1) columnsSizer.Add (self.columnsLabel, flag = wx.ALIGN_CENTER_VERTICAL | wx. ALIGN_LEFT | wx.ALL, border = 2) columnsSizer.Add (self.columns, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL, border = 2) return columnsSizer def _getThumbSizeSizer (self): # Строка для выбора размера превьюшек thumbSizer = wx.FlexGridSizer (1, 2) thumbSizer.AddGrowableCol (0) thumbSizer.AddGrowableCol (1) thumbSizer.Add (self.thumbSizeLabel, flag = wx.ALIGN_CENTER_VERTICAL | wx. ALIGN_LEFT | wx.ALL, border = 2) thumbSizer.Add (self.thumbSizeCtrl, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL, border = 2) return thumbSizer def _layout (self): columnsSizer = self._getColumsSizer () thumbSizer = self._getThumbSizeSizer() attachSizer = self._getAttachSizer() self.mainSizer = wx.FlexGridSizer (0, 1) self.mainSizer.AddGrowableCol (0) self.mainSizer.AddGrowableRow (2) self.mainSizer.Add (columnsSizer, flag = wx.EXPAND | wx.ALL, border = 2) self.mainSizer.Add (thumbSizer, flag = wx.EXPAND | wx.ALL, border = 2) self.mainSizer.Add (attachSizer, flag = wx.EXPAND | wx.ALL, border = 2) self._createOkCancelButtons (self.mainSizer) self.SetSizer (self.mainSizer) self.Layout() self.Fit() def _createOkCancelButtons (self, sizer): # Создание кнопок Ok/Cancel buttonsSizer = self.CreateButtonSizer (wx.OK | wx.CANCEL) sizer.Add (buttonsSizer, flag = wx.ALIGN_RIGHT | wx.ALL | wx.ALIGN_BOTTOM, border = 2) @property def columnsCount (self): """ Количество столбцов. 0 - не использовать таблицу """ return self.columns.GetValue() @property def thumbSize (self): """ Размер превьюшек в галерее """ return self.thumbSizeCtrl.GetValue() @property def selectedFiles (self): """ Список выбранных файлов """ return self.attachFiles.GetCheckedStrings() @property def isAllFiles (self): """ Вовзращает True, если выбраны все файлы и False в противном случае """ return len (self.selectedFiles) == self.attachFiles.GetCount() def LoadState(self): self.columnsCountConfigElement = IntegerElement (self._config.columnsCount, self.columns, 0, self._config.COLUMNS_COUNT_MAX) self.thumbSizeConfigElement = IntegerElement (self._config.thumbSize, self.thumbSizeCtrl, 0, self._config.THUMB_SIZE_MAX) def Save (self): self.columnsCountConfigElement.save() self.thumbSizeConfigElement.save() def onOk (self, event): self.Save() event.Skip()
class ThumbDialog(wx.Dialog): def __init__(self, parent, page, lang, application): super(ThumbDialog, self).__init__(parent, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.THICK_FRAME) global _ _ = lang self._page = page self._config = ThumbConfig(application.config) self.SetTitle(_(u"Gallery")) self.Center(wx.CENTRE_ON_SCREEN) self.ALL_BUTTON = wx.NewId() self.CLEAR_BUTTON = wx.NewId() # Контролы для выбора количества столбцов self.columnsLabel = wx.StaticText( self, -1, _(u"Columns count (0 - without table)")) self.columns = wx.SpinCtrl(self, min=0, max=self._config.COLUMNS_COUNT_MAX) self.columns.SetMinSize((150, -1)) # Контролы для указания размера превьюшек self.thumbSizeLabel = wx.StaticText( self, -1, _(u"Thumbnails size (0 - default size)")) self.thumbSizeCtrl = wx.SpinCtrl(self, min=0, max=self._config.THUMB_SIZE_MAX) self.thumbSizeCtrl.SetMinSize((150, -1)) # Контролы для выбора прикрепленных файлов self.attachFiles = wx.CheckListBox(self) self.attachFiles.SetMinSize((-1, 100)) self.allFilesButton = wx.Button(self, self.ALL_BUTTON, _(u"All Images")) self.clearFilesButton = wx.Button(self, self.CLEAR_BUTTON, _(u"Clear")) self.Bind(wx.EVT_BUTTON, self._onAll, id=self.ALL_BUTTON) self.Bind(wx.EVT_BUTTON, self._onClear, id=self.CLEAR_BUTTON) self.Bind(wx.EVT_BUTTON, self.onOk, id=wx.ID_OK) self._fillAttaches() self.columns.SetFocus() # Используем золотое сечение dlgWidth = 500 dlgHeight = int(500 / 1.61803399) self.SetMinSize((dlgWidth, dlgHeight)) self._layout() self.LoadState() def _onAll(self, event): self.attachFiles.SetChecked(range(self.attachFiles.GetCount())) def _onClear(self, event): self.attachFiles.SetChecked([]) def _fillAttaches(self): attach = Attachment(self._page) allFiles = attach.getAttachRelative() imagesFiles = [fname for fname in allFiles if isImage(fname)] imagesFiles.sort(Attachment.sortByName) self.attachFiles.Clear() self.attachFiles.AppendItems(imagesFiles) def _getAttachSizer(self): buttonsSizer = wx.FlexGridSizer(1, 2) buttonsSizer.AddGrowableCol(0) buttonsSizer.AddGrowableCol(1) buttonsSizer.Add(self.allFilesButton, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=2) buttonsSizer.Add(self.clearFilesButton, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=2) attachSizer = wx.FlexGridSizer(1, 1) attachSizer.AddGrowableCol(0) attachSizer.AddGrowableRow(0) attachSizer.Add(self.attachFiles, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=2) attachSizer.Add(buttonsSizer, flag=wx.EXPAND | wx.BOTTOM, border=2) return attachSizer def _getColumsSizer(self): # Строка для выбора количества столбцов columnsSizer = wx.FlexGridSizer(1, 2) columnsSizer.AddGrowableCol(0) columnsSizer.AddGrowableCol(1) columnsSizer.Add(self.columnsLabel, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL, border=2) columnsSizer.Add(self.columns, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL, border=2) return columnsSizer def _getThumbSizeSizer(self): # Строка для выбора размера превьюшек thumbSizer = wx.FlexGridSizer(1, 2) thumbSizer.AddGrowableCol(0) thumbSizer.AddGrowableCol(1) thumbSizer.Add(self.thumbSizeLabel, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL, border=2) thumbSizer.Add(self.thumbSizeCtrl, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL, border=2) return thumbSizer def _layout(self): columnsSizer = self._getColumsSizer() thumbSizer = self._getThumbSizeSizer() attachSizer = self._getAttachSizer() self.mainSizer = wx.FlexGridSizer(0, 1) self.mainSizer.AddGrowableCol(0) self.mainSizer.AddGrowableRow(2) self.mainSizer.Add(columnsSizer, flag=wx.EXPAND | wx.ALL, border=2) self.mainSizer.Add(thumbSizer, flag=wx.EXPAND | wx.ALL, border=2) self.mainSizer.Add(attachSizer, flag=wx.EXPAND | wx.ALL, border=2) self._createOkCancelButtons(self.mainSizer) self.SetSizer(self.mainSizer) self.Layout() self.Fit() def _createOkCancelButtons(self, sizer): # Создание кнопок Ok/Cancel buttonsSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL) sizer.Add(buttonsSizer, flag=wx.ALIGN_RIGHT | wx.ALL | wx.ALIGN_BOTTOM, border=2) @property def columnsCount(self): """ Количество столбцов. 0 - не использовать таблицу """ return self.columns.GetValue() @property def thumbSize(self): """ Размер превьюшек в галерее """ return self.thumbSizeCtrl.GetValue() @property def selectedFiles(self): """ Список выбранных файлов """ return self.attachFiles.GetCheckedStrings() @property def isAllFiles(self): """ Вовзращает True, если выбраны все файлы и False в противном случае """ return len(self.selectedFiles) == self.attachFiles.GetCount() def LoadState(self): self.columnsCountConfigElement = IntegerElement( self._config.columnsCount, self.columns, 0, self._config.COLUMNS_COUNT_MAX) self.thumbSizeConfigElement = IntegerElement( self._config.thumbSize, self.thumbSizeCtrl, 0, self._config.THUMB_SIZE_MAX) def Save(self): self.columnsCountConfigElement.save() self.thumbSizeConfigElement.save() def onOk(self, event): self.Save() event.Skip()
class PrefPanelController(object): """ Контроллер для панели настроек """ def __init__(self, owner, config): self.MIN_TAB_WIDTH = 1 self.MAX_TAB_WIDTH = 50 self.__owner = owner self.__config = SourceConfig(config) self.__owner.selectAllButton.Bind(wx.EVT_BUTTON, self._onSelectAll) self.__owner.clearButton.Bind(wx.EVT_BUTTON, self._onClear) def loadState(self): self._tabWidthOption = IntegerElement( self.__config.tabWidth, self.__owner.tabWidthSpin, self.MIN_TAB_WIDTH, self.MAX_TAB_WIDTH ) fillStyleComboBox(self.__config, self.__owner.styleComboBox, self.__config.defaultStyle.value.strip()) allLanguages = self._getAllLanguages() self.__owner.langList.Clear() self.__owner.langList.AppendItems(allLanguages) # Уберем языки, которых нет в списке selectedLanguages = [item for item in self.__config.languageList.value if item in allLanguages] self.__owner.langList.SetCheckedStrings(selectedLanguages) def save(self): self._tabWidthOption.save() self.__config.defaultStyle.value = self.__owner.styleComboBox.GetValue() self.__config.languageList.value = self.__owner.langList.GetCheckedStrings() def _onSelectAll(self, event): self.__owner.langList.SetChecked(range(self.__owner.langList.GetCount())) def _onClear(self, event): self.__owner.langList.SetChecked([]) def _getAllLanguages(self): """ Получить список всех языков, о которых знает pygments """ from .pygments.lexers._mapping import LEXERS languages = [self._getLongestName(lexer[2]).lower() for lexer in LEXERS.values()] # Сделаем некоторые замены languages = self._replaceLangItem(languages, "php3", "php") languages.sort() return languages def _replaceLangItem(self, items, oldname, newname): """ Заменить элемент в списке Возвращает новый список """ return [newname if item == oldname else item for item in items] @staticmethod def _getLongestName(namelist): """ Возвращает самое длинное название языка из списка имен одного и того же языка """ maxlen = 0 bestname = u"" for name in namelist: if len(name) > maxlen: maxlen = len(name) bestname = name return bestname
class WikiPrefGeneralPanel(BasePrefPanel): def __init__(self, parent): super(WikiPrefGeneralPanel, self).__init__(parent) self.__createGui() self.config = WikiConfig(Application.config) def __createGui(self): # Показывать ли результирующий HTML? self.htmlCodeCheckbox = wx.CheckBox(self, -1, _(u"Show HTML Code Tab")) # Highlight the wiki notation? self.colorizeWiki = wx.CheckBox( self, -1, _(u"Highlight the Wiki Notation")) # Размер миниатюр self.thumbSizeLabel = wx.StaticText(self, -1, _(u"Thumbnail Size")) self.thumbSize = wx.SpinCtrl(self, -1, "250", min=1, max=10000) # Шаблон для пустых страниц self.emptyTplLabel = wx.StaticText( self, -1, _(u"Template for empty page")) self.emptyTplTextCtrl = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE | wx.HSCROLL | wx.TE_WORDWRAP) # Стиль ссылок по умолчанию (при создании через диалог) self.linkStyleLabel = wx.StaticText( self, label=_(u"Default link style")) self.linkStyleCombo = wx.ComboBox( self, -1, style=wx.CB_DROPDOWN | wx.CB_READONLY) self.linkStyleCombo.AppendItems([ _(u"[[comment -> link]]"), _(u"[[link | comment]]") ]) self.linkStyleCombo.SetSelection(0) self.__do_layout() def __do_layout(self): mainSizer = wx.FlexGridSizer(cols=1) mainSizer.AddGrowableRow(5) mainSizer.AddGrowableCol(0) # Показывать ли результирующий HTML? mainSizer.Add(self.htmlCodeCheckbox, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2) # Highlight the wiki notation? mainSizer.Add(self.colorizeWiki, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2) # Размер миниатюр thumbSizer = wx.FlexGridSizer(1, 2, 0, 0) thumbSizer.AddGrowableCol(0) thumbSizer.AddGrowableCol(1) thumbSizer.Add(self.thumbSizeLabel, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2) thumbSizer.Add(self.thumbSize, 0, wx.ALL | wx.ALIGN_RIGHT, 2) mainSizer.Add(thumbSizer, 1, wx.EXPAND, 0) # Стиль ссылок по умолчанию (при создании через диалог) linkStyleSizer = wx.FlexGridSizer(1, 2, 0, 0) linkStyleSizer.AddGrowableCol(0) linkStyleSizer.AddGrowableCol(1) linkStyleSizer.Add(self.linkStyleLabel, 0, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=2) linkStyleSizer.Add(self.linkStyleCombo, 0, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=2) mainSizer.Add(linkStyleSizer, 1, wx.EXPAND, 0) # Шаблон для пустых страниц mainSizer.Add(self.emptyTplLabel, 0, wx.ALL, 4) mainSizer.Add(self.emptyTplTextCtrl, 0, wx.ALL | wx.EXPAND, 4) self.SetSizer(mainSizer) self.Layout() def LoadState(self): # Показывать ли вкладку с кодом HTML self.showHtmlCodeOption = BooleanElement( self.config.showHtmlCodeOptions, self.htmlCodeCheckbox) self.colorizeWiki.SetValue(self.config.colorizeSyntax.value) # Размер превьюшек по умолчанию self.thumbSizeOption = IntegerElement( self.config.thumbSizeOptions, self.thumbSize, 1, 10000) # Шаблон для пустых страниц emptycontent = EmptyContent(Application.config) self.emptyTplTextCtrl.SetValue(emptycontent.content) # Стиль ссылок по умолчанию linkStyle = self.config.linkStyleOptions.value self.linkStyleCombo.SetSelection( linkStyle if linkStyle >= 0 and linkStyle < self.linkStyleCombo.GetCount() else 0) def Save(self): changed = (self.showHtmlCodeOption.isValueChanged() or self.thumbSizeOption.isValueChanged()) self.showHtmlCodeOption.save() self.thumbSizeOption.save() self.config.colorizeSyntax.value = self.colorizeWiki.GetValue() emptycontent = EmptyContent(Application.config) emptycontent.content = self.emptyTplTextCtrl.GetValue() self.config.linkStyleOptions.value = self.linkStyleCombo.GetSelection() if changed: currpage = Application.wikiroot.selectedPage Application.wikiroot.selectedPage = None Application.wikiroot.selectedPage = currpage
class PrefPanelController(object): """ Контроллер для панели настроек """ def __init__(self, owner, config): self.MIN_TAB_WIDTH = 1 self.MAX_TAB_WIDTH = 50 self.__owner = owner self.__config = SourceConfig(config) self.__owner.selectAllButton.Bind(wx.EVT_BUTTON, self._onSelectAll) self.__owner.clearButton.Bind(wx.EVT_BUTTON, self._onClear) def loadState(self): self._tabWidthOption = IntegerElement(self.__config.tabWidth, self.__owner.tabWidthSpin, self.MIN_TAB_WIDTH, self.MAX_TAB_WIDTH) fillStyleComboBox(self.__config, self.__owner.styleComboBox, self.__config.defaultStyle.value.strip()) allLanguages = self._getAllLanguages() self.__owner.langList.Clear() self.__owner.langList.AppendItems(allLanguages) # Уберем языки, которых нет в списке selectedLanguages = [ item for item in self.__config.languageList.value if item in allLanguages ] self.__owner.langList.SetCheckedStrings(selectedLanguages) def save(self): self._tabWidthOption.save() self.__config.defaultStyle.value = self.__owner.styleComboBox.GetValue( ) self.__config.languageList.value = self.__owner.langList.GetCheckedStrings( ) def _onSelectAll(self, event): self.__owner.langList.SetChecked( range(self.__owner.langList.GetCount())) def _onClear(self, event): self.__owner.langList.SetChecked([]) def _getAllLanguages(self): """ Получить список всех языков, о которых знает pygments """ from .pygments.lexers._mapping import LEXERS languages = [ self._getLongestName(lexer[2]).lower() for lexer in LEXERS.values() ] # Сделаем некоторые замены languages = self._replaceLangItem(languages, "php3", "php") languages.sort() return languages def _replaceLangItem(self, items, oldname, newname): """ Заменить элемент в списке Возвращает новый список """ return [newname if item == oldname else item for item in items] @staticmethod def _getLongestName(namelist): """ Возвращает самое длинное название языка из списка имен одного и того же языка """ maxlen = 0 bestname = u"" for name in namelist: if len(name) > maxlen: maxlen = len(name) bestname = name return bestname