def __init__(self):
        View.__init__(self)
        
        # Special layout objects
        self.top_line = TopLine()
        self.corner_stone = CornerStone()

        # Visual Objects we are tracking
        self._block_items = TypedDict(int, BlockItem)
        self._band_items = TypedDict(int, BandItem)
        self._snap_items = TypedDict(str, SnapItem)
Beispiel #2
0
    def __init__(self):
        View.__init__(self)

        # Special layout objects
        self.top_line = TopLine()
        self.corner_stone = CornerStone()

        # Visual Objects we are tracking
        self._block_items = TypedDict(int, BlockItem)
        self._band_items = TypedDict(int, BandItem)
        self._snap_items = TypedDict(str, SnapItem)
class AsciiView(View):
    def __init__(self):
        View.__init__(self)
        
        # Special layout objects
        self.top_line = TopLine()
        self.corner_stone = CornerStone()

        # Visual Objects we are tracking
        self._block_items = TypedDict(int, BlockItem)
        self._band_items = TypedDict(int, BandItem)
        self._snap_items = TypedDict(str, SnapItem)

    def add_block_item(self, index):
        """ Create new a drawable object to correspond to a Block with this index. """
        if not index in self._block_items:
            print "Adding block item",index
            item = BlockItem(self, index)
            self._block_items[index] = item
            return item

    def has_block_item(self, index):
        return True if index in self._block_items else False

    def set_block_item_settings(self, index, left_index, right_index):
        item = self._block_items[index]
        item.left_block = self._block_items[left_index] if left_index is not None else None
        item.right_block = self._block_items[right_index] if right_index is not None else None

    def set_block_item_attributes(self, index, attributes):
        """ Not yet implemented """
        pass

    def remove_block_item(self, index):
        print "Removing BlockItem %d"%index
        self._block_items[index].release()
        self._block_items.pop(index)

    def add_band_item(self, altitude, rank):
        """ Create a new drawable object to correspond to a Band. """
        print "Adding BandItem with altitude %d"%altitude
        if altitude in self._band_items:
            raise DuplicateItemExistsError("BandItem with altitude %d already exists"%(altitude))
        item = BandItem(self, altitude, rank)
        self._band_items[altitude] = item
        return item

    def has_band_item(self, altitude):
        return True if altitude in self._band_items else False

    def remove_band_item(self, altitude):
        """ Remove the drawable object to correspond to a band """ 
        print "Removing BandItem altitude %d"%altitude
        self._band_items[altitude].release()
        self._band_items.pop(altitude)

    def get_band_item(self, altitude):
        return self._band_items[altitude]
    
    def set_band_item_settings(self, altitude, rank,
                                top_band_alt, bot_band_alt,
                                leftmost_snapkey, rightmost_snapkey):
        item = self._band_items[altitude]
        item.top_band = self._band_items[top_band_alt] if top_band_alt is not None else None
        item.bot_band = self._band_items[bot_band_alt] if bot_band_alt is not None else None
        item.left_most_snap = self._snap_items[leftmost_snapkey]
        item.right_most_snap = self._snap_items[rightmost_snapkey]

    def set_band_item_attributes(self, index, attributes):
        """ not yet implemented for this style view """
        pass


    def add_snap_item(self, snapkey):
        print "Adding SnapItem %s"%snapkey
        if snapkey in self._snap_items:
            raise DuplicateItemExistsError("SnapItem with snapkey %s already exists"%(snapkey))
        item = SnapItem(self, snapkey)
        item.block_item = self._block_items[item.block_index]
        if item.isSource():
            self._block_items[item.block_index].emitters.append(item)
        else:
            self._block_items[item.block_index].collectors.append(item)
        self._snap_items[snapkey] = item
        return item

    def remove_snap_item(self, snapkey):
        print "Removing SnapItem %s"%snapkey
        self._snap_items[snapkey].release()
        self._snap_items.pop(snapkey)

    def has_snap_item(self, snapkey):
        return True if snapkey in self._snap_items else False


    def set_snap_item_settings(self, snapkey, left_order, right_order, pos_band_alt, neg_band_alt):
        item = self._snap_items[snapkey]
        if left_order is not None:
            left_snapkey = gen_snapkey(item.block_index,item.container_name,left_order)
            item.left_snap = self._snap_items[left_snapkey]
        else:
            item.left_snap = None
        if right_order is not None:
            right_snapkey = gen_snapkey(item.block_index,item.container_name,right_order)
            item.right_snap = self._snap_items[right_snapkey]
        else:
            item.right_snap = None
        item.posBandItem = self._band_items[pos_band_alt] if pos_band_alt is not None else None
        item.negBandItem = self._band_items[neg_band_alt] if neg_band_alt is not None else None

    def set_snap_item_attributes(self, snapkey, attributes):
        """ not yet implemented for this style view """
        pass

    def update_view(self):
        
        # Initialize Visual Elements
        cornerStone = CornerStone()
       
        for item in self._band_items.values():
            item.layout()

        for item in self._block_items.values():
            item.layout()

        for item in self._snap_items.values():
            item.layout()

        # Draw
        grid = CharGrid()
        
        for item in self._band_items.values():
            item.draw(grid)

        for item in self._block_items.values():
            item.draw(grid)

        for item in self._snap_items.values():
            item.draw(grid)
          
        print grid
