示例#1
0
 def show_box(self, box_func):
     cursor = QtGui.QApplication.overrideCursor()
     QtGui.QApplication.restoreOverrideCursor()
     box_func()
     if cursor and isinstance(cursor, QtGui.QCursor) and cursor.shape() == QtCore.Qt.WaitCursor:
         QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
     QtGui.QApplication.processEvents()
示例#2
0
    def __init__(self, ui_module, connect_actions=True):
        self.gui = self
        QtGuiApplication.__init__(self, ui_module)
        QtGui.QMainWindow.__init__(self)

        if "Ui_Form" in dir(ui_module):
            self.ui = ui_module.Ui_Form()
            centralWidget = QtGui.QWidget(self)
            self.setCentralWidget(centralWidget)
            try:
                self.setupUI(centralWidget)
            except TypeError:
                self.compile_ui(ui_module, True)
                self.ui = ui_module.Ui_Form()
                self.setupUI(centralWidget)


#
        elif "Ui_MainWindow" in dir(ui_module):
            self.ui = ui_module.Ui_MainWindow()

            try:
                self.ui.setupUi(self)
            except TypeError:
                self.compile_ui(ui_module, True)
                self.ui = ui_module.Ui_MainWindow()
                self.ui.setupUi(self)

        if connect_actions:
            self.connect_actions()
示例#3
0
    def __init__(self, ui_module):
        self.ui_module = ui_module
        self.app_filename = os.path.basename(sys.argv[0])
        self.app_name = os.path.splitext(self.app_filename)[0]
        if QtGui.QApplication.startingUp():
            self.app = QtGui.QApplication(sys.argv)

        self.compile_ui(ui_module)
示例#4
0
    def __init__(self,
                 parent=None,
                 value_range=(0, 100),
                 slider_steps=100,
                 spinbox_steps=1000):
        QtGui.QWidget.__init__(self, parent)
        layout = QtGui.QHBoxLayout(self)
        self.setLayout(layout)
        self.horizontalSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.doubleSpinBox = QtGui.QDoubleSpinBox(self)
        layout.setMargin(0)
        layout.addWidget(self.doubleSpinBox)
        layout.addWidget(self.horizontalSlider)

        self.doubleSpinBox.valueChanged.connect(self.spinbox_changed)
        self.horizontalSlider.valueChanged.connect(self.slider_changed)

        self.wt = []
        self.changer = None
        self.slider_steps = slider_steps
        self.horizontalSlider.setMaximum(slider_steps)
        self.spinbox_steps = spinbox_steps
        self.set_range(value_range)
示例#5
0
    def key_press_event(self, event):

        self.update_dirty()
        if self.editor.__class__.__name__ == "LineTextWidget":
            return self.editor.edit.keyReleaseEvent(event)  # When using PySide without QSciScintilla

        linenr, pos_in_line = self.editor.getCursorPosition()
        line = str(self.editor.text(linenr)[:pos_in_line])
#        if event.key() == Qt.Key_ParenLeft:
#            for tip in self.autocomplete_lst:
#                try:
#                    if line.endswith(tip[:tip.index('(') ]):
#                        self.editor.insert(tip[tip.index('('):])
#                        parent, residual = self.scriptRunner.split_line(line)
#                        self.parent.show_documentation(self.scriptRunner.get_function_dict(parent, residual).values()[0])
#                        return
#                except ValueError:
#                    pass
        Qsci.QsciScintilla.keyPressEvent(self.editor, event)

        linenr, pos_in_line = self.editor.getCursorPosition()
        line = str(self.editor.text(linenr)[:pos_in_line])
        if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return:
            for tip in self.autocomplete_lst:
                try:
                    if line.endswith(tip[:tip.index('(') ]):
                        self.editor.insert(tip[tip.index('('):])
                        parent, residual = self.scriptRunner.split_line(line)
                        self.parent.show_documentation(self.scriptRunner.get_function_dict(parent, residual).values()[0])
                        return
                except ValueError:
                    pass

        if event.key() < 100 or event.key() in [Qt.Key_Backspace, Qt.Key_Shift]:
            linenr, pos_in_line = self.editor.getCursorPosition()
            line = str(self.editor.text(linenr)[:pos_in_line])

            lst = self.scriptRunner.get_autocomplete_list(line)

            if lst is not None:
                self.api.clear()
                map(self.api.add, lst)
                self.api.prepare()
                if len(lst) > 0:
                    self.autocomplete_lst = lst

            self.editor.autoCompleteFromAll()
            shift_event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, Qt.Key_Shift, Qt.NoModifier)
            Qsci.QsciScintilla.keyPressEvent(self.editor, shift_event)  # show autocomplete list
