class GraphicSection(Section):
    def __init__(self, instance):
        self.app = instance
        self.graphics = GraphicsPanel(self)
        Section.__init__(self, self.graphics, KSEGraphicWorkzone(self.app, self.graphics))

    def createTree(self, tree):
        self.tree = tree.find("graphics")
        self.workzone.createTree(self.tree)
        resources = self.tree.find("resources")
        if resources != None:
            self.graphics.loadProjectResources(resources)

    def createAtlas(self, options):
        newNode = Element("atlas", attrib = {"name" : options["name"],
                                              "path" : options["location"],
                                             "width" : str(options["width"]),
                                             "height" : str(options["height"])})
        self.tree.append(newNode)
        self.workzone.addAtlas(newNode)

    def export(self):
        self.workzone.export()

    #INTERNAL :

    def addAtlasCb(self, unused):
        AtlasCreator(self)

    def importAtlasCb(self, unused):
        chooser = gtk.FileChooserDialog(title="Import atlas", action=gtk.FILE_CHOOSER_ACTION_OPEN,
                                        buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
        response = chooser.run()
        if response == gtk.RESPONSE_OK:
            newNode = Element("atlas", attrib = {"name" : chooser.get_filename(),
                                                 "path" : chooser.get_filename(),
                                                 "width" : "",
                                                 "height" : ""})
            self.tree.append(newNode)
            self.workzone.addAtlas(newNode)
        chooser.destroy()

    # Hackish, connected to the graphics panel's treeview.
    def rowActivatedCb(self, treeview, path, column, model):
        self.app.action_log.begin("add sprite")
        self.workzone.mergeResource(self.graphics.width,
                                    self.graphics.height,
                                    model[path][2])
        self.app.action_log.commit()
class GraphicSection(Section):
    def __init__(self, instance):
        self.app = instance
        self.graphics = GraphicsPanel(self)
        Section.__init__(self, self.graphics, KSEGraphicWorkzone(self.app))

    def createTree(self, tree):
        self.tree = tree.find("graphics")
        self.workzone.createTree(self.tree)
        resources = self.tree.find("resources")
        if resources != None:
            self.graphics.loadProjectResources(resources)

    def createAtlas(self, options):
        newNode = Element("atlas", attrib = {"name" : options["name"],
                                              "path" : options["location"],
                                             "width" : str(options["width"]),
                                             "height" : str(options["height"])})
        self.tree.append(newNode)
        self.workzone.addAtlas(newNode)

    def addImagesToResources(self, uris):
        node = self.tree.find("resources")
        if node == None:
            node = Element("resources")
            self.tree.append(node)
        for uri in uris:
            newNode = Element("resource", attrib =
                              {"name" : get_name_from_uri(uri),
                               "path" : uri})
            node.append(newNode)

    def export(self):
        self.workzone.export()

    #INTERNAL :

    def addAtlasCb(self, unused):
        AtlasCreator(self)

    # Hackish, connected to the graphics panel's treeview.
    def rowActivatedCb(self, treeview, path, column, model):
        self.app.action_log.begin("add sprite")
        self.workzone.mergeResource(self.graphics.width,
                                    self.graphics.height,
                                    model[path][2])
        self.app.action_log.commit()
 def __init__(self, instance):
     self.app = instance
     self.graphics = GraphicsPanel(self)
     Section.__init__(self, self.graphics, KSEGraphicWorkzone(self.app))