def place(self, selected=None, active=None): if active == None: self.active = 1 active = 1 # turn on button if active: if selected == None: selected = self.selected if selected: cur_color = self.color_sel cur_text = self.text_color_sel else: cur_color = self.color cur_text = self.text_color #place base shape for button io.if_rect(self.x, self.y, self.width, self.height, self.radius, cur_color) if self.text != ' ': #find/calc text dimension and location text_dim = io.text_dimensions(self.x, self.y, self.text) text_x = int(self.x + self.x_offset + (self.width - text_dim[0]) / 2) - 1 text_y = int(self.y + self.y_offset + (self.height - text_dim[1]) / 2) - 1 #place text io.text(text_x, text_y, self.text, cur_text, cur_color)
def _button_error(but, message=None): if message == None: message = but.error_message io.if_rect(but.x, but.y, but.width, but.height, but.radius, io.red) io.text(but.x + but.radius, but.y + but.radius, message, background=io.red) time.sleep(1) but.place()
def place(self, refresh=1): self.active = 1 io.if_rect(self.x, self.y, self.width, self.height, self.radius, self.border_color) io.if_rect(self.x + self.border, self.y + self.border, self.width - 2 * self.border, self.height - 2 * self.border, self.radius - self.border, self.background) if refresh: self.refresh()
def refresh(self): val = max(min(self.data_func(*self.data_tup), self.max_val), self.min_val) val_width = int(self.delta_x * (val - self.min_val) / self.max_val) #print(val_width) #place bar to cover previous if val == self.min_val: self.place(refresh=0) if self.min_val <= val_width <= self.max_val: io.if_rect(self.x + val_width + self.radius * 2 + 2 * self.border, self.y + self.border, self.delta_x - val_width, self.height - 2 * self.border, self.radius - self.border, self.background) #place value bar io.if_rect(self.x + self.border * 2, self.y + 2 * self.border, val_width + (self.radius - self.border) * 2, self.height - 4 * self.border, self.radius - 2 * self.border, self.color)
def clear(self): self.active = 0 io.if_rect(self.x, self.y, self.width, self.height, self.radius, self.color_clear)
def place(self): self.active = 1 io.if_rect(self.x, self.y, self.width, self.height, self.radius, self.value)
def _button_error(but): io.if_rect(but.x, but.y, but.width, but.height, but.radius, io.red) io.text(but.x + but.radius, but.y + but.radius, 'Err', background=io.red) time.sleep(1) but.place()