本文整理汇总了Python中Base类的典型用法代码示例。如果您正苦于以下问题:Python Base类的具体用法?Python Base怎么用?Python Base使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Base类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Activated
def Activated(self):
from Base import __currentProjectPath__
Base.changeStage('PreDL')
FreeCADGui.runCommand('DDA_LoadDLInputData')
graph = DLInputGraph()
graph.showGraph4File()
FreeCADGui.runCommand('DDA_ViewFitAll')
示例2: addToTab
def addToTab(self):
'''
add selected joints into the tabwidget.
'''
if not self.ui.listWidget.currentRow() >=0 \
and self.ui.listWidget.currentRow()< self.ui.listWidget.size():
import Base
Base.showErrorMessageBox('Wrong Index', \
'Please select a joint first.')
return
self.ui.pushButton.pressed.disconnect(self.addToTab)
text = str(self.ui.listWidget.currentItem().text()).strip()
dialog = chooseJointType()
dialog.exec_()
if dialog.accepted:
tabName = dialog.slection
for i in range(7):
if self.enumList[i] == tabName:
self.ui.tabWidget.setCurrentIndex(i)
flag = self.checkElements(text, i)
if flag == 1:
break
tempItem = PySide.QtGui.QListWidgetItem(text)
self.ui.tabWidget.currentWidget().children()[0].addItem(tempItem)
item = self.ui.listWidget.takeItem(self.ui.listWidget.currentRow())
item = None
self.ui.pushButton.pressed.connect(self.addToTab)
示例3: Activated
def Activated(self, name="None"):
FreeCAD.Console.PrintMessage( 'Creator activing\n')
if FreeCAD.activeDDACommand:
FreeCAD.activeDDACommand.finish()
self.doc = FreeCAD.ActiveDocument
self.view = FreeCADGui.ActiveDocument.ActiveView
import Base
Base.changeStage('DC')
# activate DC Panel
global __currentDDAPanel__
if __currentDDAPanel__ != None :
__currentDDAPanel__.hide()
__currentDDAPanel__ = self.ui
__currentDDAPanel__.show()
self.featureName = name
if not self.doc:
FreeCAD.Console.PrintMessage( Base.translate('DDA_DC','FreeCAD.ActiveDocument get failed\n'))
self.finish()
else:
FreeCAD.activeDDACommand = self # FreeCAD.activeDDACommand 在不同的时间会接收不同的命令
self.ui.show()
示例4: getDefaultColor
def getDefaultColor(self, type, rgb=False):
"gets color from the preferences or toolbar"
if type == "snap":
color = Base.getParam("snapcolor")
r = ((color >> 24) & 0xFF) / 255
g = ((color >> 16) & 0xFF) / 255
b = ((color >> 8) & 0xFF) / 255
elif type == "ui":
r = float(self.color.red() / 255.0)
g = float(self.color.green() / 255.0)
b = float(self.color.blue() / 255.0)
elif type == "face":
r = float(self.facecolor.red() / 255.0)
g = float(self.facecolor.green() / 255.0)
b = float(self.facecolor.blue() / 255.0)
elif type == "constr":
color = QtGui.QColor(Base.getParam("constructioncolor") >> 8)
r = color.red() / 255.0
g = color.green() / 255.0
b = color.blue() / 255.0
else: print "draft: error: couldn't get a color for ", type, " type."
if rgb:
return("rgb(" + str(int(r * 255)) + "," + str(int(g * 255)) + "," + str(int(b * 255)) + ")")
else:
return (r, g, b)
示例5: __parseParaSchema
def __parseParaSchema(self):
'''
parse parameters from DF parameters file
:param infile:
'''
for i in range(7):
line = self.__file.getNextLine()
t =self.parseFloatNum(line)
if t==None: return False
if i==0: self.paras.ifDynamic = float(t)
elif i==1: self.paras.stepsNum = int(t)
elif i==2: self.paras.blockMatsNum = int(t)
elif i==3: self.paras.jointMatsNum = int(t)
elif i==4: self.paras.ratio = t
elif i==5: self.paras.OneSteptimeLimit = t
else: self.paras.springStiffness = int(t)
from DDADatabase import df_inputDatabase as dfDB
if self.paras.blockMatsNum != len(dfDB.blockMatCollections) \
or self.paras.jointMatsNum != len(dfDB.jointMatCollections):
import Base
Base.showErrorMessageBox("ParametersError", "Numbers of block materials or joint materials are not equal to that of data.df")
return False
print 'DF Para : IfDynamic: %d steps: %d blockMats: %d JointMats: %d Ratio: %f timeInterval: %d stiffness: %d'\
%(self.paras.ifDynamic, self.paras.stepsNum , self.paras.blockMatsNum , self.paras.jointMatsNum \
, self.paras.ratio, self.paras.OneSteptimeLimit, self.paras.springStiffness)
print 'Df parameters schema done'
return True
示例6: write2DLFile
def write2DLFile(self):
print 'storing DL data'
import Base
filename = None
try:
filename = Base.__currentProjectPath__ + '/data.dl'
file = open( filename , 'wb' , True) # 使用缓存,flush时再写入硬盘
print 'begin writing data to file %s'%filename
except:
FreeCAD.Console.PrintError(' %s open failed\n'%filename)
return
Base.setGraphRevised() # graph of active document has
self.writePandect( file )
self.writeJointSetsAndSlope(file)
file.flush()
self.writeBoundaryNodes(file)
file.flush()
self.writeTunnels(file)
self.writeLines( file )
file.flush()
self.writePoints( file )
file.close()
import Base
wholePath = Base.__workbenchPath__ + '\\Ff.c'
file = open( wholePath , 'wb' ) #保存文件名
file.write(filename)
file.close()
print 'file save done'
示例7: __init__
def __init__(self):
FreeCAD.Console.PrintMessage( 'MyDockWidget init begin\n')
self.taskmode = Base.getParam("UiMode")
self.paramcolor = Base.getParam("color")>>8
self.color = QtGui.QColor(self.paramcolor)
self.facecolor = QtGui.QColor(204, 204, 204)
self.linewidth = Base.getParam("linewidth")
self.fontsize = Base.getParam("textheight")
self.paramconstr = Base.getParam("constructioncolor")>>8
self.constrMode = False
self.continueMode = False
self.state = None
self.textbuffer = []
self.crossedViews = []
self.tray = None
self.sourceCmd = None
self.dockWidget = QtGui.QDockWidget()
self.mw = getMainWindow()
self.mw.addDockWidget(QtCore.Qt.TopDockWidgetArea, self.dockWidget)
self.centralWidget = QtGui.QWidget()
#self.label = QtGui.QLabel(self.dockWidget)
#self.label.setText("abc")
self.dockWidget.setWidget(self.centralWidget)
self.dockWidget.setVisible(False)
self.dockWidget.toggleViewAction().setVisible(False)
self.layout = QtGui.QHBoxLayout(self.centralWidget)
self.layout.setObjectName("layout")
self.setupToolBar()
self.setupTray()
self.setupStyle()
FreeCAD.Console.PrintMessage( 'MyDockWidget init done\n')
示例8: core
def core(self, repeats=1, w=None, data=None):
self.timestamps['core'] = prectime()
sleep_msec = 1.0
self.timestamps['before'] = []
self.timestamps['after'] = []
preplay_done = False
subs = [slice(None),slice(None)]
nsamp = Base.samples(data)
start = 0
while repeats != 0:
start %= nsamp
while start < nsamp:
while True:
if not self.keepgoing or self.timedout(): self.keepgoing=False; break
towrite = self.stream.get_write_available()
nleft = (float(nsamp) - float(start)) / float(self.speed)
if towrite >= nleft: break
if towrite >= self.buffersize: break
sleep(sleep_msec/1000.0)
if not self.keepgoing: break
speed = float(self.speed)
if speed == 1.0:
start = int(round(start))
stop = start + towrite
if repeats == 1: stop = min(nsamp, stop)
subs[across_samples] = slice(start,stop)
dd = data[subs]
else:
start = float(start)
stop = start + float(speed) * float(towrite)
if repeats == 1: stop = min(float(nsamp), stop)
xi = numpy.linspace(start=start, stop=stop, endpoint=False, num=towrite)
xi %= float(nsamp)
dd = Base.interpsamples(data, xi)
vols = float(self.vol) * Base.panhelper(self.pan, nchan=dd, norm=self.norm)
dd = dd * vols # *= won't work for broadcasting here
raw = w.dat2str(data=dd)
if not preplay_done and self.preplay != None and self.preplay['func'] != None:
self.preplay['func'](*self.preplay['pargs'], **self.preplay['kwargs'])
preplay_done = True
if len(self.timestamps['before']) < 100: self.timestamps['before'].append(prectime())
self.stream.write(raw)
if len(self.timestamps['after']) < 100: self.timestamps['after'].append(prectime())
start = stop
if not self.keepgoing: break
repeats -= 1
if self.postplay != None and self.postplay['func'] != None:
self.postplay['func'](*self.postplay['pargs'], **self.postplay['kwargs'])
self.__playing = False
towrite = self.stream.get_write_available()
bytes_per_frame = self.interface.get_sample_size(self.format) * self.stream._channels
if towrite > 0: self.stream.write('\0' * towrite * bytes_per_frame)
while self.stream.get_write_available() < self.stream._frames_per_buffer: sleep(0.001)
sleep(float(self.stream._frames_per_buffer) / float(self.stream._rate) + self.stream.get_output_latency())
示例9: action
def action(self, arg):
"scene event handler"
if arg["Type"] == "SoKeyboardEvent":
if arg["CtrlDown"] and arg["Key"] == 'z':
if arg['State'] == 'DOWN' and not self.zDown:
print 'ctrl z'
import Base
database = Base.getDatabaser4CurrentStage()
self.RedrawObject(database.undo())
if arg["CtrlDown"] and arg["Key"] == 'y':
if arg['State'] == 'DOWN' and not self.yDown:
print 'ctrl y'
import Base
database = Base.getDatabaser4CurrentStage()
self.RedrawObject(database.redo())
if arg["Key"] == 'DELETE':
if arg['State'] == 'UP':
print 'Delete pressed'
# self.handleDelete()
if arg["Key"] == 'z':
if arg['State'] == 'DOWN': self.zDown = True
elif arg['State'] == 'UP': self.zDown = False
if arg["Key"] == 'y':
if arg['State'] == 'DOWN': self.yDown = True
elif arg['State'] == 'UP': self.yDown = False
示例10: __init__
def __init__(self, seconds=None, nchan=None, fs=None, bits=None, w=None, callback=None, packetRateHz=100):
Background.ongoing.__init__(self)
if isinstance(w,player): w = p.wav
if w == None:
if not nchan: nchan = 2
if not fs: fs = 44100
if not bits: bits = 16
w = Base.wav(fs=fs,bits=bits,nchan=nchan)
if seconds: w.y = Base.silence(round(seconds*w.fs), nchan)
else:
if not seconds: seconds = w.duration()
if not nchan: nchan = w.channels()
if not fs: fs = int(w.fs)
if not bits: bits = w.bits
w.fs = fs
w.bits = bits # nbytes should be updated automatically
self.wav = w
self.seconds = seconds
self.nchan = nchan
self.packetRateHz = packetRateHz
if callback != None:
self.handle_data = callback
self.samples_recorded = 0
self.packets_recorded = 0
示例11: play
def play(self, repeats=1, bg=True, w=None, data=None, timeout=None, vol=None, pan=None):
"""
plays a wav object w, which defaults to the currently loaded instance p.wav
Set repeats=-1 to loop forever. Set bg=False to play synchronously.
p.play(w=w2) sets p.wav = w2 and then plays it (which may involve closing and
re-opening the stream if the bit depth, sampling rate or number of channels
differs between w2 and the old p.wav).
p.play(data=d) uses the raw data in numpy.array d instead of the default w.y,
playing it at the sampling frequency and bit depth dictated by w.
"""###
if self.playing: return
self.timestamps['play'] = prectime()
self.open(w)
w = self.wav
if w == None: return
if data == None: data = w.y
if Base.channels(data) != Base.channels(w): raise ValueError, 'data array and wav object have mismatched numbers of channels'
self.timeout=timeout
self.kwargs = {'w':w, 'data':data, 'repeats':repeats}
if vol != None: self.vol = vol
if pan != None: self.pan = pan
self.__playing = True
self.go(bg=bg)
示例12: checkFile
def checkFile(file):
import os
if not os.path.exists(file):
import Base
Base.showErrorMessageBox('FileError', 'file \"%s\" not found'%file)
return False
return True
示例13: checkDataValid
def checkDataValid(self,text):
if not self.xValue.hasFocus() and not self.yValue.hasFocus():
return
tmpError = False
try:
tmp = float(self.xValue.text())
except ValueError:
self.xValue.setStyleSheet(__errorStyleSheet__)
tmpError = True
else:
self.xValue.setStyleSheet(__normalStyleSheet__)
try:
tmp = float(self.yValue.text())
except ValueError:
self.yValue.setStyleSheet(__errorStyleSheet__)
tmpError = True
else:
self.yValue.setStyleSheet(__normalStyleSheet__)
if not tmpError:
import Base
Base.showErrorMessageBox('ValueError', 'please input float number')
return
else:
self.validatePoint()
示例14: getPoints
def getPoints(self):
view=FreeCADGui.ActiveDocument.ActiveView
objs = view.getObjectsInfo(view.getCursorPos())
obj = None
for o in objs:
if o['Object']=='ShapeModifier' or o['Object']=='ShapeMover':
obj = o
break
self.__selectedAssistantNodeName = obj['Object']
assert obj
name , idx = Base.getRealTypeAndIndex(obj['Object'])
print 'jointline modifier triggered by %s -> %d'%(name,idx)
pName , pIdx = Base.getRealTypeAndIndex(obj['Component'])
print 'jointline modifier triggered by subelement %s -> %d'%(pName,pIdx)
object = FreeCAD.getDocument(self.docName).getObject(self.objName)
subName , subIdx = Base.getRealTypeAndIndex(self.subElement)
print 'jointline modifier selected sub line %s -> %d'%(subName,subIdx)
from DDADatabase import dc_inputDatabase
from loadDataTools import DDALine
tmpLine = dc_inputDatabase.jointLines[subIdx-1]
p1 = None
p2 = None
if pIdx==2:
p1 = FreeCAD.Vector(tmpLine.startPoint)
p2 = FreeCAD.Vector(tmpLine.endPoint)
else:
# pIdx==1 maybe ShapeMover or ShapeModifier,
# but ShapeMover doesn't care about order of p1 and p2
p1 = FreeCAD.Vector(tmpLine.endPoint)
p2 = FreeCAD.Vector(tmpLine.startPoint)
return p1 , p2
示例15: finish
def finish(self):
if self.center:
import Base
view=FreeCADGui.ActiveDocument.ActiveView
obj = view.getObjectInfo(view.getCursorPos())
objName , objIdx = Base.getRealTypeAndIndex(obj['Object'])
assert objName == 'Block'
subName , subIdx = Base.getRealTypeAndIndex(obj['Component'])
from DDADatabase import df_inputDatabase
df_inputDatabase.blocks[subIdx-1].materialNo=11
df_inputDatabase.blocks[subIdx-1].holePointsCount+=1
# Base.__blocksMaterials__[subIdx-1] = 11 # white color, same to the background
FreeCAD.ActiveDocument.getObject('Block').ViewObject.RedrawTrigger=1 # trigger colors changes
print 'Block with hole point hided'
###############################
# temporary code , for speech
fps = df_inputDatabase.fixedPoints
if len(fps)>0:
if subIdx-1 < fps[0].blockNo:
for p in fps:
p.blockNo -=1
# tepmorary code ends
###############################
super(HolePoint,self).finish()