Exemple #1
0
 def DoAltHandler(self, event):
     """Tk callback:  Handle Alt+key events."""
     key = event.keysym
     if len(key) != 1 or key not in empDb.pathDirections:
         return
     # Put the key into the input window.
     self.Root.focus_lastfor().insert('insert', key)
     # Find the new location.
     range = self.cen.getSect()
     sect1 = empDb.directionToSector((range[0], range[2]), key)
     sect2 = empDb.directionToSector((range[1], range[3]), key)
     # Change the censor window.
     self.cen.SetSect((sect1[0], sect2[0], sect1[1], sect2[1]))
     # Ouch - something massive is also attached to these keys..  Must
     # "break" to prevent cpu hogging..
     return "break"
Exemple #2
0
    def receive(self):
        args = self.commandMatch.group('args')
        if not args:
            coords = ()
        else:
            try:
                coords = map(empParse.str2Coords, string.split(args))
            except ValueError:
                viewer.Error("Bad coords.")
            pos = []
            start = coords[0]
            pos.append(coords[0])
            for i in range(1, len(coords)):
                path = empPath.best_path(coords[i - 1], coords[i])
                if path is None:
                    viewer.Error("Path could not be completed.")
                    return
                for i in path.directions:
                    start = empDb.directionToSector(start, i)
                    pos.append(start)
            coords = pos

        apply(viewer.map.drawPath, tuple(coords))
Exemple #3
0
    def receive(self):
        args = self.commandMatch.group('args')
        if not args:
            coords = ()
        else:
            try:
                coords = map(empParse.str2Coords, string.split(args))
            except ValueError:
                viewer.Error("Bad coords.")
            pos = []
            start = coords[0]
            pos.append(coords[0])
            for i in range(1, len(coords)):
                path = empPath.best_path(coords[i-1], coords[i])
                if path is None:
                    viewer.Error("Path could not be completed.")
                    return
                for i in path.directions:
                    start = empDb.directionToSector(start, i)
                    pos.append(start)
            coords = pos

        apply(viewer.map.drawPath, tuple(coords))
Exemple #4
0
    def redraw(self, total=1):
        if not total and not empDb.updateDB.has_key('SECTOR'):
            # Nothing changed.
            return

        # Remove any existing path.
        self.map.drawPath()

        sectors = self.sectors
        if len(sectors) < 2:
            self.lblVar.set("Select sectors with the right mouse button.\n")
            return
        sDB = empDb.megaDB['SECTOR']
        try:
            quantity = empCmd.getMoveQuantity(self.Quantity.get(),
                                              self.commodity, sectors)
        except ValueError:
            msg = "Enter a valid quantity.\n"
            self.pathList = []
            quantity = 0
        else:
            first = sectors[0]
            last = sectors[-1]
            msg = "Move %d %s: (%d,%d has %s)  (%d,%d has %s)\n" % (
                quantity, self.commodity, first[0], first[1], sDB[first].get(
                    self.commodity, "??"), last[0], last[1], sDB[last].get(
                        self.commodity, "??"))

        reverse = quantity < 0
        if reverse:
            sectors = list(sectors)
            sectors.reverse()
            quantity = -quantity

        start = sectors[0]
        sectorList = [start]
        newPathList = []
        for i in range(1, len(sectors)):
            last = sectors[i - 1]
            path = empPath.best_path(last, sectors[i])
            color = "black"

            newPathList.append([last])
            if path is None:
                # No path between the two sectors.
                color = "red"
                start = sectors[i]
                newPathList[-1].append(start)
                newmob = "??"
##  		return
            else:
                # Calculate new mobility.
                db = sDB[last]
                newmob = int(
                    math.floor((db.get('mob', 0) -
                                empSector.move_weight(db, self.commodity) *
                                path.cost * quantity)))
                if newmob < 0:
                    color = "yellow"

                # Turn path into list of sector coordinates.
                for i in path.directions:
                    start = empDb.directionToSector(start, i)
                    sectorList.append(start)
                    newPathList[-1].append(start)

            # Update text description.
            msg = msg + "%d,%d=>%s    " % (last[0], last[1], newmob)

            # Draw path
            apply(self.map.drawPath, tuple(newPathList[-1]), {"fill": color})

        if reverse:
            newPathList.reverse()

        self.pathList = newPathList
        ##  	apply(self.map.drawPath, tuple(sectorList), {"color":color})
        msg = msg + "%d,%d " % sectors[-1]
        self.lblVar.set(msg)
Exemple #5
0
    def redraw(self, total=1):
        if not total and not empDb.updateDB.has_key('SECTOR'):
            # Nothing changed.
            return

        # Remove any existing path.
        self.map.drawPath()

        sectors = self.sectors
        if len(sectors) < 2:
            self.lblVar.set("Select sectors with the right mouse button.\n")
            return
        sDB = empDb.megaDB['SECTOR']
        try:
            quantity = empCmd.getMoveQuantity(self.Quantity.get(),
                                              self.commodity, sectors)
        except ValueError:
            msg = "Enter a valid quantity.\n"
            self.pathList = []
            quantity = 0
        else:
            first = sectors[0]
            last = sectors[-1]
            msg = "Move %d %s: (%d,%d has %s)  (%d,%d has %s)\n" % (
                quantity, self.commodity,
                first[0], first[1], sDB[first].get(self.commodity, "??"),
                last[0], last[1], sDB[last].get(self.commodity, "??"))

        reverse = quantity < 0
        if reverse:
            sectors = list(sectors)
            sectors.reverse()
            quantity = -quantity

        start = sectors[0]
        sectorList = [start]
        newPathList = []
        for i in range(1, len(sectors)):
            last = sectors[i-1]
            path = empPath.best_path(last, sectors[i])
            color = "black"

            newPathList.append([last])
            if path is None:
                # No path between the two sectors.
                color = "red"
                start = sectors[i]
                newPathList[-1].append(start)
                newmob = "??"
##  		return
            else:
                # Calculate new mobility.
                db = sDB[last]
                newmob = int(math.floor(
                    (db.get('mob', 0)
                     - empSector.move_weight(db, self.commodity)
                     * path.cost*quantity)))
                if newmob < 0:
                    color = "yellow"

                # Turn path into list of sector coordinates.
                for i in path.directions:
                    start = empDb.directionToSector(start, i)
                    sectorList.append(start)
                    newPathList[-1].append(start)

            # Update text description.
            msg = msg + "%d,%d=>%s    " % (last[0], last[1], newmob)

            # Draw path
            apply(self.map.drawPath, tuple(newPathList[-1]), {"fill":color})

        if reverse:
            newPathList.reverse()

        self.pathList = newPathList
##  	apply(self.map.drawPath, tuple(sectorList), {"color":color})
        msg = msg + "%d,%d " % sectors[-1]
        self.lblVar.set(msg)