def _open_file(self, item, val):
     if item.childCount() == 0 and not item.isFolder:
         fileName = os.path.join(item.path, str(item.text(val)))
         if (manage_files.get_file_extension(fileName)) in ('.jpg', '.png'):
             self._main.open_image(fileName)
         elif (manage_files.get_file_extension(fileName)).endswith('.ui'):
             self.w = uic.loadUi(fileName)
             self.w.show()
         else:
             while item.parent() is not None:
                 item = item.parent()
             self._main.open_document(fileName, self.projects[item])
 def _open_file(self, item, val):
     if item.childCount() == 0 and not item.isFolder:
         fileName = os.path.join(item.path, str(item.text(val)))
         if (manage_files.get_file_extension(fileName)) in ('.jpg', '.png'):
             self._main.open_image(fileName)
         elif (manage_files.get_file_extension(fileName)).endswith('.ui'):
             self.w = uic.loadUi(fileName)
             self.w.show()
         else:
             while item.parent() is not None:
                 item = item.parent()
             self._main.open_document(fileName, self.projects[item])
Beispiel #3
0
    def uncomment(self, start=-1, end=-1, startPosition=-1):
        lang = manage_files.get_file_extension(self.get_path())[1:]
        key = loader.extensions.get(lang, 'python')
        comment_wildcard = loader.syntax[key]['comment'][0]

        #cursor is a COPY all changes do not affect the QPlainTextEdit's cursor!!!
        cursor = self.textCursor()
        if start == -1 and end == -1 and startPosition == -1:
            start = self.document().findBlock(cursor.selectionStart()).firstLineNumber()
            end = self.document().findBlock(cursor.selectionEnd()).firstLineNumber()
            startPosition = self.document().findBlockByLineNumber(start).position()
        
        #Start a undo block
        cursor.beginEditBlock()
        
        #Move the COPY cursor
        cursor.setPosition(startPosition)
        #Move the QPlainTextEdit Cursor where the COPY cursor IS!
        self.setTextCursor(cursor)
        self.moveCursor(QTextCursor.StartOfLine)
        for i in xrange(start, end+1):
            self.moveCursor(QTextCursor.Right, QTextCursor.KeepAnchor)
            text = self.textCursor().selectedText()
            if text == comment_wildcard:
                self.textCursor().removeSelectedText()
            elif u'\u2029' in text:
                #\u2029 is the unicode char for \n
                #if there is a newline, rollback the selection made above.
                self.moveCursor(QTextCursor.Left, QTextCursor.KeepAnchor)
            
            self.moveCursor(QTextCursor.Down)
            self.moveCursor(QTextCursor.StartOfLine)
        
        #End a undo block
        cursor.endEditBlock()
Beispiel #4
0
 def comment(self):
     lang = manage_files.get_file_extension(self.get_path())[1:]
     key = loader.extensions.get(lang, 'python')
     comment_wildcard = loader.syntax[key]['comment'][0]
     
     #cursor is a COPY all changes do not affect the QPlainTextEdit's cursor!!!
     cursor = self.textCursor()
     start = self.document().findBlock(cursor.selectionStart()).firstLineNumber()
     end = self.document().findBlock(cursor.selectionEnd()).firstLineNumber()
     startPosition = self.document().findBlockByLineNumber(start).position()
     
     #Start a undo block
     cursor.beginEditBlock()
     
     #Move the COPY cursor
     cursor.setPosition(startPosition)
     #Move the QPlainTextEdit Cursor where the COPY cursor IS!
     self.setTextCursor(cursor)
     self.moveCursor(QTextCursor.StartOfLine)
     self.moveCursor(QTextCursor.Right, QTextCursor.KeepAnchor)
     text = self.textCursor().selectedText()
     if text == comment_wildcard:
         cursor.endEditBlock()
         self.uncomment(start, end, startPosition)
         return
     else:
         self.moveCursor(QTextCursor.StartOfLine)
     for i in xrange(start, end+1):
         self.textCursor().insertText(comment_wildcard)
         self.moveCursor(QTextCursor.Down)
         self.moveCursor(QTextCursor.StartOfLine)
     
     #End a undo block
     cursor.endEditBlock()
Beispiel #5
0
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()

        lang = manage_files.get_file_extension(self.get_path())[1:]
        if EditorGeneric.extraMenus.get(lang, False):
            popup_menu.insertSeparator(popup_menu.actions()[0])
            popup_menu.insertMenu(popup_menu.actions()[0], EditorGeneric.extraMenus[lang])

        popup_menu.exec_(event.globalPos())
Beispiel #6
0
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()

        lang = manage_files.get_file_extension(self.get_path())[1:]
        if EditorGeneric.extraMenus.get(lang, False):
            popup_menu.insertSeparator(popup_menu.actions()[0])
            popup_menu.insertMenu(popup_menu.actions()[0],
                                  EditorGeneric.extraMenus[lang])

        popup_menu.exec_(event.globalPos())
