def __init__(self, step_profile_dialog, step_profile, and_fork=False):
        """
        Construct the `AlreadyExistsDialog`.
        
        Set `and_fork=True` if you intend to fork right after getting the step
        profile, though note it will only affect the labels; the actual forking
        is not done here.
        """
        self.step_profile_dialog = step_profile_dialog
        self.frame = step_profile_dialog.frame
        self.step_profile = step_profile
        self.and_fork = and_fork
        assert isinstance(self.frame, garlicsim_wx.Frame)

        CuteDialog.__init__(self, step_profile_dialog, title="Step profile already exists")

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

        self.static_text = wx.StaticText(
            self,
            label="The step profile `%s` already exists."
            % step_profile.__repr__(
                short_form=True, root=self.frame.gui_project.simpack, namespace=self.frame.gui_project.namespace
            ),
        )

        self.main_v_sizer.Add(self.static_text, 0, wx.EXPAND | wx.ALL, border=10)

        self.button_sizer = wx.BoxSizer(wx.HORIZONTAL)

        self.main_v_sizer.Add(self.button_sizer, 0, wx.ALIGN_CENTER_HORIZONTAL)

        take_me_to_it_label = "Take me to it" if not and_fork else "Take me to it and fork with it"
        self.take_me_to_it_button = wx.Button(self, label=take_me_to_it_label)

        # Allowing keyboard-navigation and Esc on Ubuntu:
        self.take_me_to_it_button.SetFocus()

        self.button_sizer.Add(self.take_me_to_it_button, 0, wx.EXPAND | wx.ALL, border=10)

        self.keep_editing_button = wx.Button(self, label="Keep editing")

        self.SetEscapeId(self.keep_editing_button.Id)

        self.button_sizer.Add(self.keep_editing_button, 0, wx.EXPAND | wx.ALL, border=10)

        self.Bind(wx.EVT_BUTTON, self.on_take_me_to_it_button, source=self.take_me_to_it_button)
        self.Bind(wx.EVT_BUTTON, self.on_keep_editing_button, source=self.keep_editing_button)

        self.take_me_to_it_button.SetDefault()

        self.SetSizer(self.main_v_sizer)
        self.main_v_sizer.Fit(self)
示例#2
0
    def __init__(self, frame):
        CuteDialog.__init__(self, frame, title='Creating a root state')

        self.frame = frame
        self.simpack = frame.gui_project.simpack

        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        self.x_title = x_title = wx.StaticText(self, -1, 'Width: ')
        self.x_textctrl = x_textctrl = wx.TextCtrl(self, -1, '45')
        self.y_title = y_title = wx.StaticText(self, -1, 'Height: ')
        self.y_textctrl = y_textctrl = wx.TextCtrl(self, -1, '25')
        hbox1.Add(x_title, 0, wx.ALIGN_CENTER | wx.EXPAND | wx.ALL, 5)
        hbox1.Add(x_textctrl, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.RIGHT, 40)
        hbox1.Add(y_title, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.RIGHT, 10)
        hbox1.Add(y_textctrl, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.RIGHT, 5)

        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        self.empty = empty = wx.RadioButton(self,
                                            -1,
                                            'All empty',
                                            style=wx.RB_GROUP)
        self.full = full = wx.RadioButton(self, -1, 'All full')
        self.random = random = wx.RadioButton(self, -1, 'Random')
        random.SetValue(True)
        hbox2.Add(empty, 0, wx.ALIGN_CENTER | wx.ALL, 5)
        hbox2.Add(full, 0, wx.ALIGN_CENTER | wx.ALL, 5)
        hbox2.Add(random, 0, wx.ALIGN_CENTER | wx.ALL, 5)

        vbox = wx.BoxSizer(wx.VERTICAL)

        last_hbox = wx.BoxSizer(wx.HORIZONTAL)
        ok = wx.Button(self, wx.ID_OK, 'Create state')
        ok.SetDefault()
        self.Bind(wx.EVT_BUTTON, self.on_ok, id=ok.GetId())
        cancel = wx.Button(self, wx.ID_CANCEL, 'Cancel')
        self.Bind(wx.EVT_BUTTON, self.on_cancel, id=cancel.GetId())
        last_hbox.Add(ok, 0)
        last_hbox.Add(cancel, 0, wx.LEFT, 5)

        vbox.Add(hbox1, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10)
        vbox.Add(hbox2, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10)
        vbox.Add(last_hbox, 1, wx.ALIGN_CENTER | wx.BOTTOM, 10)

        self.SetSizer(vbox)
        vbox.Fit(self)
        ok.SetFocus()
