Пример #1
0
    def __init__(self, frame):
        wx.py.shell.Shell.__init__(
            self, frame, size=(100, 100), locals=frame.gui_project.namespace, style=wx.SUNKEN_BORDER
        )
        WorkspaceWidget.__init__(self, frame)

        # We used to import `site` here to get `help` and others when frozen,
        # but now `garlicsim` has `bootstrap_py2exe` which bundles its own
        # version of `site` which creates `help` and a few other builtins.
        import __builtin__

        assert "help" in __builtin__.__dict__
        del __builtin__
Пример #2
0
    def __init__(self, frame):
        wx.py.shell.Shell.__init__(self,
                                   frame,
                                   size=(100, 100),
                                   locals=frame.gui_project.namespace,
                                   style=wx.SUNKEN_BORDER)
        WorkspaceWidget.__init__(self, frame)

        # We used to import `site` here to get `help` and others when frozen,
        # but now `garlicsim` has `bootstrap_py2exe` which bundles its own
        # version of `site` which creates `help` and a few other builtins.
        import __builtin__
        assert 'help' in __builtin__.__dict__
        del __builtin__
Пример #3
0
    def __init__(self, frame):
        wx.lib.scrolledpanel.ScrolledPanel.__init__(self,
                                                    frame,
                                                    -1,
                                                    style=wx.SUNKEN_BORDER)
        WorkspaceWidget.__init__(self, frame)

        self.SetBackgroundColour(wx_tools.get_background_color())

        self.SetupScrolling()

        assert isinstance(self.gui_project, garlicsim_wx.GuiProject)
        # I put this assert mainly for better source assistance in Wing.
        # It may be removed.

        self.Bind(wx.EVT_SIZE, self.on_size)
        self.Bind(wx.EVT_PAINT, self.on_paint)

        self.main_v_sizer = wx.BoxSizer(wx.VERTICAL)

        self.SetSizer(self.main_v_sizer)

        self.autocrunch_controls = AutocrunchControls(self, frame)

        self.main_v_sizer.Add(self.autocrunch_controls, 0, wx.ALL, border=10)

        self.step_profiles_controls = StepProfilesControls(self, frame)

        self.main_v_sizer.Add(self.step_profiles_controls,
                              1,
                              wx.EXPAND | wx.ALL,
                              border=10)

        self.horizontal_line = wx.StaticLine(self, -1)

        self.main_v_sizer.Add(self.horizontal_line,
                              0,
                              wx.EXPAND | wx.LEFT | wx.RIGHT,
                              border=30)

        self.main_v_sizer.AddSpacer((1, 20))

        self.cruncher_controls = CruncherControls(self, frame)

        self.main_v_sizer.Add(self.cruncher_controls, 0,
                              wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 10)

        self.autocrunch_controls.SetFocus()
Пример #4
0
 def __init__(self, frame):
     locals_for_shell = {
         'f': frame,
         'gp': frame.gui_project,
         'p': frame.gui_project.project,
         't': frame.gui_project.project.tree,
         'garlicsim': garlicsim,
         'garlicsim_wx': garlicsim_wx,
         'wx': wx,
     }
     wx.py.shell.Shell.__init__(self, frame, size=(100, 100),
                                locals=locals_for_shell)
     WorkspaceWidget.__init__(self, frame)
     
     # Obscure: This causes the `site` module to add `help` and a few others
     # to `__builtin__`. For some reason `site` isn't imported when frozen
     # with py2exe, so here we make sure to import it.
     import site; del site
