本文整理汇总了Python中palette.Palette.add_drawable_type方法的典型用法代码示例。如果您正苦于以下问题:Python Palette.add_drawable_type方法的具体用法?Python Palette.add_drawable_type怎么用?Python Palette.add_drawable_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类palette.Palette
的用法示例。
在下文中一共展示了Palette.add_drawable_type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from palette import Palette [as 别名]
# 或者: from palette.Palette import add_drawable_type [as 别名]
class App_Runner:
"""
App runner that uses a Board and a Palette.
"""
def __init__(self, on_init, app_name, dev_stage, file_extension,
deserializers, board_width, board_height, palette_height,
directed_wires, label_tooltips_enabled, same_label_per_connector,
init_file=None):
"""
|on_init|: method called every time a new board of this app's type is
created.
|app_name|: name of this app.
|dev_stage|: development stage of this app.
|file_extension|: the file extension used for boards of this app's type.
|deserializers|: drawabel types to open files of this app's type.
|board_width|, |board_height|: board dimensions.
|palette_height|: height of palette, width will be the same as board width.
|directed_wires|: True if the board is to have directed wires, False
otherwise.
|label_tooltips_enabled|: if True, show wire and drawable label tooltips.
|same_label_per_connector|: if True, all wires from a connector will have
the same label. If False, this will only be true for wire connectors.
|init_file|: file to open at init time.
"""
self._on_init = on_init
self._app_name = app_name
self._dev_stage = dev_stage
self._file_extension = file_extension
self._deserializers = deserializers
self._board_width = board_width
self._board_height = board_height
self._palette_height = palette_height
self._directed_wires = directed_wires
self._label_tooltips_enabled = label_tooltips_enabled
self._same_label_per_connector = same_label_per_connector
self._init_file = init_file
self._init()
self._setup_menu()
self._setup_shortcuts()
def _switch_cursor_to_draw(self, *args):
"""
Switches board cursor state to 'draw'.
"""
self._draw_display.highlight()
self._drag_display.unhighlight()
self.board.set_cursor_state('draw')
def _switch_cursor_to_drag(self, *args):
"""
Switches board cursor state to 'drag'.
"""
self._draw_display.unhighlight()
self._drag_display.highlight()
self.board.set_cursor_state('drag')
def _toggle_cursor(self):
"""
Toggles board cursor state.
"""
if self.board.get_cursor_state() == 'draw':
self._switch_cursor_to_drag()
else:
self._switch_cursor_to_draw()
def _init(self):
"""
Creates the board and palette.
"""
self._file_name = None
self._root = Tk()
self._root.resizable(0, 0)
self._menu = Menu(self._root, tearoff=0)
self.board = Board(self._root, self._menu, width=self._board_width,
height=self._board_height, directed_wires=self._directed_wires,
label_tooltips_enabled=self._label_tooltips_enabled,
same_label_per_connector=self._same_label_per_connector,
on_changed=self._on_changed, on_exit=self._request_save)
self._init_board()
self.palette = Palette(self._root, self.board, width=self._board_width,
height=self._palette_height)
# buttons to change board cursor state
self.palette.current_left_x -= PALETTE_PADDING
self._draw_display = self.palette.add_drawable_type(Image_Run_Drawable,
LEFT, self._switch_cursor_to_draw, image_file=PENCIL_IMAGE)
self.palette.current_left_x -= PALETTE_PADDING
self._drag_display = self.palette.add_drawable_type(Image_Run_Drawable,
LEFT, self._switch_cursor_to_drag, image_file=HAND_IMAGE)
self.palette.draw_separator()
self._switch_cursor_to_draw()
def _setup_menu(self):
"""
Creates the menu.
"""
file_menu = Menu(self._menu, tearoff=0)
file_menu.add_command(label='New', command=self._new_file,
accelerator='Ctrl+N')
file_menu.add_command(label='Open', command=self._open_file,
accelerator='Ctrl+O')
file_menu.add_command(label='Save', command=self._save_file,
accelerator='Ctrl+S')
file_menu.add_command(label='Save as', command=self._save_as)
file_menu.add_separator()
file_menu.add_command(label='Quit', command=self.board.quit,
#.........这里部分代码省略.........