예제 #1
0
class DummyGUI(_SketchGUI):

    Singleton = None
    def __init__(self, filename = "xmlout.xml"):

       # Private data members
       self._serverThread = None
       self._dummyProcThread = None
       self._fname = filename
       self._setupImageServer()


       self.run()
        


    def _setupImageServer(self):
        "Set up the server thread to start listening for image data, which it puts into its response queue. Then the imgprocthread converts image data to strokes, which are enqueued in self._strokeQueue"
        self._serverThread = ServerThread(port = 30000)
        img_recv_queue = self._serverThread.getRequestQueue()
        self._xmlResponseQueue = self._serverThread.getResponseQueue()

        self._fileResponseThread = FileResponseThread(img_recv_queue, self._xmlResponseQueue, filename = self._fname)
        self._fileResponseThread.start()

        self._serverThread.start()


    def run(self):
        while True:
            time.sleep(100)
예제 #2
0
class VisionServer(object):
    def __init__(self):
        # Private data members
        self._serverThread = None
        self._recv_q = None
        self._send_q = None
        self._netDispatchThread = None
        self._setupNetworkDispatcher()


    def _setupNetworkDispatcher(self):
        self._serverThread = ServerThread(port = 30000)
        self._recv_q = self._serverThread.getRequestQueue()
        self._send_q = self._serverThread.getResponseQueue()
        self._netDispatchThread = SketchResponseThread(self._recv_q, self._send_q)
        self._netDispatchThread.start()
        self._serverThread.start()

    def run(self):
        """Reset the board and wait for some entity to add strokes to the strokeQueue. 
        Add these strokes to the board, and build the xml view of the board, then queue the
        response to send back"""
        while True:
            action = raw_input()
            if action.strip().upper() == "C":
                self._serverThread.stop()
                self._serverThread.join()
                break
            else:
                print "unknown action"
예제 #3
0
 def _setupNetworkDispatcher(self):
     self._serverThread = ServerThread(port = 30000)
     self._recv_q = self._serverThread.getRequestQueue()
     self._send_q = self._serverThread.getResponseQueue()
     self._netDispatchThread = SketchResponseThread(self._recv_q, self._send_q)
     self._netDispatchThread.start()
     self._serverThread.start()
예제 #4
0
    def _setupImageServer(self):
        "Set up the server thread to start listening for image data, which it puts into its response queue. Then the imgprocthread converts image data to strokes, which are enqueued in self._strokeQueue"
        self._serverThread = ServerThread(port = 30000)
        img_recv_queue = self._serverThread.getRequestQueue()
        self._xmlResponseQueue = self._serverThread.getResponseQueue()

        self._fileResponseThread = FileResponseThread(img_recv_queue, self._xmlResponseQueue, filename = self._fname)
        self._fileResponseThread.start()

        self._serverThread.start()
