Changeset 1146:0321756c76fe


Ignore:
Timestamp:
04/24/24 13:54:14 (8 months ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
Phase:
public
Message:

Support for delay codes that require explanations (re #386)

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • dcdatagen.py

    r1145 r1146  
    2727# Row type: an actual delay code
    2828DELAYCODE = 2
     29
     30# Row type: an actual delay code requiring a textual explanation
     31DELAYCODE_EXPLANATION_REQUIRED = 3
    2932
    3033#----------------------------------------------------------------------------
     
    702705                    print("msgid \"%srow%d\"" % (poPrefix, rowIndex), file=poFile)
    703706                    generateMsgStr(poFile, columns[i])
    704             elif type==DELAYCODE:
     707            elif type in [DELAYCODE, DELAYCODE_EXPLANATION_REQUIRED]:
    705708                columnIndex = 0
    706709                for column in columns:
     
    739742                    continue
    740743
    741                 if type==DELAYCODE:
     744                if type in [DELAYCODE, DELAYCODE_EXPLANATION_REQUIRED]:
    742745                    print("    \"%s\": \"%s\"," % \
    743746                      (str(columns[codeIndex]).strip(), columns[meaningIndex][0].replace("\n", "")), file=dcdata)
     
    756759        tableMask = 1
    757760        for i in range(0, len(tablePrefixes)):
     761            print("_%s_code2explanationRequired = {" % (tablePrefixes[i],), file=dcdata)
     762
     763            columnIndexes = []
     764            for j in range(0, len(headings)):
     765                if ( (headingFlags[j]&tableMask)==tableMask ):
     766                    columnIndexes.append(j)
     767
     768            codeIndex = columnIndexes[0]
     769            meaningIndex = columnIndexes[2]
     770
     771            rowIndex = 0
     772            for (type, mask, columns) in rows:
     773                if (mask&tableMask)!=tableMask:
     774                    continue
     775
     776                if type in [DELAYCODE, DELAYCODE_EXPLANATION_REQUIRED]:
     777                    print("    \"%s\": %s," % \
     778                          (str(columns[codeIndex]).strip(),
     779                           "True" if type==DELAYCODE_EXPLANATION_REQUIRED else
     780                           "False"),
     781                          file = dcdata)
     782
     783            print("}", file=dcdata)
     784            print(file=dcdata)
     785
     786            tableMask <<= 1
     787
     788        print("def _isExplanationRequired(table, row):", file=dcdata)
     789        print("    code = row[0].strip()", file=dcdata)
     790        print("    return table[code] if code in table else false", file=dcdata)
     791        print(file=dcdata)
     792
     793        tableMask = 1
     794        for i in range(0, len(tablePrefixes)):
    758795
    759796            print("_%s_data = (" % (tablePrefixes[i],), file=dcdata)
    760             print("    lambda row: _extract(_%s_code2meaning, row)," % \
     797            print("    (lambda row: row[0].strip(),", file=dcdata)
     798            print("     lambda row: _extract(_%s_code2meaning, row)," % \
     799              (tablePrefixes[i],), file=dcdata)
     800            print("     lambda row: _isExplanationRequired(_%s_code2explanationRequired, row))," % \
    761801              (tablePrefixes[i],), file=dcdata)
    762802            print("    [", end=' ', file=dcdata)
     
    783823                    print("        (CAPTION, xstr(\"%srow%d\"))," % \
    784824                      (poPrefix, rowIndex), file=dcdata)
    785                 elif type==DELAYCODE:
     825                elif type in [DELAYCODE, DELAYCODE_EXPLANATION_REQUIRED]:
    786826                    print("        (DELAYCODE, [", file=dcdata)
    787827                    for j in columnIndexes:
  • locale/en/mlx.po

    r1144 r1146  
    14041404msgid "info_delay"
    14051405msgstr "Delay codes"
     1406
     1407msgid "info_delay_explain"
     1408msgstr "Delay code: %s"
    14061409
    14071410msgid "statusbar_conn_tooltip"
  • locale/hu/mlx.po

    r1144 r1146  
    14071407msgid "info_delay"
    14081408msgstr "Késés kódok"
     1409
     1410msgid "info_delay_explain"
     1411msgstr "Késés kód: %s"
    14091412
    14101413msgid "statusbar_conn_tooltip"
  • src/mlx/gui/delaycodes.py

    r1035 r1146  
    191191        self._alignments = []
    192192        self._checkButtons = []
     193        self._codesToExplain = []
    193194
    194195        self._eventBox = Gtk.EventBox()
     
    203204
    204205        self._previousWidth = 0
     206
     207    @property
     208    def _delayCodeRows(self):
     209        """Get a list of the row indexes in the delay code data table of
     210        the delay codes that are enabled."""
     211        rows = []
     212
     213        for checkButton in self._checkButtons:
     214            if checkButton.get_active():
     215                rows.append(checkButton.delayCodeRow)
     216
     217        return rows
    205218
    206219    @property
     
    210223
    211224        if self._delayCodeData is not None:
    212             codeExtractor = self._delayCodeData[0]
    213             for checkButton in self._checkButtons:
    214                 if checkButton.get_active():
    215                     codes.append(codeExtractor(checkButton.delayCodeRow))
     225            codeExtractor = self._delayCodeData[0][1]
     226            for row in self._delayCodeRows:
     227                codes.append(codeExtractor(row))
    216228
    217229        return codes
     
    337349    def _delayCodesChanged(self, button):
    338350        """Called when one of the delay codes have changed."""
    339         numDelayCodes = len(self.delayCodes)
     351        delayCodeRows = self._delayCodeRows
     352        numDelayCodes = len(delayCodeRows)
    340353        if numDelayCodes>=4:
    341354            for checkButton in self._checkButtons:
     
    346359                checkButton.set_sensitive(True)
    347360
     361        codeExtractor = self._delayCodeData[0][0]
     362        isExplanationRequired = self._delayCodeData[0][2]
     363        codesToExplain = []
     364        for row in delayCodeRows:
     365            if isExplanationRequired(row):
     366                code = codeExtractor(row)
     367                codesToExplain.append(code)
     368                if code not in self._codesToExplain:
     369                    self._info.addFault("dc_" + code,
     370                                        xstr("info_delay_explain") % (code,))
     371
     372        for code in self._codesToExplain:
     373            if code not in codesToExplain:
     374                self._info.clearFault("dc_" + code)
     375        self._codesToExplain = codesToExplain
     376
    348377        self._info.delayCodesChanged()
    349378
Note: See TracChangeset for help on using the changeset viewer.