示例#3
0
    def __init__(self, frame):
        CuteDialog.__init__(self, frame, title='Creating a root state')
        
        self.frame = frame
        self.simpack = frame.gui_project.simpack

        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        self.x_title = x_title = wx.StaticText(self, -1, 'Width: ')
        self.x_textctrl = x_textctrl = wx.TextCtrl(self, -1, '45')
        self.y_title = y_title = wx.StaticText(self, -1, 'Height: ')
        self.y_textctrl = y_textctrl = wx.TextCtrl(self, -1, '25')
        hbox1.Add(x_title, 0, wx.ALIGN_CENTER | wx.EXPAND | wx.ALL, 5)
        hbox1.Add(x_textctrl, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.RIGHT, 40)
        hbox1.Add(y_title, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.RIGHT, 10)
        hbox1.Add(y_textctrl, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.RIGHT, 5)

        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        self.empty = empty = wx.RadioButton(self, -1, 'All empty',
                                            style=wx.RB_GROUP)
        self.full = full = wx.RadioButton(self, -1, 'All full')
        self.random = random = wx.RadioButton(self, -1, 'Random')
        random.SetValue(True)
        hbox2.Add(empty, 0, wx.ALIGN_CENTER | wx.ALL, 5)
        hbox2.Add(full, 0, wx.ALIGN_CENTER | wx.ALL, 5)
        hbox2.Add(random, 0, wx.ALIGN_CENTER | wx.ALL, 5)
        
        vbox = wx.BoxSizer(wx.VERTICAL)

        last_hbox = wx.BoxSizer(wx.HORIZONTAL)
        ok = wx.Button(self, wx.ID_OK, 'Create state')
        ok.SetDefault()
        self.Bind(wx.EVT_BUTTON, self.on_ok, id=ok.GetId())
        cancel = wx.Button(self, wx.ID_CANCEL, 'Cancel')
        self.Bind(wx.EVT_BUTTON, self.on_cancel, id=cancel.GetId())
        last_hbox.Add(ok, 0)
        last_hbox.Add(cancel, 0, wx.LEFT, 5)

        vbox.Add(hbox1, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10)
        vbox.Add(hbox2, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10)
        vbox.Add(last_hbox, 1, wx.ALIGN_CENTER |  wx.BOTTOM, 10)

        self.SetSizer(vbox)
        vbox.Fit(self)
        ok.SetFocus()
示例#4
0
    def __init__(self, frame):
   
        CuteDialog.__init__(self, frame, title='Creating a root state')
        
        self.frame = frame
        self.simpack = frame.gui_project.simpack
        State = self.simpack.State

        vbox = wx.BoxSizer(wx.VERTICAL)
        self.messy_check_box = messy_check_box = wx.CheckBox(self, -1, 'Messy')
        tool_tip_string = ('Make a messy chaotic state, useful for '
                           'test-driving the simpack.')
        messy_check_box.SetValue(True)
        if State.create_root is None or State.create_messy_root is None:
            messy_check_box.Disable()
            if State.create_messy_root is None:
                messy_check_box.SetValue(False)
                tool_tip_string += (" Not available because the simpack "
                                    "doesn't define `create_messy_root`.")
            else:
                tool_tip_string += (" Can't be canceled because the simpack "
                                    "doesn't define `create_root`.")
        messy_check_box.SetToolTipString(tool_tip_string)
        
        vbox.Add(messy_check_box, 0, wx.ALL, 10)
        
        # todo: add slick way to add args/kwargs

        last_hbox = wx.StdDialogButtonSizer()
        ok = wx.Button(self, wx.ID_OK, 'Create state')
        ok.SetDefault()
        last_hbox.SetAffirmativeButton(ok)
        self.Bind(wx.EVT_BUTTON, self.on_ok, id=ok.GetId())
        cancel = wx.Button(self, wx.ID_CANCEL, 'Cancel')
        self.Bind(wx.EVT_BUTTON, self.on_cancel, id=cancel.GetId())
        last_hbox.AddButton(ok)
        last_hbox.AddButton(cancel)
        last_hbox.Realize()

        vbox.Add(last_hbox, 0, wx.ALIGN_CENTER | wx.BOTTOM, 10)

        self.SetSizer(vbox)
        vbox.Fit(self)
        ok.SetFocus()
