예제 #1
0
    def updateLabelData(self):
        # remove infos from deleted layers
        layers = self.label['layer']

        numberMainLayers = 0
        firstMain, between, secondMain = (False, False, False)

        for (layerId, layerLabel, layerIndex, dummy) in self.layers:
            prefix = 'layer_%d_' % layerIndex

            if getValue(layers, prefix+'ismain') == 'true':
                numberMainLayers += 1

                if firstMain is False:
                    firstMain = True
                elif secondMain is False:
                    secondMain = True

            if (firstMain == True
                and secondMain == False
                and getValue(layers, prefix+'ismain') == 'false'
                and getValue(layers, prefix+'isused') == 'true'):
                between = True

        # if there's more than two main layer, raise a warning
        if numberMainLayers > 2:
            msg = "Warning: There's more than two main layers."
            log.outMsg(msg)
        if between is True and secondMain is True:
            msg = "Warning: The two main layers have to be consecutives.\n\
(no background or foreground layers between them)."
            log.outMsg(msg)
예제 #2
0
 def effectHook(self):
     logging.info("recreate lvl file")
     lvlfileName = join(getHomeDir(), 'last.lvl')
     try:
         svg2lvl(self.args[-1], lvlfileName)
     except Exception, e:
         log.outMsg("%s\nSee log for more informations." % str(e))
         logging.warning(format_exc())
예제 #3
0
 def urlopenread(self, url):
     """ urlopen with try/except
     """
     try:
         content = urllib2.urlopen(url).read()
     except urllib2.HTTPError, exc:
         log.outMsg("HTTP request failed with error code %d (%s)." %
                    (exc.code, exc.msg))
         raise Exception("Error accessing to the url: %s" % url)
예제 #4
0
    def apply(self, widget):
        xmGuiGtk.quit()

        conf = Conf()

        if (conf['enableRecording'] == True
                and conf['recordingSession'] != ''):
            log.outMsg("There's already a recording session in progress.")
            return

        sessionName = self.get('sessionName').get_text()

        if checkId(sessionName) == False:
            log.outMsg("Invalid session name")
            return

        if sessionName == '':
            log.outMsg("You have to set the session name")
            return

        # check if that session already exists
        sessionDir = join(getHomeDir(), 'cur_tests', sessionName)
        if isdir(sessionDir):
            log.outMsg("The session %s already exists" % sessionName)
            return

        conf['enableRecording'] = True
        conf['recordingSession'] = "%s" % sessionName
        conf['currentTest'] = 0
        conf.write()
예제 #5
0
    def effectHook(self):
        conf = Conf()

        if conf['enableRecording'] == False:
            log.outMsg("There's no recording session in progress.")
            return False

        testsCreator = TestsCreator()
        testsCreator.generateTests()

        conf['enableRecording'] = False
        conf['recordingSession'] =  ''
        conf.write()

        return False
예제 #6
0
class LaunchXmoto(XmExt):
    def __init__(self):
        XmExt.__init__(self)
        self.OptionParser.add_option("--xmoto", type="string",
                                     dest="xmoto", help="xmoto executable")
        self.OptionParser.add_option("--dummy", type="string",
                                     dest="dummy", help="dummy")

    def effectHook(self):
        # check that the xmoto executable is present
        givenXmotoPresent = True
        xmotopath = self.options.xmoto
        logging.info("xmotopath=%s" % xmotopath)

        try:
            if not isfile(xmotopath):
                givenXmotoPresent = False
                logging.info("path[%s] is not a valid file" % xmotopath)
        except Exception, e:
            givenXmotoPresent = False
            logging.info("path[%s] is not a valid file.\n%s" % (xmotopath, e))

        # export in lvl
        lvlfileName = join(getHomeDir(), 'last.lvl')
        try:
            svg2lvl(self.args[-1], lvlfileName)
        except Exception, e:
            log.outMsg("%s\nSee log for more informations." % str(e))
            logging.warning(format_exc())
            return False
