Esempio n. 1
0
 def __init__(self):
     Observable.__init__(self)
     self.options = ProcessingOptions(0, ProcessingArea(246, 266, 200, 300),
                                      5, 4, 1)
     self.folder_path = None
     self.log = None
     self.p = Processor()
Esempio n. 2
0
    def __init__(self,
                 fh,
                 map=None,
                 maxdata=None,
                 ignore_broken_pipe=False,
                 logger=None,
                 **obsopt):
        """Wrap a dispatcher around the passed filehandle.

        If `ignore_broken_pipe` is `True`, an `EPIPE` or `EBADF` error will
        call `handle_close()` instead of `handle_expt()`. Useful when broken
        pipes should be handled quietly.

        `logger` is a logger which will be used to log unusual exceptions;
        otherwise, they will be printed to stderr.
        """
        self.maxdata = maxdata if maxdata else self.pipe_maxdata
        self.__logger = logger
        if ignore_broken_pipe:
            self.__ignore_errno = [EPIPE, EBADF]
        else:
            self.__ignore_errno = []
        self.__filehandle = fh
        # Check for overduplication of the file descriptor and close the extra
        fddup = os.dup(fh.fileno())
        file_dispatcher.__init__(self, fddup, map=map)
        if (self._fileno != fddup): os.close(fddup)
        Observable.__init__(self, **obsopt)
Esempio n. 3
0
    def __init__(self, argv, map=None, timeout=None, close_when_done=True,
            stdin=PIPE, stdout=PIPE, stderr=PIPE, preexec_fn=None, bufsize=0, **popen_keyw):
        """Accepts all the same arguments and keywords as `subprocess.Popen`.
        Input or outputs specified as `PIPE` (now the default) for are wrapped
        in an asynchronous pipe dispatcher.

        The timeout is used to create an alarm, which can be cancelled by
        calling `cancel_timeout()`, `communicate()`, `wait()` or `kill()`.
        """
        Observable.__init__(self)
        self._map = map
        # Create the subprocess itself, wrapping preexec_fn in the clear_signals call
        Popen.__init__(self, argv, preexec_fn=lambda: self.clear_signals(preexec_fn),
                stdin=stdin, stdout=stdout, stderr=stderr, **popen_keyw)
        # Set the timeout on the subprocess.  If it fails, ignore the failure.
        try:
            fto = float(timeout)
            self._alarmobj = alarm.alarm(fto, self.kill) if fto > 0 else None
        except:
            self._alarmobj = None
        # Wrap the pipe I/O. Sets the Popen and pipe buffer sizes the same; perhaps not optimal.
        if stdout == PIPE:
            self.stdout = OutputPipeDispatcher(self.stdout, map=map, ignore_broken_pipe=True,
                    universal_newlines=self.universal_newlines, maxdata=bufsize)
            self.stdout.obs_add(self._pipe_event)
        if stderr == PIPE:
            self.stderr = OutputPipeDispatcher(self.stderr, map=map, ignore_broken_pipe=True,
                    universal_newlines=self.universal_newlines, maxdata=bufsize)
            self.stderr.obs_add(self._pipe_event)
        if stdin == PIPE:
            self.stdin = InputPipeDispatcher(self.stdin, map=map, ignore_broken_pipe=True,
                    close_when_done=close_when_done, maxdata=bufsize)
            self.stdin.obs_add(self._pipe_event)
Esempio n. 4
0
	def __init__(self,board,players=(),fixed_handicap=0,komi=0,custom_handicap=0,ruleset=None):

		Observable.__init__(self)
		self._board = board
		self._testboard = None

		if ruleset:
			self.ruleset = ruleset
		else:
			self.ruleset = rules.AGARules()

		self.history = [] # the board at all times in the past
		self.moves = [] # the list of moves

		if not players:
			black_player = player.PlayerSettings('black','Black')
			white_player = player.PlayerSettings('black','Black',komi=komi)
			players = [player.Player(p, self) for p in (black_player, white_player)]
		else:
			for p in players:
				p.game = self

		self.players = players

		self.next_player = self.players[0]
		self.winner = None
		self.state = PLACE_HANDICAP

		# Handle handicap, komi etc
		self.ruleset.setup(self)

		# If manual handicap stones need to be placed, change to that team;
		# otherwise, begin the game
		if not self.skip_completed_handicap():
			self.start()
Esempio n. 5
0
	def __init__(self):
		Observable.__init__(self)
		self.local_players = []
		self.remote_players = []
		self.accept_local_moves = False
		self.game = None
		self.confirmed_dead_stones_remote = set()
		self.confirmed_dead_stones = False