示例#5
0
    def __init__(self, step_profile_dialog, step_profile, and_fork=False):
        '''
        Construct the `AlreadyExistsDialog`.
        
        Set `and_fork=True` if you intend to fork right after getting the step
        profile, though note it will only affect the labels; the actual forking
        is not done here.
        '''
        self.step_profile_dialog = step_profile_dialog
        self.frame = step_profile_dialog.frame
        self.step_profile = step_profile
        self.and_fork = and_fork
        assert isinstance(self.frame, garlicsim_wx.Frame)

        CuteDialog.__init__(self,
                            step_profile_dialog,
                            title='Step profile already exists')

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


        self.static_text = wx.StaticText(
            self,
            label='The step profile `%s` already exists.' % \
                step_profile.__repr__(
                    short_form=True,
                    root=self.frame.gui_project.simpack,
                    namespace=self.frame.gui_project.namespace
                )
        )

        self.main_v_sizer.Add(self.static_text,
                              0,
                              wx.EXPAND | wx.ALL,
                              border=10)

        self.button_sizer = wx.BoxSizer(wx.HORIZONTAL)

        self.main_v_sizer.Add(self.button_sizer, 0, wx.ALIGN_CENTER_HORIZONTAL)

        take_me_to_it_label = 'Take me to it' if not and_fork else \
                              'Take me to it and fork with it'
        self.take_me_to_it_button = wx.Button(self, label=take_me_to_it_label)

        # Allowing keyboard-navigation and Esc on Ubuntu:
        self.take_me_to_it_button.SetFocus()

        self.button_sizer.Add(self.take_me_to_it_button,
                              0,
                              wx.EXPAND | wx.ALL,
                              border=10)

        self.keep_editing_button = wx.Button(self, label='Keep editing')

        self.SetEscapeId(self.keep_editing_button.Id)

        self.button_sizer.Add(self.keep_editing_button,
                              0,
                              wx.EXPAND | wx.ALL,
                              border=10)

        self.Bind(wx.EVT_BUTTON,
                  self.on_take_me_to_it_button,
                  source=self.take_me_to_it_button)
        self.Bind(wx.EVT_BUTTON,
                  self.on_keep_editing_button,
                  source=self.keep_editing_button)

        self.take_me_to_it_button.SetDefault()

        self.SetSizer(self.main_v_sizer)
        self.main_v_sizer.Fit(self)
    def __init__(self, cruncher_controls):
        CuteDialog.__init__(
            self, cruncher_controls.GetTopLevelParent(), title="Choose a cruncher type", size=(700, 300)
        )
        self.frame = cruncher_controls.frame
        self.gui_project = cruncher_controls.gui_project

        self.selected_cruncher_type = None

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

        self.general_text = wx.StaticText(
            self,
            label=(
                "Choose a cruncher type to be used when crunching the "
                "simulation. Your simulation will use the same algorithm "
                "regardless of which cruncher you'll choose; the choice of "
                "cruncher will affect how and where that algorithm will be "
                "run."
            ),
        )
        # self.general_text.SetSize((self.ClientSize[0] - 20, -1))
        self.general_text.Wrap(self.ClientSize[0] - 20)

        self.general_text.Wrap(self.general_text.Size[0])

        self.main_v_sizer.Add(self.general_text, 0, wx.EXPAND | wx.ALL, border=10)

        self.h_sizer = wx.BoxSizer(wx.HORIZONTAL)

        self.main_v_sizer.Add(self.h_sizer, 0, wx.EXPAND)

        self.cruncher_types_availability = (
            cruncher_types_availability
        ) = self.gui_project.project.simpack_grokker.cruncher_types_availability

        self.cruncher_titles = cruncher_titles = OrderedDict()

        for cruncher_type, availability in cruncher_types_availability.items():
            if availability == True:
                title = cruncher_type.__name__
            else:
                assert availability == False
                title = "%s (not available)" % cruncher_type.__name__
            cruncher_titles[title] = cruncher_type

        self.cruncher_list_box = wx.ListBox(self, choices=cruncher_titles.keys())
        self.cruncher_list_box.SetMinSize((250, 100))

        self.cruncher_list_box.Select(
            cruncher_titles.values().index(self.gui_project.project.crunching_manager.cruncher_type)
        )

        self.h_sizer.Add(self.cruncher_list_box, 2 * 0, wx.EXPAND | wx.ALL, border=10)

        self.cruncher_text_scrolled_panel = CruncherTextScrolledPanel(self)

        self.h_sizer.Add(self.cruncher_text_scrolled_panel, 3 * 0, wx.EXPAND | wx.ALL, border=10)

        self.dialog_button_sizer = wx.StdDialogButtonSizer()

        self.main_v_sizer.Add(self.dialog_button_sizer, 0, wx.ALIGN_CENTER | wx.ALL, border=10)

        self.ok_button = wx.Button(self, wx.ID_OK, "Switch cruncher type")
        self.dialog_button_sizer.AddButton(self.ok_button)
        self.ok_button.SetDefault()
        self.dialog_button_sizer.SetAffirmativeButton(self.ok_button)
        self.Bind(wx.EVT_BUTTON, self.on_ok, source=self.ok_button)

        self.cancel_button = wx.Button(self, wx.ID_CANCEL, "Cancel")
        self.dialog_button_sizer.AddButton(self.cancel_button)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, source=self.cancel_button)
        self.dialog_button_sizer.Realize()

        self.Bind(wx.EVT_LISTBOX, self.on_list_box_change, self.cruncher_list_box)
        self.Bind(wx.EVT_LISTBOX_DCLICK, self.on_list_box_double_click, self.cruncher_list_box)

        self.SetSizer(self.main_v_sizer)
        self.Layout()
        self.general_text.Wrap(self.general_text.Size[0])
        self.main_v_sizer.Fit(self)

        self.update()
示例#7
0
 def __init__(self, parent, message, caption='Error'):
     wx.MessageDialog.__init__(self, parent, message, caption,
                               wx.OK | wx.ICON_ERROR)
     CuteDialog.__init__(self, skip_dialog_init=True)
     