Пример #5
0
    def __init__(self, frame):
        wx.Panel.__init__(self, frame, size=(300, 300))
        WorkspaceWidget.__init__(self, frame)

        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        
        self.Bind(wx.EVT_PAINT, self.on_paint)        
        
        self.text_ctrl = wx.TextCtrl(
            self,
            style=wx.TE_MULTILINE | wx.NO_BORDER
        )
        
        font_size = 12 if wx.Platform == '__WXMAC__' else 9
        
        font = wx.Font(font_size, wx.DEFAULT, wx.NORMAL, wx.BOLD, False,
                       u'Courier New')
        self.text_ctrl.SetFont(font)
        
        self.sizer_v = wx.BoxSizer(wx.VERTICAL)
        self.sizer_h = wx.BoxSizer(wx.HORIZONTAL)
        self.sizer_v.Add(self.sizer_h, 1, wx.EXPAND)
        self.sizer_h.Add(self.text_ctrl, 1, wx.EXPAND)
        
        self.SetSizer(self.sizer_v)
        self.sizer_v.Layout()
        
        self.state = None
        
        self.needs_recalculation_flag = True
        
        self.needs_update_emitter = \
            self.gui_project.emitter_system.make_emitter(
                inputs=(
                    self.gui_project.active_node_changed_or_modified_emitter,
                    # todo: put the active_state_changed whatever here
                    ),
                outputs=(
                    FlagRaiser(self, 'needs_recalculation_flag',
                               function=self._recalculate, delay=0.03),
                    ),
                name='state_repr_viewer_needs_recalculation',
            )
Пример #6
0
 def __init__(self, frame):
     wx.lib.scrolledpanel.ScrolledPanel.__init__(self, frame, -1,
                                                 style=wx.SUNKEN_BORDER)
     WorkspaceWidget.__init__(self, frame)
     
     self.SetBackgroundColour(wx_tools.get_background_color())
     
     self.SetupScrolling()
     
     
     assert isinstance(self.gui_project, garlicsim_wx.GuiProject)
     # I put this assert mainly for better source assistance in Wing.
     # It may be removed.
     
     self.Bind(wx.EVT_SIZE, self.on_size)
     self.Bind(wx.EVT_PAINT, self.on_paint)
     
     self.main_v_sizer = wx.BoxSizer(wx.VERTICAL)
     
     self.SetSizer(self.main_v_sizer)
     
     self.autocrunch_controls = AutocrunchControls(self, frame)
 
     self.main_v_sizer.Add(self.autocrunch_controls, 0, wx.ALL, border=10)
     
     self.step_profiles_controls = StepProfilesControls(self, frame)
     
     self.main_v_sizer.Add(self.step_profiles_controls, 1,
                           wx.EXPAND | wx.ALL, border=10)
     
     self.horizontal_line = wx.StaticLine(self, -1)
     
     self.main_v_sizer.Add(self.horizontal_line, 0,
                           wx.EXPAND | wx.LEFT | wx.RIGHT, border=30)
     
     self.main_v_sizer.AddSpacer((1, 20))
     
     self.cruncher_controls = CruncherControls(self, frame)
     
     self.main_v_sizer.Add(self.cruncher_controls, 0,
                           wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 10)
     
     self.autocrunch_controls.SetFocus()
Пример #7
0
    def __init__(self, frame):
        wx.Panel.__init__(self, frame, size=(300, 300), style=wx.SUNKEN_BORDER)
        WorkspaceWidget.__init__(self, frame)

        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)

        self.Bind(wx.EVT_PAINT, self.on_paint)

        self.text_ctrl = wx.TextCtrl(self,
                                     style=wx.TE_MULTILINE | wx.NO_BORDER)

        font_size = 12 if wx.Platform == '__WXMAC__' else 9

        font = wx.Font(font_size, wx.DEFAULT, wx.NORMAL, wx.BOLD, False,
                       u'Courier New')
        self.text_ctrl.SetFont(font)

        self.sizer_v = wx.BoxSizer(wx.VERTICAL)
        self.sizer_h = wx.BoxSizer(wx.HORIZONTAL)
        self.sizer_v.Add(self.sizer_h, 1, wx.EXPAND)
        self.sizer_h.Add(self.text_ctrl, 1, wx.EXPAND)

        self.SetSizer(self.sizer_v)
        self.sizer_v.Layout()

        self.state = None

        self.needs_recalculation_flag = True

        self.needs_update_emitter = \
            self.gui_project.emitter_system.make_emitter(
                inputs=(
                    self.gui_project.active_node_changed_or_modified_emitter,
                    # todo: put the active_state_changed whatever here
                    ),
                outputs=(
                    FlagRaiser(self, 'needs_recalculation_flag',
                               function=self._recalculate, delay=0.03),
                    ),
                name='state_repr_viewer_needs_recalculation',
            )