Esempio n. 6
0
    def __init__(self,
                 argv,
                 map=None,
                 timeout=None,
                 close_when_done=True,
                 stdin=PIPE,
                 stdout=PIPE,
                 stderr=PIPE,
                 preexec_fn=None,
                 bufsize=0,
                 **popen_keyw):
        """Accepts all the same arguments and keywords as `subprocess.Popen`.
        Input or outputs specified as `PIPE` (now the default) for are wrapped
        in an asynchronous pipe dispatcher.

        The timeout is used to create an alarm, which can be cancelled by
        calling `cancel_timeout()`, `communicate()`, `wait()` or `kill()`.
        """
        Observable.__init__(self)
        self._map = map
        # Create the subprocess itself, wrapping preexec_fn in the clear_signals call
        Popen.__init__(self,
                       argv,
                       preexec_fn=lambda: self.clear_signals(preexec_fn),
                       stdin=stdin,
                       stdout=stdout,
                       stderr=stderr,
                       **popen_keyw)
        # Set the timeout on the subprocess.  If it fails, ignore the failure.
        try:
            fto = float(timeout)
            self._alarmobj = alarm.alarm(fto, self.kill) if fto > 0 else None
        except:
            self._alarmobj = None
        # Wrap the pipe I/O. Sets the Popen and pipe buffer sizes the same; perhaps not optimal.
        if stdout == PIPE:
            self.stdout = OutputPipeDispatcher(
                self.stdout,
                map=map,
                ignore_broken_pipe=True,
                universal_newlines=self.universal_newlines,
                maxdata=bufsize)
            self.stdout.obs_add(self._pipe_event)
        if stderr == PIPE:
            self.stderr = OutputPipeDispatcher(
                self.stderr,
                map=map,
                ignore_broken_pipe=True,
                universal_newlines=self.universal_newlines,
                maxdata=bufsize)
            self.stderr.obs_add(self._pipe_event)
        if stdin == PIPE:
            self.stdin = InputPipeDispatcher(self.stdin,
                                             map=map,
                                             ignore_broken_pipe=True,
                                             close_when_done=close_when_done,
                                             maxdata=bufsize)
            self.stdin.obs_add(self._pipe_event)
Esempio n. 7
0
    def __init__(self, master, width, *args, **kwargs):
        tk.Canvas.__init__(self,
                           master,
                           width=width,
                           height=width / 7 * 6,
                           *args,
                           **kwargs)
        Observable.__init__(self)

        self._width = width
        self._shape_ids = Matrix(7, 6)

        self._init_ui()
        self.bind('<Button-1>', self._on_click)
Esempio n. 8
0
 def __init__(self, ag_voc_params, id):
     Observable.__init__(self)
     seed()
     self.id = id
     n_ag = len(ag_voc_params)
     self.ag_voc_param = ag_voc_params[id]
     self.feat_extractor = FeatureExtraction()
     self.identificator = AgentIndentification(ag_voc_params)
     self.pres_estimator = PresenceEstimation(n_ag)
     self.val_estimator = ValueEstimation(n_ag, lr=0.05, discount=0.9)
     self.decision_maker = ActionSelection(n_ag, lr=0.05)
     self.reflex = Reflex()
     self.motor = MotorExecution(self.ag_voc_param)
     self.amp = 0
     self.adapt = True
Esempio n. 9
0
    def __init__(self, size, grid=None):
        # do need option to pass in grid ? RE FACTOR - probably don't need this
        Observable.__init__(self)
        self._colOrdStart = ord('a')
        self._colOrdEnd = self._colOrdStart + size - 1
        self._grid = grid if grid else [[None for c in range(size)]
                                        for r in range(size)]
        self.size = size

        # create regular expression to match moves. Do it here so only done once.
        r = r'[a-' + chr(self._colOrdEnd) + 'A-' + chr(
            self._colOrdEnd).upper() + ']'
        # add number range.
        r += '[1-' + str(size) + ']'
        self._movePattern = r
Esempio n. 10
0
    def __init__(self, size, root, testMode=False):
        Observable.__init__(self)
        self.pawnPromoted = False
        self._highlightMoves = tkinter.IntVar()
        self._highlightMoves.set(1)
        self._mouseOverGridRef = None
        self._mouseOverMoveGridRefs = []
        self._selectedGridRef = None
        self._selectedMoveGridRefs = []
        self._player1Type = tkinter.StringVar()
        self._player1Type.set(ChessPlayers.HUMAN)
        self._player2Type = tkinter.StringVar()
        self._player2Type.set(ChessPlayers.COMPUTER_LEVEL0)
        self.pWhiteDropDown = None
        self.pBlackDropDown = None

        middleColumn = tkinter.Frame(root)
        middleColumn.grid(row=0, column=1)

        self.playerLabel = tkinter.Label(middleColumn)
        self.playerLabel.grid(row=0, sticky='nsew')

        self.feedbackLabel = tkinter.Label(middleColumn)
        self.feedbackLabel.grid(row=1, sticky='nsew')

        self.boardCanvas = BoardCanvas(middleColumn, 8)
        self.boardCanvas.grid(row=2, sticky='nsew')
        self.addObserver(self.boardCanvas)

        self._moveText = tkinter.Text(root,
                                      width=20,
                                      state='disabled',
                                      wrap=tkinter.WORD,
                                      background=self.boardCanvas.colours[1])
        self._moveText.grid(row=0, column=0, sticky='nsew')

        helpFrame = self._createHelpFrame(root)
        helpFrame.grid(row=0, column=2, sticky='nsew')

        # follow movements of the mouse
        self.boardCanvas.bind('<Motion>', self.mouseMovement)
        self.boardCanvas.bind('<Button-1>', self.selectSquare)