示例#8
0
    def __init__(self,
                 step_profiles_controls,
                 step_profile=None,
                 and_fork=False):
        '''
        Construct the `StepProfileDialog`.
        
        If given a `step_profile`, use it as a template. If it's `None`, start
        from scratch. Set `and_fork=True` if you intend to fork right after
        getting the step profile, though note it will only affect the labels;
        the actual forking is not done here.
        '''

        self.step_profiles_controls = step_profiles_controls

        self.gui_project = step_profiles_controls.gui_project
        assert isinstance(self.gui_project, garlicsim_wx.GuiProject)

        self.frame = step_profiles_controls.frame

        self.and_fork = and_fork

        self.simpack = self.gui_project.simpack

        self.simpack_grokker = simpack_grokker = \
            self.gui_project.simpack_grokker

        title = 'Create a new step profile' if not and_fork else \
                'Create a new step profile and fork with it'
        CuteDialog.__init__(self,
                            step_profiles_controls.GetTopLevelParent(),
                            title=title)

        self.SetDoubleBuffered(True)

        self.original_step_profile = original_step_profile = step_profile

        del step_profile

        self.hue = self.gui_project.step_profiles_to_hues.default_factory()

        self.step_functions_to_argument_dicts = \
            StepFunctionsToArgumentDicts(self.describe)

        self.step_functions_to_star_args = \
            collections.defaultdict(lambda: [])

        self.step_functions_to_star_kwargs = \
            collections.defaultdict(lambda: {})

        if original_step_profile:

            original_step_function = original_step_profile.step_function

            self.step_function = original_step_function

            initial_step_function_address = self.describe(
                original_step_function)

            original_argument_dict = collections.defaultdict(
                lambda: '', original_step_profile.getcallargs_result)

            self.step_functions_to_argument_dicts[original_step_function] = \
                dict((key, self.describe(value)) for (key, value) in
                 original_argument_dict.iteritems())

            original_arg_spec = cute_inspect.getargspec(original_step_function)

            if original_arg_spec.varargs:
                star_args_value = original_step_profile.getcallargs_result[
                    original_arg_spec.varargs]

                self.step_functions_to_star_args[original_step_function] = \
                    [self.describe(value) for value in
                     star_args_value]

            if original_arg_spec.keywords:
                star_kwargs_value = original_step_profile.getcallargs_result[
                    original_arg_spec.keywords]

                self.step_functions_to_star_kwargs[original_step_function] = \
                    dict((key, self.describe(value)) for (key, value)
                         in star_kwargs_value.iteritems())

        else:

            self.step_function = None

            if len(simpack_grokker.all_step_functions) >= 2:
                initial_step_function_address = ''
            else:  # len(simpack_grokker.all_step_functions) == 1
                initial_step_function_address = self.describe(
                    simpack_grokker.default_step_function)

        #######################################################################
        # Setting up widgets and sizers:

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

        self.static_text = wx.StaticText(self, label="Choose a step function:")

        self.main_v_sizer.Add(self.static_text,
                              0,
                              wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT,
                              border=10)

        self.h_sizer = wx.BoxSizer(wx.HORIZONTAL)

        self.main_v_sizer.Add(self.h_sizer,
                              0,
                              wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
                              border=10)


        self.hue_control = \
            garlicsim_wx.widgets.general_misc.hue_control.HueControl(
                self,
                lambda: getattr(self, 'hue'),
                lambda hue: setattr(self, 'hue', hue),
                emitter=None,
                lightness=0.8,
                saturation=1,
                dialog_title='Select hue for new step profile',
                size=(25, 20)
            )

        self.h_sizer.Add(self.hue_control, 0, wx.ALIGN_CENTER_VERTICAL)

        self.h_sizer.AddSpacer(5)

        self.step_function_input = StepFunctionInput(
            self, value=initial_step_function_address)

        self.h_sizer.Add(
            self.step_function_input,
            0,
            wx.ALIGN_CENTER_VERTICAL,
        )


        self.static_function_text = StaticFunctionText(
            self,
            step_function=original_step_function if original_step_profile \
                          else None
        )

        self.h_sizer.Add(self.static_function_text,
                         0,
                         wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                         border=15)

        self.argument_control = ArgumentControl(
            self, original_step_function if original_step_profile else None)

        self.main_v_sizer.Add(self.argument_control,
                              1,
                              wx.ALIGN_CENTER_HORIZONTAL | wx.TOP,
                              border=0)

        self.dialog_button_sizer = wx.StdDialogButtonSizer()

        self.main_v_sizer.Add(self.dialog_button_sizer,
                              0,
                              wx.ALIGN_CENTER | wx.ALL,
                              border=10)

        ok_title = 'Create step profile' if not and_fork else \
                   'Create step profile and fork with it'
        self.ok_button = wx.Button(self, wx.ID_OK, title)
        self.dialog_button_sizer.AddButton(self.ok_button)
        self.ok_button.SetDefault()
        self.dialog_button_sizer.SetAffirmativeButton(self.ok_button)
        self.Bind(wx.EVT_BUTTON, self.on_ok, source=self.ok_button)

        self.cancel_button = wx.Button(self, wx.ID_CANCEL, 'Cancel')
        self.dialog_button_sizer.AddButton(self.cancel_button)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, source=self.cancel_button)
        self.dialog_button_sizer.Realize()

        self.SetSizer(self.main_v_sizer)
        self.main_v_sizer.Fit(self)
示例#9
0
 def __init__(self, frame):
     CuteDialog.__init__(
         self,
         frame,
         title='Choose simulation package',
         size=(-1, 400)
     )
     
     assert isinstance(frame, garlicsim_wx.Frame)
     self.frame = frame
     
     self.main_v_sizer = wx.BoxSizer(wx.VERTICAL)
     
     self.static_text = wx.StaticText(
         self,
         label='Choose a simulation package for your new simulation:'
     )
     self.main_v_sizer.Add(self.static_text, 0, wx.EXPAND | wx.ALL, 10)
     
     self.list_box = wx.ListBox(self)
     self.main_v_sizer.Add(self.list_box, 1, wx.EXPAND | wx.ALL, 10)
     self.list_box.Bind(wx.EVT_LEFT_DCLICK, self.on_ok, self.list_box)
     
     self.add_folder_containing_simpacks_button = wx.Button(
         self,
         label='&Add folder containing simpacks...'
     )
     self.main_v_sizer.Add(self.add_folder_containing_simpacks_button,
                           0,
                           wx.EXPAND | wx.ALL,
                           border=10)            
     self.Bind(wx.EVT_BUTTON,
               self.on_add_folder_containing_simpacks_button,
               self.add_folder_containing_simpacks_button)
     
     self.horizontal_line = wx.StaticLine(self)
     self.main_v_sizer.Add(self.horizontal_line,
                           0,
                           wx.EXPAND | wx.ALL,
                           10)
     
     self.dialog_button_sizer = wx.StdDialogButtonSizer()
     
     self.main_v_sizer.Add(self.dialog_button_sizer,
                           0,
                           wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
                           border=10)
     
     self.ok_button = wx.Button(self, wx.ID_OK, 'Create &project')
     self.dialog_button_sizer.AddButton(self.ok_button)
     self.ok_button.SetDefault()
     self.dialog_button_sizer.SetAffirmativeButton(self.ok_button)
     self.Bind(wx.EVT_BUTTON, self.on_ok, source=self.ok_button)
     
     self.cancel_button = wx.Button(self, wx.ID_CANCEL, 'Cancel')
     self.dialog_button_sizer.AddButton(self.cancel_button)
     self.Bind(wx.EVT_BUTTON, self.on_cancel, source=self.cancel_button)
     self.dialog_button_sizer.Realize()
     
     self.update_simpack_list()
     if self.list_of_simpacks:
         self.list_box.Select(0)
     
     self.SetSizer(self.main_v_sizer)
     self.Layout()
     
     self.list_box.SetFocus()
