Пример #1
0
 def __onDocumentOpened(self, sender, evt):
     document = evt
     if document is None:
         return
     
     docName =  document.getName()
     if docName is None:
         return
     
     editor = self.__getFileEditor(docName)
     if editor is None:
         raise Exception('Cannot get the editor for file.\n Filename: %s' % docName)
     
     document.setEditor(editor)
     
     pageCaption = ''
     if '' == docName:
         pageCaption = 'Unsaved Document'
     else:
         pageCaption = docName
         
     if editor.openFile(document.getFullPath()):
         if self._auiNotebook.AddPage(document.getEditor(), pageCaption, True):
             self.__getOpenedDocuments()[document.getEditor()] = document
             Application.getDocumentManager().selectDocument(document.getFullPath())
     else:
         editor.close()
         dlg = wx.MessageDialog(None, 'Cannot open file: %s' % document.getFullPath(),
                                'Error', wx.OK | wx.ICON_ERROR)
         dlg.ShowModal()
         dlg.Destroy()
         document.close()
Пример #2
0
 def initData(self, argv):
     '''init configurations'''
     Application.getSettings().load()
     
     '''init document manager'''
     
     '''init plugin manager'''
Пример #3
0
 def __createToolbar(self, toolbarInfo, id):
     if toolbarInfo is None:
         return
     
     toolbar = wx.ToolBar(self._window, id, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TB_FLAT | wx.TB_NODIVIDER)
     
     index = 0
     for itemInfo in toolbarInfo.values():
         itemId = id * 100 + index
         
         if itemInfo.getImage() is None or '' == itemInfo.getImage().strip():
             continue
         
         imagePath = Application.getSettings().getWorkPath() + os.path.sep + itemInfo.getImage()
         bmp = wx.Bitmap(imagePath, wx.BITMAP_TYPE_PNG)
         toolbar.AddLabelTool(itemId, itemInfo.getName(), bmp, longHelp=itemInfo.getTip())
         
         action = Application.getActionManager().getAction(itemInfo.getAction())
         if action is not None:
             toolbar.Bind(wx.EVT_TOOL, action.execute, id=itemId)
         index += 1
         
     if 0 == index:
         return None
     
     toolbar.Realize()
     return toolbar
Пример #4
0
 def execute(self, evt):
     wildcard = "All files (*.*)|*"
     dlg = wx.FileDialog(
         None,
         message="Open File",
         defaultDir="",
         defaultFile="",
         wildcard=wildcard,
         style=wx.OPEN | wx.CHANGE_DIR | wx.MULTIPLE,
     )
     if dlg.ShowModal() == wx.ID_OK:
         files = dlg.GetPaths()
         for file in files:
             Application.getDocumentManager().openDocument(file)
Пример #5
0
 def __setEdgeStyle(self):
     editorStyle = Application.getSettings().getEditorStyle()
     edge = editorStyle.getEdge()
     
     if edge.getVisible():
         self._editView.SetEdgeMode(stc.STC_EDGE_LINE)
         self._editView.SetEdgeColumn(edge.getMaxColumns())
     else:
         self._editView.SetEdgeMode(stc.STC_EDGE_NONE)
Пример #6
0
 def __onPageClose(self, evt):
     selectIndex = evt.GetSelection()
     if 0 <= selectIndex and self._auiNotebook.GetPageCount() > selectIndex:
         editor = self._auiNotebook.GetPage(selectIndex)
         if editor is None or not self.__getOpenedDocuments().has_key(editor):
             return
         
         closeAction = Application.getActionManager().getAction('DocumentActions.Close')
         if closeAction is not None:
             closeAction.execute(None)
Пример #7
0
 def __setDefaultFont(self, lexer):
     editorStyle = Application.getSettings().getEditorStyle()
     font = editorStyle.getFont()
     
     if highlightSymbols.SYMBOLS.has_key(lexer):
         symbols = highlightSymbols.SYMBOLS[lexer]
         if symbols is None:
             symbols = highlightSymbols.NULL_SYMBOLS
         for symbol in symbols.values():
             self._editView.StyleSetSpec(symbol, font.getSettings())
Пример #8
0
    def execute(self, evt):
        document = Application.getDocumentManager().getCurrentDocument()
        if document is None:
            return

        if document.isContentChanged():
            if (
                wx.MessageDialog(
                    None,
                    "Do you want to save file: %s?" % document.getName(),
                    "Warning",
                    wx.YES | wx.NO | wx.ICON_WARNING,
                ).ShowModal()
                == wx.ID_YES
            ):
                saveAction = Application.getActionManager().getAction("DocumentActions.Save")
                if saveAction is not None:
                    saveAction.execute(None)
        document.close()
Пример #9
0
 def execute(self, evt):
     document = Application.getDocumentManager().getCurrentDocument()
     if document is None:
         return
     
     editor = document.getEditor()
     if editor is None:
         return
     
     editor.cut()
