def getFileNameFromNum(self, number): if self.h5Flag: tempfile = QtCore.QString('%1%2.h5').arg(self.base).arg( int(number), self.numDigits, 10, QtCore.QChar('0')) else: tempfile = QtCore.QString('%1%2.tif').arg(self.base).arg( int(number), self.numDigits, 10, QtCore.QChar('0')) self.filenum = number #print 'debug :', tempfile return tempfile
def mousePressEvent(self, event): if event.button() == QtCore.Qt.LeftButton: self.lastKey = (event.y() // self.squareSize ) * self.columns + event.x() // self.squareSize if QtCore.QChar( self.lastKey).category() != QtCore.QChar.NoCategory: self.characterSelected.emit( QtCore.QString(QtCore.QChar(self.lastKey))) self.update() else: super(CharacterWidget, self).mousePressEvent(event)
def readCategoryDescription(self, categoryDir, categoryName): if categoryDir.exists("README"): file = QtCore.QFile(categoryDir.absoluteFilePath("README")) if not file.open(QtCore.QFile.ReadOnly): return inputStream = QtCore.QTextStream(file) paragraphs = [] currentPara = [] openQuote = True while not inputStream.atEnd(): line = inputStream.readLine() at = line.indexOf("\"", 0) while at != -1: if openQuote: line.replace( at, 1, QtCore.QChar( QtCore.QChar.Punctuation_InitialQuote)) else: line.replace( at, 1, QtCore.QChar(QtCore.QChar.Punctuation_FinalQuote)) openQuote = not openQuote at = line.indexOf("\"", at) if not line.trimmed().isEmpty(): currentPara.append(str(line.trimmed())) elif len(currentPara) > 0: paragraphs.append(" ".join(currentPara)) currentPara = [] else: break if len(currentPara) > 0: paragraphs.append(" ".join(currentPara)) self.categories[categoryName][ 'description'] = "<p>" + "\n</p><p>".join(paragraphs) + "</p>"
def mouseMoveEvent(self, event): widgetPosition = self.mapFromGlobal(event.globalPos()) key = (widgetPosition.y() // self.squareSize ) * self.columns + widgetPosition.x() // self.squareSize text = QtCore.QString.fromLatin1("<p>Character: <span style=\"font-size: 24pt; font-family: %1\">").arg(self.displayFont.family()) + \ QtCore.QChar(key) + \ QtCore.QString.fromLatin1("</span><p>Value: 0x") + \ QtCore.QString.number(key, 16) QtGui.QToolTip.showText(event.globalPos(), text, self)
def update(self, err): q = self.pv.value if err is None: s = QtCore.QString() for i in range(len(q)): if q[i]==0: break s.append(QtCore.QChar(q[i])) self.__display.valueSet.emit(s) else: print err
def paintEvent(self, event): painter = QtGui.QPainter(self) painter.fillRect(event.rect(), QtCore.Qt.white) painter.setFont(self.displayFont) redrawRect = event.rect() beginRow = redrawRect.top() // self.squareSize endRow = redrawRect.bottom() // self.squareSize beginColumn = redrawRect.left() // self.squareSize endColumn = redrawRect.right() // self.squareSize painter.setPen(QtCore.Qt.gray) for row in range(beginRow, endRow + 1): for column in range(beginColumn, endColumn + 1): painter.drawRect(column * self.squareSize, row * self.squareSize, self.squareSize, self.squareSize) fontMetrics = QtGui.QFontMetrics(self.displayFont) painter.setPen(QtCore.Qt.black) for row in range(beginRow, endRow + 1): for column in range(beginColumn, endColumn + 1): key = row * self.columns + column painter.setClipRect(column * self.squareSize, row * self.squareSize, self.squareSize, self.squareSize) if key == self.lastKey: painter.fillRect(column * self.squareSize + 1, row * self.squareSize + 1, self.squareSize, self.squareSize, QtCore.Qt.red) painter.drawText( column * self.squareSize + (self.squareSize / 2) - fontMetrics.width(QtCore.QChar(key)) / 2, row * self.squareSize + 4 + fontMetrics.ascent(), QtCore.QChar(key))
def __paintResidues(self, painter): brush = QtGui.QBrush(QtCore.Qt.black, QtCore.Qt.SolidPattern) metrics = QtGui.QFontMetrics(self.font) cellWidth = self.cellWidth() cellHeight = self.cellHeight() y = 2 * cellHeight # initialize loop conditions and iterate for each residue x = 0 for index in self.residueRange: # residues without coordinates are NOT BOLD and GRAY if len(self.currentChainModel[index].getAtomNames()) == 0: self.font.setBold(False) painter.setPen(QtCore.Qt.gray) painter.setFont(self.font) # residues which are hidden are NOT BOLD and GRAY elif (self.currentChainModel[index].getAtom("CA") and not self.currentChainModel[index].getAtom("CA").getVisible() ): self.font.setBold(False) painter.setPen(QtCore.Qt.gray) painter.setFont(self.font) # residues with coordinates are BOLD and BLACK else: self.font.setBold(True) painter.setPen(QtCore.Qt.black) painter.setFont(self.font) # selected residues are YELLOW with a BLACK BACKGROUND if index in self.structurePrediction.chain.getSelection(): yOffset = 0.75 * (cellHeight - metrics.ascent()) rect = QtCore.QRectF(float(x), yOffset + float(y), float(cellWidth), float(-cellHeight)) painter.fillRect(rect, brush) painter.setPen(QtCore.Qt.yellow) # draw the glyph nextChar = self.structurePrediction.chain[index].__repr__() charWidth = metrics.width(QtCore.QChar(nextChar)) xOffset = int((cellWidth - charWidth) / 2) painter.drawText(x + xOffset, y, QtCore.QString(nextChar)) x = x + cellWidth # Restore standard properties self.font.setBold(False) painter.setFont(self.font)
def testEnabled(self): strng = self.testMsgFormat.text() print "strng: ", strng import random if "$" in strng: number = random.randint(self.minRange.value(), self.maxRange.value()) strng.replace(QtCore.QChar("$"), QtCore.QString("{0}".format(number))) splittedstrng = strng.split(QtCore.QRegExp("\s")) if "$" in strng: self.sendOscMsg(splittedstrng[0], False, splittedstrng[1].toInt()[0]) else: self.sendOscMsg(splittedstrng[0], False)
def key_down(self, parent, event): key = event.key() if key == QtCore.Qt.Key_Backspace and len(label_dataset.data): shape = label_dataset.data[-1] parent.imagePanel.remove_datum(shape, from_tree=True) parent.update() parent.imagePanel.update() parent.ui.treeWidget.update() else: keystr = str(QtCore.QString(QtCore.QChar(key))).lower() shortcuts = [x['keyboard_shortcut'] for x in self.labelmap] if keystr and keystr in shortcuts: _label = shortcuts.index(keystr) label = self.labelmap[_label]['object_id'] self.label = int(label) parent.ui.item_label_txt.setText(keystr)
def __init__(self, pType, parent=None): """ QParameterEditorSelector(pType: str, parent: QWidget) -> QParameterEditorSelector Put a stacked widget and a popup button """ QtGui.QToolButton.__init__(self, parent) self.type = pType self.setAutoRaise(True) self.setToolButtonStyle(QtCore.Qt.ToolButtonTextOnly) menu = QtGui.QMenu(self) self.setPopupMode(QtGui.QToolButton.InstantPopup) if pType == 'String': self.setText(QtCore.QString(QtCore.QChar(0x25bc))) # Down triangle self.operationActionGroup = QtGui.QActionGroup(self) self.containAction = self.operationActionGroup.addAction('Contain') self.containAction.setCheckable(True) self.exactAction = self.operationActionGroup.addAction('Exact') self.exactAction.setCheckable(True) self.regAction = self.operationActionGroup.addAction('Reg Exp') self.regAction.setCheckable(True) menu.addActions(self.operationActionGroup.actions()) menu.addSeparator() self.caseActionGroup = QtGui.QActionGroup(self) self.sensitiveAction = self.caseActionGroup.addAction( 'Case Sensitive') self.sensitiveAction.setCheckable(True) self.insensitiveAction = self.caseActionGroup.addAction( 'Case Insensitive') self.insensitiveAction.setCheckable(True) menu.addActions(self.caseActionGroup.actions()) else: self.setText('') # Down triangle self.operationActionGroup = QtGui.QActionGroup(self) self.expAction = self.operationActionGroup.addAction('Expression') self.expAction.setCheckable(True) self.setEnabled(False) self.setMenu(menu)
def writeSettingsFiles(self): z = QtCore.QChar('0') for i in range(self.minImageNum, self.maxImageNum + 1): filename = QtCore.QString("%1%2.tif.txt").arg(self.base).arg( i, self.numDigits, 10, z) outfil = file(filename.toLatin1().data(), 'w') om0 = self.settingsArray[0] + ( i - self.minImageNum) * self.settingsArray[1] str = 'OMEGA0 = %f\r\n' % om0 outfil.write(str) om1 = self.settingsArray[1] str = 'OMEGAR = %f\r\n' % om1 outfil.write(str) expos = self.settingsArray[6] chi = self.settingsArray[4] detector = self.settingsArray[5] str = 'chi = %f\r\n' % chi outfil.write(str) str = 'detector = %f\r\n' % detector outfil.write(str) str = 'exp. time = %f\r\n' % expos outfil.write(str) outfil.close()
def __paintIndices(self, painter, metrics, cellWidth, cellHeight): x = 0 y = 3 * cellHeight paint = False for index in self.residueRange: # Thousands place if (index + 3) % 10 == 0: if index + 3 >= 1000: thousandsPlace = ((index + 3) / 1000) % 10 nextChar = str(thousandsPlace) paint = True # Hundreds place elif (index + 2) % 10 == 0: if index + 2 >= 100: hundredsPlace = ((index + 2) / 100) % 10 nextChar = str(hundredsPlace) paint = True # Tens place elif (index + 1) % 10 == 0: tensPlace = ((index + 1) / 10) % 10 nextChar = str(tensPlace) paint = True # Ones place elif index % 10 == 0: nextChar = '0' paint = True else: paint = False if paint: charWidth = metrics.width(QtCore.QChar(nextChar)) painter.setPen(QtCore.Qt.gray) xOffset = int((cellWidth - charWidth) / 2) painter.drawText(x + xOffset, y, QtCore.QString(nextChar)) x = x + cellWidth
def __parse_dom_element(self, f_element): """ helper function to the constructor, parses xml entries """ # check input # assert f_model lv_ok = False lf_lat = 0 lf_lng = 0 ls_indc = f_element.text().toLocal8Bit().data() # constData () # read coordinates if available if f_element.hasAttribute(QtCore.QString("longitude")) and \ f_element.hasAttribute(QtCore.QString("latitude")): lf_lat, lv_ok = f_element.attribute( QtCore.QString("latitude"), QtCore.QString("0")).toDouble() lf_lng, lv_ok = f_element.attribute( QtCore.QString("longitude"), QtCore.QString("0")).toDouble() # handle case of ARP if f_element.tagName() == QtCore.QString("ARP"): self.__arp = cfix.CFix(ls_indc, lf_lat, lf_lng) assert self.__arp # handle case of VOR elif f_element.tagName() == QtCore.QString("VOR"): l_fix = cfix.CFix(ls_indc, lf_lat, lf_lng) assert l_fix self.__dct_vor.append(l_fix) # handle case of DME elif f_element.tagName() == QtCore.QString("DME"): l_fix = cfix.CFix(ls_indc, lf_lat, lf_lng) assert l_fix self.__dct_dme.append(l_fix) # handle case of NDB elif f_element.tagName() == QtCore.QString("NDB"): l_fix = cfix.CFix(ls_indc, lf_lat, lf_lng) assert l_fix self.__dct_ndb.append(l_fix) # handle case of WPT elif f_element.tagName() == QtCore.QString("WPT"): l_fix = cfix.CFix(ls_indc, lf_lat, lf_lng) assert l_fix self.__dct_wpt.append(l_fix) # handle case of RWY elif f_element.tagName() == QtCore.QString("RWY"): l_track, lv_ok = f_element.attribute( QtCore.QString("track"), QtCore.QString("0")).toDouble() l_gp, lv_ok = f_element.attribute(QtCore.QString("glidepath"), QtCore.QString("0")).toDouble() l_rwy = crun.CRunway(ls_indc, lf_lat, lf_lng, l_track, l_gp) assert l_rwy is not None self.__dct_rwy.append(l_rwy) # handle case of holding elif f_element.tagName() == QtCore.QString("holding"): l_inb, lv_ok = f_element.attribute(QtCore.QString("inbound"), QtCore.QString("0")).toDouble() l_dir = 'l' if f_element.attribute( QtCore.QString("direction"), QtCore.QString("0")).startsWith( QtCore.QString("l")) else 'r' l_hold = cesp.CHolding( f_element.attribute(QtCore.QString("waypoint"), QtCore.QString("")).toLocal8Bit().data(), l_inb, l_dir) assert l_hold is not None self.dct_esp.append(l_hold) # handle case of standard route elif (f_element.tagName() == QtCore.QString("departure")) or \ (f_element.tagName() == QtCore.QString("arrival")) or \ (f_element.tagName() == QtCore.QString("transition")): ls_rt = stdrt.CStandardRoute() assert ls_rt is not None ls_rt.s_indc = f_element.attribute( QtCore.QString("name"), QtCore.QString("")).toLocal8Bit().data() l_nodeList = f_element.elementsByTagName(QtCore.QString("runway")) for l_iI in xrange(l_nodeList.length()): l_e = l_nodeList.at(l_iI).toElement() if l_e.isNull(): continue ls_rt.addRunway(l_e.text().toLocal8Bit().data()) l_nodeList = f_element.elementsByTagName( QtCore.QString("waypoint")) for l_iI in xrange(l_nodeList.length()): l_e = l_nodeList.at(l_iI).toElement() if l_e.isNull(): continue l_fpItem = cfpi.CFlightPlanItem() assert l_fpItem is not None l_fpItem.s_indc = l_e.text().toLocal8Bit().data() l_fpItem._iSpeedConstraint, lv_ok = l_e.attribute( QtCore.QString("speed"), QtCore.QString("0")).toInt() # parse the altitude constraint altc = l_e.attribute(QtCore.QString("altitude"), QtCore.QString("0")) if altc.endsWith(QtCore.QChar('B')): altc = altc.mid(0, altc.length() - 1) l_fpItem._iAltConstraint, lv_ok = altc.toInt() l_fpItem._iAltConstraintType = cfpi.CFlightPlanItem._OR_BELOW elif altc.endsWith(QtCore.QChar('A')): altc = altc.mid(0, altc.length() - 1) l_fpItem._iAltConstraint, lv_ok = altc.toInt() l_fpItem._iAltConstraintType = cfpi.CFlightPlanItem._OR_ABOVE else: l_fpItem._iAltConstraint, lv_ok = altc.toInt() l_fpItem._iAltConstraintType = cfpi.CFlightPlanItem._EXACTLY l_fpItem._vFlyOver = l_e.hasAttribute("flyover") ls_rt.addItem(l_fpItem) if f_element.tagName() == QtCore.QString("departure"): self.__dct_dep.append(ls_rt) if f_element.tagName() == QtCore.QString("arrival"): self.__dct_pso.append(ls_rt) if f_element.tagName() == QtCore.QString("transition"): self.__dct_transitions.append(ls_rt)
def getHospitalizationEventIdList(self): self.dialogInfo = {} lastName = forceStringEx(self.edtLastName.text()) firstName = forceStringEx(self.edtFirstName.text()) patrName = forceStringEx(self.edtPatrName.text()) birthDate = forceDate(self.edtBirthDate.date()) clientId = forceRef(self.edtClientId.text()) sex = self.cmbSex.currentIndex() docTypeId = self.cmbDocType.value() leftSerial = forceStringEx(self.edtLeftSerial.text()) rightSerial = forceStringEx(self.edtRightSerial.text()) number = forceStringEx(self.edtNumber.text()) contactText = self.edtContact.text() contact = forceString( (contactText.remove(QtCore.QChar('-'), QtCore.Qt.CaseInsensitive)).remove( QtCore.QChar(' '), QtCore.Qt.CaseInsensitive)) policyType = self.cmbPolicyType.value() policySerial = forceStringEx(self.edtPolicySerial.text()) policyNumber = forceStringEx(self.edtPolicyNumber.text()) policyInsurer = self.cmbPolicyInsurer.value() policyBegDate = self.edtPolicyBegDate.date() policyEndDate = self.edtPolicyEndDate.date() self.dialogInfo['lastName'] = lastName self.dialogInfo['firstName'] = firstName self.dialogInfo['patrName'] = patrName self.dialogInfo['birthDate'] = birthDate self.dialogInfo['clientId'] = clientId self.dialogInfo['sex'] = sex self.dialogInfo['docType'] = docTypeId self.dialogInfo['serialLeft'] = leftSerial self.dialogInfo['serialRight'] = rightSerial self.dialogInfo['docNumber'] = number self.dialogInfo['contact'] = forceString(self.edtContact.text()) self.dialogInfo['polisSerial'] = policySerial self.dialogInfo['polisNumber'] = policyNumber self.dialogInfo['polisCompany'] = policyInsurer self.dialogInfo['polisType'] = policyType self.dialogInfo['polisTypeName'] = self.cmbPolicyType.model().getName( self.cmbPolicyType.currentIndex()) self.dialogInfo['polisBegDate'] = policyBegDate self.dialogInfo['polisEndDate'] = policyEndDate serial = u'' if leftSerial: serial = leftSerial if rightSerial: if serial != u'': serial += u' ' + rightSerial else: serial += rightSerial db = QtGui.qApp.db tableClient = db.table('Client') tableDocument = db.table('ClientDocument') tableAddress = db.table('ClientAddress') tableRBDocumentType = db.table('rbDocumentType') tableClientPolicy = db.table('ClientPolicy') tablePolicyType = db.table('rbPolicyType') tableOrganisation = db.table('Organisation') tableClientContact = db.table('ClientContact') queryTable = tableClient.leftJoin( tableAddress, db.joinAnd([ tableClient['id'].eq(tableAddress['client_id']), tableAddress['deleted'].eq(0) ])) cond = [tableClient['deleted'].eq(0)] if self.clientId: cond.append(tableClient['id'].ne(self.clientId)) orderList = ['Client.lastName', 'Client.firstName', 'Client.patrName'] if clientId: cond.append(tableClient['id'].eq(clientId)) if lastName: cond.append(tableClient['lastName'].like('%%%s%%' % lastName)) if firstName: cond.append(tableClient['firstName'].like('%%%s%%' % firstName)) if patrName: cond.append(tableClient['patrName'].like('%%%s%%' % patrName)) if birthDate: cond.append(tableClient['birthDate'].eq(birthDate)) if sex: cond.append(tableClient['sex'].eq(sex)) if docTypeId: cond.append(tableDocument['documentType_id'].eq(docTypeId)) if serial: cond.append(tableDocument['serial'].eq(serial)) if number: cond.append(tableDocument['number'].eq(number)) if docTypeId or serial or number: queryTable = queryTable.innerJoin( tableDocument, tableClient['id'].eq(tableDocument['client_id'])) queryTable = queryTable.innerJoin( tableRBDocumentType, tableDocument['documentType_id'].eq(tableRBDocumentType['id'])) cond.append(tableDocument['deleted'].eq(0)) if contact: queryTable = queryTable.innerJoin( tableClientContact, tableClient['id'].eq(tableClientContact['client_id'])) strContact = u'%' for element in contact: strContact += element + u'%' if len(strContact) > 1: cond.append(tableClientContact['contact'].like(strContact)) if policySerial or policyNumber or policyInsurer or policyType: queryTable = queryTable.innerJoin( tableClientPolicy, tableClient['id'].eq(tableClientPolicy['client_id'])) if policyType: queryTable = queryTable.innerJoin( tablePolicyType, tableClientPolicy['policyType_id'].eq( tablePolicyType['id'])) if policyInsurer: queryTable = queryTable.innerJoin( tableOrganisation, tableClientPolicy['insurer_id'].eq( tableOrganisation['id'])) if policySerial: cond.append(tableClientPolicy['serial'].eq(policySerial)) if policyNumber: cond.append(tableClientPolicy['number'].eq(policyNumber)) if policyInsurer: cond.append(tableClientPolicy['insurer_id'].eq(policyInsurer)) if policyType: cond.append(tableClientPolicy['policyType_id'].eq(policyType)) if policyBegDate.isValid(): cond.append(tableClientPolicy['begDate'].eq(policyBegDate)) if policyEndDate.isValid(): cond.append(tableClientPolicy['endDate'].eq(policyEndDate)) orderStr = ', '.join([fieldName for fieldName in orderList]) idList = db.getDistinctIdList(queryTable, tableClient['id'].name(), where=cond, order=orderStr, limit=1000) return idList
def __init__(self,application,path=None,piter=None,threads=4): """application is an QApplication instance. ptclstack is the path to the file containing the particles to analyze. path is the path for ouput files""" QtGui.QWidget.__init__(self) self.aliimg=None # This is the unmasked alignment reference image self.alisig=None # This is the standard deviation of the alignment reference self.alimask=None # This is the drawn-upon version of aliimg used to generate the mask self.alimasked=None # This is the masked alignment reference used for the actual alignments self.roidrawmask=None # Region of interest mask drawing image self.roimask=None # Region of interest actual mask self.roimasked=None # Region of interest display widget self.particles=None self.app=weakref.ref(application) self.path=path self.iter=piter self.setWindowTitle("Main Window (e2motion.py)") # self.setWindowTitle("e2motion.py") # Menu Bar self.mfile=self.menuBar().addMenu("File") self.mfileopen=self.mfile.addAction("Select Particles") self.mfileopencls=self.mfile.addAction("Particles from Classes") self.mfileopencls.setEnabled(False) self.mfilequit=self.mfile.addAction("Quit") #self.mwin=self.menuBar().addMenu("Window") #self.mwin_boxes=self.mwin.addAction("Particles") #self.mwin_single=self.mwin.addAction("Single Particle") #self.mwin_average=self.mwin.addAction("Averaging") self.setCentralWidget(QtGui.QWidget()) self.gbl = QtGui.QGridLayout(self.centralWidget()) cen=self.centralWidget() ###### # Folder parameters self.vgb0=QtGui.QGroupBox("Particle Data") self.gbl.addWidget(self.vgb0,0,0,1,4) self.gbl2=QtGui.QGridLayout(self.vgb0) self.wlpath=QtGui.QLabel("Path: {}".format(self.path)) self.gbl2.addWidget(self.wlpath,0,0) self.gbl2.setColumnStretch(0,1) self.wvbiter=ValBox(label="Iter:",value=self.iter) self.wvbiter.setIntonly(True) self.gbl2.addWidget(self.wvbiter,0,2) self.gbl2.setColumnStretch(2,0) self.wvsnum=ValSlider(rng=(-.2,0),label="Nptcl:",value=250) self.wvsnum.setIntonly(True) self.gbl2.addWidget(self.wvsnum,0,3) self.gbl2.setColumnStretch(3,4) self.wlnptcl=QtGui.QLabel(" ") self.gbl2.addWidget(self.wlnptcl,0,5) self.gbl2.setColumnStretch(5,2) self.wbdoavg=QtGui.QPushButton("Make Avg") self.gbl2.addWidget(self.wbdoavg,0,8) ###### Alignment Mask # widget for editing the alignment mask self.wlalimaskdraw=QtGui.QLabel("<big><pre>Edit</pre></big>") self.wlalimaskdraw.setAlignment(Qt.AlignHCenter) self.gbl.addWidget(self.wlalimaskdraw,2,1) self.wlalimaskdraw2=QtGui.QLabel("<big><pre>A\nl\ni\ng\nn</pre></big>") self.gbl.addWidget(self.wlalimaskdraw2,3,0) self.w2dalimaskdraw=EMImage2DWidget() self.gbl.addWidget(self.w2dalimaskdraw,3,1) # Buttons for controlling mask self.hbl1=QtGui.QHBoxLayout() self.gbl.addLayout(self.hbl1,4,1) self.hbl1.addStretch(5) self.wbdrawali=QtGui.QPushButton("Draw") self.hbl1.addWidget(self.wbdrawali) self.wbdrawali.hide() # this functionality won't work with the current widget self.wbautoali=QtGui.QPushButton("Auto") self.hbl1.addWidget(self.wbautoali) self.wbresetali=QtGui.QPushButton("Reset") self.hbl1.addWidget(self.wbresetali) self.hbl1.addStretch(5) # Widget for setting alignment mask blur and base level self.vbl1=QtGui.QVBoxLayout() self.gbl.addLayout(self.vbl1,3,2) self.vbl1.addStretch(5) self.wlalimaskblur=QtGui.QLabel("Blur") self.vbl1.addWidget(self.wlalimaskblur) self.wsbalimaskblur=QtGui.QSpinBox() self.wsbalimaskblur.setRange(0,25) self.vbl1.addWidget(self.wsbalimaskblur) self.vbl1.addSpacing(16) self.wlalimaskbase=QtGui.QLabel("Base") self.vbl1.addWidget(self.wlalimaskbase) self.wsbalimaskbase=QtGui.QSpinBox() self.wsbalimaskbase.setRange(0,100) self.wsbalimaskbase.setValue(10) self.vbl1.addWidget(self.wsbalimaskbase) self.vbl1.addSpacing(16) self.wlalimaskrot=QtGui.QLabel("Rot") self.vbl1.addWidget(self.wlalimaskrot) self.wsbalimaskrot=QtGui.QSpinBox() self.wsbalimaskrot.setRange(0,360) self.wsbalimaskrot.setValue(0) self.vbl1.addWidget(self.wsbalimaskrot) self.vbl1.addSpacing(16) self.wbaligo=QtGui.QPushButton(QtCore.QChar(0x2192)) self.vbl1.addWidget(self.wbaligo) self.vbl1.addStretch(5) # widget for displaying the masked alignment reference self.wlalimask=QtGui.QLabel("<big><pre>Reference</pre></big>") self.wlalimask.setAlignment(Qt.AlignHCenter) self.gbl.addWidget(self.wlalimask,2,3) self.w2dalimask=EMImage2DWidget() self.gbl.addWidget(self.w2dalimask,3,3) self.hbl1a=QtGui.QHBoxLayout() self.gbl.addLayout(self.hbl1a,4,3) self.hbl1a.addStretch(5) self.wbrecalcref=QtGui.QPushButton("Realign") self.hbl1a.addWidget(self.wbrecalcref) self.wbrrecalcref=QtGui.QPushButton("Rerefine") self.hbl1a.addWidget(self.wbrrecalcref) self.hbl1a.addStretch(5) ###### ROI Mask # widget for editing the ROI mask self.wlroimaskdraw=QtGui.QLabel("<big><pre>R\nO\nI</pre></big>") self.gbl.addWidget(self.wlroimaskdraw,6,0) self.w2droimaskdraw=EMImage2DWidget() self.gbl.addWidget(self.w2droimaskdraw,6,1) # Buttons for controlling mask self.hbl2=QtGui.QHBoxLayout() self.gbl.addLayout(self.hbl2,5,1) self.hbl2.addStretch(5) self.wbdrawroi=QtGui.QPushButton("Draw") self.hbl1.addWidget(self.wbdrawroi) self.wbdrawroi.hide() # this button won't work right for now self.wbautoroi=QtGui.QPushButton("Auto") self.hbl2.addWidget(self.wbautoroi) self.wbresetroi=QtGui.QPushButton("Reset") self.hbl2.addWidget(self.wbresetroi) self.hbl2.addStretch(5) # Widget for setting alignment mask blur and base level self.vbl2=QtGui.QVBoxLayout() self.gbl.addLayout(self.vbl2,6,2) self.vbl2.addStretch(5) self.wlroimaskblur=QtGui.QLabel("Blur") self.vbl2.addWidget(self.wlroimaskblur) self.wsbroimaskblur=QtGui.QSpinBox() self.wsbroimaskblur.setRange(0,25) self.vbl2.addWidget(self.wsbroimaskblur) self.vbl2.addSpacing(16) self.wbroigo=QtGui.QPushButton(QtCore.QChar(0x2192)) self.vbl2.addWidget(self.wbroigo) # widget for displaying the masked ROI self.w2droimask=EMImage2DWidget() self.gbl.addWidget(self.w2droimask,6,3) self.vbl2.addStretch(5) self.wlarrow1=QtGui.QLabel(QtCore.QChar(0x2192)) self.gbl.addWidget(self.wlarrow1,4,4) ###### Results # Widget showing lists of different result sets self.vbl3=QtGui.QVBoxLayout() self.gbl.addLayout(self.vbl3,3,6,5,1) self.wllistresult=QtGui.QLabel("Results") # self.wllistresult.setAlignment(Qt.AlignHCenter) self.vbl3.addWidget(self.wllistresult) self.wlistresult=QtGui.QListWidget() self.vbl3.addWidget(self.wlistresult) ###### Parameters for processing self.vgb1=QtGui.QGroupBox("Launch Job") self.vbl3.addWidget(self.vgb1) self.vbl3a=QtGui.QVBoxLayout() self.vgb1.setLayout(self.vbl3a) self.wvbclasses=ValBox(None,(0,256),"# Classes",32) self.wvbclasses.setIntonly(True) self.vbl3a.addWidget(self.wvbclasses) self.wvbnbasis=ValBox(None,(0,64),"# PCA Vec",8) self.wvbnbasis.setIntonly(True) self.vbl3a.addWidget(self.wvbnbasis) #self.wvbptclpct=ValBox(None,(0,100),"% Ptcl Incl",60) #self.wvbptclpct.setIntonly(True) #self.vbl3a.addWidget(self.wvbptclpct) ## fill in a default value for number of threads #try : #cores=num_cpus() #except: #cores=2 #if cores==1 : cores=2 cores=threads+1 # one thread for GUI self.wvbcores=ValBox(None,(0,256),"# Threads",cores) self.wvbcores.setIntonly(True) self.vbl3a.addWidget(self.wvbcores) self.wcbprocmode=QtGui.QComboBox() self.wcbprocmode.addItem("PCA / k-means") self.wcbprocmode.addItem("Average Density") self.vbl3a.addWidget(self.wcbprocmode) self.wpbprogress=QtGui.QProgressBar() self.wpbprogress.setEnabled(False) self.wpbprogress.setMinimum(0) self.wpbprogress.setMaximum(100) self.wpbprogress.reset() self.vbl3a.addWidget(self.wpbprogress) # doubles as a cancel button self.wbcompute=QtGui.QPushButton("Compute") self.vbl3a.addWidget(self.wbcompute) self.wlarrow2=QtGui.QLabel(QtCore.QChar(0x2192)) self.gbl.addWidget(self.wlarrow2,4,7) ###### Output widgets # Class-averages self.wlclasses=QtGui.QLabel("<big><pre>Classes</pre></big>") self.wlclasses.setAlignment(Qt.AlignHCenter) self.gbl.addWidget(self.wlclasses,2,9) self.w2dclasses=EMImage2DWidget() self.gbl.addWidget(self.w2dclasses,3,9) self.wbshowptcl=QtGui.QPushButton(QtCore.QChar(0x2193)) self.gbl.addWidget(self.wbshowptcl,4,9) self.w2dptcl=EMImage2DWidget() self.gbl.addWidget(self.w2dptcl,6,9) ## Buttons for controlling mask #self.hbl1=QtGui.QHBoxLayout() #self.gbl.addLayout(self.hbl1,2,1) #self.hbl1.addStretch(5) #self.wbautoali=QtGui.QPushButton("Auto") #self.hbl1.addWidget(self.wbautoali) #self.wbresetali=QtGui.QPushButton("Reset") #self.hbl1.addWidget(self.wbresetali)"bdb:%s" #self.hbl1.addStretch(5) QtCore.QObject.connect(self.wbdrawali,QtCore.SIGNAL("clicked(bool)"),self.aliDrawMode) QtCore.QObject.connect(self.wbautoali,QtCore.SIGNAL("clicked(bool)"),self.aliAutoPress) QtCore.QObject.connect(self.wbresetali,QtCore.SIGNAL("clicked(bool)"),self.aliResetPress) QtCore.QObject.connect(self.wbaligo,QtCore.SIGNAL("clicked(bool)"),self.aliGoPress) QtCore.QObject.connect(self.wbrecalcref,QtCore.SIGNAL("clicked(bool)"),self.aliRecalcRefPress) QtCore.QObject.connect(self.wbrrecalcref,QtCore.SIGNAL("clicked(bool)"),self.aliRRecalcRefPress) QtCore.QObject.connect(self.wbdrawroi,QtCore.SIGNAL("clicked(bool)"),self.roiDrawMode) QtCore.QObject.connect(self.wbautoroi,QtCore.SIGNAL("clicked(bool)"),self.roiAutoPress) QtCore.QObject.connect(self.wbresetroi,QtCore.SIGNAL("clicked(bool)"),self.roiResetPress) QtCore.QObject.connect(self.wbroigo,QtCore.SIGNAL("clicked(bool)"),self.roiGoPress) QtCore.QObject.connect(self.wbcompute,QtCore.SIGNAL("clicked(bool)"),self.doCompute) QtCore.QObject.connect(self.wbshowptcl,QtCore.SIGNAL("clicked(bool)"),self.showParticles) QtCore.QObject.connect(self.wvbiter,QtCore.SIGNAL("valueChanged"),self.newIter) QtCore.QObject.connect(self.wvsnum,QtCore.SIGNAL("valueChanged"),self.newThresh) QtCore.QObject.connect(self.wbdoavg,QtCore.SIGNAL("clicked(bool)"),self.avgPress) QtCore.QObject.connect(self.mfileopen,QtCore.SIGNAL("triggered(bool)") ,self.menuFileOpen ) # set up draw mode insp=self.w2dalimaskdraw.get_inspector() insp.hide() insp.mmtab.setCurrentIndex(5) insp.dtpenv.setText("0.0") insp=self.w2droimaskdraw.get_inspector() insp.hide() insp.mmtab.setCurrentIndex(5) insp.dtpenv.setText("0.0") self.path=path QtCore.QTimer.singleShot(500,self.afterStart)
def update_display(self): h = QtCore.QString("%1").arg(self.hours, 2, 10, QtCore.QChar('0')) m = QtCore.QString("%1").arg(self.minutes, 2, 10, QtCore.QChar('0')) s = QtCore.QString("%1").arg(self.seconds, 2, 10, QtCore.QChar('0')) self.label.setText(h + " : " + m + " : " + s)
def Generate(self): if self.fontLabel == 'No font selected': return fontMap = '' fontMetrics = '' fontMetricsPS3 = '' fontTextureTiles = [] fontPS3Tiles = [] LatinSet = [ 0x20, 0x8141, 0x2E, 0x2C, 0x2E, 0x8145, 0x3A, 0x3B, 0x3F, 0x21, 0x22 ] #Space to Quotations LatinSet.extend(range(0x814B, 0x8165)) #Degree sign to half-ellipsis LatinSet.extend([0x27, 0x27, 0x22, 0x22, 0x28, 0x29]) #quotations and braces LatinSet.extend(range(0x816B, 0x817B)) #A lot more brackets LatinSet.extend([0x2B, 0x2D, 0x817D, 0x817E, 0x00, 0x8180, 0x3D]) #math signs LatinSet.extend(range(0x8182, 0x8190)) #Symbols LatinSet.extend([0x24, 0x8191, 0x7E, 0x25, 0x23, 0x26]) #Monetary and Numeric signs LatinSet.extend(range(0x8196, 0x820F)) #symbols LatinSet.extend(range(0x30, 0x3A)) #Numbers LatinSet.extend([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) LatinSet.extend(range(0x41, 0x5B)) #Uppercase Letters LatinSet.extend([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) LatinSet.extend(range(0x61, 0x7B)) #Lowercase Letters LatinSet.extend([0x00, 0x00, 0x00, 0x00]) BasicKanji = range(0x8890 - 0x50, 0x8900) MediumKanji = [] SpecialKanji = [] for i in range(0x89, 0x98): BasicKanji.extend(range(i * 0x100 + 0x40, i * 0x100 + 0x100)) BasicKanji.extend(range(0x9840, 0x9880)) for i in range(0xE0, 0xEA): MediumKanji.extend(range(i * 0x100 + 0x40, i * 0x100 + 0x100)) for i in range(0xED, 0xEF): SpecialKanji.extend(range(i * 0x100 + 0x40, i * 0x100 + 0x100)) for i in range(0xF9, 0xFD): SpecialKanji.extend(range(i * 0x100 + 0x40, i * 0x100 + 0x100)) MediumKanji.extend(SpecialKanji) LoopPoints = [ LatinSet, range(0x829F, 0x8300), range(0x8340, 0x839F), range(0x839F, 0x8400), range(0x8440, 0x8500), range(0x8740, 0x8850), BasicKanji, MediumKanji ] # Loop = [] # # file = open('Resources/CP932.txt') # for line in file: # num = int(line[:6], 16) # Loop.append(num) # print hex(num) # file.close() # # # LoopPoints = [Loop] self.font.setStyleStrategy(QtGui.QFont.ForceOutline) # self.font.setWeight(100) gradient = QtGui.QLinearGradient(0, 0, 0, 100) gradient.setColorAt(0.0, QtGui.QColor(255, 255, 255)) gradient.setColorAt(1.0, QtGui.QColor(208, 208, 208)) brush = QtGui.QBrush(gradient) pen = QtGui.QPen(QtGui.QColor(128, 128, 128), 0, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin) fontMet = QtGui.QFontMetrics(self.font) # i = 0 # p = 0 # for Loop in LoopPoints: # print 'Loop: {0}'.format(p) # # Wii # for char in Loop: # if self.rangeList[p].isChecked(): # text = struct.unpack('>2s', struct.pack('>H', char))[0] ## try: # text = text.decode('cp932', 'ignore') # i += 1 # fontMap += struct.pack('>H', i) # image = QtGui.QImage(25, 25, QtGui.QImage.Format_ARGB32) # image.fill(QtCore.Qt.black) # painter = QtGui.QPainter(image) # painter.setRenderHint(QtGui.QPainter.Antialiasing) # painter.setBrush(brush) # painter.setPen(pen) # textPath = QtGui.QPainterPath() # textPath.addText(12 - (fontMet.width(text)/2), 25-fontMet.descent(), self.font, text) # painter.drawPath(textPath) # painter.end() # lleading = 12-(fontMet.width(text)/2) # rleading = 13-(fontMet.width(text)/2) # lbearing = lleading # rbearing = rleading # lleadOutline = lleading + 1 # rleadOutline = rleading + 1 # lbearOutline = lbearing + 1 # rbearOutline = rbearing + 1 # try: # fontMetrics += struct.pack('>8B', lleading, rleading, lbearing, rbearing, lleadOutline, rleadOutline, lbearOutline, rbearOutline) # fontTextureTiles.append(image) # #image.save('{0}.png'.format(hex(char))) # except: # print "{0} didn't work:".format(hex(char)) # fontMap += '\x00\x00' # else: # fontMap += '\x00\x00' # p += 1 #PS3 i = 0 p = 0 #self.font.setPointSize(self.font.pointSize()+12) gradient = QtGui.QLinearGradient(0, 0, 0, 100) gradient.setColorAt(0.0, QtGui.QColor(255, 255, 255)) gradient.setColorAt(1.0, QtGui.QColor(158, 158, 158)) #brush = QtGui.QBrush(gradient) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255, 255)) #pen = QtGui.QPen(QtGui.QColor(0,0,0), 1, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin) pen = QtGui.QPen(QtGui.QColor(255, 255, 255, 0), 1, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin) fontMet = QtGui.QFontMetrics(self.font) if self.fontAlt is not None: fontMetAlt = QtGui.QFontMetrics(self.fontAlt) for Loop in LoopPoints: # if p == 3: # tmpfont = QtGui.QFontDialog.getFont(QtGui.QFont("Square721 BT", 20), self, 'Choose a Font'); # if tmpfont[1] == True: # self.font = tmpfont[0] # self.fontLabel.setText('{0}, {1} pt'.format(self.font.family(), self.font.pointSize())) # #self.font.setPointSize(self.font.pointSize()+12) # fontMet = QtGui.QFontMetrics(self.font) print 'Loop: {0}'.format(p) for char in Loop: if self.rangeList[p].isChecked(): text = struct.unpack('>2s', struct.pack('>H', char))[0] # try: text = text.decode('cp932', 'ignore') text = text.replace('\x00', '') if text == '': text = ' ' i += 1 image = QtGui.QImage(32, 32, QtGui.QImage.Format_ARGB32) image.fill(0x00000000) painter = QtGui.QPainter(image) painter.setRenderHint(QtGui.QPainter.Antialiasing) painter.setBrush(brush) painter.setPen(pen) textPath = QtGui.QPainterPath() # textPath.addText(0, 0, self.font, text) # textPath.addText(18 - (fontMet.width(text)/2), 32-fontMet.descent(), self.font, text) if self.fontAlt is None or fontMet.inFont( QtCore.QChar(ord(text[0]))): if char >= 0x20 and char < 0x80: textPath.addText(0, fontMet.ascent() - 4, self.font, text) else: textPath.addText(0, fontMet.ascent() - 4, self.font, text) else: if char >= 0x20 and char < 0x80: textPath.addText(0, fontMetAlt.ascent() - 2, self.fontAlt, text) else: textPath.addText(0, fontMetAlt.ascent(), self.fontAlt, text) #print 'tile 0x{0}: '.format(hex(char)) + str(fontMet.ascent()) painter.drawPath(textPath) painter.end() lleading = 0 rleading = 0 #lleading = 18-(fontMet.width(text)/2) #rleading = 19-(fontMet.width(text)/2) lbearing = 0 rbearing = 0 lleadOutline = lleading + 1 rleadOutline = rleading + 1 lbearOutline = lbearing + 1 rbearOutline = rbearing + 1 fontMetricsPS3 += struct.pack('>8B', lleading, rleading, lbearing, rbearing, lleadOutline, rleadOutline, lbearOutline, rbearOutline) fontPS3Tiles.append(image) # image.save('{0}.png'.format(hex(char))) # except: # print "{0} didn't work:".format(hex(char)) # fontMap += '\x00\x00' else: pass p += 1 print '{0} characters total'.format(i) # print 'Fontmap: {0}'.format(len(fontMap)/2) # (0x21C0) # Wii #self.fontMap = fontMap #self.fontMetrics = fontMetrics #self.fontMetricsPS3 = fontMetricsPS3 #Xoffset = 0 #Yoffset = 0 #tex = QtGui.QImage(1024, 1024, QtGui.QImage.Format_ARGB32) #tex.fill(QtCore.Qt.black) #painter = QtGui.QPainter(tex) #p = 1 #for i in fontTextureTiles: # painter.drawImage(Xoffset, Yoffset, i) # Xoffset += 25 # if Xoffset >= 1024: # Xoffset = 0 # Yoffset += 25 # if Yoffset >=1024: # painter.end() # xpixel = 0 # ypixel = 0 # for xpixel in range(1024): # for ypixel in range(1024): # curVal = tex.pixel(xpixel, ypixel) # g = (curVal & 0xFF) * ((curVal >> 24) / 256.0) # g = int(g)/16*16 # if curVal == 0x1FFFFFFF: # tex.setPixel(xpixel, ypixel, 0xFF << 24) # else: # tex.setPixel(xpixel, ypixel, (0xFF << 24 | g << 16 | g << 8 | g)) # booli = tex.save('Font Texture {0}.png'.format(p)) # self.fontImages.append('') # tex = QtGui.QImage(1024, 1024, QtGui.QImage.Format_ARGB32) # tex.fill(QtCore.Qt.black) # painter = QtGui.QPainter(tex) # p += 1 # Xoffset = 0 # Yoffset = 0 #painter.end() #xpixel = 0 #ypixel = 0 #for xpixel in range(1024): # for ypixel in range(1024): # curVal = tex.pixel(xpixel, ypixel) # g = (curVal & 0xFF) * ((curVal >> 24) / 256.0) # g = int(g)/16*16 # if curVal == 0x1FFFFFFF: # tex.setPixel(xpixel, ypixel, 0xFF << 24) # else: # tex.setPixel(xpixel, ypixel, (0xFF << 24 | g << 16 | g << 8 | g)) #booli = tex.save('Font Texture {0}.png'.format(p)) #self.fontImages.append('') print len(self.fontImages) # PS3 Xoffset = 0 Yoffset = 0 tex = QtGui.QImage(2048, 2048, QtGui.QImage.Format_ARGB32) tex.fill(0x00000000) painter = QtGui.QPainter(tex) p = 1 i = 0 try: for z in range(16): if z == 0: Xoffset = 0 Yoffset = 0 if z == 1: Xoffset = 512 Yoffset = 0 if z == 2: Xoffset = 0 Yoffset = 512 if z == 3: Xoffset = 512 Yoffset = 512 if z == 4: Xoffset = 1024 Yoffset = 0 if z == 5: Xoffset = 1536 Yoffset = 0 if z == 6: Xoffset = 1024 Yoffset = 512 if z == 7: Xoffset = 1536 Yoffset = 512 if z == 8: Xoffset = 0 Yoffset = 1024 if z == 9: Xoffset = 512 Yoffset = 1024 if z == 10: Xoffset = 0 Yoffset = 1536 if z == 11: Xoffset = 512 Yoffset = 1536 if z == 12: Xoffset = 1024 Yoffset = 1024 if z == 13: Xoffset = 1536 Yoffset = 1024 if z == 14: Xoffset = 1024 Yoffset = 1536 if z == 15: Xoffset = 1536 Yoffset = 1536 for y in range(16): for x in range(16): painter.drawImage(Xoffset + (x * 32), Yoffset + (y * 32), fontPS3Tiles[i]) i += 1 except: pass painter.end() xpixel = 0 ypixel = 0 booli = tex.save('Font Texture {0} PS3.png'.format(p)) self.GeneratedLabel.setText( 'Font preview available in Grace Note directory\nFont ready to save.' )