Пример #8
0
    def __init__(self, frame):
        
        wx.Panel.__init__(self, frame, size=(100, 100), style=wx.SUNKEN_BORDER)
        WorkspaceWidget.__init__(self, frame)
        
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        
        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_SIZE, self.on_size)
        self.Bind(wx.EVT_MOUSE_EVENTS, self.on_mouse_event)

        self.zoom = 1.
        self.start = 0.

        self.screenify = lambda x: (x-self.start)*self.zoom
        '''Translate from time point to on-screen coordinate.'''
        
        self.unscreenify = lambda x: (x/self.zoom)+self.start
        '''Translate from on-screen coordinate to time point.'''
        
        self.menu = garlicsim_wx.general_misc.cute_menu.CuteMenu.add_menus(
            [garlicsim_wx.misc.menu_bar.node_menu.NodeMenu(self.frame),
             garlicsim_wx.misc.menu_bar.block_menu.BlockMenu(self.frame)]
        )

        self.was_playing_before_mouse_click = None
        self.was_playing_before_mouse_click_but_then_paused_and_mouse_left = None
        self.active_triangle_width = 13 # Must be odd number

        self.view_changed_flag = False
        self.active_node_changed_or_modified_flag = False
        self.path_contents_changed_flag = False
        
        self.view_change_emitter = emitters.Emitter()
        self.gui_project.active_node_changed_or_modified_emitter.add_output(
            FlagRaiser(self, 'active_node_changed_or_modified_flag')
        )
        self.gui_project.path_contents_changed_emitter.add_output(
            FlagRaiser(self, 'path_contents_changed_flag')
        )
Пример #9
0
    def __init__(self, frame):
        
        wx.Panel.__init__(self, frame, size=(100, 100), style=wx.SUNKEN_BORDER)
        WorkspaceWidget.__init__(self, frame)
        
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        self.SetBackgroundColour(wx_tools.get_background_color())
        
        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_SIZE, self.on_size)
        self.Bind(wx.EVT_MOUSE_EVENTS, self.on_mouse_event)
        self.Bind(wx.EVT_KEY_DOWN, self.on_key_down)

        self.zoom = 1.
        self.start = 0.

        self.screenify = lambda x: (x-self.start)*self.zoom
        '''Translate from time point to on-screen coordinate.'''
        
        self.unscreenify = lambda x: (x/self.zoom)+self.start
        '''Translate from on-screen coordinate to time point.'''

        self.was_playing_before_mouse_click = None
        self.was_playing_before_mouse_click_but_then_paused_and_mouse_left = \
            None
        self.active_triangle_width = 13 # Must be odd number

        self.view_changed_flag = False
        self.active_node_changed_or_modified_flag = False
        self.path_contents_changed_flag = False
        
        self.view_change_emitter = emitters.Emitter()
        self.gui_project.active_node_changed_or_modified_emitter.add_output(
            FlagRaiser(self, 'active_node_changed_or_modified_flag')
        )
        self.gui_project.path_contents_changed_emitter.add_output(
            FlagRaiser(self, 'path_contents_changed_flag')
        )
