コード例 #1
0
class Walker(object):
    def __init__(self):
        self.position = PVector(width / 2, height / 2)
        self.history = ArrayList()

    def display(self):
        stroke(0)
        fill(175)
        rectMode(CENTER)
        rect(self.position.x, self.position.y, 16, 16)

        beginShape()
        stroke(0)
        noFill()
        for v in self.history:
            vertex(v.x, v.y)
        endShape()

    # Randomly move up, down, left, right, or stay in one place
    def walk(self):
        vel = PVector(int(random(-2, 2)), int(random(-2, 2)))
        self.position.add(vel)
        print(self.position)

        # Stay on the screen
        self.position.x = constrain(self.position.x, 0, width - 1)
        self.position.y = constrain(self.position.y, 0, height - 1)

        self.history.add(self.position.get())
        # print(self.history)
        if self.history.size() > 1000:
            self.history.remove(0)
コード例 #2
0
def ensureSIFTFeatures(filepath,
                       paramsSIFT,
                       properties,
                       csvDir,
                       validateByFileExists=False):
    """
     filepath: to the image from which SIFT features have been or have to be extracted.
     params: dict of registration parameters, including the key "scale".
     paramsSIFT: FloatArray2DSIFT.Params instance.
     csvDir: directory into which serialized features have been or will be saved.
     load: function to load an image as an ImageProcessor from the filepath.
     validateByFileExists: whether to merely check that the .obj file exists as a quick form of validation.
     
     First check if serialized features exist for the image, and if the Params match.
     Otherwise extract the features and store them serialized.
     Returns the ArrayList of Feature instances.
  """
    path = os.path.join(csvDir,
                        os.path.basename(filepath) + ".SIFT-features.obj")
    if validateByFileExists:
        if os.path.exists(path):
            return True
    # An ArrayList whose last element is a mpicbg.imagefeatures.FloatArray2DSIFT.Param
    # and all other elements are mpicbg.imagefeatures.Feature
    features = deserialize(path) if os.path.exists(path) else None
    if features:
        if features.get(features.size() - 1).equals(paramsSIFT):
            features.remove(features.size() - 1)  # removes the Params
            syncPrintQ("Loaded %i SIFT features for %s" %
                       (features.size(), os.path.basename(filepath)))
            return features
        else:
            # Remove the file: paramsSIFT have changed
            os.remove(path)
    # Else, extract de novo:
    try:
        # Extract features
        imp = loadImp(filepath)
        ip = imp.getProcessor()
        paramsSIFT = paramsSIFT.clone()
        ijSIFT = SIFT(FloatArray2DSIFT(paramsSIFT))
        features = ArrayList()  # of Feature instances
        ijSIFT.extractFeatures(ip, features)
        ip = None
        imp.flush()
        imp = None
        features.add(
            paramsSIFT
        )  # append Params instance at the end for future validation
        serialize(features, path)
        features.remove(features.size() -
                        1)  # to return without the Params for immediate use
        syncPrintQ("Extracted %i SIFT features for %s" %
                   (features.size(), os.path.basename(filepath)))
    except:
        printException()
    return features
コード例 #3
0
ファイル: AssignmentFunction.py プロジェクト: hobson/ggpy
 def create(cls, conjunct, functionInfo, rightmostVar, varOrder, preassignment):
     """ generated source for method create """
     # We have to set up the things mentioned above...
     internalFunctions = ArrayList()
     # We can traverse the conjunct for the list of variables/constants...
     terms = ArrayList()
     gatherVars(conjunct.getBody(), terms)
     # Note that we assume here that the var of interest only
     # appears once in the relation...
     varIndex = terms.indexOf(rightmostVar)
     if varIndex == -1:
         print "conjunct is: " + conjunct
         print "terms are: " + terms
         print "righmostVar is: " + rightmostVar
     terms.remove(rightmostVar)
     function_ = functionInfo.getValueMap(varIndex)
     # Set up inputs and such, using terms
     querySize = len(terms)
     isInputConstant = ArrayList(len(terms))
     queryConstants = Maps.newHashMap()
     queryInputIndices = ArrayList(len(terms))
     i = 0
     while i < len(terms):
         if isinstance(term, (GdlConstant, )):
             isInputConstant.add(True)
             queryConstants.put(i, term)
             queryInputIndices.add(-1)
         elif isinstance(term, (GdlVariable, )):
             # Is it in the head assignment?
             if preassignment.containsKey(term):
                 isInputConstant.add(True)
                 queryConstants.put(i, preassignment.get(term))
                 queryInputIndices.add(-1)
             else:
                 isInputConstant.add(False)
                 # 						queryConstants.add(null);
                 # What value do we put here?
                 # We want to grab some value out of the
                 # input tuple, which uses functional ordering
                 # Index of the relevant variable, by the
                 # assignment's ordering
                 queryInputIndices.add(varOrder.indexOf(term))
         i += 1
     return AssignmentFunction(ImmutableList.copyOf(internalFunctions), querySize, ImmutableList.copyOf(isInputConstant), ImmutableMap.copyOf(queryConstants), ImmutableList.copyOf(queryInputIndices), ImmutableMap.copyOf(function_))