示例#10
0
    def __init__(self, cruncher_controls):
        CuteDialog.__init__(
            self,
            cruncher_controls.GetTopLevelParent(),
            title='Choose a cruncher type',
            size=(700, 300)
        )
        self.frame = cruncher_controls.frame
        self.gui_project = cruncher_controls.gui_project
        
        self.selected_cruncher_type = None
        
        self.main_v_sizer = wx.BoxSizer(wx.VERTICAL)
        
        self.general_text = wx.StaticText(
            self,
            label=("Choose a cruncher type to be used when crunching the "
                   "simulation. Your simulation will use the same algorithm "
                   "regardless of which cruncher you'll choose; the choice of "
                   "cruncher will affect how and where that algorithm will be "
                   "run.")
        )
        #self.general_text.SetSize((self.ClientSize[0] - 20, -1))
        self.general_text.Wrap(self.ClientSize[0] - 20)
                                  
        self.general_text.Wrap(self.general_text.Size[0])
        
        self.main_v_sizer.Add(self.general_text, 0, wx.EXPAND | wx.ALL,
                              border=10)
        
        self.h_sizer = wx.BoxSizer(wx.HORIZONTAL)
        
        self.main_v_sizer.Add(self.h_sizer, 0, wx.EXPAND)
        
        self.cruncher_types_availability = cruncher_types_availability = \
            self.gui_project.project.simpack_grokker.\
            cruncher_types_availability

        self.cruncher_titles = cruncher_titles = OrderedDict()
        
        for cruncher_type, availability in cruncher_types_availability.items():
            if availability == True:
                title = cruncher_type.__name__
            else:
                assert availability == False
                title = '%s (not available)' % cruncher_type.__name__
            cruncher_titles[title] = cruncher_type
        
        self.cruncher_list_box = wx.ListBox(
            self,
            choices=cruncher_titles.keys()
        )
        self.cruncher_list_box.SetMinSize((250, 100))
        
        self.cruncher_list_box.Select(
            cruncher_titles.values().index(
                self.gui_project.project.crunching_manager.cruncher_type
            )
        )
        
        self.h_sizer.Add(self.cruncher_list_box, 2*0, wx.EXPAND | wx.ALL,
                              border=10)
        
        self.cruncher_text_scrolled_panel = CruncherTextScrolledPanel(self)
        
        self.h_sizer.Add(self.cruncher_text_scrolled_panel, 3*0,
                         wx.EXPAND | wx.ALL, border=10)
        
        self.dialog_button_sizer = wx.StdDialogButtonSizer()
        
        self.main_v_sizer.Add(self.dialog_button_sizer, 0,
                              wx.ALIGN_CENTER | wx.ALL, border=10)
        
        self.ok_button = wx.Button(self, wx.ID_OK, 'Switch cruncher type')
        self.dialog_button_sizer.AddButton(self.ok_button)
        self.ok_button.SetDefault()
        self.dialog_button_sizer.SetAffirmativeButton(self.ok_button)
        self.Bind(wx.EVT_BUTTON, self.on_ok, source=self.ok_button)
        
        self.cancel_button = wx.Button(self, wx.ID_CANCEL, 'Cancel')
        self.dialog_button_sizer.AddButton(self.cancel_button)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, source=self.cancel_button)
        self.dialog_button_sizer.Realize()
        
        
        self.Bind(wx.EVT_LISTBOX, self.on_list_box_change,
                  self.cruncher_list_box)
        self.Bind(wx.EVT_LISTBOX_DCLICK, self.on_list_box_double_click,
                  self.cruncher_list_box)
        
        self.SetSizer(self.main_v_sizer)
        self.Layout()
        self.general_text.Wrap(self.general_text.Size[0])
        self.main_v_sizer.Fit(self)
        
        self.update()
示例#11
0
 def __init__(self, frame):
     CuteDialog.__init__(self, frame, title='Creating a root state')
     
     self.frame = frame
