当前位置: 首页>>代码示例>>Python>>正文


Python Console.updateNamespace方法代码示例

本文整理汇总了Python中console.Console.updateNamespace方法的典型用法代码示例。如果您正苦于以下问题:Python Console.updateNamespace方法的具体用法?Python Console.updateNamespace怎么用?Python Console.updateNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在console.Console的用法示例。


在下文中一共展示了Console.updateNamespace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Script

# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import updateNamespace [as 别名]
class Script(QtGui.QWidget):
    def __init__(self, parent=None, conn=None):
        super(Script, self).__init__(parent)
        #   sql tab
        self.connection = parent
        self.alias = {}

        self.saveTo = None
        self.query = []
        self.fetchedall = True
        self.fetchednum = 0
        self.fetchto = 0
        self.model = QtGui.QStandardItemModel(0, 0)

        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setMargin(0)

        # catalog tree
        headers = ["DB Tree"]
        #self.catalogtree = CatalogTree([["", "", "", "", ""]])
        #self.catalogtree.model().headers = headers

        # sql editor
        self.editor = Editor(self)
        self.editor.setautocomplete(self.connection.catalog)
        self.findDialog = FindDialog(self)
        QtCore.QObject.connect(self.editor, QtCore.SIGNAL("userListActivated(int,QString)"), self.userlistselected)

        # table
        self.table = Table(self)
        QtCore.QObject.connect(self.table.verticalScrollBar(), QtCore.SIGNAL("valueChanged(int)"), self.maybefetchmore)

        # console
        self.console = Console(startup_message='--there is table')
        self.console.updateNamespace({  'table' : self.table,
                                        'self': self,
                                        'mainwindow': self.connection.mainwindow})

        # layout
        self.leftsplitter = QtGui.QSplitter(QtCore.Qt.Vertical, self)
        self.leftsplitter.addWidget(self.editor)
        #self.leftsplitter.addWidget(self.console)
        self.leftsplitter.setStretchFactor(0, 4)
        self.leftsplitter.setStretchFactor(1, 1)

        self.splitter = QtGui.QSplitter(self)
        self.splitter.addWidget(self.leftsplitter)
        self.splitter.addWidget(self.table)
        self.splitter.setStretchFactor(0, 1)
        self.splitter.setStretchFactor(1, 3)
        self.horizontalLayout.addWidget(self.splitter)

        self.setLayout(self.horizontalLayout)


    def showfinddialog(self):
        self.findDialog.show()

    def defaultStretch(self):
        self.splitter.setSizes([200, 200])

    def expandTable(self):
        s = self.splitter.sizes()
        s[1] *= 2
        self.splitter.setSizes(s)

    def shrinkTable(self):
        s = self.splitter.sizes()
        s[1] /= 2
        self.splitter.setSizes(s)


    def getalias(self):
        self.alias = dict([(i[2].upper(), i[2].upper()) for i in self.connection.catalog])

        # create a set of tables that appear in sql (for regex)
        sql = self.editor.getsql().upper()
        words = set(re.split("\s", sql))
        searchFor = words & set([i[2].upper() for i in self.connection.catalog])
        regex = re.compile("|".join(("%s\s+a?s?\s?[\w\_]+" % re.escape(i) for i in searchFor)), re.IGNORECASE)

        for line in sql.splitlines():
            for newAlias in re.findall(regex, line):
                if newAlias:
                    print '"%s"' % newAlias
                    name, alias = re.split("\s|as", newAlias)
                    print name, alias
                    if alias not in keywords:
                        print ' set alias'
                        self.alias[alias] = name
    # TODO: very ugly
    def showcolumnautocomplete(self):
        columns = []
        self.getalias()

        # get string till the first space or newline
        x, y = self.editor.getCursorPosition()
        self.editor.findFirst("[\s\n]", True, False, False, False, False, x, y, False)
        x2, y2 = self.editor.getCursorPosition()
#.........这里部分代码省略.........
开发者ID:davideuler,项目名称:simple-database-explorer,代码行数:103,代码来源:elements.py


注:本文中的console.Console.updateNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。