def __init__(self, parent): super().__init__(parent, style=wx.CAPTION | wx.CLOSE | wx.SYSTEM_MENU | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.CLOSE_BOX | wx.RESIZE_BORDER | wx.FRAME_TOOL_WINDOW | wx.FRAME_NO_TASKBAR | wx.FRAME_FLOAT_ON_PARENT) global _ _ = get_() self.ICON_WIDTH = 16 self.ICON_HEIGHT = 16 self._imagesPath = getImagesPath() self._dirImageId = None self._snippetImageId = None self.addGroupBtn = None self.addSnippetBtn = None self._varMenuItems = [ (_(u'Selected text'), defines.VAR_SEL_TEXT), (_(u'Current date'), defines.VAR_DATE), (_(u'Page title'), defines.VAR_TITLE), (_(u'Page type'), defines.VAR_PAGE_TYPE), (_(u'Page tags list'), defines.VAR_TAGS), (_(u'Attachments path'), defines.VAR_ATTACH), (_(u'Path to page'), defines.VAR_FOLDER), (_(u'Relative page path'), defines.VAR_SUBPATH), (_(u'Page creation date'), defines.VAR_DATE_CREATING), (_(u'Page modification date'), defines.VAR_DATE_EDITIND), (_(u'Page Id'), defines.VAR_PAGE_ID), (_(u'Attachments list'), defines.VAR_ATTACHLIST), (_(u'Child pages'), defines.VAR_CHILDLIST), ] self._blocksMenuItems = [ (_('{% if %}'), (u'{% if %}', '{% elif %}{% else %}{% endif %}')), (_('{% include %}'), (u"{% include '", u"' %}")), (_('{# comment #}'), (u'{# ', ' #}')), ] self._createGUI() self.SetTitle(_(u'Snippets management')) self.disableSnippetEditor()
def __init__(self, parent): super().__init__( parent, style=wx.CAPTION | wx.CLOSE | wx.SYSTEM_MENU | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.CLOSE_BOX | wx.RESIZE_BORDER | wx.FRAME_TOOL_WINDOW | wx.FRAME_NO_TASKBAR | wx.FRAME_FLOAT_ON_PARENT ) global _ _ = get_() self.ICON_WIDTH = 16 self.ICON_HEIGHT = 16 self._imagesPath = getImagesPath() self._dirImageId = None self._snippetImageId = None self.addGroupBtn = None self.addSnippetBtn = None self._varMenuItems = [ (_(u'Selected text'), defines.VAR_SEL_TEXT), (_(u'Current date'), defines.VAR_DATE), (_(u'Page title'), defines.VAR_TITLE), (_(u'Page type'), defines.VAR_PAGE_TYPE), (_(u'Page tags list'), defines.VAR_TAGS), (_(u'Attachments path'), defines.VAR_ATTACH), (_(u'Path to page'), defines.VAR_FOLDER), (_(u'Relative page path'), defines.VAR_SUBPATH), (_(u'Page creation date'), defines.VAR_DATE_CREATING), (_(u'Page modification date'), defines.VAR_DATE_EDITIND), (_(u'Page Id'), defines.VAR_PAGE_ID), (_(u'Attachments list'), defines.VAR_ATTACHLIST), (_(u'Child pages'), defines.VAR_CHILDLIST), ] self._blocksMenuItems = [ (_('{% if %}'), (u'{% if %}', '{% elif %}{% else %}{% endif %}')), (_('{% include %}'), (u"{% include '", u"' %}")), (_('{# comment #}'), (u'{# ', ' #}')), ] self._createGUI() self.SetTitle(_(u'Snippets management')) self.disableSnippetEditor()
class StringVariableCtrl(wx.Panel): ''' Control to edit string variable ''' _expandBitmap = wx.Bitmap(os.path.join(getImagesPath(), u'expand.png')) _collapseBitmap = wx.Bitmap(os.path.join(getImagesPath(), u'collapse.png')) def __init__(self, parent, varname): super(StringVariableCtrl, self).__init__(parent) self._TEXT_CTRL_SIZER_POSITION = 2 self._varname = varname self._createGUI() def SetFocus(self): if self._textCtrlExpanded.IsShown(): self._textCtrlExpanded.SetFocus() else: self._textCtrlCollapsed.SetFocus() def _createGUI(self): # Label self._label = wx.StaticText(self, label=self._varname) # Expanded TextCtrl self._textCtrlExpanded = wx.TextCtrl(self, style=wx.TE_MULTILINE) self._textCtrlExpanded.SetMinSize((-1, 75)) self._textCtrlExpanded.Bind(wx.EVT_TEXT, handler=self._onTextEdit) self._textCtrlExpanded.Hide() # Collapsed TextCtrl self._textCtrlCollapsed = wx.TextCtrl(self) self._textCtrlCollapsed.Bind(wx.EVT_TEXT, handler=self._onTextEdit) self._textCtrlCollapsed.Bind(wx.EVT_CHAR_HOOK, handler=self._onChar) # Expand / Collapse button self._expandButton = wx.BitmapButton(self, bitmap=self._expandBitmap) self._expandButton.SetToolTip(_(u'Expand (Shift+Enter)')) self._expandButton.Bind(wx.EVT_BUTTON, handler=self._onExpand) self._mainSizer = wx.FlexGridSizer(cols=2) self._mainSizer.AddGrowableCol(0) self._mainSizer.Add(self._label, flag=wx.ALL, border=2) self._mainSizer.AddStretchSpacer() self._mainSizer.Add(self._textCtrlCollapsed, flag=wx.EXPAND | wx.TOP | wx.BOTTOM | wx.LEFT, border=2) self._mainSizer.Add(self._expandButton) self.SetSizer(self._mainSizer) self.Layout() def GetValue(self): if self._textCtrlCollapsed.IsShown(): return self._textCtrlCollapsed.GetValue() else: return self._textCtrlExpanded.GetValue() def SetValue(self, value): self._textCtrlCollapsed.SetValue(value) self._textCtrlExpanded.SetValue(value) def _onChar(self, event): if event.GetKeyCode() == wx.WXK_RETURN and event.ShiftDown(): self._onExpand(None) self._textCtrlExpanded.Value = self._textCtrlExpanded.Value + u'\n' self._textCtrlExpanded.SetInsertionPointEnd() else: event.Skip() def _onExpand(self, event): self._expandButton.Unbind(wx.EVT_BUTTON, handler=self._onExpand) self._expandButton.Bind(wx.EVT_BUTTON, handler=self._onCollapse) self._expandButton.SetBitmapLabel(self._collapseBitmap) self._expandButton.SetToolTip(_(u'Collapse')) self._textCtrlCollapsed.Hide() self._textCtrlExpanded.Show() self._mainSizer.Remove(self._TEXT_CTRL_SIZER_POSITION) self._mainSizer.Insert(self._TEXT_CTRL_SIZER_POSITION, self._textCtrlExpanded, flag=wx.EXPAND | wx.TOP | wx.BOTTOM | wx.LEFT, border=2) self._textCtrlExpanded.Value = self._textCtrlCollapsed.Value self.GetParent().Layout() self._textCtrlExpanded.SetFocus() self._textCtrlExpanded.SetInsertionPointEnd() def _onCollapse(self, event): self._expandButton.Bind(wx.EVT_BUTTON, handler=self._onExpand) self._expandButton.Unbind(wx.EVT_BUTTON, handler=self._onCollapse) self._expandButton.SetBitmapLabel(self._expandBitmap) self._expandButton.SetToolTip(_(u'Expand (Shift+Enter)')) self._textCtrlExpanded.Hide() self._textCtrlCollapsed.Show() self._mainSizer.Remove(self._TEXT_CTRL_SIZER_POSITION) self._mainSizer.Insert(self._TEXT_CTRL_SIZER_POSITION, self._textCtrlCollapsed, flag=wx.EXPAND | wx.TOP | wx.BOTTOM | wx.LEFT, border=2) old_text = self._textCtrlExpanded.GetValue() if old_text: new_text = old_text.split(u'\n')[0] self._textCtrlCollapsed.SetValue(new_text) self.GetParent().Layout() self._textCtrlCollapsed.SetFocus() self._textCtrlCollapsed.SetInsertionPointEnd() def _onTextEdit(self, event): propagationLevel = 10 newevent = VarChangeEvent() newevent.ResumePropagation(propagationLevel) wx.PostEvent(self, newevent)