Пример #10
0
 def __setIndentStyle(self):
     editorStyle = Application.getSettings().getEditorStyle()
     indent = editorStyle.getIndent()
     
     self._editView.SetIndent(indent.getSize())
     self._editView.SetIndentationGuides(indent.getShowIndentGuide())
     self._editView.SetBackSpaceUnIndents(indent.getBackspaceUnindents())
     self._editView.SetTabIndents(indent.getTabIndes())
     self._editView.SetTabWidth(indent.getTabWidth())
     self._editView.SetUseTabs(indent.getUseTabs())
     self._editView.SetViewWhiteSpace(indent.getViewWhitespace())
Пример #11
0
 def __onClose(self, evt):
     ''' close all documents '''
     closeAllFileAction = Application.getActionManager().getAction('DocumentActions.Close All')
     if closeAllFileAction is not None:
         closeAllFileAction.execute(None)
         
     ''' close all panes '''
     self.getLayoutManager().clear()
     
     ''' destroy frame '''
     self.Destroy()
     
Пример #12
0
 def __checkChanged(self, evt):
     index = evt.GetSelection()
     label = self._toolbarListBox.GetString(index)
     
     isChecked = False
     if self._toolbarListBox.IsChecked(index):
         isChecked = True
         
     shownToolbars = Application.getMainFrame().getLayoutManager().getToolbars()
         
     toolbars = Application.getMainFrame().getToolbarManager().getToolbars()
     if not toolbars.has_key(label):
         return
     
     toolbar = toolbars[label]
     if toolbar is None:
         return
     
     if isChecked:
         if shownToolbars.has_key(label):
             return
         Application.getMainFrame().getLayoutManager().addToolbar(label, toolbar)
     else:
         if not shownToolbars.has_key(label):
             return
         Application.getMainFrame().getLayoutManager().removeToolbar(label)
Пример #13
0
 def __initializeComponents(self):
     sizer = wx.BoxSizer(wx.VERTICAL)
     
     toolbars = Application.getMainFrame().getToolbarManager().getToolbars()
     shownToolbars = Application.getMainFrame().getLayoutManager().getToolbars()
     
     self._toolbarListBox = wx.CheckListBox(self, -1, choices=toolbars.keys())
     
     index = 0
     indexes = []
     for toolbarName in toolbars.keys():
         if shownToolbars.has_key(toolbarName):
             indexes.append(index)
         index += 1
     self._toolbarListBox.SetChecked(indexes)            
     
     sizer.Add(self._toolbarListBox, 0, wx.EXPAND | wx.ALL, 5)
     
     self.Bind(wx.EVT_CHECKLISTBOX, self.__checkChanged, self._toolbarListBox)
     
     self.SetSizer(sizer)
     sizer.Fit(self)
Пример #14
0
 def __getFileEditor(self, filename):
     editorClass = ''
     
     filePatterns = Application.getSettings().getFileAssociations().keys()
     for filePattern in filePatterns:
         if fnmatch(filename, filePattern):
             editorClass = Application.getSettings().getFileAssociations()[filePattern]
             
     if editorClass is None or '' == editorClass:
         editorClass = Application.getSettings().getDefaultEditor()
                 
     if editorClass is None or '' == editorClass:
         return None
     
     editorClsObj = createClassInstance(editorClass)
     if editorClsObj is None:
         return None
     
     editor = editorClsObj(self)
     if editor is None:
         return None
     
     return editor
Пример #15
0
 def __setMarkerStyle(self):
     editorStyle = Application.getSettings().getEditorStyle()
     marker = editorStyle.getMarker()
     
     style = EditorStyle.MARKER_STYLES[marker.getStyle()]
     fgColor = marker.getFgColor()
     bgColor = marker.getBgColor()
     
     for key, value in style.items():
         try:
             self._editView.MarkerDefine(key, value, fgColor, bgColor)
         except:
             continue
     
     self.Bind(stc.EVT_STC_MARGINCLICK, self.__onMarginClick)
     self.Bind(stc.EVT_STC_UPDATEUI, self._onUpdateUI)
Пример #16
0
    def execute(self, evt):
        document = Application.getDocumentManager().getCurrentDocument()
        if document is None:
            return

        wildcard = "All files (*.*)|*"
        dlg = wx.FileDialog(
            None,
            message="Save file as ...",
            defaultDir=os.getcwd(),
            defaultFile="",
            wildcard=wildcard,
            style=wx.SAVE | wx.CHANGE_DIR,
        )
        if dlg.ShowModal() == wx.ID_OK:
            document.rename(dlg.GetPath())
            document.save()
Пример #17
0
 def __loadFileWithEncoding(self, filename):
     import codecs
     encodings=Application.getSettings().getEncodings()
     if encodings is None:
         encodings = ['utf-8']
     for encoding in encodings:
         try:
             file = codecs.open(filename, 'r', encoding=encoding)
             context = file.read()
             self._encoding = encoding
             file.close()
             return context
         except UnicodeDecodeError:
             file.close()
         except LookupError:
             pass # invalid encoding
     return None
