Exemple #1
0
    def __is_new_fig(self, new_fig_type: str, force_new_fig: bool = False):
        try:
            assert self.fig  # look the figure is created or not
            if get_config("new_fig", False) or force_new_fig:
                raise AttributeError(
                    "a fig was created because of force config set by policy.")

            elif self.fig_type != new_fig_type:
                option = self.__show_message_window(
                    TRANS_TO_POLAR_MESSAGE, wx.OK | wx.CANCEL | wx.OK_DEFAULT)

                fprintf(f"{new_fig_type} change fig event raised. {option=}",
                        self_=self.__is_new_fig)
                if option == wx.ID_OK:
                    if new_fig_type == '2d':
                        self.__new_fig2d()
                    elif new_fig_type == '3d':
                        self.__new_fig3d()
                    else:
                        self.__new_fig2d_polar()
                elif option == wx.ID_CANCEL:
                    raise KeyboardInterrupt(
                        "User has canceled this operation.")

        except AttributeError as _:
            fprintf(f"No {new_fig_type} figure left, creating fig. {_})",
                    self_=self.__is_new_fig)
            if new_fig_type == '2d':
                self.__new_fig2d()
            elif new_fig_type == '3d':
                self.__new_fig3d()
            else:
                self.__new_fig2d_polar()
Exemple #2
0
def save(file_type=get_config("save_format"), file_dir=None) -> str:
    if current_plt is None:
        raise RaisedCritical(message="the current_plot object haven't create yet.", module_name=save)
    if file_dir is None:
        file_dir = f'Saved Image\\figure{str(get_config("fig_number", 1))}'
    fprintf("save the file with " + file_type + ' in ' + file_dir)
    current_plt.export_fig(file_type, file_dir)
    set_config(fig_number=get_config("fig_number", 1) + 1)
    return f'{file_dir}.{str(file_type)}'
Exemple #3
0
def __analyze_function(input_str: str) -> str:
    """
    transfer the syntax from python to the math -- adding auto "*" sign between signed variables
    :param input_str: ~
    :return: the modified input str
    """
    var_element = []  # the variables and element which used in the input_str. it contains all the element (signs and
    # variables)
    var_element_category = []  # the category of the
    element_index: int = 0  # the count of the next index which will be analyzed.
    is_negative: bool = False  # is the current situation negative
    element_str: str  # the current var

    while True:
        element_str, element_index, element_content = __analyze_find_vars(input_str, element_index)
        if not element_content:
            break

        # save the negative sign.
        if element_content == CONST_MINUS and (var_element_category == [] or var_element_category[-1] in (CONST_SIGNS, CONST_FUNCTION)):
            is_negative = not is_negative
            continue

        if is_negative:
            var_element.append('-' + element_str)
            is_negative = False
        else:
            var_element.append(element_str)
        var_element_category.append(element_content)

    fprintf(f"{var_element=}, {var_element_category=}", self_=__analyze_function)
    var_element_category, var_element = __analyze_add_signs(var_element, var_element_category)
    input_str = ' ' + ' '.join(var_element) + ' '
    input_str = input_str.replace("^", "**")
    fprintf(f"{input_str=}", self_=__analyze_function)
    return input_str
Exemple #4
0
    def start_plot_button(self, new_fig: bool):
        if not self.__is_runable():
            wx.MessageBox(
                "please input your math equation or commands in the box!")
            return None

        try:
            self.trig_set_basic_opt()
        except SyntaxError:
            wx.MessageBox(
                "Please check the syntax of the expression in domain/range settings. Only Python syntax could"
                " be input in the box.")
            return None
        except Exception as _:
            wx.MessageBox(
                f"A error occurs when trying to interpret the expression in domain/range settings: {_}"
            )
            return None

        inputed_function: str = self.tc_equ.GetValue()

        fprintf(
            f"python_mode = {(python_mode := self.input_syntax.GetValue())}",
            self_=self.start_plot_button)

        if inputed_function != '':
            current_line = 'unknown'
            function = 'unknown'
            try:  # TODO: move these
                if python_mode is False:  # it is none python mode
                    current_line = 1
                    function: str  # the input equation in each line
                    for function in inputed_function.split('\n'):
                        if not function.isspace() and function != '':
                            fprintf(f"{function=}",
                                    self_=self.start_plot_button)
                            Benjamin.plot(function, False, new_fig)
                            new_fig = False
                        current_line += 1

                else:
                    fprintf(f"{inputed_function=}",
                            self_=self.start_plot_button)
                    Benjamin.plot(inputed_function, True, new_fig)
                    wx.MessageBox("Done!")

            except KeyboardInterrupt:
                fprintf(
                    f"User has canceled the operation in line {current_line}",
                    self_=self.start_plot_button)
                wx.MessageBox(
                    f"User has canceled the operation in line {current_line}")
            except Exception as _:
                fprintf(
                    f"A error occurs during the executing progress in line {current_line}: '{function}': {str(_)}",
                    self_=self.start_plot_button)
                wx.MessageBox(
                    f"A error occurs during the executing progress in line {current_line}: '{function}' \n {str(_)}"
                )
            Benjamin.show()
        return None