コード例 #4
0
    def getAvailMethodsUser(self, user, skip):
        methods = ArrayList()

        for method in self.authenticators:
            try:
                module = self.authenticators[method]
                if module.hasEnrollments(module.configAttrs, user):
                    methods.add(method)
            except:
                print "Casa. getAvailMethodsUser. hasEnrollments call could not be issued for %s module" % method

        try:
            #skip is guaranteed to be a member of methods (if hasEnrollments routines are properly implemented).
            #A call to remove strangely crashes if skip is absent
            methods.remove(skip)
        except:
            print "Casa. getAvailMethodsUser. methods list does not contain %s" % skip

        print "Casa. getAvailMethodsUser %s" % methods.toString()
        return methods
コード例 #5
0
class Walker(object):
    def __init__(self):
        self.position = PVector(width/2, height/2)
        self.velocity = PVector()
        self.acceleration = PVector() 
        self.history = ArrayList()
        self.noff = PVector(random(1000), random(1000))
        
    def display(self):
        stroke(0)
        fill(175)
        rectMode(CENTER)
        rect(self.position.x, self.position.y, 16, 16)
        
        beginShape()
        stroke(0)
        noFill()
        for v in self.history:
            vertex(v.x, v.y)
        endShape()
    
    # Randomly move up, down, left, right, or stay in one place
    def walk(self):
        
        self.acceleration.x = map(noise(self.noff.x), 0, 1, -1, 1)
        self.acceleration.y = map(noise(self.noff.y), 0, 1, -1, 1)
        self.acceleration.mult(0.1) # Multiply a vector by a scalar
    
        self.noff.add(0.01, 0.01, 0)
        
        self.velocity.add(self.acceleration)
        self.velocity.limit(1) # Limit the magnitude of the vector
        self.position.add(self.velocity)
        
        self.history.add(self.position.get())
        if self.history.size() > 1000 : 
            self.history.remove(0)
        
        # Stay on the screen
        self.position.x = constrain(self.position.x, 0, width-1)
        self.position.y = constrain(self.position.y, 0, height-1)
コード例 #6
0
ファイル: test_list_jy.py プロジェクト: Stewori/jython
    def test_remove(self):
        # Verifies that overloaded java.util.List#remove(int) method can still be used, but with Python index semantics
        # http://bugs.jython.org/issue2456
        jl = ArrayList(xrange(10, -1, -1))      # 10 .. 0, inclusive
        jl.remove(0)  # removes jl[-1] (=0) 
        self.assertEqual(jl, range(10, 0, -1))  # 10 .. 1
        self.assertRaises(ValueError, jl.remove, Integer(0))  # j.l.Integer does not support __index__ - maybe it should!
        jl.remove(0)  # removes jl[0] (=10)
        self.assertEqual(jl, range(9, 0, -1))   #  9 .. 1
        jl.remove(-1) # removes jl[-1] (=1) - support same index calculations as Python (= del jl[-1])
        self.assertEqual(jl, range(9, 1, -1))   #  9 .. 2
        jl.remove(3)
        jl.remove(5)
        self.assertEqual(jl, [9, 8, 7, 6, 4, 2])

        a_to_z = list(chr(i) for i in xrange(ord('a'), ord('z') + 1))
        b_to_z_by_2 = list(chr(i) for i in xrange(ord('b'), ord('z') + 1, 2))
        jl = ArrayList(a_to_z)
        for i in xrange(13):
            jl.remove(i)
        self.assertEqual(jl, b_to_z_by_2)