Пример #10
0
    def __init__(self, frame):
        # todo: on mouse drag should pause like seek bar does
        ScrolledPanel.__init__(self,
                               frame,
                               size=(100, 100),
                               style=wx.SUNKEN_BORDER)
        WorkspaceWidget.__init__(self, frame)

        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        self.SetBackgroundColour(wx_tools.get_background_color())

        self.SetupScrolling()
        #self.SetScrollRate(20,20)
        #self.sizer=wx.BoxSizer(wx.VERTICAL)
        #self.panel=wx.StaticBitmap(self,-1,wx.Bitmap("images\\snail.gif", wx.BITMAP_TYPE_ANY))#wx.Panel(self,-1,size=(-1,200))#wx.TextCtrl(self, -1, size=(-1,200), style=wx.TE_MULTILINE)
        #self.panel=wx.Panel(self,-1,size=(-1,100))
        #self.sizer.Add(self.panel,1,wx.EXPAND)
        #self.SetSizer(self.sizer)
        #self.EnableScrolling(True, True)
        #self.SetScrollbars(5, 30, 1055, 40)
        #self.sizer.Fit(self)
        #self.Centre()
        #self.SetVirtualSize((1000,1000))

        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_SIZE, self.on_size)
        self.Bind(wx.EVT_MOUSE_EVENTS, self.on_mouse_event)
        self.Bind(wx.EVT_KEY_DOWN, self.on_key_down)

        self.tree_remapping_flag = False
        self.recalculation_flag = False

        self.needs_tree_remapping_emitter = \
            self.gui_project.emitter_system.make_emitter(
                inputs=(
                    self.gui_project.tree_structure_modified_emitter,
                ),
                outputs=(
                    FlagRaiser(self, 'tree_remapping_flag'),
                ),
                name='needs_tree_remapping',
            )


        self.needs_recalculation_emitter = \
            self.gui_project.emitter_system.make_emitter(
                inputs=(
                    self.needs_tree_remapping_emitter,
                    self.gui_project.step_profiles_to_hues_modified_emitter,
                    self.gui_project.active_node_changed_or_modified_emitter,
                    self.gui_project.tree_modified_on_path_emitter,
                    # Note that if there's a non-structure tree change not on
                    # the path it won't affect us.
                ),
                outputs=(
                    FlagRaiser(self, 'recalculation_flag'),
                ),
                name='needs_recalculation',
            )

        self.clickable_map = {}

        elements_raw = {
            'Untouched': 'graysquare.png',
            'Touched': 'graystar.png',
            'Unfinalized Touched': 'grayunfinalizedstar.png',
            'Untouched End': 'grayendsquare.png',
            'Touched End': 'grayendstar.png',
            'Block': 'grayblock.png',
            'Active Untouched': 'orangesquare.png',
            'Active Touched': 'orangestar.png',
            'Active Unfinalized Touched': 'orangeunfinalizedstar.png',
            'Active Untouched End': 'orangeendsquare.png',
            'Active Touched End': 'orangeendstar.png',
            'Active Block': 'orangeblock.png',
        }

        self.elements = {}
        for key in elements_raw:
            stream = pkg_resources.resource_stream(images_package,
                                                   elements_raw[key])
            self.elements[key] = wx.BitmapFromImage(
                wx.ImageFromStream(stream, wx.BITMAP_TYPE_ANY))