示例#12
0
    def __init__(self, frame):
   
        wx.Dialog.__init__(self, frame, title='About GarlicSim',
                           size=(628, 600))
        CuteDialog.__init__(self, frame, skip_dialog_init=True)
        
        self.SetDoubleBuffered(True)
        
        self.frame = frame

        v_sizer = wx.BoxSizer(wx.VERTICAL)
        

        self._original_image = wx.ImageFromStream(
            pkg_resources.resource_stream(
                images_package,
                'about.png'
            )
        )
        
        self.bitmap_viewer = BitmapViewer(self, size=(627, 271))
        v_sizer.Add(self.bitmap_viewer, 0)
        
        self.html_window = wx.html.HtmlWindow(self, size=(628, 270))
        v_sizer.Add(self.html_window, 0)
        
        foreground_color_in_hex = \
            wx_tools.wx_color_to_html_color(wx_tools.get_background_color())
        background_color_in_hex = \
            wx_tools.wx_color_to_html_color(wx.Colour(0, 0, 0))
        
        
        self.html_window.SetPage(
            '''
            <html>
                <body bgcolor="%s" color="%s">
                    <div align="center"> <font size="1">
                        &copy; 2009-2011 Ram Rachum (a.k.a. cool-RR)
                        <br />                        
                        This program is distributed under the LGPL2.1 license.
                        <br />
                    </font></div>
                    <div> 
                        GarlicSim is a platform for writing, running and
                        analyzing computer simulations. It is general enough to
                        handle any kind of simulation: Physics, game theory,
                        epidemic spread, electronics, etc.<br />
                        <font size="1"><br /></font>
                        <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Version %s</b>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Website:
                        <a href="http://garlicsim.org">http://garlicsim.org</a>
                    </div>
                    <div>
                        <font size="1"><br /></font>
                        I would like to thank the open source community for
                        making this program possible. This includes the
                        developers of Python, Psyco, wxPython, wxWidgets,
                        Mayavi, git, and so many others... And more thanks to
                        the many people who spent many hours helping me out
                        with various issues, on mailing lists such as
                        wxpython-users and on the StackOverflow website.
                    </div>
                </body>
            </html>
            ''' % (
                    foreground_color_in_hex,
                    background_color_in_hex,
                    garlicsim_wx.__version__
                )
        )
        
        self.html_window.Bind(
            wx.html.EVT_HTML_LINK_CLICKED, 
            lambda event: webbrowser.open_new_tab(
                event.GetLinkInfo().GetHref()
                ),
            self.html_window
        )

        
        self.button_sizer = button_sizer = wx.StdDialogButtonSizer()
        self.ok_button = wx.Button(self, wx.ID_OK,
                                   "Let's get back to simulating!")
        self.ok_button.SetDefault()
        button_sizer.SetAffirmativeButton(self.ok_button)
        self.Bind(wx.EVT_BUTTON, self.on_ok, self.ok_button)
        button_sizer.AddButton(self.ok_button)
        button_sizer.Realize()
        button_sizer.SetMinSize((500, -1))
        v_sizer.Add(button_sizer, 0)
        
        
        self.SetSizer(v_sizer)
        self.Layout()

        
        self.timer = garlicsim_wx.general_misc.cute_timer.CuteTimer(self)
        self.timer.Start(40, oneShot=True)
        self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
        
        self._rotate_image_hue()
示例#13
0
    def __init__(self, frame):

        wx.Dialog.__init__(self,
                           frame,
                           title='About GarlicSim',
                           size=(628, 600))
        CuteDialog.__init__(self, frame, skip_dialog_init=True)

        self.SetDoubleBuffered(True)

        self.frame = frame

        v_sizer = wx.BoxSizer(wx.VERTICAL)

        self._original_image = wx.ImageFromStream(
            pkg_resources.resource_stream(images_package, 'about.png'))

        self.bitmap_viewer = BitmapViewer(self, size=(627, 271))
        v_sizer.Add(self.bitmap_viewer, 0)

        self.html_window = wx.html.HtmlWindow(self, size=(628, 270))
        v_sizer.Add(self.html_window, 0)

        foreground_color_in_hex = \
            wx_tools.wx_color_to_html_color(wx_tools.get_background_color())
        background_color_in_hex = \
            wx_tools.wx_color_to_html_color(wx.Colour(0, 0, 0))

        self.html_window.SetPage('''
            <html>
                <body bgcolor="%s" color="%s">
                    <div align="center"> <font size="1">
                        &copy; 2009-2011 Ram Rachum (a.k.a. cool-RR)
                        <br />                        
                        This program is distributed under the LGPL2.1 license.
                        <br />
                    </font></div>
                    <div> 
                        GarlicSim is a platform for writing, running and
                        analyzing computer simulations. It is general enough to
                        handle any kind of simulation: Physics, game theory,
                        epidemic spread, electronics, etc.<br />
                        <font size="1"><br /></font>
                        <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Version %s</b>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Website:
                        <a href="http://garlicsim.org">http://garlicsim.org</a>
                    </div>
                    <div>
                        <font size="1"><br /></font>
                        I would like to thank the open source community for
                        making this program possible. This includes the
                        developers of Python, Psyco, wxPython, wxWidgets,
                        Mayavi, git, and so many others... And more thanks to
                        the many people who spent many hours helping me out
                        with various issues, on mailing lists such as
                        wxpython-users and on the StackOverflow website.
                    </div>
                </body>
            </html>
            ''' % (foreground_color_in_hex, background_color_in_hex,
                   garlicsim_wx.__version__))

        self.html_window.Bind(
            wx.html.EVT_HTML_LINK_CLICKED,
            lambda event: webbrowser.open_new_tab(event.GetLinkInfo().GetHref(
            )), self.html_window)

        self.button_sizer = button_sizer = wx.StdDialogButtonSizer()
        self.ok_button = wx.Button(self, wx.ID_OK,
                                   "Let's get back to simulating!")
        self.ok_button.SetDefault()
        button_sizer.SetAffirmativeButton(self.ok_button)
        self.Bind(wx.EVT_BUTTON, self.on_ok, self.ok_button)
        button_sizer.AddButton(self.ok_button)
        button_sizer.Realize()
        button_sizer.SetMinSize((500, -1))
        v_sizer.Add(button_sizer, 0)

        self.SetSizer(v_sizer)
        self.Layout()

        self.timer = garlicsim_wx.general_misc.cute_timer.CuteTimer(self)
        self.timer.Start(40, oneShot=True)
        self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)

        self._rotate_image_hue()