コード例 #7
0
ファイル: test_list_jy.py プロジェクト: gatech-csl/jes
    def test_remove(self):
        # Verifies that overloaded java.util.List#remove(int) method can still be used, but with Python index semantics
        # http://bugs.jython.org/issue2456
        jl = ArrayList(xrange(10, -1, -1))      # 10 .. 0, inclusive
        jl.remove(0)  # removes jl[-1] (=0) 
        self.assertEqual(jl, range(10, 0, -1))  # 10 .. 1
        self.assertRaises(ValueError, jl.remove, Integer(0))  # j.l.Integer does not support __index__ - maybe it should!
        jl.remove(0)  # removes jl[0] (=10)
        self.assertEqual(jl, range(9, 0, -1))   #  9 .. 1
        jl.remove(-1) # removes jl[-1] (=1) - support same index calculations as Python (= del jl[-1])
        self.assertEqual(jl, range(9, 1, -1))   #  9 .. 2
        jl.remove(3)
        jl.remove(5)
        self.assertEqual(jl, [9, 8, 7, 6, 4, 2])

        a_to_z = list(chr(i) for i in xrange(ord('a'), ord('z') + 1))
        b_to_z_by_2 = list(chr(i) for i in xrange(ord('b'), ord('z') + 1, 2))
        jl = ArrayList(a_to_z)
        for i in xrange(13):
            jl.remove(i)
        self.assertEqual(jl, b_to_z_by_2)
	    time.sleep(2)	
	 
	  myProject.neuronFileManager.setSuggestedRemoteRunTime(10)
	  myProject.neuronFileManager.generateTheNeuronFiles(simConfig, None, NeuronFileManager.RUN_HOC, randomseed)
      
	  print "Generated NEURON files for: "+simRef	
	  compileProcess = ProcessManager(myProject.neuronFileManager.getMainHocFile())	
	  compileSuccess = compileProcess.compileFileWithNeuron(0,0)	
	  print "Compiled NEURON files for: "+simRef

	  if compileSuccess:
	     pm.doRunNeuron(simConfig)
	     print "Set running simulation: "+simRef
	  time.sleep(2) # wait for the process to be sent out  
	  
	  simInputs.remove("backgroundExc")	 

	  #####################''' 
	  
	  
	  ########  Rerunning the same configuration + background exc1500 /inh150% ###############

	  simInputs.add("backgroundExc")
	  simInputs.add("backgroundInh150")
	  simInputs.add("NGF")

	  
	  simConfig.setInputs(simInputs)

	  print "group generated: "+simConfig.getCellGroups().toString()
	  print "going to stimulate: "+simConfig.getInputs().toString()
コード例 #9
0
 def getLimitQueryWithout(self, fq):
     limits = ArrayList(self.__fqParts)
     limits.remove("category/" + fq)
     if limits.isEmpty():
         return ""
     return "/".join(limits)
コード例 #10
0
# importing and using a java array list in jython code

import java.util.ArrayList as ArrayList

aList = ArrayList()
aList.add(10)
aList.add(20)

print(aList, type(aList))

aList.add(30)
aList.remove(20)