Exemple #5
0
class Donald(wx.Frame):
    dpi_scale: float = config["dpi_scale"]
    fprintf(f"the settings opened with {dpi_scale=} on {__name__}")

    x = lambda me, _, __: (int(_ * me.dpi_scale), int(__ * me.dpi_scale))

    ui_xpoz_plus: int = 0  # used to set the start xpoz for the elements.

    current_poz_ = 2  # used to set the start ypoz for the elements

    @debug_log
    def __init__(self):
        wx.Frame.__init__(self, None, title='Settings Frame')
        wx.Frame.SetBackgroundColour(self, 'white')
        self.panel = wx.ScrolledWindow(self)
        self.Bind(wx.EVT_CLOSE, self.on_close)
        self.SetSize(_ := (STATIC_WINDOW_SIZE[0] * self.dpi_scale, STATIC_WINDOW_SIZE[1] * self.dpi_scale))
        self.SetMaxSize(_)
        self.SetMinSize(_)
        self.Center()

        self.set_font()
        self.set_panel()
        self.panel.SetScrollbars(-1, 12 * self.dpi_scale, -1, (self.current_poz_ + 50) / 12)

        self.panel_elements = []
        for keys in self.__dict__:
            if keys.startswith('input'):
                self.panel_elements.append(keys)

        self.display_value_to_frame()

    def get_next_poz(self, const: int) -> int:
        """
        this is the recommended method for getting the position. returns the raw poz
        :param const: the constant value of the nest position
        :return: the y value of the position
        """
        self.current_poz_ += [
            0,
            STATIC_SMALL_GAP,
            STATIC_MID_GAP,
            STATIC_LARGE_GAP] \
            [const]
        return self.current_poz_

    # noinspection PyAttributeOutsideInit,PyUnresolvedReferences
    def set_font(self):
        self.winfont = wx.Font(9, wx.MODERN, wx.NORMAL, wx.NORMAL, False, "Segoe UI")
        self.title_font = wx.Font(13, wx.MODERN, wx.ITALIC, wx.BOLD, False, "Segoe UI")
        self.large_winfont = wx.Font(10, wx.MODERN, wx.NORMAL, wx.BOLD, False, "Segoe UI")

    # noinspection PyAttributeOutsideInit
    def set_panel(self):

        def header():
            wx.StaticText(self.panel, pos=self.x(10, self.get_next_poz(0) + 3),
                          label="This is the setting utility of the Datanalyze. \nChange the settings are NOT "
                                "recommended, \nunless for advanced users.").SetFont(self.large_winfont)

            reset_btn = wx.Button(self.panel, pos=self.x(40, self.get_next_poz(CONST_LARGE_GAP) + 5),
                                  label="RESET ALL SETTINGS AND EXIT.", size=self.x(240, 40))
            reset_btn.SetFont(self.winfont)
            reset_btn.Bind(wx.EVT_BUTTON, self.on_reset)

        def get_input(ypoz: Union[int, float], /, font: wx.Font = self.winfont) -> wx.TextCtrl:
            _ = wx.TextCtrl(self.panel, pos=self.x(200 + self.ui_xpoz_plus, ypoz), size=self.x(100, 22))
            _.SetFont(font)
            return _

        def get_checkbox(content: str, constant: int = CONST_SMALL_GAP, /, font: wx.Font = self.winfont):
Exemple #6
0
 def __init__(self, *args):
     fprintf(f"Raised return triggered. {args=}", self_=self)
     self.args = args
     pass