示例#14
0
    def __init__(self, parent, getter, setter, emitter, lightness=1,
                 saturation=1, id=-1, title='Select hue',
                 pos=wx.DefaultPosition, size=wx.DefaultSize,
                 style=wx.DEFAULT_DIALOG_STYLE, name=wx.DialogNameStr):

        
        CuteDialog.__init__(self, parent, id, title, pos, size, style, name)
        
        self.getter = getter
        
        self.setter = setter
        
        assert isinstance(emitter, Emitter)
        self.emitter = emitter
        
        self.lightness = lightness

        self.saturation = saturation
        
        self.hue = getter()
        
        self.old_hue = self.hue
        
        self.old_hls = (self.old_hue, lightness, saturation)
        
        
        
        
        self.main_v_sizer = wx.BoxSizer(wx.VERTICAL)
        
        self.h_sizer = wx.BoxSizer(wx.HORIZONTAL)
        
        self.main_v_sizer.Add(self.h_sizer, 0)
        
        self.wheel = Wheel(self)
        
        self.h_sizer.Add(self.wheel, 0)
        
        self.v_sizer = wx.BoxSizer(wx.VERTICAL)
        
        self.h_sizer.Add(self.v_sizer, 0, wx.ALIGN_CENTER)
        
        self.comparer = Comparer(self)
        
        self.v_sizer.Add(self.comparer, 0, wx.RIGHT | wx.TOP | wx.BOTTOM,
                         border=10)
        
        self.textual = Textual(self)
        
        self.v_sizer.Add(self.textual, 0, wx.RIGHT | wx.TOP | wx.BOTTOM,
                         border=10)
                
        self.dialog_button_sizer = wx.StdDialogButtonSizer()
        
        self.main_v_sizer.Add(self.dialog_button_sizer, 0,
                              wx.ALIGN_CENTER | wx.ALL, border=10)
        
        self.ok_button = wx.Button(self, wx.ID_OK, 'Okay')
        self.dialog_button_sizer.AddButton(self.ok_button)
        self.ok_button.SetDefault()
        self.dialog_button_sizer.SetAffirmativeButton(self.ok_button)
        self.Bind(wx.EVT_BUTTON, self.on_ok, source=self.ok_button)
        
        self.cancel_button = wx.Button(self, wx.ID_CANCEL, 'Cancel')
        self.dialog_button_sizer.AddButton(self.cancel_button)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, source=self.cancel_button)
        self.dialog_button_sizer.Realize()

        
        self.SetSizer(self.main_v_sizer)
        self.main_v_sizer.Fit(self)
        
        
        self.emitter.add_output(self.update)