print(aList)
コード例 #11
0
	    time.sleep(2)	
	 
	  myProject.neuronFileManager.setSuggestedRemoteRunTime(10)
	  myProject.neuronFileManager.generateTheNeuronFiles(simConfig, None, NeuronFileManager.RUN_HOC, randomseed)
      
	  print "Generated NEURON files for: "+simRef	
	  compileProcess = ProcessManager(myProject.neuronFileManager.getMainHocFile())	
	  compileSuccess = compileProcess.compileFileWithNeuron(0,0)	
	  print "Compiled NEURON files for: "+simRef

	  if compileSuccess:
	     pm.doRunNeuron(simConfig)
	     print "Set running simulation: "+simRef
	  time.sleep(2) # wait for the process to be sent out  
	  
	  simInputs.remove("backgroundExc")	 

	  #####################''' 
	  
	  '''##### Rerunning the same configuration + background exc/inh #####
	  
	  simRef = prefix+"syn"+str(synapses)+"E1500I43_"+str(t)
	  print "Simref: "+simRef
	  myProject.simulationParameters.setReference(simRef)
	  refStored.append(simRef)
	  
	  ##### RUN BLOCK background exc/inh #####
	  
	  simInputs.add("backgroundExc")	  
          simInputs.add("backgroundInh")	  
	  simConfig.setInputs(simInputs)
コード例 #12
0
ファイル: search.py プロジェクト: kiranba/the-fascinator
 def getLimitQueryWithout(self, fq):
     limits = ArrayList(self.__fqParts)
     limits.remove("category/" + fq)
     if limits.isEmpty():
         return ""
     return "/".join(limits)
	    time.sleep(2)
		    
	  myProject.neuronFileManager.setSuggestedRemoteRunTime(10)
	  myProject.neuronFileManager.generateTheNeuronFiles(simConfig, None, NeuronFileManager.RUN_HOC, randomseed)
	
	  print "Generated NEURON files for: "+simRef	
	  compileProcess = ProcessManager(myProject.neuronFileManager.getMainHocFile())	
	  compileSuccess = compileProcess.compileFileWithNeuron(0,0)	
	  print "Compiled NEURON files for: "+simRef

	  if compileSuccess:
	    pm.doRunNeuron(simConfig)
	    print "Set running simulation: "+simRef
	  
	  time.sleep(30) # Wait for sim to be kicked off
	  simInputs.remove("backgroundExc")


	  #####################'''
	  
	      	########  Rerunning the same configuration + background exc 1200 ###############

	  simInputs.add("backgroundExc1200")
	  
	  simConfig.setInputs(simInputs)

	  print "group generated: "+simConfig.getCellGroups().toString()
	  print "going to stimulate: "+simConfig.getInputs().toString()
	  print "going to record: "+simConfig.getPlots().toString()
          
          ##########################################################################################
コード例 #14
0
print("tup1[0]: ", tup1[0])

# Jython Dictionary
dict = {'011': 'New Delhi', '022': 'Mumbai', '033': 'Kolkata', 'Age': 25}
print("dict['011']: ", dict['011'])
print("dict['Age']: ", dict['Age'])

########################################################################################################################

import java.util.ArrayList as ArrayList

arr = ArrayList()
arr.add(10)
arr.add(20)
print("ArrayList: ", arr)
arr.remove(10)  #remove 10 from arraylist
arr.add(0, 5)  #add 5 at 0th index
print("ArrayList: ", arr)
print("element at index 1:", arr.get(1))  #retrieve item at index 1
arr.set(0,100)  #set item at 0th index to 100
print("ArrayList: ", arr)

# Jarray Class
from jarray import array