Пример #18
0
 def __setHighlightStyle(self, lexer):
     if not highlightSymbols.SYMBOLS.has_key(lexer) or stc.STC_LEX_NULL == lexer:
         return
             
     editorStyle = Application.getSettings().getEditorStyle()
     highlightStyles = editorStyle.getHighlightStyles()
     if not highlightStyles.has_key(lexer):
         return
     
     highlight = highlightStyles[lexer]        
     
     self._editView.SetKeyWords(0, highlight.getKeywords())
     
     styles = highlight.getHighlightStyles()
     
     symbols = highlightSymbols.SYMBOLS[lexer]
     for key, value in styles.items():
         if symbols.has_key(key):
             self._editView.StyleSetSpec(symbols[key], value.getSettings())
Пример #19
0
 def __createMenu(self, menuInfo, parentMenu):
     menu = None
     if parentMenu == self.__getMenubar() or 0 < len(menuInfo.getChildren().keys()):
         menu = wx.Menu()
         self.__getMenubar().Append(menu, menuInfo.getName())
     else:
         if '-' == menuInfo.getName():
             parentMenu.AppendSeparator()
         else:
             menu = parentMenu.Append(-1, menuInfo.getName(), menuInfo.getTip())
         
     if menuInfo.getAction() is not None and '' != menuInfo.getAction():
         action = Application.getActionManager().getAction(menuInfo.getAction())
         if action is not None:
             self._window.Bind(wx.EVT_MENU, action.execute, menu)
         
     for sub in menuInfo.getChildren().values():
         self.__createMenu(sub, menu)
         
Пример #20
0
    def execute(self, evt):
        info = wx.AboutDialogInfo()
        info.Name = "Graver"
        info.Version = "0.0.1"
        #        info.Copyright = "(C) 2006 Programmers and Coders Everywhere"
        info.Description = wordwrap(
            "Graver is a light text editor which created by Python and wxPython.\n"
            "This text editor implemented plugin interface for developers.\n"
            "Developers could create their own panels, editors, menus and toolbars to extend the function of this editor.\n"
            "In the future, this text editor will be implemented to a lightly IDE.\n",
            350,
            wx.ClientDC(Application.getMainFrame()),
        )
        info.WebSite = ("http://graver.sourceforge.net", "Graver Home Page")
        info.Developers = ["Tiny Strimp"]

        #        info.License = wordwrap(licenseText, 500, wx.ClientDC(self))

        # Then we call wx.AboutBox giving it that info object
        wx.AboutBox(info)
Пример #21
0
 def __init__(self, parent):
     Pane.__init__(self, parent, 'EditorContainer', '', pos=wx.CENTER, showCaption=False)
     
     self._openedDocuments = None
     
     Application.getDocumentManager().getDocumentOpenedEventHandler().add(self.__onDocumentOpened)
     Application.getDocumentManager().getDocumentClosedEventHandler().add(self.__onDocumentClosed)
     Application.getDocumentManager().getDocumentSavedEventHandler().add(self.__onDocumentSaved)
     Application.getDocumentManager().getDocumentChangedEventHandler().add(self.__onDocumentChanged)
     Application.getDocumentManager().getDocumentRenamedEventHandler().add(self.__onDocumentRenamed)
     Application.getDocumentManager().getSelectedDocumentChangedEventHandler().add(self.__selectDocument)
     
     self.__initializeComponent()
Пример #22
0
 def __setEOLStyle(self):
     editorStyle = Application.getSettings().getEditorStyle()
     eol = editorStyle.getEOL()
     
     self._editView.SetEOLMode(stc.STC_EOL_LF)
     self._editView.SetViewEOL(eol.getShowEOL())
Пример #23
0
 def execute(self, evt):
     Application.getDocumentManager().openDocument("")
Пример #24
0
 def __setCaretStyle(self):
     editorStyle = Application.getSettings().getEditorStyle()
     caret = editorStyle.getCaret()
     self._editView.SetCaretForeground(caret.getColor())
Пример #25
0
 def initUI(self, argv):
     mainfrm = MainFrame('Graver', displaySize=(800,600))
     self.SetTopWindow(mainfrm)
     Application.setMainFrame(mainfrm)
Пример #26
0
 def execute(self, evt):
     mainFrm = Application.getMainFrame()
     if mainFrm is None:
         return
     mainFrm.Close()
Пример #27
0
 def initApp(self, argv):
     self.initData(argv)
     self.initUI(argv)
     
     Application.getMainFrame().Show(True)
Пример #28
0
 def __init__(self, workPath):
     wx.App.__init__(self)
     Application.getSettings().setWorkPath(workPath)
Пример #29
0
 def __onPageChanged(self, evt):
     index = self._auiNotebook.GetSelection()
     editor = self._auiNotebook.GetPage(index)
     if self.__getOpenedDocuments().has_key(editor):
         document = self.__getOpenedDocuments()[editor]
         Application.getDocumentManager().selectDocument(document.getFullPath())
Пример #30
0
 def initializes(self):
     toolbarInfos = Application.getSettings().getToolbars()
     self.__createToolbars(toolbarInfos);