示例#6
0
    def setupUI(self, widget):
        self.ui.setupUi(widget)
        root_widgets = [
            w for w in widget.children() if w.__class__.__name__ == "QWidget"
        ]
        if len(root_widgets) == 0 or widget.layout() is not None:
            self.ui_widget = self
        else:
            self.ui_widget = root_widgets[-1]
            g = QtGui.QGridLayout()
            if isinstance(self, QtWidgetLoader):
                g.setMargin(0)
                g.setSpacing(0)
            widget.setLayout(g)

            g.addWidget(self.ui_widget)
示例#7
0
文件: TabWidget.py 项目: luasdtu/MMPE
    def __init__(self, tab_widget):
        QTabWidget.__init__(self)
        self.tab_widget = tab_widget
        self.setTabsClosable(True)
        self.setMovable(True)
        self.insertTab(0, QtGui.QWidget(), "")
        self.new_label = QLabel("*")
        self.tabBar().setTabButton(0, QtGui.QTabBar.RightSide, self.new_label)
        self.currentChanged.connect(self.current_tab_changed)
        QtCore.QObject.connect(self, QtCore.SIGNAL("tabCloseRequested(int)"), self.close_tab)
        QtCore.QObject.connect(self.tabBar(), QtCore.SIGNAL("tabMoved(int,int)"), self.tabMoved)

        self.labels = lambda: [str(self.tabBar().tabText(i)).lower() for i in range(self.count())]
        self.tabBar().setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.tabBar().customContextMenuRequested.connect(self.openMenu)
        self.add_tab()
示例#8
0
 def start_wait(self):
     """Changes mouse icon to waitcursor"""
     QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
示例#9
0
 def test_text_qt_status(self):
     app = QtGui.QApplication([])
     compare(TextStatusUI(), QtStatusUI(None))
示例#10
0
    def initialize_editor(self):



        self.editor = Qsci.QsciScintilla()