예제 #7
0
class InstallKeys(XmExt):
    def __init__(self):
        XmExt.__init__(self)

    def effectHook(self):
        logging.info("install default.xml in home directory")
        src = join(getSystemDir(), 'xmoto_install', 'default.xml')
        if not exists(src):
            src = join(getHomeDir(), 'inksmoto', 'xmoto_install',
                       'default.xml')
            if not exists(src):
                log.outMsg(
                    "xmoto_install/default.xml is present neither in the\
 system directory nor in the home directory.")
                return False

        destDir = join(getHomeDir(), '..', 'keys')
        destDir = normpath(destDir)
        dest = join(destDir, 'default.xml')

        try:
            if not isdir(destDir):
                makedirs(destDir)
        except Exception, e:
            log.outMsg("Can't create the directory [%s]\n%s" % (destDir, e))
            return False

        try:
            copyfile(src, dest)
        except Exception, e:
            log.outMsg("Can't copy the shorcuts file \
from [%s] to [%s].\n%s" % (src, dest, e))
예제 #8
0
    def effectHook(self):
        if len(self.selected) != 1:
            log.outMsg("You have to only select the object whose you want \
to copy the Xmoto parameters.")
            return False

        node = self.selected[self.options.ids[0]]
        label = node.get(addNS('xmoto_label', 'xmoto'))

        if label is None:
            log.outMsg("The selected object has no Xmoto properties to copy.")
            return False

        node = self.svg.getAndCreateMetadataNode()
        node.set(addNS('saved_xmoto_label', 'xmoto'), label)

        return False
예제 #9
0
    def effectUnloadHook(self):
        nodeNewId = self.get('objectId').get_text()
        if checkVarId(nodeNewId) == False:
            log.outMsg("You can only use alphanumerical characters and the \
underscore for the id.\nThe id can't begin with a number.")
            return False

        if nodeNewId != self.nodeId:
            if self.isBitmap == True:
                self.circle.set('id', nodeNewId)
                self.node.set('id', 'g_' + nodeNewId)
                image = self.node.find(addNS('image', 'svg'))
                if image is not None:
                    image.set('id', 'image_' + nodeNewId)
            else:
                self.node.set('id', nodeNewId)

        return False
예제 #10
0
    def effectHook(self):
        self.update = False

        # TODO::create the window showing what's going on

        #logging.info("self.options=[%s]" % str(self.options))

        # get the xml file
        self.connexion = self.options.connexion
        logging.info('Connexion method: %s' % self.connexion)
        if self.connexion == 'web':
            self.getXmlFromTheWeb()

        elif self.connexion == 'proxy':
            proxy_info = {'host': self.options.host, 'port': self.options.port}
            if self.options.user not in [None, '', 'None']:
                proxy_info['user'] = self.options.user
                proxy_info['password'] = self.options.password
                proxyDic = {
                    "http":
                    "http://%(user)s:%(password)s@%(host)s:%(port)s" %
                    proxy_info
                }
                logging.info('proxydic: %s' % str(proxyDic))
            else:
                proxyDic = {"http": "http://%(host)s:%(port)s" % proxy_info}
                logging.info('proxydic: %s' % str(proxyDic))

            try:
                proxy_support = urllib2.ProxyHandler(proxyDic)
            except urllib2.URLError, exc:
                log.outMsg("Error while creating proxy handler.. Cause: %s." %
                           exc.reason)
                raise Exception("FATAL ERROR::can't create proxy handler")

            try:
                opener = urllib2.build_opener(proxy_support)
            except Exception, e:
                log.outMsg('Error while creating proxy opener.\n%s' % e)
                raise Exception("FATAL ERROR::can't create proxy opener")
예제 #11
0
    def effectHook(self):
        logging.info("install default.xml in home directory")
        src = join(getSystemDir(), 'xmoto_install', 'default.xml')
        if not exists(src):
            src = join(getHomeDir(), 'inksmoto', 'xmoto_install',
                       'default.xml')
            if not exists(src):
                log.outMsg(
                    "xmoto_install/default.xml is present neither in the\
 system directory nor in the home directory.")
                return False

        destDir = join(getHomeDir(), '..', 'keys')
        destDir = normpath(destDir)
        dest = join(destDir, 'default.xml')

        try:
            if not isdir(destDir):
                makedirs(destDir)
        except Exception, e:
            log.outMsg("Can't create the directory [%s]\n%s" % (destDir, e))
            return False