Esempio n. 11
0
    def __init__(self, serial, callback, do_timestamp=True):
        """
        :param serial: A Serial object for communicating with a serial port. It needs to have
                       a read timeout set. Otherwise, this class object might hang forever if
                       a end line character is never received.
                       http://pyserial.readthedocs.io/en/latest/shortintro.html#readline
        :type Serial
        :param callback: A callback method for calling back to owner when error occurs.
        :param do_timestamp: Add a timestamp to each line intercepted from the serial port.
        """
        Thread.__init__(self, name=self.__class__.__name__)
        Observable.__init__(self)
        self.setDaemon(True)

        self._stop = Event()
        self._do_timestamp = do_timestamp
        self._port = serial
        self.logger = logging.getLogger(self.__class__.__name__)
        self._start_time = None  # Is set when first log line arrives from serial port.
        self._callback = callback
        codecs.register_error('backslashreplace', self.backslash_replace)
Esempio n. 12
0
    def __init__(self, fh, map=None, maxdata=None, ignore_broken_pipe=False, logger=None, **obsopt):
        """Wrap a dispatcher around the passed filehandle.

        If `ignore_broken_pipe` is `True`, an `EPIPE` or `EBADF` error will
        call `handle_close()` instead of `handle_expt()`. Useful when broken
        pipes should be handled quietly.

        `logger` is a logger which will be used to log unusual exceptions;
        otherwise, they will be printed to stderr.
        """
        self.maxdata = maxdata if maxdata else self.pipe_maxdata
        self.__logger = logger
        if ignore_broken_pipe:
            self.__ignore_errno = [EPIPE, EBADF]
        else:
            self.__ignore_errno = []
        self.__filehandle = fh
        # Check for overduplication of the file descriptor and close the extra
        fddup = os.dup(fh.fileno())
        file_dispatcher.__init__(self, fddup, map=map)
        if (self._fileno != fddup): os.close (fddup)
        Observable.__init__(self, **obsopt)
Esempio n. 13
0
    def __init__(self, lattice, basis, connections, default_value=None):
        """Store points and connections"""
        Observable.__init__(self)
        self.points = {}
        self.connections = {}
        self.xmax = -1000
        self.ymax = -1000
        self.xmin = 1000
        self.ymin = 1000

        for lx, ly in lattice.items():

            # Add the points by superimposing the basis onto each lattice point
            for b in basis:
                bx, by = b
                self.points[(lx + bx, ly + by)] = default_value
                self.connections[(lx + bx, ly + by)] = []

                self.xmin = min(self.xmin, lx + bx)
                self.ymin = min(self.ymin, ly + by)
                self.ymax = max(self.ymax, ly + by)
                self.xmax = max(self.xmax, lx + bx)

                # Now connect the points
        for lx, ly in lattice.items():

            try:
                for c in connections:
                    cx1, cy1, cx2, cy2 = c
                    a = (lx + cx1, ly + cy1)
                    b = (lx + cx2, ly + cy2)
                    if a in self.points and b in self.points:
                        self.connections[a].append(b)
                        self.connections[b].append(a)
            except KeyError:
                raise Exception("Invalid connections")
Esempio n. 14
0
 def __init__(self):
     Observable.__init__(self)
     self._game = Game()
Esempio n. 15
0
 def __init__(self, entries, destiny, use_common_path=True):
     threading.Thread.__init__(self)
     Observable.__init__(self)
     self.entries = entries[:]
     self.destiny = destiny.replace(' ', '\\ ')
     self.use_common_path = use_common_path
Esempio n. 16
0
	def __init__(self,grid):
		Observable.__init__(self)
		self.grid = grid
		self.territory = {}
Esempio n. 17
0
 def __init__(self, category, drawCallback=None):
     SimObject.__init__(self, category, drawCallback)
     Observable.__init__(self)
     self.gid = entityManager.nextGID(self)
Esempio n. 18
0
 def __init__(self, entries, destiny, use_common_path=True):
     threading.Thread.__init__(self)
     Observable.__init__(self)
     self.entries = entries[:]
     self.destiny = destiny.replace(' ', '\\ ')
     self.use_common_path = use_common_path