예제 #1
0
    def GenerateBlankConf(self):
        conf_file = XMLParser()
        conf_file.addTag("tipsOfTheDay", {"show":"True", "version":TIPS_VER})

        for tipInstance in range(len(TIPS)):
            conf_file.appendToTag("tipsOfTheDay", "tip", {"enabled":"True", "id":tipInstance})

        self.confFile = file(os.path.expanduser(self.confFilePath), 'w')
        self.confFile.write(conf_file.getXML())
        self.confFile.close()
예제 #2
0
    def __init__(self, diagram, block_type, block_id=1):

        self.block_type = block_type
        self.diagram = diagram
        self.data_dir = os.environ['HARPIA_DATA_DIR']
        if s2idirectory.block.has_key(block_type):
            self.block_description = s2idirectory.block[block_type]
        else:
            self.block_description = s2idirectory.block[0]
            print "Bad block type.. assuming 00"

        self.block_id = block_id
        self.widgets = {}
        self.focus = False
        self.has_flow = False
        self.m_bTimeShifts = False
        self.m_bIsSource = False

        if self.block_description.has_key("IsSource"):  #all data sources
            self.m_bIsSource = self.block_description["IsSource"]

        if self.block_description.has_key("TimeShifts"):  #delay block
            self.m_bTimeShifts = self.block_description["TimeShifts"]

        self.m_oPropertiesXML = XMLParser(
            self.data_dir + str(self.block_description["Path"]["Xml"]))
        self.m_oPropertiesXML.getTag("properties").getTag("block").setAttr(
            "id", str(self.block_id))

        self.m_oBorderColor = [0, 0, 0, 255]
        self.m_oBackColor = [0, 0, 0, 150]
        self.input_port_centers = []
        self.output_port_centers = []
        self.width = WIDTH_DEFAULT

        t_nMaxIO = max(len(self.block_description["InTypes"]),
                       len(self.block_description["OutTypes"]))

        ## Generates the block size, based on the number of inputs,outputs
        # Comment block is too small...
        if not t_nMaxIO:
            t_nMaxIO = 1

        self.height = max(
            ((t_nMaxIO - 1) * 5)  #espacamento entre ports = 5
            + (RADIUS * 2)  #tirando a margem superior e inferior
            + (t_nMaxIO * INPUT_HEIGHT),  #adicionando a altura de cada port
            HEIGHT_DEFAULT)

        self.__gobject_init__()
        self.group = self.diagram.root().add(self, x=0, y=0)
        self.group.connect("event", self.__group_event)
        self.group.set_flags(gtk.CAN_FOCUS)
        self.build()
예제 #3
0
    def __saveConfFile(self):

        conf_file = XMLParser()
        conf_file.addTag("tipsOfTheDay", {"show":str(self.showTips), "version":TIPS_VER})

        for tipInstance in self.avTips.keys():
            conf_file.appendToTag("tipsOfTheDay", "tip", {"enabled":self.avTips[tipInstance], "id":tipInstance})

        self.confFile = file(os.path.expanduser(self.confFilePath), 'w')
        self.confFile.write(conf_file.getXML())
        self.confFile.close()
예제 #4
0
    def __loadConfFile(self):

        if(not os.path.exists(os.path.expanduser(self.confFilePath))):
            self.GenerateBlankConf()

        self.confFile = XMLParser(os.path.expanduser(self.confFilePath))

        tipsOfTheDay = self.confFile.getTag("tipsOfTheDay")
        tips_ver = tipsOfTheDay.getAttr("version")

        if tips_ver != TIPS_VER:
            self.GenerateBlankConf()
            self.confFile = XMLParser(os.path.expanduser(self.confFilePath))

        show_tips = tipsOfTheDay.getAttr("show")

        if show_tips == "True":
            for tip in tipsOfTheDay.getChildTags("tip"):
                self.avTips[int(tip.getAttr("id"))]=(tip.getAttr("enabled") == "True")

        print self.avTips