예제 #12
0
class RefreshMenu(XmExt):
    def __init__(self):
        XmExt.__init__(self)
        self.OptionParser.add_option("--tab",
                                     type="string",
                                     dest="tab",
                                     help="tab")
        self.OptionParser.add_option("--xmlfile",
                                     type="string",
                                     dest="xmlfile",
                                     help="xml file")
        self.OptionParser.add_option("--urlbase",
                                     type="string",
                                     dest="urlbase",
                                     help="web site url")
        self.OptionParser.add_option("--connexion",
                                     type="string",
                                     dest="connexion",
                                     help="update method. (web, proxy, local)")
        self.OptionParser.add_option("--host",
                                     type="string",
                                     dest="host",
                                     help="proxy hostname")
        self.OptionParser.add_option("--port",
                                     type="string",
                                     dest="port",
                                     help="proxy port")
        self.OptionParser.add_option("--user",
                                     type="string",
                                     dest="user",
                                     help="proxy user")
        self.OptionParser.add_option("--password",
                                     type="string",
                                     dest="password",
                                     help="proxy password")

    def urlopenread(self, url):
        """ urlopen with try/except
        """
        try:
            content = urllib2.urlopen(url).read()
        except urllib2.HTTPError, exc:
            log.outMsg("HTTP request failed with error code %d (%s)." %
                       (exc.code, exc.msg))
            raise Exception("Error accessing to the url: %s" % url)
        except urllib2.URLError, exc:
            log.outMsg("URL error. Cause: %s." % exc.reason)
            raise Exception("Error accessing to the url: %s" % url)
예제 #13
0
    def effectLoadHook(self):
        def setSublayerAttrs():
            self.node = convertToXmNode(self.node, self.svg)
            self.circle = self.node.getCircleChild()
            self.isBitmap = True
            self.nodeId = self.circle.get('id', '')

        if len(self.selected) != 1:
            log.outMsg("You have to only select the object whose you want to \
change the id.")
            return (True, False)

        # this extension exists to handle the case when you want to
        # change an entity id
        self.isBitmap = False

        self.node = self.selected[self.options.ids[0]]
        if self.node.tag == addNS('g', 'svg'):
            if self.node.get(addNS('xmoto_label', 'xmoto')) is None:
                # if someone group a single sprite, and then try to
                # change it's id, it will spit this on his face :
                log.outMsg("You have to only select the object whose you want \
to change the id.")
                return (True, False)
            else:
                setSublayerAttrs()
        elif self.node.tag in [addNS('use', 'svg'), addNS('image', 'svg')]:
            if self.node.getparent().tag != addNS('g', 'svg'):
                log.outMsg("You have selected an image which is not part of a \
sublayer entity.\nStop doing that.")
                return (True, False)
            else:
                self.node = self.node.getparent()
                setSublayerAttrs()
        else:
            self.nodeId = self.node.get('id', '')

        return (False, False)
예제 #14
0
    def effectHook(self):
        if len(self.selected) == 0:
            log.outMsg("You have to select the objects whose you want to \
paste the Xmoto parameters.")
            return False
        
        descNode = self.svg.getMetaDataNode()
        if descNode is None:
            log.outMsg("You have to copy the Xmoto properties of an \
object first.")
            return False

        self.label = descNode.get(addNS('saved_xmoto_label', 'xmoto'))

        if self.label is None:
            log.outMsg("You have to copy the Xmoto properties of an \
object first.")
            return False

        applyOnElements(self, self.selected, self.setLabel)

        # we want to update the nodes shapes with their new style
        return True
예제 #15
0
                proxy_support = urllib2.ProxyHandler(proxyDic)
            except urllib2.URLError, exc:
                log.outMsg("Error while creating proxy handler.. Cause: %s." %
                           exc.reason)
                raise Exception("FATAL ERROR::can't create proxy handler")

            try:
                opener = urllib2.build_opener(proxy_support)
            except Exception, e:
                log.outMsg('Error while creating proxy opener.\n%s' % e)
                raise Exception("FATAL ERROR::can't create proxy opener")

            try:
                urllib2.install_opener(opener)
            except Exception, e:
                log.outMsg('Error while installing proxy opener.\n%s' % e)
                raise Exception("FATAL ERROR::can't install proxy opener")

            self.getXmlFromTheWeb()

        elif self.connexion == 'local':
            if self.options.xmlfile in [None, '', 'None']:
                filename = join(getHomeDir(), 'inksmoto',
                                'listAvailableElements.xml')
                xmlFile = open(filename, 'rb')
            else:
                xmlFile = open(self.options.xmlfile, 'rb')

            self.localXmlContent = xmlFile.read()
            xmlFile.close()