Пример #11
0
    def __init__(self, frame):
        # todo: on mouse drag should pause like seek bar does
        ScrolledPanel.__init__(self, frame, size=(100, 100),
                               style=wx.SUNKEN_BORDER)
        WorkspaceWidget.__init__(self, frame)
        
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        self.SetBackgroundColour(wx_tools.get_background_color())
        
        self.SetupScrolling()
        #self.SetScrollRate(20,20)
        #self.sizer=wx.BoxSizer(wx.VERTICAL)
        #self.panel=wx.StaticBitmap(self,-1,wx.Bitmap("images\\snail.gif", wx.BITMAP_TYPE_ANY))#wx.Panel(self,-1,size=(-1,200))#wx.TextCtrl(self, -1, size=(-1,200), style=wx.TE_MULTILINE)
        #self.panel=wx.Panel(self,-1,size=(-1,100))
        #self.sizer.Add(self.panel,1,wx.EXPAND)
        #self.SetSizer(self.sizer)
        #self.EnableScrolling(True, True)
        #self.SetScrollbars(5, 30, 1055, 40)
        #self.sizer.Fit(self)
        #self.Centre()
        #self.SetVirtualSize((1000,1000))

        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_SIZE, self.on_size)
        self.Bind(wx.EVT_MOUSE_EVENTS, self.on_mouse_event)
        self.Bind(wx.EVT_KEY_DOWN, self.on_key_down)

        self.tree_remapping_flag = False
        self.recalculation_flag = False
        
        self.needs_tree_remapping_emitter = \
            self.gui_project.emitter_system.make_emitter(
                inputs=(
                    self.gui_project.tree_structure_modified_emitter,
                ),
                outputs=(
                    FlagRaiser(self, 'tree_remapping_flag'),
                ),
                name='needs_tree_remapping',
            )

        
        self.needs_recalculation_emitter = \
            self.gui_project.emitter_system.make_emitter(
                inputs=(
                    self.needs_tree_remapping_emitter,
                    self.gui_project.step_profiles_to_hues_modified_emitter,
                    self.gui_project.active_node_changed_or_modified_emitter,
                    self.gui_project.tree_modified_on_path_emitter,
                    # Note that if there's a non-structure tree change not on
                    # the path it won't affect us.
                ),
                outputs=(
                    FlagRaiser(self, 'recalculation_flag'),
                ),
                name='needs_recalculation',
            )
        
        self.clickable_map = {}
        
        elements_raw = {            
            'Untouched': 'graysquare.png',
            'Touched': 'graystar.png',
            'Unfinalized Touched': 'grayunfinalizedstar.png',
            'Untouched End': 'grayendsquare.png',
            'Touched End': 'grayendstar.png',
            'Block': 'grayblock.png',
            'Active Untouched': 'orangesquare.png',
            'Active Touched': 'orangestar.png',
            'Active Unfinalized Touched': 'orangeunfinalizedstar.png',
            'Active Untouched End': 'orangeendsquare.png',
            'Active Touched End': 'orangeendstar.png',
            'Active Block': 'orangeblock.png',
        }
        
        self.elements = {}
        for key in elements_raw:
            stream = pkg_resources.resource_stream(images_package,
                                                   elements_raw[key])
            self.elements[key] = wx.BitmapFromImage(
                wx.ImageFromStream(
                    stream,
                    wx.BITMAP_TYPE_ANY
                )
            )