예제 #5
0
class NetSketchGUI(_SketchGUI):

    Singleton = None
    def __init__(self):
       "Set up members for this GUI"
       NetSketchGUI.Singleton = self

       #Board related init
       self._Board = None
       self.ResetBoard()

       # Private data members
       self._strokeQueue = Queue.Queue()
       self._serverThread = None
       self._xmlResponseQueue = None
       self._imgProcThread = None
       self._setupImageServer()

       self._drawQueue = []

       self._onBoard = set([])
       self._onBoardDrawOrder = []

       self.run()

    def ResetBoard(self):
        "Clear all strokes and board observers from the board (logically and visually)"
        self._Board = BoardSingleton(reset = True)
        CircleObserver.CircleMarker()
        #CircleObserver.CircleVisualizer()
        ArrowObserver.ArrowMarker()
        #ArrowObserver.ArrowVisualizer()
        #LineObserver.LineMarker()
        #LineObserver.LineVisualizer()
        TextObserver.TextCollector()
        #TextObserver.TextVisualizer()
        DiGraphObserver.DiGraphMarker()
        #DiGraphObserver.DiGraphVisualizer()
        #DiGraphObserver.DiGraphExporter()
        TuringMachineObserver.TuringMachineCollector()
        #TuringMachineObserver.TuringMachineVisualizer()
        #TuringMachineObserver.TuringMachineExporter()
        
        #TemplateObserver.TemplateMarker()
        #TemplateObserver.TemplateVisualizer()
        
        
        d = DebugObserver.DebugObserver()
        #d.trackAnnotation(TestAnimObserver.TestAnnotation)
        #d.trackAnnotation(MSAxesObserver.LabelMenuAnnotation)
        #d.trackAnnotation(MSAxesObserver.LegendAnnotation)
        #d.trackAnnotation(LineObserver.LineAnnotation)
        #d.trackAnnotation(ArrowObserver.ArrowAnnotation)
        #d.trackAnnotation(MSAxesObserver.AxesAnnotation)
        #d.trackAnnotation(TemplateObserver.TemplateAnnotation)
        #d.trackAnnotation(CircleObserver.CircleAnnotation)
        #d.trackAnnotation(RaceTrackObserver.RaceTrackAnnotation)
        #d.trackAnnotation(RaceTrackObserver.SplitStrokeAnnotation)
        
        #d.trackAnnotation(TuringMachineObserver.TuringMachineAnnotation)
        #d.trackAnnotation(DiGraphObserver.DiGraphAnnotation)
        #d.trackAnnotation(TextObserver.TextAnnotation)
        #d.trackAnnotation(BarAnnotation)
        


    def _setupImageServer(self):
        "Set up the server thread to start listening for image data, which it puts into its response queue. Then the imgprocthread converts image data to strokes, which are enqueued in self._strokeQueue"
        self._serverThread = ServerThread(port = 30000)
        img_recv_queue = self._serverThread.getRequestQueue()
        self._xmlResponseQueue = self._serverThread.getResponseQueue()

        self._imgProcThread = ImgProcThread(img_recv_queue, self._strokeQueue)
        self._imgProcThread.start()

        self._serverThread.start()

    def drawCircle(self, x, y, radius=1, color="#000000", fill="", width=1.0):
        "Draw a circle on the canvas at (x,y) with radius rad. Color should be 24 bit RGB string #RRGGBB. Empty string is transparent"
        drawAction = DrawCircle(x,y,radius, color, fill, width)
        self._drawQueue.append(drawAction)
    def drawLine(self, x1, y1, x2, y2, width=2, color="#000000"):
        "Draw a line on the canvas from (x1,y1) to (x2,y2). Color should be 24 bit RGB string #RRGGBB"
        drawAction = DrawLine(x1,y1,x2,y2, width, color)
        self._drawQueue.append(drawAction)

    def drawText (self, x, y, InText="", size=10, color="#000000"):
        "Draw some text (InText) on the canvas at (x,y). Color as defined by 24 bit RGB string #RRGGBB"
        drawAction = DrawText(x,y,InText,size,color)
        self._drawQueue.append(drawAction)

    def drawStroke(self, stroke, width = 2, color="#000000", erasable = False):
        logger.debug("Drawing stroke")
        drawAction = DrawStroke(stroke, width, color)       
        self._drawQueue.append(drawAction)


    def _serializeAnnotations(self):
        "Add raw annotations to the draw queue so that they are sent with the strokes"
        for anno in self._Board.FindAnnotations():
            self._drawQueue.append(anno)

    def run(self):
        while True:
            logger.debug("Waiting on queue")
            try:
                
                self.ResetBoard()
                strokeList = self._strokeQueue.get(True, 300000)
                for stk in strokeList:
                    self._Board.AddStroke(stk)
                self._strokeQueue.task_done()

                for stk in self._Board.Strokes:
                    stk.drawMyself()

                self._serializeAnnotations()
                    
                for obs in self._Board.GetBoardObservers():
                    obs.drawMyself()

                self._processDrawQueue()
            except Queue.Empty as e:
                logger.debug("No strokes yet...")
    def _processDrawQueue(self):
        "Go through the draw queue and draw what needs to be drawn"
        drawXML = ET.Element("Board")
        drawXML.attrib['height'] = str(HEIGHT)
        drawXML.attrib['width'] = str(WIDTH)
        count = 0
        for action in self._drawQueue:
            drawXML.append(action.xml())
            count+= 1

        fp = open("xmlout.xml", "w")
        print >> fp, ET.tostring(drawXML)
        fp.close()

        self._xmlResponseQueue.put(ET.tostring(drawXML))
        logger.debug("Drawing\n%s" % (ET.tostring(drawXML)[:5000]))
        logger.debug("Done drawing")
        self._drawQueue = []