Esempio n. 1
0
 def toButtonDict(self):
     return {
         "id": self.variantID,
         "commandID": UserCommands.getCommandIDFromIndex(self.usrcmdfk),
         "label": self.label,
         "info": self.info,
         "icon": self.icon,
     }
Esempio n. 2
0
 def toDict(self):
     return {
         "id": self.variantID,
         "commandID": UserCommands.getCommandIDFromIndex(self.usrcmdfk),
         "label": self.label,
         "info": self.info,
         "icon": self.icon,
         "language": self.language,
         "location": self.location,
         "script": self.script,
     }
Esempio n. 3
0
    def getVariants(cls, commandID):
        session      = Session()
        commandIndex = UserCommands.getIndexFromCommandID(commandID)
        result       = session.query(CommandVariants).filter(
            CommandVariants.usrcmdfk == commandIndex
        ).order_by(CommandVariants.row.asc()).all()

        out = []
        for r in result:
            out.append(r.toButtonDict())

        return out
Esempio n. 4
0
    def getCommandData(cls, commandID):
        session      = Session()
        commandIndex = UserCommands.getIndexFromCommandID(commandID)
        result       = session.query(UserCommands).filter(UserCommands.i == commandIndex).first()

        if result is None:
            session.close()
            return {'error':'No Such Command'}

        out = result.toDict()
        session.close()
        return out
Esempio n. 5
0
    def createCommand(cls, categoryID, column, row =None, **kwargs):
        session       = Session()
        categoryIndex = CommandCategories.getIndexFromCategoryID(categoryID)

        if row is None or row < 0:
            row = session.query(UserCommands).filter(
                and_(
                    UserCommands.categoryfk == categoryIndex,
                    UserCommands.column == column
                )
            ).count()

        for n,v in kwargs.iteritems():
            if isinstance(v, str):
                kwargs[n] = unicode(v)

        command = UserCommands(categoryfk=categoryIndex, column=column, row=row, **kwargs)
        session.add(command)
        session.commit()

        out = command.toButtonDict()
        session.close()
        return out
Esempio n. 6
0
    def reorderColumn(cls, column, commandIDs):
        session = Session()
        index   = 0
        out     = []
        for cmdID in commandIDs:
            cmdIndex = UserCommands.getIndexFromCommandID(cmdID)
            cmd      = session.query(UserCommands).filter(UserCommands.i == cmdIndex).first()
            if not cmd:
                continue

            cmd.column = column
            cmd.row    = index
            out.append(cmd.commandID)
            index  += 1

        session.commit()
        session.close()
        return out
Esempio n. 7
0
    def deleteCommand(cls, commandID):
        session      = Session()
        commandIndex = UserCommands.getIndexFromCommandID(commandID)
        result       = session.query(UserCommands).filter(UserCommands.i == commandIndex).first()

        if result is None:
            session.close()
            return {'id':commandID}

        session.delete(result)

        result = session.query(CommandVariants).filter(CommandVariants.usrcmdfk == commandIndex).all()
        for r in result:
            session.delete(result)

        session.commit()
        session.close()

        return {'id':commandID}
Esempio n. 8
0
    def modifyCommand(cls, commandID, **kwargs):
        session      = Session()
        commandIndex = UserCommands.getIndexFromCommandID(commandID)
        result       = session.query(UserCommands).filter(UserCommands.i == commandIndex).first()

        if result is None:
            session.close()
            return {'error':'No Such Command'}

        for n,v in kwargs.iteritems():
            if isinstance(v, str):
                v = unicode(v)
            setattr(result, n, v)

        session.commit()

        out = result.toButtonDict()
        session.close()
        return out
Esempio n. 9
0
    def createVariant(cls, commandID, row =None, **kwargs):
        session      = Session()
        commandIndex = UserCommands.getIndexFromCommandID(commandID)

        if row is None or row < 0:
            row = session.query(CommandVariants).filter(
                CommandVariants.usrcmdfk == commandIndex
            ).count()

        for n,v in kwargs.iteritems():
            if isinstance(v, str):
                kwargs[n] = unicode(v)

        variant = CommandVariants(usrcmdfk=commandIndex, row=row, **kwargs)
        session.add(variant)
        session.commit()

        out = variant.toButtonDict()
        session.close()
        return out