Пример #12
0
    def __init__(self, frame):
        wx.Panel.__init__(self, frame, -1, size=(184, 128),
                          style=wx.SUNKEN_BORDER)
        WorkspaceWidget.__init__(self, frame)
        
        #self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        self.SetBackgroundColour(wx.Color(212, 208, 200))
        
        assert isinstance(self.gui_project, garlicsim_wx.GuiProject)
        # I put this assert mainly for better source assistance in Wing.
        # It may be removed.
        
        self.Bind(wx.EVT_SIZE, self.on_size)
        self.Bind(wx.EVT_PAINT, self.on_paint)
        
        self.inner_panel = wx.Panel(self, -1, size=(184, 124))
        '''The panel that contains all the subwidgets.'''
        
        self.inner_panel.SetBackgroundColour(wx.Color(212, 208, 200))
        
        self.center_button_mode = PlayMode
        '''The current mode of the center button.'''

        bitmap_list = ['to_start', 'previous_node', 'play',
                                'next_node', 'to_end', 'pause',
                                'finalize']
        
        bitmaps_dict = self.bitmap_dict = {}
        for bitmap_name in bitmap_list:
            stream = pkg_resources.resource_stream(images_package,
                                                 bitmap_name + '.png')
            self.bitmap_dict[bitmap_name] = wx.BitmapFromImage(
                wx.ImageFromStream(
                    stream,
                    wx.BITMAP_TYPE_ANY
                )
            )
            
        
        self.center_button_bitmap_dict = {
            PlayMode: bitmaps_dict['play'],
            PauseMode: bitmaps_dict['pause'],
            FinalizeMode: bitmaps_dict['finalize'],
            }
        

        v_sizer = self.v_sizer = wx.BoxSizer(wx.VERTICAL)


        playing_speed_getter = lambda: \
            self.gui_project.official_playing_speed / \
            self.gui_project.standard_playing_speed
        
        playing_speed_setter = lambda value: \
            self.gui_project.set_official_playing_speed(
                value * self.gui_project.standard_playing_speed
            )
        
        self.playing_speed_knob = Knob(
            self.inner_panel,
            getter = playing_speed_getter,
            setter = playing_speed_setter
        )
        '''Knob which controls the official playback speed.'''
        
        self.playing_speed_knob.set_snap_point(-1)
        self.playing_speed_knob.set_snap_point(1)
        
        
        self.knob_sizer = knob_sizer = wx.BoxSizer(wx.HORIZONTAL)
        knob_sizer.Add(
            self.playing_speed_knob,
            1,
            wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL |\
            wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
            75
        )
        
        
        v_sizer.Add(
            knob_sizer, #self.playing_speed_knob, # knob_sizer,
            0,
            #wx.ALIGN_CENTER_HORIZONTAL #wx.EXPAND #|
        )


        h_sizer = wx.BoxSizer(wx.HORIZONTAL)
        
                           
        self.button_to_start = wx.BitmapButton(
            self.inner_panel, -1, bitmaps_dict['to_start'], size=(31, 50)
        )
        '''Button for moving to start of path.'''
        
        self.button_previous_node = wx.BitmapButton(
            self.inner_panel, -1, bitmaps_dict['previous_node'], size=(31, 50)
        )
        '''Button for moving to previous node.'''
        
        self.button_center_button = wx.BitmapButton(
            self.inner_panel, -1, bitmaps_dict['play'], size=(60, 50)
        )
        '''Button for playing/pausing playback, and finalizing edited node.'''
        
        self.button_next_node= wx.BitmapButton(
            self.inner_panel, -1, bitmaps_dict['next_node'], size=(31, 50)
        )
        '''Button for moving to next node.'''
        
        self.button_to_end = wx.BitmapButton(
            self.inner_panel, -1, bitmaps_dict['to_end'], size=(31, 50)
        )
        '''Button for moving to end of path.'''
        
        
        self.Bind(wx.EVT_BUTTON, self.on_button_to_start,
                  source=self.button_to_start)
        
        self.Bind(wx.EVT_BUTTON, self.on_button_previous_node,
                  source=self.button_previous_node)
        
        self.Bind(wx.EVT_BUTTON, self.on_button_center_button,
                  source=self.button_center_button)
        
        self.Bind(wx.EVT_BUTTON, self.on_button_next_node,
                  source=self.button_next_node)
        
        self.Bind(wx.EVT_BUTTON, self.on_button_to_end,
                  source=self.button_to_end)
        
        button_line = (
            self.button_to_start,
            self.button_previous_node,
            self.button_center_button,
            self.button_next_node,
            self.button_to_end
        )
        
        for button in button_line:
            h_sizer.Add(button, 0)
        v_sizer.Add(h_sizer, 0)#1, wx.EXPAND)


        self.scratch_wheel = ScratchWheel(self.inner_panel, self.gui_project,
                                          -1, size=(184, 44))
        v_sizer.Add(self.scratch_wheel, 0)


        self.inner_panel.SetSizer(v_sizer)
        knob_sizer.Layout()
        h_sizer.Layout()
        v_sizer.Layout()
        
        
        self.center_button_update_flag = True
        '''Flag saying whether the center button needs update.'''
        
        self.navigation_buttons_update_flag = True
        '''Flag saying whether the navigation buttons need update.'''
        
        self.playing_speed_knob_update_flag = True
        '''Flag saying whether the playing speed knob needs update.'''
        
        self.center_button_needs_update_emitter = \
            self.gui_project.emitter_system.make_emitter(
                inputs=(
                    self.gui_project.playing_toggled_emitter,
                    self.gui_project.active_node_changed_or_modified_emitter,
                    self.gui_project.active_node_finalized_emitter
                ),
                outputs=(
                    FlagRaiser(self, 'center_button_update_flag',
                               function=self._update_center_button, delay=0.03),
                ),
                name='playback_controls_center_button_needs_update',
        )
        

        self.navigation_buttons_need_update_emitter = \
            self.gui_project.emitter_system.make_emitter(
                inputs=(
                    self.gui_project.active_node_changed_emitter,
                    self.gui_project.path_contents_changed_emitter
                ),            
                outputs=(
                    FlagRaiser(
                        self, 'navigation_buttons_update_flag',
                        function=self._update_navigation_buttons, delay=0.03
                        ),
                ),
                name='playback_controls_navigation_buttons_need_update',
        )
        
        
        self.gui_project.official_playing_speed_modified_emitter.add_output(
            FlagRaiser(self.playing_speed_knob, 'recalculation_flag',
                       self.playing_speed_knob._recalculate, delay=0.03)
        )