my_seq = (1, 2, 3, 4, 5)
arr1 = array(my_seq, 'i')
print(arr1)
myStr = "Hello Jython"
arr2 = array(myStr, 'c')
print(arr2)
コード例 #15
0
ファイル: burp_git_bridge.py プロジェクト: 0x24bin/BurpSuite
class GuiLog(AbstractTableModel):
    '''
    Acts as an AbstractTableModel for the table that is shown in the UI tab: 
    when this data structure changes, the in-UI table is updated.
    '''

    def __init__(self, callbacks):
        '''
        Creates a Java-style ArrayList to hold LogEntries that appear in the table
        '''

        self.ui = None
        self._log = ArrayList()
        self._lock = Lock()
        self._callbacks = callbacks
        self._helpers = callbacks.getHelpers()

    def clear(self):
        '''
        Clears all entries from the table
        '''

        self._lock.acquire()
        last = self._log.size()
        if last > 0:
            self._log.clear()
            self.fireTableRowsDeleted(0, last-1)
        # Note: if callees modify table this could deadlock
        self._lock.release()

    def add_entry(self, entry):
        '''
        Adds entry to the table
        '''

        self._lock.acquire()
        row = self._log.size()
        self._log.add(entry)
        # Note: if callees modify table this could deadlock
        self.fireTableRowsInserted(row, row)
        self._lock.release()

    def remove_entry(self, entry):
        '''
        Removes entry from the table
        '''

        self._lock.acquire()
        for i in range(0, len(self._log)):
            ei = self._log[i] 
            if ei.md5 == entry.md5:
                self._log.remove(i)
                break
        self.fireTableRowsDeleted(i, i) 
        self._lock.release()

    def getRowCount(self):
        '''
        Used by the Java Swing UI 
        '''

        try:
            return self._log.size()
        except:
            return 0
    
    def getColumnCount(self):
        '''
        Used by the Java Swing UI 
        '''

        return 5
    
    def getColumnName(self, columnIndex):
        '''
        Used by the Java Swing UI 
        '''

        cols = ["Time added", 
                "Tool",
                "URL",
                "Issue",
                "Who"]
        try:
            return cols[columnIndex]
        except KeyError:
            return ""

    def get(self, rowIndex):
        '''
        Gets the LogEntry at rowIndex
        '''
        return self._log.get(rowIndex)
    
    def getValueAt(self, rowIndex, columnIndex):
        '''
        Used by the Java Swing UI 
        '''

        logEntry = self._log.get(rowIndex)
        if columnIndex == 0:
            return logEntry.timestamp
        elif columnIndex == 1:
            return logEntry.tool.capitalize()
        elif columnIndex == 2:
            return logEntry.url
        elif columnIndex == 3:
            if logEntry.tool == "scanner":
                return logEntry.issue_name
            else:
                return "N/A"
        elif columnIndex == 4:
            return logEntry.who

        return ""
コード例 #16
0
ファイル: burp_git_bridge.py プロジェクト: btpfadhil/Fulwin
class GuiLog(AbstractTableModel):
    '''
    Acts as an AbstractTableModel for the table that is shown in the UI tab: 
    when this data structure changes, the in-UI table is updated.
    '''
    def __init__(self, callbacks):
        '''
        Creates a Java-style ArrayList to hold LogEntries that appear in the table
        '''

        self.ui = None
        self._log = ArrayList()
        self._lock = Lock()
        self._callbacks = callbacks
        self._helpers = callbacks.getHelpers()

    def clear(self):
        '''
        Clears all entries from the table
        '''

        self._lock.acquire()
        last = self._log.size()
        if last > 0:
            self._log.clear()
            self.fireTableRowsDeleted(0, last - 1)
        # Note: if callees modify table this could deadlock
        self._lock.release()

    def add_entry(self, entry):
        '''
        Adds entry to the table
        '''

        self._lock.acquire()
        row = self._log.size()
        self._log.add(entry)
        # Note: if callees modify table this could deadlock
        self.fireTableRowsInserted(row, row)
        self._lock.release()

    def remove_entry(self, entry):
        '''
        Removes entry from the table
        '''

        self._lock.acquire()
        for i in range(0, len(self._log)):
            ei = self._log[i]
            if ei.md5 == entry.md5:
                self._log.remove(i)
                break
        self.fireTableRowsDeleted(i, i)
        self._lock.release()

    def getRowCount(self):
        '''
        Used by the Java Swing UI 
        '''

        try:
            return self._log.size()
        except:
            return 0

    def getColumnCount(self):
        '''
        Used by the Java Swing UI 
        '''

        return 5

    def getColumnName(self, columnIndex):
        '''
        Used by the Java Swing UI 
        '''

        cols = ["Time added", "Tool", "URL", "Issue", "Who"]
        try:
            return cols[columnIndex]
        except KeyError:
            return ""

    def get(self, rowIndex):
        '''
        Gets the LogEntry at rowIndex
        '''
        return self._log.get(rowIndex)

    def getValueAt(self, rowIndex, columnIndex):
        '''
        Used by the Java Swing UI 
        '''

        logEntry = self._log.get(rowIndex)
        if columnIndex == 0:
            return logEntry.timestamp
        elif columnIndex == 1:
            return logEntry.tool.capitalize()
        elif columnIndex == 2:
            return logEntry.url
        elif columnIndex == 3:
            if logEntry.tool == "scanner":
                return logEntry.issue_name
            else:
                return "N/A"
        elif columnIndex == 4:
            return logEntry.who

        return ""