예제 #16
0
        except Exception, e:
            log.outMsg("%s\nSee log for more informations." % str(e))
            logging.warning(format_exc())
            return False

        if os.name == 'nt':
            lvlfileName = "\"" + lvlfileName + "\""
        params = ['xmoto', '--testTheme', '--fps', lvlfileName]
        # launch it in xmoto
        if givenXmotoPresent == True:
            logging.info("launching executable: [%s][%s]" % (xmotopath,
                                                             lvlfileName))
            try:
                os.execl(xmotopath, *params)
            except Exception, e:
                log.outMsg("Cant execute %s.\n%s" % (xmotopath, e))
        else:
            try:
                os.execlp('xmoto', *params)
            except Exception, e:
                log.outMsg("The xmoto executable is present neither in the \
given location (%s) nor in the PATH.\n%s" % (xmotopath, e))

        return False

def run():
    ext = LaunchXmoto()
    ext.affect()
    return ext

if __name__ == "__main__":
예제 #17
0
    def effectHook(self):
        #read svg information, find selected path to use in the line.
        if len(self.selected) != 1:
            log.outMsg("You have to select only one object.")
            return False

        for node in self.selected.values():
            if node.tag not in [addNS('path', 'svg'), addNS('rect', 'svg')]:
                log.outMsg("You need to select path and rectangle only.")
                return False

        # there's only one selected object
        node = self.selected.values()[0]

        self.jointType = self.options.joint
        self.space = self.options.space
        self.numBlocks = self.options.blocks

        # is it a physic block?
        node = convertToXmNode(node, self.svg)
        label = node.getParsedLabel()
        createIfAbsent(label, 'position')
        if 'physics' not in label['position']:
            log.outMsg("The selected object has to be an Xmoto physics block.")
            return False

        # we need uniq ids
        idPrefix = node.get('id')
        blockPrefix = idPrefix + 'jl_block'
        jointPrefix = idPrefix + 'jl_joint'

        # TODO::if called different times on the same object
        node.set('id', blockPrefix + '0')

        aabb = node.getAABB()
        offset = self.space + aabb.width()
        jointHeight = 10
        if jointHeight > aabb.height() / 2.0:
            jointHeight = aabb.height() / 2.0

        ex = AddJoint(self.jointType)
        for no in xrange(1, self.numBlocks + 1):
            node = node.duplicate(blockPrefix + str(no))
            node.translate(offset, 0)

            if no < self.numBlocks + 1:
                newJoint = None
                if self.jointType == 'pin':
                    jointX = aabb.x() - aabb.width() / 2.0 - self.space
                    jointY = aabb.y() + aabb.height() / 2.0 - jointHeight / 2.0
                    jointWidth = aabb.width() + self.space
                    newJoint = etree.Element(addNS('rect', 'svg'))
                    newJoint.set('x', str(jointX))
                    newJoint.set('y', str(jointY))
                    newJoint.set('width', str(jointWidth))
                    newJoint.set('height', str(jointHeight))
                elif self.jointType == 'pivot':
                    jointX = aabb.x() - self.space / 2.0
                    jointY = aabb.cy()
                    newJoint = etree.Element(addNS('path', 'svg'))
                    newJoint.set(
                        'd',
                        getCenteredCircleSvgPath(jointX, jointY,
                                                 jointHeight / 2.0))

                node.getparent().append(newJoint)
                newJoint.set('id', jointPrefix + str(no))

                transform = node.get('transform')
                if transform is not None:
                    newJoint.set('transform', transform)

                label, style = ex.getLabelAndStyle(blockPrefix + str(no - 1),
                                                   blockPrefix + str(no))
                ex.updateNodeSvgAttributes(newJoint, label, style)

        return False
예제 #18
0
        destDir = normpath(destDir)
        dest = join(destDir, 'default.xml')

        try:
            if not isdir(destDir):
                makedirs(destDir)
        except Exception, e:
            log.outMsg("Can't create the directory [%s]\n%s" % (destDir, e))
            return False

        try:
            copyfile(src, dest)
        except Exception, e:
            log.outMsg("Can't copy the shorcuts file \
from [%s] to [%s].\n%s" % (src, dest, e))
        else:
            log.outMsg("Inksmoto shorcuts installed.\n\
Restart Inkscape to activate them.")

        return False


def run():
    ext = InstallKeys()
    ext.affect()
    return ext


if __name__ == "__main__":
    run()