#        self.editor.cursorPositionChanged.connect(self.e)
#        self.editor.copyAvailable.connect(self.e)
#        self.editor.indicatorClicked.connect(self.e)
#        self.editor.indicatorReleased.connect(self.e)
#        self.editor.linesChanged.connect(self.e)
#        self.editor.marginClicked.connect(self.e)
#        self.editor.modificationAttempted.connect(self.e)
#        self.editor.modificationChanged.connect(self.e)
#        self.editor.selectionChanged.connect(self.e)
#        self.editor.textChanged.connect(self.e)
#        self.editor.userListActivated.connect(self.e)

        if self.editor.__class__.__name__ == "LineTextWidget":
            return  # When using PySide without QSciScintilla

        # define the font to use
        font = QtGui.QFont()
        font.setFamily("Consolas")
        font.setFixedPitch(True)
        font.setPointSize(10)
        # the font metrics here will help
        # building the margin width later
        fm = QtGui.QFontMetrics(font)

        # set the default font of the self.editor
        # and take the same font for line numbers
        self.editor.setFont(font)
        self.editor.setMarginsFont(font)

        # Line numbers
        # conventionnaly, margin 0 is for line numbers
        self.editor.setMarginWidth(0, fm.width("00000") + 5)
        self.editor.setMarginLineNumbers(0, True)

        self.editor.setTabWidth(4)

        # Folding visual : we will use boxes
        self.editor.setFolding(Qsci.QsciScintilla.BoxedTreeFoldStyle)

        self.editor.setAutoIndent(True)

        # Braces matching
        self.editor.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch)

        # Editing line color
        self.editor.setCaretLineVisible(True)
        self.editor.setCaretLineBackgroundColor(QtGui.QColor("#CDA869"))

        # Margins colors
        # line numbers margin
        self.editor.setMarginsBackgroundColor(QtGui.QColor("#333333"))
        self.editor.setMarginsForegroundColor(QtGui.QColor("#CCCCCC"))

        # folding margin colors (foreground,background)
        self.editor.setFoldMarginColors(QtGui.QColor("#99CC66"), QtGui.QColor("#333300"))

        # Choose a lexer
        self.lexer = Qsci.QsciLexerPython()
        self.lexer.setDefaultFont(font)

        # Set the length of the string before the editor tries to autocomplete
        # In practise this would be higher than 1
        # But its set lower here to make the autocompletion more obvious
        self.editor.setAutoCompletionThreshold(1)
        # Tell the editor we are using a QsciAPI for the autocompletion
        self.editor.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs)

        self.editor.setLexer(self.lexer)
        self.editor.setCallTipsStyle(Qsci.QsciScintilla.CallTipsContext)

        # self.editor.setCallTipsVisible(0)
        # Create an API for us to populate with our autocomplete terms
        self.api = Qsci.QsciAPIs(self.lexer)

        # Compile the api for use in the lexer
        self.api.prepare()
示例#11
0
#class WorkThread(QtCore.QThread):
#    done = QtCore.pyqtSignal(float)
#
#    def __init__(self, holdIt, value):
#        QtCore.QThread.__init__(self)
#        self.holdIt = holdIt
#        self.value = value
#
#    def run(self):
#        t = time.time()
#        time.sleep(2)
#        self.holdIt.update_duration = time.time() - t
#        print "update finished", self.value

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    m = QtGui.QMainWindow()

    w = QtGui.QWidget()
    m.setCentralWidget(w)
    vlayout = QtGui.QVBoxLayout(w)
    s_log = LogaritmicSliderSpinBox(m, slider_steps=100)
    s_lin = SliderSpinBox(m, slider_steps=100)
    s_pol = PolynomialSliderSpinBox(m, 2, slider_steps=100, spinbox_steps=1000)
    vlayout.addWidget(s_lin)
    vlayout.addWidget(s_log)
    vlayout.addWidget(s_pol)
    #m.setCentralWidget(s)

    s_log.set_range((0.001, 1000))
    m.show()
示例#12
0
文件: TabWidget.py 项目: luasdtu/MMPE
 def new_widget():
     return QtGui.QPushButton("hello")
示例#13
0
文件: TabWidget.py 项目: luasdtu/MMPE
 def edit():
     menu = QtGui.QMenu()
     editAction = menu.addAction("Rename")
     return editAction == menu.exec_(self.mapToGlobal(position))
示例#14
0
文件: TabWidget.py 项目: luasdtu/MMPE
            if edit():
                tabname, ok = QtGui.QInputDialog.getText(self, "Enter new name", "New name", text=self.tabText(tabindex))
                if ok:
                    self.widget(tabindex).name = tabname
                    self.setTabText(tabindex, str(tabname))


    def close_all_tabs(self):
        for i in range(self.count() - 1):
            self.close_tab(0)




if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    def ptt(txt):
        print (txt)
    m = QtGui.QMainWindow()
    def new_widget():
        return QtGui.QPushButton("hello")
    t = TabWidget(new_widget)

    m.setCentralWidget(t)
    t.connect
    m.show()
    sys.exit(app.exec_())