Ejemplo n.º 1
0
 def NormalizeValueStr(self, Item, ValueStr):
     IsArray = True if Item['value'].startswith('{') else False
     if IsArray and not ValueStr.startswith('{'):
         ValueStr = "{ %s }" % ValueStr
     try:
         OldBytes = self.CfgDataObj.ValueToByteArray(
             Item['value'], Item['length'])
         NewBytes = self.CfgDataObj.ValueToByteArray(
             ValueStr, Item['length'])
         if OldBytes == NewBytes:
             NewValue = Item['value']
         else:
             if IsArray:
                 NewValue = Bytes2Str(NewBytes)
             else:
                 if Item['value'].startswith('0x'):
                     HexLen = Item['length'] * 2
                     if len(Item['value']) == HexLen + 2:
                         Fmt = '0x%%0%dX' % HexLen
                     else:
                         Fmt = '0x%X'
                 else:
                     Fmt = '%d'
                 NewValue = Fmt % Bytes2Val(NewBytes)
     except:
         NewValue = Item['value']
     return NewValue
Ejemplo n.º 2
0
    def UpdateConfigDataFromWidget(self, Widget, Args):
        Item = self.GetConfigDataItemFromWidget(Widget)
        if Item is None:
            return
        elif not Item:
            if isinstance(Widget, Label):
                return
            raise Exception('Failed to find "%s" !' %
                            self.GetObjectName(Widget))

        Type = Item['type'].split(',')[0]
        if Type == "Combo":
            if Item['option'] in self.CfgDataObj._BuidinOption:
                OptList = [('0', 'Disable'), ('1', 'Enable')]
            else:
                OptList = self.CfgDataObj.GetItemOptionList(Item)
            TmpList = [Opt[0] for Opt in OptList]
            Idx = Widget.current()
            self.SetConfigItemValue(Item, TmpList[Idx])
        elif Type in ["EditNum", "EditText"]:
            self.SetConfigItemValue(Item, Widget.get())
        elif Type in ["Table"]:
            NewValue = Bytes2Str(Widget.get())
            self.SetConfigItemValue(Item, NewValue)
Ejemplo n.º 3
0
    def SyncConfigDataFromSubRegion(self):
        if not len(self.PageList) or not self.PageId:
            return

        for Item in self.GetCurrentConfigData():
            if not Item['subreg']:
                continue
            ValArray = self.CfgDataObj.ValueToByteArray(
                Item['value'], Item['length'])
            for SubItem in Item['subreg']:
                Value = Array2Val(SubItem['value'])
                self.CfgDataObj.UpdateBsfBitFields(SubItem, Value, ValArray)
            if Item['value'].startswith('{'):
                NewValue = Bytes2Str(ValArray)
            else:
                BitsValue = ''.join('{0:08b}'.format(i)
                                    for i in ValArray[::-1])
                NewValue = '0x%X' % (int(BitsValue, 2))
                NewValue = self.NormalizeValueStr(Item, NewValue)
            if NewValue != Item['value']:
                if self.Debug:
                    print('Update Subregion %s from %s to %s' %
                          (Item['cname'], Item['value'], NewValue))
                Item['value'] = NewValue