예제 #5
0
    def load(self, file_name=None):
        if file_name != None:
            self.diagram.set_file_name(file_name)
        else:
            if self.diagram.file_name == None:
                self.diagram.file_name = "Cannot Load without filename"
                return False

        # reseting present diagram..
        self.diagram.blocks = {}
        self.diagram.connectors = []
        self.diagram.curr_connector = None
        self.diagram.session_id = 0

        # this two must be updated at each block/conn insertion
        self.diagram.block_id = 1  # since block counts are kept, render this from the saved file
        self.diagram.connector_id = 1  # since connector Ids are generated from scratch, just reset it

        t_oLoad = XMLParser(self.diagram.file_name)
        blocks = t_oLoad.getTag("harpia").getTag("GcState").getChildTags("block")

        #for block in t_oLoad.harpia.GcState.block:
        for block in blocks:
            block_id =  block.getAttr("id")
            block_type =  block.getAttr("type")
            position = block.getTag("position")
            x = position.getAttr("x")
            y = position.getAttr("y")

            self.diagram.insert_blockPosId(int(block_type), float(x), float(y), int(block_id))
            self.diagram.block_id = max(self.diagram.block_id, int(block_id))

        self.diagram.block_id += 1

        blocks = t_oLoad.getTag("harpia").getTag("network").getChildTags("block")

        # loading connectors on canvas
        try:
            #for block in t_oLoad.harpia.network.block:
            for block in blocks:
                block_id =  block.getAttr("id")
                outputs = block.getTag("outputs")

                #for connector in block.outputs.output:
                for connector in outputs.getChildTags("output"):
                    conn_input = connector.getAttr("input")
                    conn_inblock = connector.getAttr("inBlock")
                    conn_id = connector.getAttr("id")

                    print conn_input, conn_inblock, conn_id

                    if conn_inblock != "--" and conn_input != "--":
                        #(int(connector.input) - 1))
                        self.diagram.insert_ready_connector(
                                                int(block_id),
                                                (int(conn_id) - 1),
                                                int(conn_inblock),
                                                (int(conn_input) - 1))
        except AttributeError:
            pass

        # loading properties
        blocks = t_oLoad.getTag("harpia").getTag("properties").getChildTags("block")

        for block in blocks:
            block_xml = str(block)
            block_id =  block.getAttr("id")
            t_sBlockProperties = '<?xml version="1.0" encoding="UTF-8"?>\n<properties>\n' + block_xml + '\n</properties>\n'
            self.diagram.blocks[int(block_id)].SetPropertiesXML(XMLParser(t_sBlockProperties, fromString=True))

        self.diagram.update_scrolling()
        self.diagram.goto_scrolling(0, 0)
        return True
예제 #6
0
    def Load(self, file_name=None):
        if file_name != None:
            self.set_file_name(file_name)
        else:
            if self.file_name == None:
                self.file_name = "Cannot Load without filename"
                return False

                # reseting present diagram..
        self.blocks, self.connectors, self.curr_connector, self.session_id = {}, [], None, 0

        # this two must be updated at each block/conn insertion
        self.block_id = 1  # since block counts are kept, render this from the saved file
        self.connector_id = 1  # since connector Ids are generated from scratch, just reset it

        #t_oLoad = bt.bind_file(self.file_name)  # binding saved project
        #print t_oLoad.xml()
        t_oLoad = XMLParser(self.file_name)

        # loading blocks on canvas
        #GcState_root = t_oLoad.getTagChild("harpia", "GcState")
        #blocks = t_oLoad.getChildTags(GcState_root, "block")
        blocks = t_oLoad.getTag("harpia").getTag("GcState").getChildTags(
            "block")

        #for block in t_oLoad.harpia.GcState.block:
        for block in blocks:
            #block_id =  t_oLoad.getTagAttr(block, "id")
            #block_type =  t_oLoad.getTagAttr(block, "type")
            block_id = block.getAttr("id")
            block_type = block.getAttr("type")
            position = block.getTag("position")
            x = position.getAttr("x")
            y = position.getAttr("y")

            self.__insert_blockPosId(int(block_type), float(x), float(y),
                                     int(block_id))
            self.block_id = max(self.block_id, int(block_id))

        self.block_id += 1

        blocks = t_oLoad.getTag("harpia").getTag("network").getChildTags(
            "block")

        # loading connectors on canvas
        try:
            #for block in t_oLoad.harpia.network.block:
            for block in blocks:
                block_id = block.getAttr("id")
                outputs = block.getTag("outputs")

                #for connector in block.outputs.output:
                for connector in outputs.getChildTags("output"):
                    conn_input = connector.getAttr("input")
                    conn_inblock = connector.getAttr("inBlock")
                    conn_id = connector.getAttr("id")

                    print conn_input, conn_inblock, conn_id

                    #self.InsertReadyConnector(int(block.id), (int(connector.id) - 1), int(connector.inBlock),
                    if conn_inblock != "--" and conn_input != "--":
                        #(int(connector.input) - 1))
                        self.InsertReadyConnector(int(block_id),
                                                  (int(conn_id) - 1),
                                                  int(conn_inblock),
                                                  (int(conn_input) - 1))
                        # this "-1" are "paired" with those "+1" at line 286 (GetProcessChain:offset=14)
        except AttributeError:
            pass

        # loading properties
        blocks = t_oLoad.getTag("harpia").getTag("properties").getChildTags(
            "block")

        for block in blocks:
            block_xml = str(block)
            block_id = block.getAttr("id")
            #t_sBlockProperties = '<?xml version="1.0" encoding="UTF-8"?>\n<properties>\n' + block.xml() + '\n</properties>\n'
            t_sBlockProperties = '<?xml version="1.0" encoding="UTF-8"?>\n<properties>\n' + block_xml + '\n</properties>\n'

            #self.blocks[int(block.id)].SetPropertiesXML(bt.bind_string(t_sBlockProperties))
            self.blocks[int(block_id)].SetPropertiesXML(
                XMLParser(t_sBlockProperties, fromString=True))

        self.UpdateScrolling()
        self.GotoScrolling(0, 0)
        return True