def Gague_Value_ColorChange(self): # 打开颜色识获器 my_color_picker = ColorPicker(useAlpha=False) picker_color = my_color_picker.rgb2hex(my_color_picker.getColor()) # print("------->") # print(picker_color) value_color = '#' + picker_color self.label_value.setStyleSheet('color:' + value_color + '; background: transparent;') # 将数值颜色写入Config json文件 with open('./gaguge_config.json', 'r', encoding='utf8') as read_congfig_file: str = read_congfig_file.read() json_data = json.loads(str) self.pointer_color = json_data['pointer_color'] json_data['value_color'] = value_color write_json = json_data with open('./gaguge_config.json','w+',encoding = 'utf-8') as congfig_file: json.dump(write_json, congfig_file, indent=4, sort_keys=True) # 生成新的home_page.xml文件 with open('./meter_images/home_page.xml','w',encoding = 'utf-8') as f: f.write('''<?xml ruler_y="220" ruler_x="297,42,-439,-112"?> <window name="home_page" style:normal:bg_color="#FFFFFF"> <guage name="guage" x="0" y="0" w="320" h="240" draw_type="scale_auto" image="voltmeter"> <guage_pointer name="guage_pointer" x="294" y="10" w="7" h="420" value="0" angle="-90" anchor_x="0.5" anchor_y="0.5" animation="value(easing=bounce_out,from=0,to=-90)" min="-90" max="0" style:normal:fg_color="#00000000" style:normal:bg_color="''' + self.pointer_color + '''" image="pointer_2" style:normal:border="all" style:normal:border_color="#00000000"/> </guage> <label name="val" x="221" y="155" w="89" h="75" style:normal:font_size="30" style:normal:text_color="'''+ value_color +'''" style:normal:text_align_h="right" visible="true" min="0" max="40" enable="true" style:normal:font_name="default" text="0"/> </window>''') f.close()
def Gague_Pointer_ColorChange(self): # 打开颜色识获器 my_color_picker = ColorPicker(useAlpha=False) picker_color = my_color_picker.rgb2hex(my_color_picker.getColor()) # print("------->") # print(picker_color) pointer_color = '#' + picker_color # 生成新的svg图形 with open('./meter_images/dx.svg','w',encoding = 'utf-8') as f: f.write('<svg id="图层_1" data-name="图层 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 5.67 127.56"><defs><style>.cls-1,.cls-2{fill:'+ pointer_color + ';}.cls-2{stroke:#000;stroke-miterlimit:10;stroke-width:0.25px;}</style></defs><title>指针45</title><polygon class="cls-1" points="5.67 127.56 0 127.56 2.83 0 4.25 63.78 5.67 127.56"/><polygon class="cls-1" points="1.42 63.78 2.83 63.78 4.25 63.78 5.67 127.56 0 127.56 1.42 63.78"/><polygon class="cls-2" points="1.42 63.78 4.25 63.78 2.83 0 1.42 63.78"/></svg>') f.close() # 将表盘指针颜色写入Config json文件 with open('./gaguge_config.json', 'r', encoding='utf8') as read_congfig_file: str_temp = read_congfig_file.read() json_data = json.loads(str_temp) self.value_color = json_data['value_color'] self.value_min = json_data['value_min'] self.value_max = json_data['value_max'] value_min_str = str(self.value_min) value_max_str = str(self.value_max) json_data['pointer_color'] = pointer_color write_json = json_data with open('./gaguge_config.json','w+',encoding = 'utf-8') as congfig_file: json.dump(write_json, congfig_file, indent=4, sort_keys=True) # 生成新的home_page.xml文件 with open('./meter_images/home_page.xml','w',encoding = 'utf-8') as f: f.write('''<?xml ruler_y="220" ruler_x="297,42,-439,-112"?> <window name="home_page" style:normal:bg_color="#FFFFFF"> <guage name="guage" x="0" y="0" w="320" h="240" draw_type="scale_auto" image="voltmeter"> <guage_pointer name="guage_pointer" x="294" y="10" w="7" h="420" value="0" angle="-90" anchor_x="0.5" anchor_y="0.5" animation="value(easing=bounce_out,from=0,to=-90)" min="-90" max="0" style:normal:fg_color="#00000000" style:normal:bg_color="''' + pointer_color + '''" image="pointer_2" style:normal:border="all" style:normal:border_color="#00000000"/> </guage> <label name="val" x="221" y="155" w="89" h="75" style:normal:font_size="30" style:normal:text_color="'''+ self.value_color +'''" style:normal:text_align_h="right" visible="true" min="'''+ value_min_str + '''" max="'''+ value_max_str + '''" enable="true" style:normal:font_name="default" text="0"/> </window>''') f.close() # 刷新表盘指针svg defaultPix2 = QtGui.QPixmap("./meter_images/dx.svg") # 旋转pix self.rotation = -45 self.transform = QtGui.QTransform().rotate(self.rotation) defaultPix2 = defaultPix2.transformed(self.transform, QtCore.Qt.SmoothTransformation) self.label_pointer.setPixmap(defaultPix2)