예제 #1
0
 def save(self, minus=False, forced=False):
     """save the ruleset to the database.
     If it does not yet exist in database, give it a new id
     If the name already exists in the database, also give it a new name
     If the hash already exists in the database, only save if forced=True"""
     if not forced:
         if minus:
             # if we save a template, only check for existing templates. Otherwise this could happen:
             # clear kajongg.db, play game with DMJL, start ruleset editor, copy DMJL.
             # since play Game saved the used ruleset with id 1, id 1 is found here and no new
             # template is generated. Next the ruleset editor shows the original ruleset in italics
             # and the copy with normal font but identical name, and the
             # copy is never saved.
             qData = Query("select id from ruleset where hash=? and id<0",
                           (self.hash, )).records
         else:
             qData = Query("select id from ruleset where hash=?",
                           (self.hash, )).records
         if qData:
             # is already in database
             self.rulesetId = qData[0][0]
             return
     with Internal.db:
         self.rulesetId, self.name = self._newKey(minus)
         Query(
             'INSERT INTO ruleset(id,name,hash,description) VALUES(?,?,?,?)',
             (self.rulesetId, english(
                 self.name), self.hash, self.description),
             failSilent=True)
         cmd = 'INSERT INTO rule(ruleset, list, position, name, definition, ' \
             'points, doubles, limits, parameter) VALUES(?,?,?,?,?,?,?,?,?)'
         args = list(self.ruleRecord(x) for x in self.allRules)
         Query(cmd, args)
예제 #2
0
 def __generateName(widget):
     """generate a name for this widget to be used in the config file"""
     orgWidget = widget
     name = english(widget.objectName())
     if not name:
         while widget.parentWidget():
             name = widget.__class__.__name__ + name
             widget = widget.parentWidget()
             if widget.parentWidget():
                 widgetName = english(widget.parentWidget().objectName())
                 if widgetName:
                     name = widgetName + name
                     break
     if not name:
         name = orgWidget.__class__.__name__
     return str(name)
예제 #3
0
 def __setRuleData(self, column, content, value):
     """change rule data in the model"""
     dirty, message = False, None
     if column == 0:
         if content.name != english(value):
             dirty = True
             content.name = english(value)
     elif column == 1 and isinstance(content, ParameterRule):
         oldParameter = content.parameter
         if isinstance(content, BoolRule):
             return False, ''
         else:
             if content.parameter != value:
                 dirty = True
                 content.parameter = value
         message = content.validate()
         if message:
             content.parameter = oldParameter
             dirty = False
     else:
         unitName = self.rootItem.content(column)
         dirty, message = content.score.change(unitName, value)
     return dirty, message
예제 #4
0
 def setData(self, index, value, role=Qt.EditRole):
     """change data in the model"""
     # pylint:  disable=too-many-branches
     if not index.isValid():
         return False
     try:
         dirty = False
         column = index.column()
         item = index.internalPointer()
         ruleset = item.ruleset()
         content = item.rawContent
         if role == Qt.EditRole:
             if isinstance(content, Ruleset) and column == 0:
                 oldName = content.name
                 content.rename(english(value))
                 dirty = oldName != content.name
             elif isinstance(content, RuleBase):
                 dirty, message = self.__setRuleData(column, content, value)
                 if message:
                     Sorry(message)
                     return False
             else:
                 return False
         elif role == Qt.CheckStateRole:
             if isinstance(content, BoolRule) and column == 1:
                 if not isinstance(ruleset, PredefinedRuleset):
                     newValue = value == Qt.Checked
                     if content.parameter != newValue:
                         dirty = True
                         content.parameter = newValue
             else:
                 return False
         if dirty:
             if isinstance(content, RuleBase):
                 ruleset.updateRule(content)
             self.dataChanged.emit(index, index)
         return True
     except BaseException:
         return False
예제 #5
0
파일: login.py 프로젝트: zero804/kajongg
    def __new__(cls, url):
        assert url
        host = None
        port = None
        urlParts = url.split(':')
        host = urlParts[0]
        if english(host) == Query.localServerName:
            host = '127.0.0.1'
        if len(urlParts) > 1:
            port = int(urlParts[1])
        obj = str.__new__(cls, url)
        obj.host = host
        obj.port = port
        if Options.port:
            obj.port = int(Options.port)
        if obj.port is None and obj.isLocalHost and not obj.useSocket:
            obj.port = obj.findFreePort()
        if obj.port is None and not obj.isLocalHost:
            obj.port = Internal.defaultPort
        if Debug.connections:
            logDebug(repr(obj))

        return obj
예제 #6
0
def ruleKey(name):
    """the key is used for finding a rule in a RuleList"""
    return english(name).replace(' ', '').replace('.', '')
예제 #7
0
파일: login.py 프로젝트: zero804/kajongg
 def url(self):
     """abstracts the url of the dialog"""
     return english(self.cbServer.currentText())