Beispiel #4
0
class AsciiView(View):
    def __init__(self):
        View.__init__(self)

        # Special layout objects
        self.top_line = TopLine()
        self.corner_stone = CornerStone()

        # Visual Objects we are tracking
        self._block_items = TypedDict(int, BlockItem)
        self._band_items = TypedDict(int, BandItem)
        self._snap_items = TypedDict(str, SnapItem)

    def add_block_item(self, index):
        """ Create new a drawable object to correspond to a Block with this index. """
        if not index in self._block_items:
            print "Adding block item", index
            item = BlockItem(self, index)
            self._block_items[index] = item
            return item

    def has_block_item(self, index):
        return True if index in self._block_items else False

    def set_block_item_settings(self, index, left_index, right_index):
        item = self._block_items[index]
        item.left_block = self._block_items[
            left_index] if left_index is not None else None
        item.right_block = self._block_items[
            right_index] if right_index is not None else None

    def set_block_item_attributes(self, index, attributes):
        """ Not yet implemented """
        pass

    def remove_block_item(self, index):
        print "Removing BlockItem %d" % index
        self._block_items[index].release()
        self._block_items.pop(index)

    def add_band_item(self, altitude, rank):
        """ Create a new drawable object to correspond to a Band. """
        print "Adding BandItem with altitude %d" % altitude
        if altitude in self._band_items:
            raise DuplicateItemExistsError(
                "BandItem with altitude %d already exists" % (altitude))
        item = BandItem(self, altitude, rank)
        self._band_items[altitude] = item
        return item

    def has_band_item(self, altitude):
        return True if altitude in self._band_items else False

    def remove_band_item(self, altitude):
        """ Remove the drawable object to correspond to a band """
        print "Removing BandItem altitude %d" % altitude
        self._band_items[altitude].release()
        self._band_items.pop(altitude)

    def get_band_item(self, altitude):
        return self._band_items[altitude]

    def set_band_item_settings(self, altitude, rank, top_band_alt,
                               bot_band_alt, leftmost_snapkey,
                               rightmost_snapkey):
        item = self._band_items[altitude]
        item.top_band = self._band_items[
            top_band_alt] if top_band_alt is not None else None
        item.bot_band = self._band_items[
            bot_band_alt] if bot_band_alt is not None else None
        item.left_most_snap = self._snap_items[leftmost_snapkey]
        item.right_most_snap = self._snap_items[rightmost_snapkey]

    def set_band_item_attributes(self, index, attributes):
        """ not yet implemented for this style view """
        pass

    def add_snap_item(self, snapkey):
        print "Adding SnapItem %s" % snapkey
        if snapkey in self._snap_items:
            raise DuplicateItemExistsError(
                "SnapItem with snapkey %s already exists" % (snapkey))
        item = SnapItem(self, snapkey)
        item.block_item = self._block_items[item.block_index]
        if item.isSource():
            self._block_items[item.block_index].emitters.append(item)
        else:
            self._block_items[item.block_index].collectors.append(item)
        self._snap_items[snapkey] = item
        return item

    def remove_snap_item(self, snapkey):
        print "Removing SnapItem %s" % snapkey
        self._snap_items[snapkey].release()
        self._snap_items.pop(snapkey)

    def has_snap_item(self, snapkey):
        return True if snapkey in self._snap_items else False

    def set_snap_item_settings(self, snapkey, left_order, right_order,
                               pos_band_alt, neg_band_alt):
        item = self._snap_items[snapkey]
        if left_order is not None:
            left_snapkey = gen_snapkey(item.block_index, item.container_name,
                                       left_order)
            item.left_snap = self._snap_items[left_snapkey]
        else:
            item.left_snap = None
        if right_order is not None:
            right_snapkey = gen_snapkey(item.block_index, item.container_name,
                                        right_order)
            item.right_snap = self._snap_items[right_snapkey]
        else:
            item.right_snap = None
        item.posBandItem = self._band_items[
            pos_band_alt] if pos_band_alt is not None else None
        item.negBandItem = self._band_items[
            neg_band_alt] if neg_band_alt is not None else None

    def set_snap_item_attributes(self, snapkey, attributes):
        """ not yet implemented for this style view """
        pass

    def update_view(self):

        # Initialize Visual Elements
        cornerStone = CornerStone()

        for item in self._band_items.values():
            item.layout()

        for item in self._block_items.values():
            item.layout()

        for item in self._snap_items.values():
            item.layout()

        # Draw
        grid = CharGrid()

        for item in self._band_items.values():
            item.draw(grid)

        for item in self._block_items.values():
            item.draw(grid)

        for item in self._snap_items.values():
            item.draw(grid)

        print grid
