def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) freecadSettings = FreeCAD.ParamGet( "User parameter:BaseApp/Preferences/Mod/PCB") # self.listaBibliotek = QtGui.QComboBox() libraryFrame = QtGui.QGroupBox(u'Library:') libraryFrameLay = QtGui.QHBoxLayout(libraryFrame) libraryFrameLay.addWidget(self.listaBibliotek) # self.listaElementow = updateObjectTable() przSelectAllT = QtGui.QPushButton('') przSelectAllT.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) przSelectAllT.setFlat(True) przSelectAllT.setIcon( QtGui.QIcon(":/data/img/checkbox_checked_16x16.png")) przSelectAllT.setToolTip('Select all') self.connect(przSelectAllT, QtCore.SIGNAL('pressed ()'), self.selectAllObj) przSelectAllTF = QtGui.QPushButton('') przSelectAllTF.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) przSelectAllTF.setFlat(True) przSelectAllTF.setIcon( QtGui.QIcon(":/data/img/checkbox_unchecked_16x16.PNG")) przSelectAllTF.setToolTip('Deselect all') self.connect(przSelectAllTF, QtCore.SIGNAL('pressed ()'), self.unselectAllObj) self.adjustParts = QtGui.QCheckBox(u'Adjust part name/value') self.adjustParts.setChecked( freecadSettings.GetBool("adjustNameValue", False)) self.groupParts = QtGui.QCheckBox(u'Group parts') self.groupParts.setChecked(freecadSettings.GetBool( "groupParts", False)) self.plytkaPCB_elementyKolory = QtGui.QCheckBox(u"Colorize elements") self.plytkaPCB_elementyKolory.setChecked( freecadSettings.GetBool("partsColorize", True)) packagesFrame = QtGui.QGroupBox(u'Packages:') packagesFrameLay = QtGui.QGridLayout(packagesFrame) packagesFrameLay.addWidget(przSelectAllT, 0, 0, 1, 1) packagesFrameLay.addWidget(przSelectAllTF, 1, 0, 1, 1) packagesFrameLay.addWidget(self.listaElementow, 0, 1, 3, 1) # lay = QtGui.QVBoxLayout() lay.addWidget(libraryFrame) lay.addWidget(packagesFrame) lay.addWidget(self.adjustParts) lay.addWidget(self.groupParts) lay.addWidget(self.plytkaPCB_elementyKolory) lay.setStretch(1, 10) self.setLayout(lay) # self.readLibs()
def quotes(self): QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) conn = sqlite3.connect('HSAsserts.db') cursor = conn.cursor() stocks='' #select c.Code,TradeMarket from b_code c where c.Enable=1 and c.TradeMarket notnull for row in cursor.execute("select c.Code,TradeMarket from b_code c,v_assets a where c.Enable=1 and c.TradeMarket notnull and a.code= c.code and a.sumvollum !=0 "): if( stocks == ''): stocks = row[1].lower() + row[0] else: stocks = stocks + ',' + row[1].lower()+row[0] qd = SinaQuote.GetQuote( stocks ) #print(qd) sql = "INSERT OR REPLACE INTO D_LatestQuote VALUES (?, ?, ?)" for i in range( len(qd) ): CValue = qd.iloc[i]['C'] if CValue == 0: CValue = qd.iloc[i]['PC'] sqltuple = (qd.iloc[i]['code'][2:] , qd.iloc[i]['datetime'].strftime('%Y-%m-%d %H:%M:%S'), str(CValue) ) cursor.execute(sql,sqltuple) conn.commit() conn.close() QtGui.QApplication.restoreOverrideCursor() QtGui.QMessageBox.information(self,self.tr('Get Quotes'), self.tr('[{0}] records updated.'.format(i)) , QtGui.QMessageBox.Ok)
def __init__(self, callback=lambda: None, text='Loading ...'): """Initialize the LoadingDialog.""" super(LoadingDialog, self).__init__() self.setupUi(self) self.callback = callback self.return_value = None self.painted = False # Set the window opacity self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setAttribute(QtCore.Qt.WA_PaintOnScreen) self.setWindowFlags(QtCore.Qt.Widget | QtCore.Qt.FramelessWindowHint) # Fill the screen desktop = QtGui.QApplication.instance().desktop() self.setGeometry(desktop.screenGeometry(QtGui.QCursor().pos())) # Set the semi-transparent background palette = QtGui.QPalette() pxm = QtGui.QPixmap( os.path.join(os.path.dirname(__file__), 'resource', 'semi_transparent_bg.png')) brush = QtGui.QBrush(pxm) palette.setBrush(QtGui.QPalette.Window, brush) self.setPalette(palette) # Set the text self.label.setText(text) # Show the loading dialog self.exec_()
def mouseMoveEvent(self, e): if e.buttons() != qc.Qt.MiddleButton: return globalPos = self.mapToGlobal(e.pos()) #print(globalPos) tabBar = self.tabBar #print(tabBar) posInTab = tabBar.mapFromGlobal(globalPos) #print(posInTab) self.indexTab = tabBar.tabAt(e.pos()) #print(self.indexTab) tabRect = tabBar.tabRect(self.indexTab) #print(tabRect) #print(tabRect.size()) pixmap = qg.QPixmap(tabRect.size()) tabBar.render(pixmap, qc.QPoint(), qg.QRegion(tabRect)) mimeData = qc.QMimeData() drag = qg.QDrag(tabBar) drag.setMimeData(mimeData) drag.setPixmap(pixmap) cursor = qg.QCursor(qc.Qt.OpenHandCursor) drag.setHotSpot(e.pos() - posInTab) drag.setDragCursor(cursor.pixmap(), qc.Qt.MoveAction) dropAction = drag.exec_(qc.Qt.MoveAction)
def updatehkd2rmb(self): QtGui.QApplication.setOverrideCursor( QtGui.QCursor(QtCore.Qt.WaitCursor)) url = "http://www.sse.com.cn/services/hkexsc/home/" urllib.request.urlretrieve(url, 'local_filename.html') f = open('local_filename.html', 'rt', encoding='utf-8') for line in f: if 'var SELL_PRICE_clear =' in line: idoc = line.find('.', 10) iend = line.find("'", idoc) #print( line[idoc-1:iend] ) self.hkd2rmb = float(line[idoc - 1:iend]) self.teHKD.setText(str(self.hkd2rmb)) conn = sqlite3.connect('HKAsserts.db') cursor = conn.cursor() cursor.execute('update d_param set HKD2RMB=?', (self.hkd2rmb, )) conn.commit() conn.close() QtGui.QApplication.restoreOverrideCursor() QtGui.QMessageBox.information( self, self.tr('Update HKD2RMB'), self.tr('HKD2RMB = [{0}].'.format(self.hkd2rmb)), QtGui.QMessageBox.Ok) else: QtGui.QApplication.restoreOverrideCursor()
def onProjectContextMenu(self, ids, col): menu = QtGui.QMenu() def onNew(): def onAccepted(fields): p = zookeeper.zkDB.zkProject.createNew(self.__conn) p.name = fields[0]['value'] p.write() self.poll() dialog = zookeeper.zkUI.zkNewProjectDialog(onAccepted, None) dialog.exec_() menu.addAction('new project').triggered.connect(onNew) menu.addSeparator() def setupGroupAction(menu, group): insideAll = True for id in ids: project = zookeeper.zkDB.zkProject.getById(self.__conn, id = id) inside = group.id == project.machinegroup if not inside: insideAll = False def onToggled(state): for id in ids: project = zookeeper.zkDB.zkProject.getById(self.__conn, id = id) project.machinegroup = group.id project.write() self.poll() action = menu.addAction('group %s' % group.name) action.setCheckable(True) action.setChecked(insideAll) action.toggled.connect(onToggled) groups = zookeeper.zkDB.zkMachineGroup.getAll(self.__conn) for group in groups: setupGroupAction(menu, group) menu.addSeparator() def onDelete(): msgBox = QtGui.QMessageBox() msgBox.setText("Are you sure?") msgBox.setInformativeText("This will remove all jobs, frames and outputs (from scratch disc only)...!") msgBox.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel) msgBox.setDefaultButton(QtGui.QMessageBox.Ok) ret = msgBox.exec_() if ret == QtGui.QMessageBox.Ok: for id in ids: self.__conn.call('delete_project', [id]) self.poll() menu.addAction('delete').triggered.connect(onDelete) pos = QtGui.QCursor().pos() menu.exec_(pos)
def mouseMoveEvent(self, event): contains = self.grab_rect().contains(event.pos()) if contains and not self.over_grab_hotspot: QtGui.qApp.setOverrideCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor)) self.over_grab_hotspot = True elif not contains and self.over_grab_hotspot: restore_cursor() self.over_grab_hotspot = False
def showSelectionSetsMenu(self, **kwargs): """ :rtype: QtGui.QAction """ menu = self.selectionSetsMenu(**kwargs) position = QtGui.QCursor().pos() action = menu.exec_(position) return action
def __init__(self, cv_impl, logger, testdata): """Main window constructor. Keyword Arguments: cv_impl -- Class conforming to the vision implementation interface logger -- InteractionLogger instance""" super(MainWindow, self).__init__() self.logger = logger self.testdata = testdata self.cvImpl = cv_impl cv_impl.setMainWindow(self) self.initUI(cv_impl) # Initialize cursors that will be used self.normalCursor = QtGui.QCursor(QtCore.Qt.ArrowCursor) self.dragCursor = QtGui.QCursor(QtCore.Qt.DragLinkCursor)
def cursor_position(self): """ Desc: Return the position on the board of the mouse cursor Input: self Output: position (tuple(int)) """ pos = self.mapFromGlobal(QtGui.QCursor().pos()) return (pos.y() - 29) // 52, (pos.x() - 29) // 52
def cursor(self): """ cursor() -> QCursor Return the cursor that will be shown inside the resizer """ cursor = QtGui.QCursor() cursor.setShape(QtCore.Qt.SizeFDiagCursor) return cursor
def load_blocks(self, set_blocks): editor = self.main.tabWidget_graphical.currentWidget() editor.graphical_area.isOpening = True toFitInside = [] #restaurPos = [] #all_icons = [] #dummy, pos = editor.graphical_area.new_bloq("output", all_sets["convert_"], QtCore.QPoint(), "dummy_block", "dummy_block") #dummy.metadata.self_id = self.serialize_widgets([dummy])[0] for block in set_blocks: name = block["name"] args = ["", ""] + block["constructor"] pos = QtCore.QPoint(*block["position"]) basename = block["basename"] ID = block["self_id"] newIcon = editor.graphical_area.new_bloq(name, args, pos, basename)[0] newIcon.metadata.self_id = ID newIcon.move(pos) newIcon.setCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor)) newIcon.metadata.to = block["to"] newIcon.metadata.from_ = block["from"] newIcon.metadata.inside = block["inside"] #for i in range(newIcon.metadata.inside.count(None)): #newIcon.metadata.inside.remove(None) newIcon.metadata.nested = block["nested"] self.replace_id_by_widgets() for block in editor.graphical_area.get_project_blocks(): if block.metadata.inside: toFitInside.append([block, block.metadata.inside[:]]) #self.force_inside(block, block.metadata.inside) all_dummies = [] for parent, toFit in toFitInside: for ins in toFit: wdg = self.get_widget_from_id(ins) if wdg: wdg.metadata.add_parent([parent, wdg], force=True) else: dummy, pos = editor.graphical_area.new_bloq( "output", all_sets["convert_"], QtCore.QPoint(), "dummy_block", "dummy_block") dummy.metadata.self_id = self.serialize_widgets([dummy])[0] dummy.metadata.add_parent([parent, dummy], force=True) all_dummies.append(dummy) #dummy. for dummy in all_dummies: dummy.metadata.remove_parent() dummy.metadata.destroy_this()
def load_old_note(self, sliderpos): if sliderpos == self.ui.historySlider.maximum(): self.update_ui_views() self.old_data = None else: self.setCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) self.old_data = self.current_note.load_old_note(sliderpos) self.update_ui_views_history() self.unsetCursor()
def __init__(self, parent=None, size=6.0): super(NodeSizerItem, self).__init__(QtCore.QRectF(-size/2, -size/2, size, size), parent) self.posChangeCallbacks = [] self.setPen(QtGui.QPen(QtGui.QColor('#A18961'), 1)) self.setBrush(QtGui.QBrush(QtGui.QColor('#57431A'))) self.setFlag(self.ItemIsSelectable, False) self.setFlag(self.ItemIsMovable, True) self.setFlag(self.ItemSendsScenePositionChanges, True) self.setCursor(QtGui.QCursor(QtCore.Qt.SizeFDiagCursor))
def getWidgetAtMouse(): """ Get the widget under the mouse :return: QtGui.QWidget or None """ currentPos = QtGui.QCursor().pos() widget = QtGui.qApp.widgetAt(currentPos) return widget
def shorcutClicked(self, i): fMap = [self.renderChain, self.saveImage] try: QtGui.QApplication.setOverrideCursor( QtGui.QCursor(QtCore.Qt.WaitCursor)) fMap[i]() except: raise finally: QtGui.QApplication.restoreOverrideCursor()
def on_click(self): if self._base is None: return try: QtGui.QApplication.setOverrideCursor( QtGui.QCursor(QtCore.Qt.WaitCursor)) widget = self.sender() self._base._presenter.on(ViewEvent("click", widget._py_mvp_id)) finally: QtGui.QApplication.restoreOverrideCursor()
def setModelOnView(self, index, view): """Set an index's model (if any) on a view """ self.g.mainwindow.setCursor(QtGui.QCursor(Qt.WaitCursor)) try: model = index.data(Qt.UserRole).model if model: view.setModel(model) finally: self.g.mainwindow.unsetCursor()
def resort(): if not self._sortChanged: return self._sortChanged = False QtGui.QApplication.setOverrideCursor(QtGui.QCursor(Qt.WaitCursor)) try: self.layoutAboutToBeChanged.emit() self._setQuery() self.layoutChanged.emit() finally: QtGui.QApplication.restoreOverrideCursor()
def getMousePos(self): """ Get mouse position relative to this rendering canvas. Returns None if mouse is outside canvas. """ relPos = self.mapFromGlobal(QtGui.QCursor().pos()) if relPos.x() < 0 or relPos.x() > G.windowWidth: return None if relPos.y() < 0 or relPos.y() > G.windowHeight: return None return (relPos.x(), relPos.y())
def showSelectionSetsMenu(self): """ :rtype: None """ import selectionsetmenu dirname = self.dirname() menu = selectionsetmenu.SelectionSetMenu.fromPath(dirname) position = QtGui.QCursor().pos() menu.exec_(position)
def initUI(self): app = QtGui.QApplication.instance() cursor_pos = QtGui.QCursor().pos() parent = app.topLevelAt(cursor_pos) self.setGeometry(200, 200, 500, 300) self.setWindowTitle("Color Lab") self.setWindowFlags(QtCore.Qt.Window) # header = QtGui.QLabel("Color Node") # header.setStyleSheet('font-size: 30px; font-family: Arial;') # header.move(10, 10) grid = QtGui.QGridLayout() grid_widget = QtGui.QWidget() grid_widget.setLayout(grid) scroll = QtGui.QScrollArea() scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) scroll.setWidget(grid_widget) save_button = QtGui.QPushButton('Save') # save_button.setStyleSheet('font-size: 20px; font-family: Arial;') save_button.setFixedWidth(100) save_button.clicked.connect(lambda: self.saveChanges()) apply_button = QtGui.QPushButton('Apply') # apply_button.setStyleSheet('font-size: 20px; font-family: Arial;') apply_button.setFixedWidth(100) apply_button.clicked.connect(lambda: self.applyToScene(grid)) add_button = QtGui.QPushButton('Add') # add_button.setStyleSheet('font-size: 20px; font-family: Arial;') add_button.setFixedWidth(100) add_button.clicked.connect(lambda: self.addRow(grid)) qhbox = QtGui.QHBoxLayout() qhbox.addWidget(save_button) qhbox.addWidget(apply_button) qhbox.addWidget(add_button) qhbox.insertStretch(2) qvbox = QtGui.QVBoxLayout() qvbox.addWidget(scroll) qvbox.addLayout(qhbox) self.setLayout(qvbox) self.buidInterface(grid) self.show()
def _get_end_geometry(self): """The optimal geometry for the final display appearance. @return a QRect with the correct geometry data. """ desktop = QtGui.QApplication.instance().desktop() available_geometry = desktop.screenGeometry(QtGui.QCursor().pos()) x = available_geometry.x() + available_geometry.width() y = (available_geometry.height() / 2) - (self.height() / 2) w = 0 h = self.height() return QtCore.QRect(x, y, w, h)
def _get_start_geometry(self): """The optimal geometry for the dialog in it's smallest form. @return a QRect with the correct geometry data. """ desktop = QtGui.QApplication.instance().desktop() available_geometry = desktop.screenGeometry(QtGui.QCursor().pos()) x = available_geometry.x() - self.width() y = (available_geometry.height() / 2) - (self.height() / 2) w = self.width() h = self.height() return QtCore.QRect(x, y, w, h)
def mouseReleaseEvent(self, event): width = self.frameGeometry().width() height = self.frameGeometry().height() cursor = QtGui.QCursor() new_pos = self.mapFromGlobal(cursor.pos()) x = new_pos.x() y = new_pos.y() if x < 2*width/3 and x > width/3 and y > height/9 and y < 8*height/9: self.__selector_y = (y)/(8*height/9.0) print self.__selector_y self.updatePixelColor() self.repaint()
def createContinueBtn(self): self.contBtn = QtGui.QPushButton(self.musicCtrl) self.contBtn.setObjectName("contBtn") self.contBtn.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) self.contBtn.setMaximumSize(100, 100) self.contBtn.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.contBtn.setStyleSheet( "max-height:100px;max-width:100px;border-radius:49px;") self.contBtn.setIcon(self.playImg) self.contBtn.setIconSize(QtCore.QSize(100, 100)) self.contBtn.setShortcut("Space")
def __init__(self, *args, **kwargs): super(CustomTextEdit, self).__init__(*args, **kwargs) self.completer = PinguinoAutoCompleter() self.completer.text_edit = self self.cursorC = QtGui.QCursor() self.mousePressEvent = self.mouseAction self.completer.setFont(self.font()) self.connect(self.completer, QtCore.SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.insertItem) self.completer.keyPressEvent = self.keyPressEvent_autocompleter self.resize(500, 500) self.completer.setFont(self.font()) #self.setAutoClose({}) icons = CompleteIcons() self.completer.addItemsCompleter(Autocompleter["directive"], icons.iconDirectives) self.completer.addItemsCompleter(Autocompleter["reserved"], icons.iconReserved) self.completer.addItemsCompleter(Snippet.keys(), icons.iconSnippet) #namespaces = pickle.load(open(Constants.IDE_NAMESPACES_FILE, "r")) #self.completer.addItemsCompleter(namespaces["all"], icons.iconLibrary) #palette = QtGui.QPalette(self.palette()) #self.setAutoFillBackground(True) #palette.setColor(QtGui.QPalette.Base, QtGui.QColor("#FFFFFF")) #self.initialize() #self.setPalette(palette) self.last_w = "" self.next_ignore = None #Highlighter(self) Highlighter(self.document()) #self.set_highlighter() self.setStyleSheet(""" QTextEdit { background-color: #FFF; font-family: mono; font-weight: normal; font-size: 11pt; } """)
def showContextMenu(self, position=None, showApplyButton=True): """ @type position: QPoint """ position = QtGui.QCursor().pos() position = self.mapTo(self, position) menu = QtGui.QMenu(self) self.record().selectionSetsMenu(menu, self.window().selectedRecords(), includeSelectContents=True, showApplyButton=showApplyButton) menu.exec_(position)
def mouseReleaseEvent(self, event): # updates the poition of the color selector width = self.frameGeometry().width() height = self.frameGeometry().height() cursor = QtGui.QCursor() new_pos = self.mapFromGlobal( cursor.pos()) #position relative to the widget x = new_pos.x() y = new_pos.y() self.__selector_y = y / float( height) # normalized value of the new selector y-pos self.updatePixelColor() self.repaint()
def mousePressEvent(self, event): """The mouse press event Captures the position of the press event, so the window can be moved relative to the cursor position. @param event the move event @return a standard mousePressEvent """ self.mouse_press_position = event.pos() self.top_line_lbl.setStyleSheet('background-color:#4ca64f;') QtGui.QApplication.setOverrideCursor( QtGui.QCursor(QtCore.Qt.ClosedHandCursor)) return QtGui.QWidget.mousePressEvent(self, event)