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 addRepoHandler(self): path = self.ui.path.text() for r in enumerate(self.repos): if r[1][0] == path: errbox = QMessageBox() errbox.setText(f"{path} is already listed in {self.json_path}") errbox.exec() return colour = ColorPicker().getColor() hexcolour = '%02x%02x%02x' % ( int(colour[0]), # this is actually so dumb int(colour[1]) if int(colour[0]) != 255 or not int(colour[1]) else int(colour[1]) + 1, int(colour[2]) if int(colour[0]) != 255 or not int(colour[2]) else int(colour[2]) + 1) if self.ui.checkBox.isChecked(): if not re.match(self.urlregexp, self.ui.remote.text()): errbox = QMessageBox() errbox.setText("Invalid URL") errbox.exec() return self.addNewRepo(path, self.ui.remote.text(), hexcolour, self.repos) else: self.addRepoFromExisting(path, hexcolour, self.repos) self.updateTables()
def onClick(self): proxy = self.proxy() if proxy: self.dialog = ColorPicker(self.attribs['widget_label'], hsv_degree_to_rgb_hex_str(self.attribs['item_state'])) color = self.dialog.show() self.dialog = None if color is not None: proxy.cmd_set_hsv(rgb_hex_str_to_hsv_degree(color))
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)
def openColorDialog(self): # color = QColorDialog.getColor() # if color.isValid(): # # print(color.name()) # print(color.name()) # color_R = color.red() # color_G = color.green() # color_B = color.blue() # self.udp_send[40] = color_R # self.udp_send[41] = color_G # self.udp_send[42] = color_B # # print(color_R) my_color_picker = ColorPicker(useAlpha=False) my_color_picker.DX_Color_OutSingal.connect(self.dx_color) picked_color = my_color_picker.hsv2hex(my_color_picker.getColor())
def pick_color(self, mode): cp = ColorPicker() self.unfocusGui() if mode == "diffuse": try: oldr, oldg, oldb = (int(self.ui.difx.text()), int(self.ui.dify.text()), int(self.ui.difz.text())) except: oldr, oldg, oldb = (0, 0, 0) r, g, b = cp.getColor((oldr, oldg, oldb)) self.ui.difx.setText(str(int(r))) self.ui.dify.setText(str(int(g))) self.ui.difz.setText(str(int(b))) if mode == "specular": try: oldr, oldg, oldb = (int(self.ui.specx.text()), int(self.ui.specy.text()), int(self.ui.specz.text())) except: oldr, oldg, oldb = (0, 0, 0) r, g, b = cp.getColor((oldr, oldg, oldb)) self.ui.specx.setText(str(int(r))) self.ui.specy.setText(str(int(g))) self.ui.specz.setText(str(int(b))) if mode == "emission": try: oldr, oldg, oldb = (int(self.ui.emisx.text()), int(self.ui.emisy.text()), int(self.ui.emisz.text())) except: oldr, oldg, oldb = (0, 0, 0) r, g, b = cp.getColor((oldr, oldg, oldb)) self.ui.emisx.setText(str(int(r))) self.ui.emisy.setText(str(int(g))) self.ui.emisz.setText(str(int(b))) self.focusGui()
def __init__(self, source, parent=None): super().__init__(parent) self.source = source self.grid = QGridLayout() self.grid.setSpacing(0) self.grid.setContentsMargins(0, 0, 0, 0) self.picker = ColorPicker(self) self.color_preview = ColorPreview(self.source, self) self.color_preview.switch.connect(self.switchColors) self.palette = [Color(n, self.source, self) for n in range(16)] positions = [(row, col) for row in range(4) for col in range(4)] for position, swatch in zip(positions, self.palette): swatch.color_selected.connect(self.selectColor) swatch.edit.connect(self.openPicker) self.grid.addWidget(swatch, *position) self.enabled = False self.main_layout = QHBoxLayout() self.main_layout.addLayout(self.grid) self.main_layout.addWidget(self.color_preview) self.main_layout.setContentsMargins(0, 0, 5, 0) self.main_layout.setSpacing(19) self.setLayout(self.main_layout)
from colorpicker import ColorPicker from PyQt5.QtWidgets import QApplication app = QApplication([]) my_color_picker = ColorPicker(useAlpha=True) my_color_picker_light = ColorPicker(lightTheme=True) old_color = (255, 255, 255, 50) picked_color = my_color_picker.getColor(old_color) print(picked_color) old_color = (255, 0, 255) picked_color = my_color_picker_light.getColor(old_color) print(picked_color) # Don't have your color in RGB format? my_color = (50, 50, 100, 60) # HSV Color in percent old_color = my_color_picker.hsv2rgb(my_color) picked_color = my_color_picker.rgb2hsv(my_color_picker.getColor(old_color)) print(picked_color)
def __init__(self, label, parent=None): super(ColorEditor, self).__init__(parent) layout = QGridLayout() self.color = QLineEdit() self.colorPicker = ColorPicker() self.colorPicker.setVisible(False) self.hueSlider = QSlider() self.hueSlider.setVisible(False) self.hueSlider.setMinimum(0) self.hueSlider.setMaximum(100.0) self.hueSlider.setOrientation(Qt.Vertical) self.hueSlider.setMaximumHeight(100.0) self.rect = ColorRect() self.hue = QSpinBox() self.saturation = QSpinBox() self.lightness = QSpinBox() self.labelHue = QLabel("H") self.labelSaturation = QLabel("S") self.labelLightness = QLabel("L") self.red = QSpinBox() self.green = QSpinBox() self.blue = QSpinBox() self.labelRed = QLabel("R") self.labelGreen = QLabel("G") self.labelBlue = QLabel("B") self.hue.setVisible(False) self.saturation.setVisible(False) self.lightness.setVisible(False) self.red.setVisible(False) self.green.setVisible(False) self.blue.setVisible(False) self.labelHue.setVisible(False) self.labelSaturation.setVisible(False) self.labelLightness.setVisible(False) self.labelRed.setVisible(False) self.labelGreen.setVisible(False) self.labelBlue.setVisible(False) self.red.setMinimum(0) self.red.setMaximum(255) self.green.setMinimum(0) self.green.setMaximum(255) self.blue.setMinimum(0) self.blue.setMaximum(255) self.hue.setMinimum(0) self.hue.setMaximum(100.0) self.saturation.setMinimum(0) self.saturation.setMaximum(100.0) self.lightness.setMinimum(0) self.lightness.setMaximum(100.0) self.labelHue.setFixedWidth(15) self.labelSaturation.setFixedWidth(15) self.labelLightness.setFixedWidth(15) self.labelRed.setFixedWidth(15) self.labelGreen.setFixedWidth(15) self.labelBlue.setFixedWidth(15) l = QLabel(label) l.setMinimumWidth(100.0) layout.addWidget(l, 0, 0) layout.addWidget(self.rect, 0, 1) layout.addWidget(self.color, 0, 2, 1, 3) layout.addWidget(self.colorPicker, 1, 0, 3, 2) layout.addWidget(self.hueSlider, 1, 2, 3, 1) layout.addWidget(self.labelHue, 1, 3) layout.addWidget(self.hue, 1, 4) layout.addWidget(self.labelSaturation, 2, 3) layout.addWidget(self.saturation, 2, 4) layout.addWidget(self.labelLightness, 3, 3) layout.addWidget(self.lightness, 3, 4) layout.addWidget(self.labelRed, 1, 5) layout.addWidget(self.red, 1, 6) layout.addWidget(self.labelGreen, 2, 5) layout.addWidget(self.green, 2, 6) layout.addWidget(self.labelBlue, 3, 5) layout.addWidget(self.blue, 3, 6) self.setLayout(layout) self.connectControls()
def pick_bg_color(self): cp = ColorPicker(self.parent, "Select color", self.select_bg_color)
def main_prog(): # init objects every state will have mouse = MouseHandler() drawablesController = DrawablesController() colorPicker = None trashCan = None # create state manager depending on operation type selected in menu: if program_OperationType == MULTIPLICATION: stateManager = StateManagerMult(program_CuttingType,screen) stateManager.setMouse(mouse) # link state manager and mouse stateManager.setDrawablesController(drawablesController) # link state manager and drawables controller testRectangle = Rectangle(WIDTH/2,HEIGHT/2,350,350,screen,drawablesController,True,mouse,stateManager, 1) cutter = testRectangle.getCutter() # need to get cutter here for draw call colorPicker = ColorPicker(screen,WIDTH,HEIGHT,mouse,stateManager,drawablesController) stateManager.setColorPicker(colorPicker) elif program_OperationType == ADDITION: stateManager = StateManagerAdd(program_CuttingType,screen) stateManager.setMouse(mouse) # link state manager and mouse stateManager.setDrawablesController(drawablesController) # link state manager and drawables controller # Create rectangles and their respective cutters testRectangle = Rectangle((int)(WIDTH/3),HEIGHT/3,270,270,screen,drawablesController,True,mouse,stateManager, 1) cutter = testRectangle.getCutter() # need to get cutter here for draw call testRectangle2 = Rectangle((int)(WIDTH/3),HEIGHT-(HEIGHT/4.5)+15,270,270,screen,drawablesController,True,mouse,stateManager, 2) cutter2 = testRectangle2.getCutter() testRectangle3 = Rectangle(WIDTH-(int)(WIDTH/5.7),HEIGHT/3,270,270,screen,drawablesController,True,mouse,stateManager, 3) cutter3 = testRectangle3.getCutter() testRectangle4 = Rectangle(WIDTH-(int)(WIDTH/5.7),HEIGHT-(HEIGHT/4.5)+15,270,270,screen,drawablesController,True,mouse,stateManager, 4) cutter4 = testRectangle4.getCutter() colorPicker = ColorPicker(screen,WIDTH,HEIGHT,mouse,stateManager,drawablesController) stateManager.setColorPicker(colorPicker) elif program_OperationType == SUBTRACTION: stateManager = StateManagerSub(program_CuttingType,screen) stateManager.setMouse(mouse) # link state manager and mouse stateManager.setDrawablesController(drawablesController) # link state manager and drawables controller testRectangle = Rectangle((int)((WIDTH/3)),HEIGHT/2-30,280, 280,screen,drawablesController,True,mouse,stateManager, 1) cutter = testRectangle.getCutter() # need to get cutter here for draw call testRectangle2 = Rectangle((int)((WIDTH/3)*2),HEIGHT/2-30,280,280,screen,drawablesController,True,mouse,stateManager, 2) cutter2 = testRectangle2.getCutter() # need to get cutter here for draw call colorPicker = ColorPicker(screen,WIDTH,HEIGHT,mouse,stateManager,drawablesController) trashCan = TrashCan(screen,WIDTH,HEIGHT,mouse,stateManager,drawablesController) stateManager.setColorPicker(colorPicker) stateManager.setTrashCan(trashCan) elif program_OperationType == DIVISION: # For division, rectangles are created later because the number of rectangles depends on the fractions stateManager = StateManagerDiv(program_CuttingType,screen) stateManager.setMouse(mouse) # link state manager and mouse stateManager.setDrawablesController(drawablesController) # link state manager and drawables controller colorPicker = ColorPicker(screen,WIDTH,HEIGHT,mouse,stateManager,drawablesController) stateManager.setColorPicker(colorPicker) positionSet = 0 # init problemDisplay here, every operation will have problemDisplay = ProblemDisplay(screen,WIDTH,HEIGHT,stateManager,program_OperationType) # set up problemGenerator here because it needs to know problemDisplay problemGenerator.setProblemDisplay(problemDisplay) problemGenerator.setOperationType(program_OperationType) # Checks whether a new problem needs to be created or just reset the current problem if problemGenerator.needsNewProblem == True: problemGenerator.getProblem() problemGenerator.needsNewProblem = False else: problemGenerator.resetCurrentProblem() # Creating division rectangles down here because we first need to know what the problem answer will be stateManager.cpuDenomAns = problemGenerator.problemDisplay.denominatorAnswer stateManager.cpuNumerAns = problemGenerator.problemDisplay.numeratorAnswer if program_OperationType == DIVISION: extraRect = False answerCeiling = math.ceil(problemGenerator.problemDisplay.numeratorAnswer/problemGenerator.problemDisplay.denominatorAnswer) fractionReciprocal = problemGenerator.problemDisplay.denominator2/problemGenerator.problemDisplay.numerator2 if fractionReciprocal < answerCeiling: extraRect = True if extraRect is True: testRectangle = Rectangle((int)((WIDTH/4))-50,HEIGHT/2-30,280, 280,screen,drawablesController,True,mouse,stateManager, 1) cutter = testRectangle.getCutter() # need to get cutter here for draw call testRectangle2 = Rectangle((int)((WIDTH/4)*2),HEIGHT/2-30,280,280,screen,drawablesController,True,mouse,stateManager, 2) cutter2 = testRectangle2.getCutter() # need to get cutter here for draw call stateManager.hasThreeSquares = True # The third rectangle is created in stateManagerDiv when in moving state else: testRectangle = Rectangle((int)((WIDTH/3)),HEIGHT/2-30,280, 280,screen,drawablesController,True,mouse,stateManager, 1) cutter = testRectangle.getCutter() # need to get cutter here for draw call testRectangle2 = Rectangle((int)((WIDTH/3)*2),HEIGHT/2-30,280,280,screen,drawablesController,True,mouse,stateManager, 2) cutter2 = testRectangle2.getCutter() # need to get cutter here for draw call # bring in userAnswerSystem userAnswerSystem = UserAnswerSystem(screen, stateManager, WIDTH, HEIGHT,problemDisplay) isProgramRunning = True check = False click = False # To check if Main Menu button is clicked keyDown = None # for passing information to userAnswerSystem # main loop while isProgramRunning: # main event loop -- user keyboard/mouse input here for event in pygame.event.get(): if event.type == QUIT: isProgramRunning = False break if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: check = True click = True if mouse.isHeld == False: mouse.setHeld(True) else: mouse.setHeld(False) if event.type == pygame.MOUSEBUTTONUP: if event.button == 1: mouse.leftMouseReleasedThisFrame = True check = False #setClick(check) click = False #hold = False if event.type == KEYDOWN: if event.key == pygame.K_1: keyDown = "1" elif event.key == pygame.K_2: keyDown = "2" elif event.key == pygame.K_3: keyDown = "3" elif event.key == pygame.K_4: keyDown = "4" elif event.key == pygame.K_5: keyDown = "5" elif event.key == pygame.K_6: keyDown = "6" elif event.key == pygame.K_7: keyDown = "7" elif event.key == pygame.K_8: keyDown = "8" elif event.key == pygame.K_9: keyDown = "9" elif event.key == pygame.K_0: keyDown = "0" elif event.key == pygame.K_BACKSPACE: keyDown = "Backspace" #---------UPDATE BEGIN-------UPDATE ALL OBJECTS mouse.update(check) if program_OperationType == MULTIPLICATION: stateManager.update(testRectangle.myCutter) elif program_OperationType == DIVISION: if (stateManager.cpuNumerAns/stateManager.cpuDenomAns) > 2: stateManager.update(testRectangle.myCutter, testRectangle2.myCutter) else: stateManager.update(testRectangle.myCutter, testRectangle2.myCutter) elif program_OperationType == SUBTRACTION: stateManager.update(testRectangle.myCutter, testRectangle2.myCutter) if TrashCan != None: trashCan.update() elif program_OperationType == ADDITION: stateManager.update(testRectangle.myCutter, testRectangle2.myCutter, testRectangle3.myCutter, testRectangle4.myCutter) for rect in drawablesController.rectangles: rect.update(mouse) for cm in drawablesController.cutmarkers: cm.update(mouse.isClick) if colorPicker != None: colorPicker.update() userAnswerSystem.update(mouse.leftMouseReleasedThisFrame,keyDown) if program_OperationType == DIVISION: if stateManager.hasThreeSquares is True: if positionSet == 0: secondLeft, secondTop = stateManager.getSecondBorderPos() positionSet = 1 borderTop, borderLeft, numBoundaries = stateManager.getBorderPos() borderHeight = testRectangle2.height borderWidth = (testRectangle2.width/problemGenerator.problemDisplay.denominator2)*problemGenerator.problemDisplay.numerator2 else: numBoundaries = 0 borderTop, borderLeft, numBoundaries = stateManager.getBorderPos() borderHeight = testRectangle2.height borderWidth = (testRectangle2.width/problemGenerator.problemDisplay.denominator2)*problemGenerator.problemDisplay.numerator2 elif program_OperationType == ADDITION: border1Top, border1Left = stateManager.border1Top, stateManager.border1Left borderHeight, borderWidth = testRectangle3.height, testRectangle3.width if stateManager.twoWholes is True: border2Top, border2Left = stateManager.border2Top, stateManager.border2Left elif program_OperationType == MULTIPLICATION: borderTop, borderLeft = stateManager.borderTop, stateManager.borderLeft borderHeight, borderWidth = testRectangle.height, testRectangle.width elif program_OperationType == SUBTRACTION: borderTop, borderLeft = stateManager.borderTop, stateManager.borderLeft borderHeight, borderWidth = testRectangle.height, testRectangle.width # ---------UPDATE END---------------------------------- # ---------DRAW BEGIN-------------------------------- # Menu button and logic to go back to main screen and get new problem menu_button = pygame.Rect(WIDTH-100, 0, 100, 50) if menu_button.collidepoint((mouse.mx, mouse.my)): if click: problemGenerator.needsNewProblem = True main_menu() isProgramRunning = False break restart_button = pygame.Rect(WIDTH-220, 0, 100, 50) if restart_button.collidepoint((mouse.mx, mouse.my)): if click: main_prog() isProgramRunning = False break newProblem_button = pygame.Rect(WIDTH - 370, 0 , 130, 50) if newProblem_button.collidepoint((mouse.mx, mouse.my)): if click: if problemGenerator.program_problemCreationType == problemGenerator.USERPROBLEM: createUserProblem() problemGenerator.needsNewProblem = True main_prog() isProgramRunning = False break if program_OperationType == ADDITION: if stateManager.currentState == stateManager.CHECKCUTS or stateManager.currentState == stateManager.CHECKCUTS2 or stateManager.currentState == stateManager.CHECKCUTS3: undoCut_button = pygame.Rect(WIDTH/3-testRectangle.width+5, HEIGHT/3, 130, 50) undoCut_button2 = pygame.Rect(WIDTH/3-testRectangle.width+5, HEIGHT/3*2+100, 130, 50) undoCut_button3 = pygame.Rect(WIDTH/3*2-75, HEIGHT/3, 130, 50) undoCut_button4 = pygame.Rect(WIDTH/3*2-75, HEIGHT/3*2+175, 130, 50) if undoCut_button.collidepoint((mouse.mx, mouse.my)): if click: if stateManager.lastCuts == 0: stateManager.undoCutsVert(1, cutter) elif stateManager.lastCuts == 1: stateManager.undoCutsHoriz(1, cutter) if undoCut_button2.collidepoint((mouse.mx, mouse.my)): if click: if stateManager.lastCuts == 0: stateManager.undoCutsVert(2, cutter2) elif stateManager.lastCuts == 1: stateManager.undoCutsHoriz(2, cutter2) if undoCut_button3.collidepoint((mouse.mx, mouse.my)): if click: if stateManager.lastCuts == 2: stateManager.undoCutsVert(3, cutter3) elif stateManager.lastCuts == 3: stateManager.undoCutsHoriz(3, cutter3) if undoCut_button4.collidepoint((mouse.mx, mouse.my)): if click: if stateManager.lastCuts == 4: stateManager.undoCutsVert(4, cutter4) elif stateManager.lastCuts == 5: stateManager.undoCutsHoriz(4, cutter4) elif program_OperationType == DIVISION: if stateManager.currentState == stateManager.CHECKCUTS: if stateManager.hasThreeSquares: undoCut_button = pygame.Rect(WIDTH/5 - 55, HEIGHT/2 + testRectangle.height/2 - 30 , 130, 50) undoCut_button2 = pygame.Rect(WIDTH/2-65, HEIGHT/2 + testRectangle.height/2 - 30 , 130, 50) else: undoCut_button = pygame.Rect(WIDTH/3 - 60, HEIGHT/2 + testRectangle.height/2 - 30 , 130, 50) undoCut_button2 = pygame.Rect(WIDTH/3*2 - 65, (HEIGHT/2 + testRectangle.height/2)-30, 130, 50) if undoCut_button.collidepoint((mouse.mx, mouse.my)): if click: if stateManager.lastCuts == 0: stateManager.undoCutsVert(1, cutter) else: stateManager.undoCutsHoriz(1, cutter) if undoCut_button2.collidepoint((mouse.mx, mouse.my)): if click: if stateManager.lastCuts == 0: stateManager.undoCutsVert(2, cutter2) else: stateManager.undoCutsHoriz(2, cutter2) elif program_OperationType == SUBTRACTION: if stateManager.currentState == stateManager.CHECKCUTS: undoCut_button = pygame.Rect(WIDTH/3 - 65, (HEIGHT/2 + testRectangle.height/2)-30 , 130, 50) undoCut_button2 = pygame.Rect(WIDTH/3*2 - 65, (HEIGHT/2 + testRectangle.height/2)-30, 130, 50) if undoCut_button.collidepoint((mouse.mx, mouse.my)): if click: if stateManager.lastCuts == 0: stateManager.undoCutsVert(1, cutter) else: stateManager.undoCutsHoriz(1, cutter) if undoCut_button2.collidepoint((mouse.mx, mouse.my)): if click: if stateManager.lastCuts == 0: stateManager.undoCutsVert(2, cutter2) else: stateManager.undoCutsHoriz(2, cutter2) elif program_OperationType == MULTIPLICATION: if stateManager.currentState == stateManager.CHECKCUTS: undoCut_button = pygame.Rect(WIDTH/4, HEIGHT/2, 130, 50) if undoCut_button.collidepoint((mouse.mx, mouse.my)): if click: if stateManager.lastCuts == 0: stateManager.undoCutsVert(cutter) else: stateManager.undoCutsHoriz(cutter) # drawing here screen.fill(colors.BGCOLOR) #fill screen bg # Drawing menu button pygame.draw.rect(screen, (8, 41, 255), menu_button) draw_text('Main Menu', button_font, (0,0,0), screen, WIDTH-50, 25) pygame.draw.rect(screen, (8, 41, 255), restart_button) draw_text('Restart', button_font, (0,0,0), screen, WIDTH-170, 25) pygame.draw.rect(screen, (8, 41, 255), newProblem_button) # for new prob button draw_text('New Problem', button_font, (0,0,0), screen, WIDTH-305, 25) # for new prob button # ALL LOGIC FOR DRAWING UNDO BUTTONS HERE if program_OperationType == ADDITION: if stateManager.currentState == stateManager.CHECKCUTS: pygame.draw.rect(screen, (8, 41, 255), undoCut_button) pygame.draw.rect(screen, (8, 41, 255), undoCut_button2) draw_text('Undo Cut', button_font, (0,0,0), screen, WIDTH/3 - testRectangle.width/1.5-20, (HEIGHT/3)+25) draw_text('Undo Cut', button_font, (0,0,0), screen, WIDTH/3 - testRectangle.width/1.5-20, (HEIGHT/3)*2+125) elif stateManager.currentState == stateManager.CHECKCUTS2: pygame.draw.rect(screen, (8, 41, 255), undoCut_button3) draw_text('Undo Cut', button_font, (0,0,0), screen, WIDTH/3*2-10, (HEIGHT/3)+25) elif stateManager.currentState == stateManager.CHECKCUTS3: pygame.draw.rect(screen, (8, 41, 255), undoCut_button4) draw_text('Undo Cut', button_font, (0,0,0), screen, WIDTH/3*2-10, (HEIGHT/3)*2+200) elif program_OperationType == DIVISION: if stateManager.currentState == stateManager.CHECKCUTS: pygame.draw.rect(screen, (8, 41, 255), undoCut_button) pygame.draw.rect(screen, (8, 41, 255), undoCut_button2) if stateManager.hasThreeSquares is True: draw_text('Undo Cut', button_font, (0,0,0), screen, WIDTH/4-55, (HEIGHT/2)+(testRectangle.height/2)) draw_text('Undo Cut', button_font, (0,0,0), screen, WIDTH/4*2, (HEIGHT/2)+(testRectangle.height/2)) else: draw_text('Undo Cut', button_font, (0,0,0), screen, WIDTH/3, (HEIGHT/2)+(testRectangle.height/2)) draw_text('Undo Cut', button_font, (0,0,0), screen, WIDTH/3*2, (HEIGHT/2)+(testRectangle.height/2)) elif program_OperationType == SUBTRACTION: if stateManager.currentState == stateManager.CHECKCUTS: pygame.draw.rect(screen, (8, 41, 255), undoCut_button) draw_text('Undo Cut', button_font, (0,0,0), screen, WIDTH/3, (HEIGHT/2)+(testRectangle.height/2)-5) pygame.draw.rect(screen, (8, 41, 255), undoCut_button2) draw_text('Undo Cut', button_font, (0,0,0), screen, WIDTH/3*2, (HEIGHT/2)+(testRectangle.height/2)-5) else: if stateManager.currentState == stateManager.CHECKCUTS: pygame.draw.rect(screen, (8, 41, 255), undoCut_button) draw_text('Undo Cut', button_font, (0,0,0), screen, WIDTH/4 + 65, (HEIGHT/2)+25) if stateManager.getCurrentState() != "Finished": state_message = "Current state: " + stateManager.getCurrentState() else: state_message = "" draw_textLeftToRight(state_message, button_font, (0,0,0), screen, 15, 15) tempRectList = list() for bgS in drawablesController.bgSquares: bgS.draw() if program_OperationType == MULTIPLICATION: for rect in drawablesController.rectangles: rect.draw() if program_OperationType == SUBTRACTION: for rect in drawablesController.rectangles: rect.draw() if rect.isMarked == True: rect.drawMark() if program_OperationType != MULTIPLICATION and program_OperationType != SUBTRACTION: for rect in drawablesController.rectangles: #move to rectangle class if rect.ownerID == 2: rect.draw() if rect.isShadedB: rect.drawBLines(rect.colorHatch) else: tempRectList.append(rect) for trect in tempRectList: trect.draw() if trect.isShadedV == True and trect.isShadedH != True: trect.drawVLines(trect.colorHatch) if trect.isShadedH == True and trect.isShadedV != True: trect.drawHLines(trect.colorHatch) if trect.isShadedB: trect.drawBLines(trect.colorHatch) for gl in drawablesController.guidelines: gl.draw() for cm in drawablesController.cutmarkers: cm.draw() cutter.draw() if program_OperationType == DIVISION or program_OperationType == SUBTRACTION: cutter2.draw() if stateManager.cpuNumerAns > stateManager.cpuDenomAns: pass if program_OperationType == ADDITION: cutter2.draw() cutter3.draw() cutter4.draw() stateManager.draw() if colorPicker != None: colorPicker.draw() problemDisplay.draw() userAnswerSystem.draw() # DRAW BORDER HERE TO HIGHLIGHT CURRENT SECTION if program_OperationType == DIVISION: if stateManager.hasThreeSquares is True: if stateManager.currentState == stateManager.MOVING or stateManager.currentState == stateManager.ANSWERSUBMISSION or stateManager.currentState == stateManager.DONE: pygame.draw.rect(screen, colors.GOLD, (borderLeft, borderTop, borderWidth, borderHeight), 4) # width = 4 pygame.draw.rect(screen, colors.GOLD, (secondLeft, secondTop, borderWidth, borderHeight), 4) # width = 4 else: if stateManager.currentState == stateManager.MOVING or stateManager.currentState == stateManager.ANSWERSUBMISSION or stateManager.currentState == stateManager.DONE: numBoundaries += 1 for i in range(numBoundaries): if i < stateManager.answerCeiling: pygame.draw.rect(screen, colors.GOLD, (borderLeft-((i)*borderWidth), borderTop, borderWidth, borderHeight), 4) # width = 4 elif program_OperationType == ADDITION: if stateManager.currentState == stateManager.MOVING or stateManager.currentState == stateManager.ANSWERSUBMISSION or stateManager.currentState == stateManager.DONE or stateManager.currentState == stateManager.CUTTINGHORIZONTALLY3 or stateManager.currentState == stateManager.CUTTINGVERTICALLY3 or stateManager.currentState == stateManager.CHECKCUTS3: pygame.draw.rect(screen, colors.GOLD, (border1Left, border1Top, borderWidth, borderHeight), 4) if stateManager.twoWholes is True: pygame.draw.rect(screen, colors.GOLD, (border2Left, border2Top, borderWidth, borderHeight), 4) elif program_OperationType == MULTIPLICATION: if stateManager.currentState == stateManager.ANSWERSUBMISSION or stateManager.currentState == stateManager.DONE: pygame.draw.rect(screen, colors.GOLD, (borderLeft, borderTop, borderWidth, borderHeight), 4) elif program_OperationType == SUBTRACTION: if stateManager.currentState == stateManager.ANSWERSUBMISSION or stateManager.currentState == stateManager.DONE: pygame.draw.rect(screen, colors.GOLD, (borderLeft, borderTop, borderWidth, borderHeight), 4) if mouse.whoisHeld != None: mouse.whoisHeld.draw() #-----------------------------DRAW END--------------------------------------- mouse.leftMouseReleasedThisFrame = False keyDown = None #update screen and set framerate pygame.display.flip() clock.tick(fps) #end of main loop pygame.quit()
def build_gui(self): self.win = gtk.Window() self.win.set_title("Elicit") self.win.set_icon_name('rephorm-elicit') self.win.connect('destroy', self.quit, None) vbox = gtk.VBox(False, 2) self.win.add(vbox) menubar = self.build_menu() vbox.pack_start(menubar, False) # notebook with magnifier, etc hbox = gtk.HBox(False, 0) vbox.pack_start(hbox, True, True) notebook = gtk.Notebook() self.notebook = notebook hbox.pack_start(notebook, True, True, padding=HPAD) # magnifier tab mag_vbox = gtk.VBox(False, 2) mag_tab_icon = gtk.Image() mag_tab_icon.set_from_file( os.path.join(self.icon_path, "magnify-16.png")) notebook.append_page(mag_vbox, mag_tab_icon) # the magnifier hbox = gtk.HBox(False, 0) mag_vbox.pack_start(hbox, True, True) frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_IN) hbox.pack_start(frame, True, True, padding=HPAD) self.mag = Magnifier() frame.add(self.mag) self.mag.connect('zoom-changed', self.mag_zoom_changed) self.mag.connect('grid-toggled', self.mag_grid_toggled) self.mag.connect('measure-changed', self.mag_measure_changed) self.mag.connect('location-changed', self.mag_location_changed) # magnifier information (coordinates) hbox = gtk.HBox(False, 0) mag_vbox.pack_start(hbox, False) self.mag_label = gtk.Label() hbox.pack_start(self.mag_label, False, padding=HPAD) self.measure_label = gtk.Label() hbox.pack_end(self.measure_label, False) # magnifier tools hbox = gtk.HBox(False, 0) mag_vbox.pack_start(hbox, False) button = gtk.Button() button.set_relief(gtk.RELIEF_NONE) img = gtk.Image() img.set_from_file(os.path.join(self.icon_path, "magnify-button.png")) button.set_image(img) button.set_tooltip_text("Start Magnifying\n(Left Click to stop)") button.connect('clicked', self.magnify_clicked) hbox.pack_end(button, False, padding=HPAD) check = gtk.CheckButton("Show Grid") check.set_active(self.mag.show_grid) check.connect('toggled', self.grid_check_toggled) hbox.pack_start(check, padding=HPAD) self.grid_check = check spin = gtk.SpinButton() spin.set_range(1, 50) spin.set_increments(1, 10) spin.set_value(self.mag.zoom) spin.connect('value-changed', self.zoom_spin_value_changed) hbox.pack_end(spin, False, padding=HPAD) self.zoom_spin = spin zoom_label = gtk.Label("Zoom:") hbox.pack_end(zoom_label, False) # color wheel wheel_frame = gtk.Frame() wheel_tab_icon = gtk.Image() wheel_tab_icon.set_from_file( os.path.join(self.icon_path, "color-wheel-16.png")) notebook.append_page(wheel_frame, wheel_tab_icon) if hasattr(gtk, 'HSV'): wheel = gtk.HSV() self.wheel = wheel wheel_frame.add(wheel) wheel_frame.connect('size-allocate', self.wheel_size_allocate) wheel_frame.connect('size-request', self.wheel_size_request) wheel.connect('changed', self.wheel_changed) else: self.wheel = None label = gtk.Label( "The color wheel requires gtk ver. 2.28 or higher.") wheel_frame.add(label) # swatch and eyedropper button hbox = gtk.HBox(False, 0) vbox.pack_start(hbox, False) button = gtk.Button() button.set_relief(gtk.RELIEF_NONE) img = gtk.Image() img.set_from_file(os.path.join(self.icon_path, "dropper-button.png")) button.set_image(img) button.set_tooltip_text("Start Selecting Color\n(Left Click to stop)") button.connect('clicked', self.select_color_clicked) hbox.pack_end(button, False, padding=HPAD) frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_IN) hbox.pack_start(frame, True, True, padding=HPAD) self.colorpicker = ColorPicker() frame.add(self.colorpicker) self.colorpicker.connect('save-color', self.picker_save_color) self.colorpicker.set_magnifier(self.mag) # color values (sliders and spinboxes) hbox = gtk.HBox(False, 5) vbox.pack_start(hbox, False) self.colorspin = {} table = gtk.Table(6, 4) hbox.pack_start(table, True, True, padding=HPAD) row = 0 for type in ("r", "g", "b"): label = gtk.Label(type.upper()) table.attach(label, 0, 1, row, row + 1, 0, 0, 2, 2) cslider = CSlider(self.color, type) table.attach(cslider, 1, 2, row, row + 1, gtk.FILL | gtk.EXPAND, gtk.EXPAND, 2, 2) spin = gtk.SpinButton() spin.set_range(0, 255) spin.set_increments(1, 10) spin.connect('value-changed', self.color_spin_rgb_changed) table.attach(spin, 2, 3, row, row + 1, 0, gtk.EXPAND, 2, 2) self.colorspin[type] = spin row += 1 row = 0 for type in ("h", "s", "v"): label = gtk.Label(type.upper()) table.attach(label, 3, 4, row, row + 1, 0, 0, 2, 2) cslider = CSlider(self.color, type) table.attach(cslider, 4, 5, row, row + 1, gtk.FILL | gtk.EXPAND, gtk.EXPAND, 2, 2) spin = gtk.SpinButton() if type == 'h': spin.set_range(0, 360) spin.set_increments(1, 10) else: spin.set_digits(2) spin.set_range(0, 1.0) spin.set_increments(.01, .1) spin.connect('value-changed', self.color_spin_hsv_changed) table.attach(spin, 5, 6, row, row + 1, 0, gtk.EXPAND, 2, 2) self.colorspin[type] = spin row += 1 self.hex_label = gtk.Label("Hex") table.attach(self.hex_label, 0, 1, 3, 4, gtk.FILL, gtk.EXPAND, 2, 2) self.hex_entry = gtk.Entry() table.attach(self.hex_entry, 1, 6, 3, 4, gtk.FILL, gtk.EXPAND, 2, 2) self.hex_entry.connect('changed', self.hex_entry_changed) sep = gtk.HSeparator() vbox.pack_start(sep, False) # palette tools hbox = gtk.HBox(False, 5) vbox.pack_start(hbox, False) hbox.pack_start(gtk.Label("Palette:"), False, padding=HPAD) self.palette_combo = PaletteCombo() hbox.pack_start(self.palette_combo) self.palette_combo.connect('selected', self.palette_combo_selected) button = gtk.Button() button.set_image( gtk.image_new_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON)) button.set_tooltip_text("Add Palette") button.set_relief(gtk.RELIEF_NONE) button.connect('clicked', self.add_palette) hbox.pack_start(button, False) button = gtk.Button() button.set_image( gtk.image_new_from_stock(gtk.STOCK_DELETE, gtk.ICON_SIZE_BUTTON)) button.set_tooltip_text("Delete Palette") button.set_relief(gtk.RELIEF_NONE) button.connect('clicked', self.delete_palette) hbox.pack_start(button, False, padding=HPAD) # palette view hbox = gtk.HBox(False, 5) vbox.pack_start(hbox, False) frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_IN) hbox.pack_start(frame, True, padding=HPAD) self.palette_view = PaletteView() self.palette_view.connect('select-color', self.palette_view_select_color) self.palette_view.connect('delete-color', self.palette_view_delete_color) frame.add(self.palette_view) # color name entry hbox = gtk.HBox(False, 5) vbox.pack_start(hbox, False, padding=VPAD) hbox.pack_start(gtk.Label("Color Name:"), False, padding=HPAD) self.color_name_entry = gtk.Entry() self.color_name_entry.set_sensitive(False) self.color_name_entry.connect('changed', self.color_name_entry_changed) hbox.pack_start(self.color_name_entry, True, True, padding=HPAD)
def colorpicker(self): """ Deprecated. A better solution actually came with tkinter. :return: """ ColorPicker(self)
def getColor(self): self.color_picker = ColorPicker() self.picked_color = self.color_picker.getColor() self.picked_color = tuple([int(x) for x in self.picked_color]) self.borderStylesheet()