Beispiel #5
0
 def __init__(self, view, filename):
     super(FabrikLayoutManagerWidget, self).__init__(view)
     self._hook_items = TypedDict(str, HookItem)
     self._flow_items = TypedDict(str, FlowItem)
     log.debug("Initialized Fabrik Layout Manager")
     self.print_button = PrintButtonWidget(self, filename)
Beispiel #6
0
class FabrikLayoutManagerWidget(qt_view.LayoutManagerWidget):
    def __init__(self, view, filename):
        super(FabrikLayoutManagerWidget, self).__init__(view)
        self._hook_items = TypedDict(str, HookItem)
        self._flow_items = TypedDict(str, FlowItem)
        log.debug("Initialized Fabrik Layout Manager")
        self.print_button = PrintButtonWidget(self, filename)

    def add_block_item(self, index):
        log.debug("... Adding FabrikBlockItem %d" % index)
        """create a new FabrikBlockItem"""
        if index in self._block_items:
            raise qt_view.DuplicateItemExistsError("Block Item with index %d already exists" % index)
        item = FabrikBlockItem(self, index)
        self._block_items[index] = item
        return item

    def add_band_item(self, altitude, rank):
        """ Create a new drawable object to correspond to a Band. """
        log.debug("... Adding FabrikBandItem with altitude %d" % altitude)
        if altitude in self._band_items:
            raise DuplicateItemExistsError("BandItem with altitude %d already exists" % (altitude))
        item = FabrikBandItem(self, altitude, rank)
        self._band_items[altitude] = item
        return item

    def add_snap_item(self, snapkey):
        # snapkey gets passed as a QString automatically since it goes across
        # a signal/slot interface
        snapkey = str(snapkey)
        log.debug("... Adding SnapItem %s" % snapkey)
        if snapkey in self._snap_items:
            raise DuplicateItemExistsError("SnapItem with snapkey %s already exists" % (snapkey))
        item = FabrikSnapItem(self, snapkey)
        self._snap_items[snapkey] = item
        return item

    def set_band_item_settings(
        self, altitude, rank, top_band_alt, bot_band_alt, leftmost_object_label, rightmost_object_label
    ):
        item = self._band_items[altitude]
        item.rank = rank
        item.top_band = self._band_items[top_band_alt] if top_band_alt is not None else None
        item.bot_band = self._band_items[bot_band_alt] if bot_band_alt is not None else None

        if leftmost_object_label == "":
            item.left_most_obj = self.bandStack
        else:
            if ("e" in leftmost_object_label) or ("c" in leftmost_object_label):
                item.left_most_obj = self._snap_items[str(leftmost_object_label)]
                left_index = snapkey.parse_snapkey(leftmost_object_label)[0]
            else:  # Not snap, but hook
                item.left_most_obj = self._hook_items[str(leftmost_object_label)]
                left_index = hooklabel.parse_hooklabel(leftmost_object_label)[2]

        if rightmost_object_label == "":
            item.right_most_obj = self.bandStack
        else:
            if ("e" in rightmost_object_label) or ("c" in rightmost_object_label):
                item.right_most_obj = self._snap_items[str(rightmost_object_label)]
                right_index = snapkey.parse_snapkey(rightmost_object_label)[0]
            else:  # Not snap, but hook
                item.right_most_obj = self._hook_items[str(rightmost_object_label)]
                right_index = hooklabel.parse_hooklabel(rightmost_object_label)[2]

        try:
            if right_index == left_index:
                # Make sure it won't stick weirdly out to the left
                if left_index > 0:
                    item.left_most_obj = self._block_items[left_index - 1]
                # Make sure it doesn't stick out weirdly to the right
                if right_index < max(self._block_items.keys()):
                    item.right_most_obj = self._block_items[right_index + 1]
        except:  # right_index and left_index don't exist
            pass

    def add_hook_item(self, hook_label):
        # hook_label gets passed in as a QString, since it goes across a signal/slot interface
        hook_label = str(hook_label)
        log.debug("... Adding FabrikHookItem %s" % hook_label)
        if hook_label in self._hook_items:
            raise DuplicateItemExistsError("HookItem with hook_label %s already exists" % hook_label)
        item = HookItem(self, hook_label)
        self._hook_items[hook_label] = item
        return item

    def remove_hook_item(self, hook_label):
        # hook_label gets passed in as a QString, since it goes across a signal/slot interface
        hook_label = str(hook_label)
        log.debug("... Removing HookItem %s" % hook_label)
        self._hook_items[hook_label].release()
        self._hook_items.pop(hook_label)

    def set_hook_item_settings(self, hook_label):
        # hook_label gets passed in as a QString, since it goes across a signal/slot interface
        hook_label = str(hook_label)
        return

    def set_hook_item_attributes(self, hook_label, attributes):
        # hook_label gets passed in as a QString, since it goes across a signal/slot interface
        hook_label = str(hook_label)
        self._hook_items[hook_label].set_attributes(attributes)

    def has_hook_item(self, hook_label):
        return True if hook_label in self._hook_items else False

    def get_hook_item(self, hook_label):
        # hook_label gets passed in as a QString, since it goes across a signal/slot interface
        hook_label = str(hook_label)
        return self._hook_items[hook_label]

    def add_flow_item(self, flow_label):
        # flow_label gets passed in as a QString, since it goes across a signal/slot interface
        flow_label = str(flow_label)
        log.debug("... Adding FabrikFlowItem %s" % flow_label)
        if flow_label in self._flow_items:
            raise DuplicateItemExistsError("FlowItem with flow_label %s already exists" % flow_label)
        item = FlowItem(self, flow_label)
        self._flow_items[flow_label] = item
        return item

    def remove_flow_item(self, flow_label):
        # flow_label gets passed in as a QString, since it goes across a signal/slot interface
        flow_label = str(flow_label)
        log.debug("... Removing FlowItem %s" % flow_label)
        self._flow_items[flow_label].release()
        self._flow_items.pop(flow_label)

    def set_flow_item_settings(self, flow_label):
        # flow_label gets passed in as a QString, since it goes across a signal/slot interface
        flow_label = str(flow_label)

    def set_flow_item_attributes(self, flow_label, attributes):
        # flow_label gets passed in as a QString, since it goes across a signal/slot interface
        flow_label = str(flow_label)
        self._flow_items[flow_label].set_attributes(attributes)

    def has_flow_item(self, flow_label):
        return True if flow_label in self._flow_items else False

    def get_flow_item(self, flow_label):
        # flow_label gets passed in as a QString, since it goes across a signal/slot interface
        flow_label = str(flow_label)
        return self._flow_items[flow_label]

    def link(self):
        log.debug("*** Begining Linking ***")
        sys.stdout.flush()
        # Create a new anchored layout. Until I can figure out how to remove
        # objects from the layout, I need to make a new one each time
        l = QGraphicsAnchorLayout()
        l.setSpacing(0.0)
        self.setLayout(l)

        self.layout().addAnchor(self.print_button, Qt.AnchorBottom, self.bandStack, Qt.AnchorTop)
        self.layout().addAnchor(self.print_button, Qt.AnchorRight, self.bandStack, Qt.AnchorRight)

        # Anchor BandStack to Layout, and BlockContainer to BandStack
        self.layout().addAnchor(self.block_container, Qt.AnchorTop, self.layout(), Qt.AnchorTop)
        self.layout().addAnchor(self.block_container, Qt.AnchorLeft, self.layout(), Qt.AnchorLeft)
        self.layout().addAnchor(self.bandStack, Qt.AnchorLeft, self.block_container, Qt.AnchorLeft)
        self.layout().addAnchor(self.bandStack, Qt.AnchorRight, self.block_container, Qt.AnchorRight)

        # Link block items
        for item in self._block_items.values():
            item.link()

        # Link band items
        for item in self._band_items.values():
            item.link()

        # Link Snap Items
        for item in self._snap_items.values():
            item.link()

        # Link Hook Items
        for item in self._hook_items.values():
            item.link()

        # Link Flow Items
        for item in self._flow_items.values():
            item.link()

        log.debug("*** Finished Linking ***\n")
        sys.stdout.flush()