Beispiel #7
0
 def register_syntax(self, fileName):
     ext = manage_files.get_file_extension(fileName)[1:]
     if self.highlighter is not None and \
         not self.path.endswith(ext):
         self.highlighter.deleteLater()
     if not self.path.endswith(ext):
         if ext in loader.extensions:
             self.highlighter = Highlighter(self.document(),
                 loader.extensions.get(ext, 'py'))
         else:
             try:
                 self.highlighter = HighlighterPygments(self.document(), fileName)
             except:
                 print 'There is no lexer for this file'
         #for apply rehighlighting (rehighlighting form highlighter not responding)
         self.firstVisibleBlock().document().find('\n').insertText('')
Beispiel #8
0
 def register_syntax(self, fileName):
     ext = manage_files.get_file_extension(fileName)[1:]
     if self.highlighter is not None and \
         not self.path.endswith(ext):
         self.highlighter.deleteLater()
     if not self.path.endswith(ext):
         if ext in loader.extensions:
             self.highlighter = Highlighter(
                 self.document(), loader.extensions.get(ext, 'py'))
         else:
             try:
                 self.highlighter = HighlighterPygments(
                     self.document(), fileName)
             except:
                 print 'There is no lexer for this file'
         #for apply rehighlighting (rehighlighting form highlighter not responding)
         self.firstVisibleBlock().document().find('\n').insertText('')
Beispiel #9
0
    def uncomment(self, start=-1, end=-1, startPosition=-1):
        lang = manage_files.get_file_extension(self.get_path())[1:]
        key = loader.extensions.get(lang, 'python')
        comment_wildcard = loader.syntax[key]['comment'][0]

        #cursor is a COPY all changes do not affect the QPlainTextEdit's cursor!!!
        cursor = self.textCursor()
        if start == -1 and end == -1 and startPosition == -1:
            start = self.document().findBlock(
                cursor.selectionStart()).firstLineNumber()
            end = self.document().findBlock(
                cursor.selectionEnd()).firstLineNumber()
            startPosition = self.document().findBlockByLineNumber(
                start).position()

        #Start a undo block
        cursor.beginEditBlock()

        #Move the COPY cursor
        cursor.setPosition(startPosition)
        #Move the QPlainTextEdit Cursor where the COPY cursor IS!
        self.setTextCursor(cursor)
        self.moveCursor(QTextCursor.StartOfLine)
        for i in xrange(start, end + 1):
            self.moveCursor(QTextCursor.Right, QTextCursor.KeepAnchor)
            text = self.textCursor().selectedText()
            if text == comment_wildcard:
                self.textCursor().removeSelectedText()
            elif u'\u2029' in text:
                #\u2029 is the unicode char for \n
                #if there is a newline, rollback the selection made above.
                self.moveCursor(QTextCursor.Left, QTextCursor.KeepAnchor)

            self.moveCursor(QTextCursor.Down)
            self.moveCursor(QTextCursor.StartOfLine)

        #End a undo block
        cursor.endEditBlock()
Beispiel #10
0
    def comment(self):
        lang = manage_files.get_file_extension(self.get_path())[1:]
        key = loader.extensions.get(lang, 'python')
        comment_wildcard = loader.syntax[key]['comment'][0]

        #cursor is a COPY all changes do not affect the QPlainTextEdit's cursor!!!
        cursor = self.textCursor()
        start = self.document().findBlock(
            cursor.selectionStart()).firstLineNumber()
        end = self.document().findBlock(
            cursor.selectionEnd()).firstLineNumber()
        startPosition = self.document().findBlockByLineNumber(start).position()

        #Start a undo block
        cursor.beginEditBlock()

        #Move the COPY cursor
        cursor.setPosition(startPosition)
        #Move the QPlainTextEdit Cursor where the COPY cursor IS!
        self.setTextCursor(cursor)
        self.moveCursor(QTextCursor.StartOfLine)
        self.moveCursor(QTextCursor.Right, QTextCursor.KeepAnchor)
        text = self.textCursor().selectedText()
        if text == comment_wildcard:
            cursor.endEditBlock()
            self.uncomment(start, end, startPosition)
            return
        else:
            self.moveCursor(QTextCursor.StartOfLine)
        for i in xrange(start, end + 1):
            self.textCursor().insertText(comment_wildcard)
            self.moveCursor(QTextCursor.Down)
            self.moveCursor(QTextCursor.StartOfLine)

        #End a undo block
        cursor.endEditBlock()
Beispiel #11
0
 def get_file_extension(self, fileName):
     return manage_files.get_file_extension(fileName)[1:]
 def get_file_extension(self, fileName):
     return manage_files.get_file_extension(fileName)[1:]
 def lang(self):
     if self.mainFile != '':
         return manage_files.get_file_extension(self.mainFile)[1:]
 def obtain_icon(self, fileName):
     return QIcon(self.images.get(manage_files.get_file_extension(fileName), resources.images['tree-generic']))
 def lang(self):
     if self.mainFile != '':
         return manage_files.get_file_extension(self.mainFile)[1:]
 def obtain_icon(self, fileName):
     return QIcon(
         self.images.get(manage_files.get_file_extension(fileName),
                         resources.images['tree-generic']))