示例#15
0
    def __init__(self, step_profiles_controls, step_profile=None,
                 and_fork=False):
        '''
        Construct the `StepProfileDialog`.
        
        If given a `step_profile`, use it as a template. If it's `None`, start
        from scratch. Set `and_fork=True` if you intend to fork right after
        getting the step profile, though note it will only affect the labels;
        the actual forking is not done here.
        '''
        
        self.step_profiles_controls = step_profiles_controls
        
        self.gui_project = step_profiles_controls.gui_project
        assert isinstance(self.gui_project, garlicsim_wx.GuiProject)
        
        self.frame = step_profiles_controls.frame
        
        self.and_fork = and_fork
        
        self.simpack = self.gui_project.simpack
        
        self.simpack_grokker = simpack_grokker = \
            self.gui_project.simpack_grokker
        
        title = 'Create a new step profile' if not and_fork else \
                'Create a new step profile and fork with it'
        CuteDialog.__init__(self, step_profiles_controls.GetTopLevelParent(),
                            title=title)
        
        self.SetDoubleBuffered(True)
        
        self.original_step_profile = original_step_profile = step_profile
        
        del step_profile        
        
        
        self.hue = self.gui_project.step_profiles_to_hues.default_factory()
        
        self.step_functions_to_argument_dicts = \
            StepFunctionsToArgumentDicts(self.describe)
        
        self.step_functions_to_star_args = \
            collections.defaultdict(lambda: [])
        
        self.step_functions_to_star_kwargs = \
            collections.defaultdict(lambda: {})

        
        if original_step_profile:
            
            original_step_function = original_step_profile.step_function

            self.step_function = original_step_function
            
            initial_step_function_address = self.describe(
                original_step_function
            )

            original_argument_dict = collections.defaultdict(
                lambda: '',
                original_step_profile.getcallargs_result
            )

            self.step_functions_to_argument_dicts[original_step_function] = \
                dict((key, self.describe(value)) for (key, value) in
                 original_argument_dict.iteritems())
            

            original_arg_spec = cute_inspect.getargspec(original_step_function)
            
            
            if original_arg_spec.varargs:
                star_args_value = original_step_profile.getcallargs_result[
                    original_arg_spec.varargs
                ]
                
                self.step_functions_to_star_args[original_step_function] = \
                    [self.describe(value) for value in
                     star_args_value]
            
            
            if original_arg_spec.keywords:
                star_kwargs_value = original_step_profile.getcallargs_result[
                    original_arg_spec.keywords
                ]
                
                self.step_functions_to_star_kwargs[original_step_function] = \
                    dict((key, self.describe(value)) for (key, value)
                         in star_kwargs_value.iteritems())
                
            
            
            
        else:
            
            self.step_function = None
            
            if len(simpack_grokker.all_step_functions) >= 2:
                initial_step_function_address = ''
            else: # len(simpack_grokker.all_step_functions) == 1
                initial_step_function_address = self.describe(
                    simpack_grokker.default_step_function
                )
        
            
        #######################################################################
        # Setting up widgets and sizers:
        
        self.main_v_sizer = wx.BoxSizer(wx.VERTICAL)

        
        
        self.static_text = wx.StaticText(self, label="Choose a step function:")
        
        self.main_v_sizer.Add(self.static_text,
                              0,
                              wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT,
                              border=10)
        
        
        self.h_sizer = wx.BoxSizer(wx.HORIZONTAL)
        
        self.main_v_sizer.Add(
            self.h_sizer,
            0,
            wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,            
            border=10
        )
        
        
        self.hue_control = \
            garlicsim_wx.widgets.general_misc.hue_control.HueControl(
                self,
                lambda: getattr(self, 'hue'),
                lambda hue: setattr(self, 'hue', hue),
                emitter=None,
                lightness=0.8,
                saturation=1,
                dialog_title='Select hue for new step profile',
                size=(25, 20)
            )
        
        self.h_sizer.Add(
            self.hue_control,
            0,
            wx.ALIGN_CENTER_VERTICAL
        )
        
        
        self.h_sizer.AddSpacer(5)
        
        
        self.step_function_input = StepFunctionInput(
            self,
            value=initial_step_function_address
        )
        
        self.h_sizer.Add(
            self.step_function_input,
            0,
            wx.ALIGN_CENTER_VERTICAL,
        )
        
        
        self.static_function_text = StaticFunctionText(
            self,
            step_function=original_step_function if original_step_profile \
                          else None
        )
        
        self.h_sizer.Add(
            self.static_function_text,
            0,
            wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
            border=15
        )
        
        
        self.argument_control = ArgumentControl(
            self,
            original_step_function if original_step_profile else None
        )
        
        self.main_v_sizer.Add(
            self.argument_control,
            1,
            wx.ALIGN_CENTER_HORIZONTAL | wx.TOP,
            border=0
        )
        
        
        self.dialog_button_sizer = wx.StdDialogButtonSizer()
        
        self.main_v_sizer.Add(
            self.dialog_button_sizer,
            0,
            wx.ALIGN_CENTER | wx.ALL,
            border=10
        )
        
        ok_title = 'Create step profile' if not and_fork else \
                   'Create step profile and fork with it'
        self.ok_button = wx.Button(self, wx.ID_OK, title)
        self.dialog_button_sizer.AddButton(self.ok_button)
        self.ok_button.SetDefault()
        self.dialog_button_sizer.SetAffirmativeButton(self.ok_button)
        self.Bind(wx.EVT_BUTTON, self.on_ok, source=self.ok_button)
        
        self.cancel_button = wx.Button(self, wx.ID_CANCEL, 'Cancel')
        self.dialog_button_sizer.AddButton(self.cancel_button)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, source=self.cancel_button)
        self.dialog_button_sizer.Realize()
    
        
        self.SetSizer(self.main_v_sizer)
        self.main_v_sizer.Fit(self)
示例#16
0
    def __init__(self,
                 parent,
                 getter,
                 setter,
                 emitter,
                 lightness=1,
                 saturation=1,
                 id=-1,
                 title='Select hue',
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 style=wx.DEFAULT_DIALOG_STYLE,
                 name=wx.DialogNameStr):

        CuteDialog.__init__(self, parent, id, title, pos, size, style, name)

        self.getter = getter

        self.setter = setter

        assert isinstance(emitter, Emitter)
        self.emitter = emitter

        self.lightness = lightness

        self.saturation = saturation

        self.hue = getter()

        self.old_hue = self.hue

        self.old_hls = (self.old_hue, lightness, saturation)

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

        self.h_sizer = wx.BoxSizer(wx.HORIZONTAL)

        self.main_v_sizer.Add(self.h_sizer, 0)

        self.wheel = Wheel(self)

        self.h_sizer.Add(self.wheel, 0)

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

        self.h_sizer.Add(self.v_sizer, 0, wx.ALIGN_CENTER)

        self.comparer = Comparer(self)

        self.v_sizer.Add(self.comparer,
                         0,
                         wx.RIGHT | wx.TOP | wx.BOTTOM,
                         border=10)

        self.textual = Textual(self)

        self.v_sizer.Add(self.textual,
                         0,
                         wx.RIGHT | wx.TOP | wx.BOTTOM,
                         border=10)

        self.dialog_button_sizer = wx.StdDialogButtonSizer()

        self.main_v_sizer.Add(self.dialog_button_sizer,
                              0,
                              wx.ALIGN_CENTER | wx.ALL,
                              border=10)

        self.ok_button = wx.Button(self, wx.ID_OK, 'Okay')
        self.dialog_button_sizer.AddButton(self.ok_button)
        self.ok_button.SetDefault()
        self.dialog_button_sizer.SetAffirmativeButton(self.ok_button)
        self.Bind(wx.EVT_BUTTON, self.on_ok, source=self.ok_button)

        self.cancel_button = wx.Button(self, wx.ID_CANCEL, 'Cancel')
        self.dialog_button_sizer.AddButton(self.cancel_button)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, source=self.cancel_button)
        self.dialog_button_sizer.Realize()

        self.SetSizer(self.main_v_sizer)
        self.main_v_sizer.Fit(self)

        self.emitter.add_output(self.update)