Пример #13
0
    def __init__(self, frame):
        wx.Panel.__init__(self,
                          frame,
                          -1,
                          size=(184, 128),
                          style=wx.SUNKEN_BORDER)
        WorkspaceWidget.__init__(self, frame)

        #self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        self.SetBackgroundColour(wx_tools.get_background_color())
        self.SetDoubleBuffered(True)

        assert isinstance(self.gui_project, garlicsim_wx.GuiProject)
        # I put this assert mainly for better source assistance in Wing.
        # It may be removed.

        self.Bind(wx.EVT_SIZE, self.on_size)
        self.Bind(wx.EVT_PAINT, self.on_paint)

        self.inner_panel = wx.Panel(self, -1, size=(184, 124))
        '''The panel that contains all the subwidgets.'''

        self.inner_panel.SetBackgroundColour(wx_tools.get_background_color())

        self.center_button_mode = PlayMode
        '''The current mode of the center button.'''

        bitmap_list = [
            'to_start', 'previous_node', 'play', 'next_node', 'to_end',
            'pause', 'finalize'
        ]

        bitmaps_dict = self.bitmap_dict = {}
        for bitmap_name in bitmap_list:
            stream = pkg_resources.resource_stream(images_package,
                                                   bitmap_name + '.png')
            self.bitmap_dict[bitmap_name] = wx.BitmapFromImage(
                wx.ImageFromStream(stream, wx.BITMAP_TYPE_ANY))

        self.center_button_bitmap_dict = {
            PlayMode: bitmaps_dict['play'],
            PauseMode: bitmaps_dict['pause'],
            FinalizeMode: bitmaps_dict['finalize'],
        }

        v_sizer = self.v_sizer = wx.BoxSizer(wx.VERTICAL)


        playing_speed_getter = lambda: \
            self.gui_project.official_playing_speed / \
            self.gui_project.standard_playing_speed

        playing_speed_setter = lambda value: \
            self.gui_project.set_official_playing_speed(
                value * self.gui_project.standard_playing_speed
            )

        self.playing_speed_knob = Knob(self.inner_panel,
                                       getter=playing_speed_getter,
                                       setter=playing_speed_setter)
        '''Knob which controls the official playback speed.'''

        self.playing_speed_knob.set_snap_point(-1)
        self.playing_speed_knob.set_snap_point(1)

        self.knob_sizer = knob_sizer = wx.BoxSizer(wx.HORIZONTAL)
        knob_sizer.Add(
            self.playing_speed_knob,
            1,
            wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL |\
            wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
            75
        )

        v_sizer.Add(
            knob_sizer,  #self.playing_speed_knob, # knob_sizer,
            0,
            #wx.ALIGN_CENTER_HORIZONTAL #wx.EXPAND #|
        )

        h_sizer = wx.BoxSizer(wx.HORIZONTAL)

        self.button_to_start = wx.BitmapButton(self.inner_panel,
                                               -1,
                                               bitmaps_dict['to_start'],
                                               size=(31, 50))
        '''Button for moving to start of path.'''

        self.button_previous_node = wx.BitmapButton(
            self.inner_panel, -1, bitmaps_dict['previous_node'], size=(31, 50))
        '''Button for moving to previous node.'''

        self.button_center_button = wx.BitmapButton(self.inner_panel,
                                                    -1,
                                                    bitmaps_dict['play'],
                                                    size=(60, 50))
        '''Button for playing/pausing playback, and finalizing edited node.'''

        self.button_next_node = wx.BitmapButton(self.inner_panel,
                                                -1,
                                                bitmaps_dict['next_node'],
                                                size=(31, 50))
        '''Button for moving to next node.'''

        self.button_to_end = wx.BitmapButton(self.inner_panel,
                                             -1,
                                             bitmaps_dict['to_end'],
                                             size=(31, 50))
        '''Button for moving to end of path.'''

        self.Bind(wx.EVT_BUTTON,
                  self.on_button_to_start,
                  source=self.button_to_start)

        self.Bind(wx.EVT_BUTTON,
                  self.on_button_previous_node,
                  source=self.button_previous_node)

        self.Bind(wx.EVT_BUTTON,
                  self.on_button_center_button,
                  source=self.button_center_button)

        self.Bind(wx.EVT_BUTTON,
                  self.on_button_next_node,
                  source=self.button_next_node)

        self.Bind(wx.EVT_BUTTON,
                  self.on_button_to_end,
                  source=self.button_to_end)

        button_line = (self.button_to_start, self.button_previous_node,
                       self.button_center_button, self.button_next_node,
                       self.button_to_end)

        for button in button_line:
            h_sizer.Add(button, 0)
        v_sizer.Add(h_sizer, 0)  #1, wx.EXPAND)

        self.scratch_wheel = ScratchWheel(self.inner_panel,
                                          self.gui_project,
                                          -1,
                                          size=(184, 44))
        v_sizer.Add(self.scratch_wheel, 0)

        self.inner_panel.SetSizer(v_sizer)
        knob_sizer.Layout()
        h_sizer.Layout()
        v_sizer.Layout()

        self.center_button_update_flag = True
        '''Flag saying whether the center button needs update.'''

        self.navigation_buttons_update_flag = True
        '''Flag saying whether the navigation buttons need update.'''

        self.playing_speed_knob_update_flag = True
        '''Flag saying whether the playing speed knob needs update.'''

        self.center_button_needs_update_emitter = \
            self.gui_project.emitter_system.make_emitter(
                inputs=(
                    self.gui_project.playing_toggled_emitter,
                    self.gui_project.active_node_changed_or_modified_emitter,
                    self.gui_project.active_node_finalized_emitter
                ),
                outputs=(
                    FlagRaiser(self, 'center_button_update_flag',
                               function=self._update_center_button, delay=0.03),
                ),
                name='playback_controls_center_button_needs_update',
        )


        self.navigation_buttons_need_update_emitter = \
            self.gui_project.emitter_system.make_emitter(
                inputs=(
                    self.gui_project.active_node_changed_emitter,
                    self.gui_project.path_contents_changed_emitter
                ),
                outputs=(
                    FlagRaiser(
                        self, 'navigation_buttons_update_flag',
                        function=self._update_navigation_buttons, delay=0.03
                        ),
                ),
                name='playback_controls_navigation_buttons_need_update',
        )

        self.gui_project.official_playing_speed_modified_emitter.add_output(
            FlagRaiser(self.playing_speed_knob,
                       'recalculation_flag',
                       self.playing_speed_knob._recalculate,
                       delay=0.03))