def on_key_up_callback(wid_id, sym, mod): wid = all_wids[wid_id] if wid is not None: if wid.on_key_up is None: return False return wid.on_key_up(sym, mod) mm.err("Widget not found for on_key_up, id {0:x}".format(wid_id)) return False
def on_m_over_e_callback(wid_id): wid = all_wids[wid_id] if wid is not None: if wid.on_m_over_e is None: return False wid.on_m_over_e() return mm.err("Widget not found for on_m_over_e, id {0:x}".format(wid_id))
def on_tooltip_callback(wid_id, tooltip): wid = all_wids[wid_id] if wid is not None: if wid.on_tooltip is None: return False wid.on_tooltip(tooltip) return mm.err("Widget not found for on_tooltip, id {0:x}".format(wid_id))
def on_m_over_b_callback(wid_id, relx, rely, wheelx, wheely): wid = all_wids[wid_id] if wid is not None: if wid.on_m_over_b is None: return False return wid.on_m_over_b(relx, rely, wheelx, wheely) mm.err("Widget not found for on_m_over_b, id {0:x}".format(wid_id)) return False
def on_m_up_callback(wid_id, x, y, button): wid = all_wids[wid_id] if wid is not None: if wid.on_m_up is None: return False return wid.on_m_up(x, y, button) mm.err("Widget not found for on_m_up, id {0:x}".format(wid_id)) return False
def on_m_focus_b_callback(wid_id): wid = all_wids[wid_id] if wid is not None: if wid.on_focus_b is None: return False wid.on_m_focus_b() return mm.err("Widget not found for " + "on_m_focus_b, id {0:x}".format(wid_id))
def on_m_motion_callback(wid_id, x, y, relx, rely, wheelx, wheely): wid = all_wids[wid_id] if wid is not None: if wid.on_m_motion is None: return False return wid.on_m_motion(x, y, relx, rely, wheelx, wheely) mm.err("Widget not found for" + "on_m_motion_callback, id {0:x}".format(wid_id)) return False
def on_display_win_callback(wid_id): wid = all_wids[wid_id] if wid is not None: if wid.on_display_win is None: return wid.on_display_win() return mm.err("Widget not found for " + "on_display_win, id {0:x}".format(wid_id)) return
def on_tick_callback(wid_id): wid = all_wids[wid_id] if wid is not None: if wid.on_tick is None: return wid.on_tick() return mm.err("Widget not found for on_tick, id {0:x}".format(wid_id)) return
def on_destroy_b_callback(wid_id): wid = all_wids[wid_id] if wid is not None: if wid.on_destroy_b is None: return wid.on_destroy_b() return mm.err("Widget not found for on_destroy_b, id {0:x}".format(wid_id)) return
def on_display_callback(wid_id): wid = all_wids[wid_id] if wid is not None: if wid.on_display is None: return wid.on_display() return mm.err("Widget not found for on_display, id {0:x}".format(wid_id)) return
def on_joy_button(self, button_a, button_b, button_x, button_y, button_top_left, button_top_right, button_left_stick_down, button_right_stick_down, button_start, button_xbox, button_back, button_up, button_down, button_left, button_right, button_left_fire, button_right_fire): if self.callback_on_joy_button is not None: self.callback_on_joy_button( self, button_a, button_b, button_x, button_y, button_top_left, button_top_right, button_left_stick_down, button_right_stick_down, button_start, button_xbox, button_back, button_up, button_down, button_left, button_right, button_left_fire, button_right_fire) mm.err("wid_set_on_joy_button not handled")
def on_joy_button_callback(wid_id, button_a, button_b, button_x, button_y, button_top_left, button_top_right, button_left_stick_down, button_right_stick_down, button_start, button_xbox, button_back, button_up, button_down, button_left, button_right, button_left_fire, button_right_fire): wid = all_wids[wid_id] if wid is not None: if wid.on_joy_button is None: return False wid.on_joy_button(button_a, button_b, button_x, button_y, button_top_left, button_top_right, button_left_stick_down, button_right_stick_down, button_start, button_xbox, button_back, button_up, button_down, button_left, button_right, button_left_fire, button_right_fire) return mm.err("Widget not found for on_joy_button, id {0:x}".format(wid_id)) return False
def on_joy_button(self, button_a, button_b, button_x, button_y, button_top_left, button_top_right, button_left_stick_down, button_right_stick_down, button_start, button_xbox, button_back, button_up, button_down, button_left, button_right, button_left_fire, button_right_fire): if self.callback_on_joy_button is not None: self.callback_on_joy_button(self, button_a, button_b, button_x, button_y, button_top_left, button_top_right, button_left_stick_down, button_right_stick_down, button_start, button_xbox, button_back, button_up, button_down, button_left, button_right, button_left_fire, button_right_fire) mm.err("wid_set_on_joy_button not handled")
def on_tick(self): if self.callback_on_tick is not None: self.callback_on_tick(self) return mm.err("wid_set_on_tick not handled")
def on_destroy_b(self): if self.callback_on_destroy_b is not None: self.callback_on_destroy_b(self) return mm.err("wid_set_on_destroy_b not handled")
def on_m_over_e(self): if self.callback_on_m_over_e is not None: self.callback_on_m_over_e(self) return mm.err("wid_set_on_m_over_e not handled")
def on_m_up(self, x, y, button): if self.callback_on_m_up is not None: return self.callback_on_m_up(self, x, y, button) mm.err("wid_set_on_m_up not handled")
def on_display_win(self): if self.callback_on_display_win is not None: self.callback_on_display_win(self) return mm.err("wid_set_on_display_win not handled")
def on_tooltip(self, tooltip): if self.callback_on_tooltip is not None: self.callback_on_tooltip(self, tooltip) return mm.err("wid_set_on_tooltip not handled")
def on_key_up(self, sym, mod): if self.callback_on_key_up is not None: return self.callback_on_key_up(self, sym, mod) mm.err("wid_set_on_key_up not handled")
def err(self, msg): mm.con("".join(traceback.format_stack())) mm.err("Level {}: ERROR: {}".format(self, msg))
def __init__(self, name, x1, y1, x2, y2, row_text, row_font, row_color, row_center, row_rhs, row_width, line_width, row_on_tooltip, row_tooltip, row_on_key_down, row_on_key_sym, row_on_key_mod, row_on_key_up, row_on_joy_button, row_on_m_down, row_on_m_up, row_on_m_motion, row_on_m_focus_b, row_on_m_focus_e, row_on_m_over_b, row_on_m_over_e, row_on_destroy, row_on_destroy_b, row_on_tick, row_on_button_list, row_on_display, row_on_display_win, parent=0, tiles=None, debug=False, **kw): self.parent = parent self.name = name if tiles is not None: super().__init__(name, parent=parent, tiles=tiles, **kw) self.set_color(tl=True, bg=True, br=True, name="white") else: super().__init__(name, parent=parent, **kw) self.set_pos_pct(x1, y1, x2, y2) self.to_front() self.children = [] self.width, self.height = self.get_size_pct() self.usable_w = self.width self.usable_h = self.height self.text_wids = [] y = 0 h = 0 for row in range(0, len(row_text)): text = row_text[row] font = row_font[row] color = row_color[row] width = row_width[row] center = row_center[row] rhs = row_rhs[row] # # This magic is to allow splitting of the string # into words but maintain a space char for display # text = text.replace(" ", "\\ ") lines = text.split("\n") begin_y = y l = 0 button_count = 0 col = 0 for line in lines: lexer = shlex.shlex(line) lexer.wordchars += '.$%=' words = list(lexer) x = 0 if center is True: w = width x = (self.usable_w - w) / 2.0 x *= 1.0 / self.usable_w if rhs is True: x = self.usable_w - width x = x / self.usable_w max_h = 0 for word in words: w, h, c = mm.text_size_pct(font=font, text=word) if c != "none": color = c w = w / self.usable_w h = h / self.usable_h if x + w > 1.0: x = 0 y = y + max_h max_h = 0 if h > max_h: max_h = h if word[:1] == "\'": # # Grab the next button event # button_event_list = row_on_button_list[row] button_tiles = "button_plain" tooltip = None set_on_m_down = None set_on_m_over_b = None set_on_m_over_e = None context = None if button_event_list is not None: if button_count < len(button_event_list): # # Settings per button # d = button_event_list[button_count] if d is not None: try: button_tiles = d["tiles"] except KeyError: pass try: tooltip = d["tooltip"] except KeyError: pass try: event = d["on_m_down"] set_on_m_down = event except KeyError: pass try: event = d["on_m_over_b"] set_on_m_over_b = event except KeyError: pass try: event = d["on_m_over_e"] set_on_m_over_e = event except KeyError: pass try: val = d["context"] context = val except KeyError: pass else: mm.err("missing callback " "for button {0} text {1}".format( button_count, line)) button_count += 1 # # Now make the button # new_word = word[1:-1] word = new_word child = wid.Wid(name="wid text child", tiles=button_tiles, parent=self.wid_id) child.set_color(tl=True, bg=True, br=True, name="grey") if set_on_m_down is not None: child.set_on_m_down(set_on_m_down) if tooltip is not None: child.set_tooltip(text=tooltip) child.context = context child.row_on_m_over_b = set_on_m_over_b child.row_on_m_over_e = set_on_m_over_e child.set_on_m_over_b( wid_text_button_on_m_over_b_callback) child.set_on_m_over_e( wid_text_button_on_m_over_e_callback) else: child = wid.Wid(name="wid text child", parent=self.wid_id) child.set_pos_pct(x, y, x + w, y + h) if color is not None: child.set_text(text=word, centerx=True, font=font, color=color) else: child.set_text(text=word, centerx=True, font=font) self.children.append(child) x = x + w child.row = row child.button = button_count child.col = col col += 1 y = y + max_h max_h = 0 l += 1 w = wid.Wid(name="wid text multi line box", parent=self.wid_id) w.row = row w.set_pos_pct(0, begin_y, 1, y) w.to_back() w.set_do_not_raise() w.row_text = row_text[row] w.row_font = row_font[row] w.row_color = row_color[row] w.row_center = row_center[row] w.row_rhs = row_rhs[row] w.row_width = row_width[row] w.line_width = line_width[row] w.row_on_tooltip = row_on_tooltip w.row_tooltip = row_tooltip w.row_on_key_down = row_on_key_down[row] w.row_on_key_sym = row_on_key_sym[row] w.row_on_key_mod = row_on_key_mod[row] w.row_on_key_up = row_on_key_up[row] w.row_on_joy_button = row_on_joy_button[row] w.row_on_m_down = row_on_m_down[row] w.row_on_m_up = row_on_m_up[row] w.row_on_m_motion = row_on_m_motion[row] w.row_on_m_focus_b = row_on_m_focus_b[row] w.row_on_m_focus_e = row_on_m_focus_e[row] w.row_on_m_over_b = row_on_m_over_b[row] w.row_on_m_over_e = row_on_m_over_e[row] w.row_on_destroy = row_on_destroy[row] w.row_on_destroy_b = row_on_destroy_b[row] w.row_on_tick = row_on_tick[row] w.row_on_button_list = row_on_button_list[row] w.row_on_display = row_on_display[row] w.row_on_display_win = row_on_display_win[row] w.set_on_tooltip(row_on_tooltip[row]) if row_tooltip[row] is not None: w.set_tooltip(text=row_tooltip[row]) w.set_on_joy_button(row_on_joy_button[row]) w.set_on_m_motion(row_on_m_motion[row]) if row_on_key_down[row] is not None or \ row_on_m_down[row] is not None or \ row_on_m_over_b[row] is not None: wid_text_colorize_row(w) w.set_on_key_up(wid_text_on_key_up_callback) w.set_on_key_down(wid_text_on_key_down_callback) w.set_on_m_up(wid_text_on_m_up_callback) w.set_on_m_down(wid_text_on_m_down_callback) w.set_on_m_over_b( wid_text_on_m_over_b_callback) w.set_on_m_over_e(wid_text_on_m_over_e_callback) else: w.set_on_key_up(row_on_key_up[row]) w.set_on_key_down(row_on_key_down[row]) w.set_on_m_up(row_on_m_up[row]) w.set_on_m_down(row_on_m_down[row]) w.set_on_m_over_b(row_on_m_over_b[row]) w.set_on_m_over_e(row_on_m_over_e[row]) w.set_on_destroy(row_on_destroy[row]) w.set_on_destroy_b(wid_text_on_destroy) w.set_on_tick(row_on_tick[row]) w.set_on_display(row_on_display[row]) w.set_on_display_win(row_on_display_win[row]) self.text_wids.append(w) self.update()
def __init__(self, name, x1, y1, x2, y2, row_text, row_font, row_color, row_center, row_rhs, row_width, line_width, row_on_tooltip, row_tooltip, row_on_key_down, row_on_key_sym, row_on_key_mod, row_on_key_up, row_on_joy_button, row_on_m_down, row_on_m_up, row_on_m_motion, row_on_m_focus_b, row_on_m_focus_e, row_on_m_over_b, row_on_m_over_e, row_on_destroy, row_on_destroy_b, row_on_tick, row_on_button_list, row_on_display, row_on_display_win, parent=0, tiles=None, debug=False, **kw): self.parent = parent self.name = name if tiles is not None: super().__init__(name, parent=parent, tiles=tiles, **kw) self.set_color(tl=True, bg=True, br=True, name="white") else: super().__init__(name, parent=parent, **kw) self.set_pos_pct(x1, y1, x2, y2) self.to_front() self.children = [] self.width, self.height = self.get_size_pct() self.usable_w = self.width self.usable_h = self.height self.text_wids = [] y = 0 h = 0 for row in range(0, len(row_text)): text = row_text[row] font = row_font[row] color = row_color[row] width = row_width[row] center = row_center[row] rhs = row_rhs[row] # # This magic is to allow splitting of the string # into words but maintain a space char for display # text = text.replace(" ", "\\ ") lines = text.split("\n") begin_y = y l = 0 button_count = 0 col = 0 for line in lines: lexer = shlex.shlex(line) lexer.wordchars += '.$%=' words = list(lexer) x = 0 if center is True: w = width x = (self.usable_w - w) / 2.0 x *= 1.0 / self.usable_w if rhs is True: x = self.usable_w - width x = x / self.usable_w max_h = 0 for word in words: w, h, c = mm.text_size_pct(font=font, text=word) if c != "none": color = c w = w / self.usable_w h = h / self.usable_h if x + w > 1.0: x = 0 y = y + max_h max_h = 0 if h > max_h: max_h = h if word[:1] == "\'": # # Grab the next button event # button_event_list = row_on_button_list[row] button_tiles = "button_plain" tooltip = None set_on_m_down = None set_on_m_over_b = None set_on_m_over_e = None context = None if button_event_list is not None: if button_count < len(button_event_list): # # Settings per button # d = button_event_list[button_count] if d is not None: try: button_tiles = d["tiles"] except KeyError: pass try: tooltip = d["tooltip"] except KeyError: pass try: event = d["on_m_down"] set_on_m_down = event except KeyError: pass try: event = d["on_m_over_b"] set_on_m_over_b = event except KeyError: pass try: event = d["on_m_over_e"] set_on_m_over_e = event except KeyError: pass try: val = d["context"] context = val except KeyError: pass else: mm.err("missing callback " "for button {} text {}".format( button_count, line)) button_count += 1 # # Now make the button # new_word = word[1:-1] word = new_word child = wid.Wid(name="wid text child", tiles=button_tiles, parent=self.wid_id) child.set_color(tl=True, bg=True, br=True, name="grey") if set_on_m_down is not None: child.set_on_m_down(set_on_m_down) if tooltip is not None: child.set_tooltip(text=tooltip) child.context = context child.row_on_m_over_b = set_on_m_over_b child.row_on_m_over_e = set_on_m_over_e child.set_on_m_over_b( wid_text_button_on_m_over_b_callback) child.set_on_m_over_e( wid_text_button_on_m_over_e_callback) else: child = wid.Wid(name="wid text child", parent=self.wid_id) child.set_pos_pct(x, y, x + w, y + h) if color is not None: child.set_text(text=word, centerx=True, font=font, color=color) else: child.set_text(text=word, centerx=True, font=font) self.children.append(child) x = x + w child.row = row child.button = button_count child.col = col col += 1 y = y + max_h max_h = 0 l += 1 w = wid.Wid(name="wid text multi line box", parent=self.wid_id) w.row = row w.set_pos_pct(0, begin_y, 1, y) w.to_back() w.set_do_not_raise() w.row_text = row_text[row] w.row_font = row_font[row] w.row_color = row_color[row] w.row_center = row_center[row] w.row_rhs = row_rhs[row] w.row_width = row_width[row] w.line_width = line_width[row] w.row_on_tooltip = row_on_tooltip w.row_tooltip = row_tooltip w.row_on_key_down = row_on_key_down[row] w.row_on_key_sym = row_on_key_sym[row] w.row_on_key_mod = row_on_key_mod[row] w.row_on_key_up = row_on_key_up[row] w.row_on_joy_button = row_on_joy_button[row] w.row_on_m_down = row_on_m_down[row] w.row_on_m_up = row_on_m_up[row] w.row_on_m_motion = row_on_m_motion[row] w.row_on_m_focus_b = row_on_m_focus_b[row] w.row_on_m_focus_e = row_on_m_focus_e[row] w.row_on_m_over_b = row_on_m_over_b[row] w.row_on_m_over_e = row_on_m_over_e[row] w.row_on_destroy = row_on_destroy[row] w.row_on_destroy_b = row_on_destroy_b[row] w.row_on_tick = row_on_tick[row] w.row_on_button_list = row_on_button_list[row] w.row_on_display = row_on_display[row] w.row_on_display_win = row_on_display_win[row] w.set_on_tooltip(row_on_tooltip[row]) if row_tooltip[row] is not None: w.set_tooltip(text=row_tooltip[row]) w.set_on_joy_button(row_on_joy_button[row]) w.set_on_m_motion(row_on_m_motion[row]) if row_on_key_down[row] is not None or \ row_on_m_down[row] is not None or \ row_on_m_over_b[row] is not None: wid_text_colorize_row(w) w.set_on_key_up(wid_text_on_key_up_callback) w.set_on_key_down(wid_text_on_key_down_callback) w.set_on_m_up(wid_text_on_m_up_callback) w.set_on_m_down(wid_text_on_m_down_callback) w.set_on_m_over_b(wid_text_on_m_over_b_callback) w.set_on_m_over_e(wid_text_on_m_over_e_callback) else: w.set_on_key_up(row_on_key_up[row]) w.set_on_key_down(row_on_key_down[row]) w.set_on_m_up(row_on_m_up[row]) w.set_on_m_down(row_on_m_down[row]) w.set_on_m_over_b(row_on_m_over_b[row]) w.set_on_m_over_e(row_on_m_over_e[row]) w.set_on_destroy(row_on_destroy[row]) w.set_on_destroy_b(wid_text_on_destroy) w.set_on_tick(row_on_tick[row]) w.set_on_display(row_on_display[row]) w.set_on_display_win(row_on_display_win[row]) self.text_wids.append(w) self.update()
def err(self, msg): mm.con("".join(traceback.format_stack())) mm.err("Chunk {0}: ERROR: {1}".format(str(self), msg))
def err(self, msg): mm.con("".join(traceback.format_stack())) mm.err("p_wid {0}: ERROR: {1}".format(self.name, msg))
def err(self, msg): mm.con("".join(traceback.format_stack())) mm.err("Level {0}: ERROR: {1}".format(self, msg))
def err(self, msg): mm.con("".join(traceback.format_stack())) mm.err("p_wid {}: ERROR: {}".format(self.name, msg))