예제 #1
0
    def __init__(self, **kwargs):
        super(Themes, self).__init__(**kwargs)
        self.orientation = "vertical"
        self.selector = MyBoxLayout(padding=dp(10))
        self.image_item = MDSwiper(
            swipe_distance=dp(40), size_hint_y=None, height=dp(200), width_mult=6
        )
        self.image_item.bind(on_swipe=lambda a: self.on_theme_swipe(a))
        for x, name in enumerate([j for j in theme_image]):
            self.item = Swiper(source=str(x + 1), title=name)
            if name == config_data["theme"]:
                self.item.layout.select.active = self.item.hover = True

            self.theme_check.append(self.item.layout.select)
            self.image_item.add_widget(self.item)
        self.theme()
        self.items = self.image_item.get_items()
        self.selector.add_widget(self.image_item)

        self.add_widget(MyBoxLayout(size_hint_x=0.1))
        self.add_widget(self.selector)
        self.image_item.set_current(list(theme_image.keys()).index(config_data["theme"]))

        self.theme_active = MLabel(
            text=f"{self.active_theme.parent.parent.title} is applied!"
        )
        self.add_widget(self.theme_active)

        self.restart_text = MLabel(size_hint_y=0.4)
        self.add_widget(self.restart_text)
        Window.bind(
            on_key_up=lambda *args: self.image_item.swipe_left()
            if args[2] == 80
            else self.image_item.swipe_right()
        )
예제 #2
0
    def __init__(self, *args, **kwargs):
        super(Page, self).__init__(**kwargs)
        self.orientation = "vertical"

        self.textbox = MyBoxLayout(padding=[dp(10), 0], size_hint_y=0.3)
        self.text_container = ScrollView(
            scroll_type=["bars"],
            effect_cls="ScrollEffect",
            bar_width=15,
            do_scroll_y=False,
        )

        self.entry = Text(
            size_hint=(None, 1),
            base_direction="rtl",
            font_size="75dp",
            unfocus_on_touch=False,
        )

        self.preview = MLabel(
            halign="right",
            valign="bottom",
            font_size=self.entry.font_size // 3,
            color=self.entry.foreground_color[:3] + [0.8],
            size_hint_y=0.1,
            padding_x=10,
            markup=True,
            text=self.preview_text,
        )
        self.preview.bind(on_ref_press=lambda object, text: setattr(
            self.entry, "text", eval(text)))
        self.preview.bind(
            on_ref_press=lambda object, text: setattr(object, "text", ""))

        self.layout = ButtonStack(
            size_hint=(1, 0.5),
            spacing=5,
            rows=self.rows,
            cols=self.cols,
            font_size=dp(19),
            text_list=self.text_list,
        )

        self.text_container.add_widget(self.entry)
        self.textbox.add_widget(self.text_container)
        Clock.schedule_interval(self.scroll_focus, 0.1)

        self.layout.buttons[0][0].text = self.page_name
        self.layout.size_change(0, 0, 2)
        self.layout.size_change(-1, -1, 2)
        self.spacing = 5
        for widget in (self.preview, self.textbox, self.layout):
            self.add_widget(widget)
예제 #3
0
class MainScreen(EffectWidget):
    def options_open(self, button, *args, **kwargs):
        global hover
        self.effects = [HorizontalBlurEffect(size=10), VerticalBlurEffect(size=10)]
        hover[0] = False

    def options_close(self, *args, **kwargs):
        global hover
        self.effects = []
        hover[0] = True

    def settings_open(self, *args, **kwargs):
        self.effect_layout.settings.open(self.effect_layout)
        return self

    def text_halign(self, *args):
        input = self.pages.current_screen.children[0].entry
        top = (input.parent.size[1] // 3) - input.parent.parent.parent.preview.size[
            1
        ] // 2
        input.padding = [0, top]

    def __init__(self, *args, **kwargs):
        super(MainScreen, self).__init__(**kwargs)
        self.effect_layout = MyBoxLayout(orientation="vertical")
        self.header_buttons = MyBoxLayout(size_hint_y=0.1)
        self.header_buttons.add_widget(ClipButtons(size_hint_x=0.3))
        self.header_buttons.add_widget(MyBoxLayout(size_hint_x=0.4))
        self.header_buttons.history = Icon(icon="history", size_hint_x=0.1)
        self.header_buttons.history_modal = ModalView(size_hint=(0.9, 0.8))
        self.header_buttons.history_modal.add_widget(History(main = self))
        self.header_buttons.history.bind(
            on_release=self.header_buttons.history_modal.children[0].refresh
        )
        self.header_buttons.history.bind(
            on_release=self.header_buttons.history_modal.open
        )
        self.header_buttons.history.bind(on_release=self.options_open)
        self.header_buttons.history_modal.bind(on_dismiss=self.options_close)

        self.header_buttons.add_widget(self.header_buttons.history)
        self.pages = Pages(size_hint=(1, 0.9))

        self.effect_layout.add_widget(self.header_buttons)
        self.effect_layout.add_widget(self.pages)

        self.add_widget(self.effect_layout)

        self.effect_layout.settings = ModalView(size_hint=(0.9, 0.9))
        self.settings_page = Settings(padding=5, spacing=0)
        self.settings_page.save_buttons.save_button.bind(
            on_release=self.effect_layout.settings.dismiss
        )
        self.effect_layout.settings.add_widget(self.settings_page)
        self.effect_layout.settings.bind(on_dismiss=self.options_close)

        Clock.schedule_interval(self.text_halign, 0.1)

        Window.set_icon('icon.png')
        Window.set_title('Calculator')
예제 #4
0
    def __init__(self, *args, **kwargs):
        super(MainScreen, self).__init__(**kwargs)
        self.effect_layout = MyBoxLayout(orientation="vertical")
        self.header_buttons = MyBoxLayout(size_hint_y=0.1)
        self.header_buttons.add_widget(ClipButtons(size_hint_x=0.3))
        self.header_buttons.add_widget(MyBoxLayout(size_hint_x=0.4))
        self.header_buttons.history = Icon(icon="history", size_hint_x=0.1)
        self.header_buttons.history_modal = ModalView(size_hint=(0.9, 0.8))
        self.header_buttons.history_modal.add_widget(History(main = self))
        self.header_buttons.history.bind(
            on_release=self.header_buttons.history_modal.children[0].refresh
        )
        self.header_buttons.history.bind(
            on_release=self.header_buttons.history_modal.open
        )
        self.header_buttons.history.bind(on_release=self.options_open)
        self.header_buttons.history_modal.bind(on_dismiss=self.options_close)

        self.header_buttons.add_widget(self.header_buttons.history)
        self.pages = Pages(size_hint=(1, 0.9))

        self.effect_layout.add_widget(self.header_buttons)
        self.effect_layout.add_widget(self.pages)

        self.add_widget(self.effect_layout)

        self.effect_layout.settings = ModalView(size_hint=(0.9, 0.9))
        self.settings_page = Settings(padding=5, spacing=0)
        self.settings_page.save_buttons.save_button.bind(
            on_release=self.effect_layout.settings.dismiss
        )
        self.effect_layout.settings.add_widget(self.settings_page)
        self.effect_layout.settings.bind(on_dismiss=self.options_close)

        Clock.schedule_interval(self.text_halign, 0.1)

        Window.set_icon('icon.png')
        Window.set_title('Calculator')
예제 #5
0
    def __init__(self, **kwargs):
        super(ButtonStack, self).__init__(**kwargs)
        self.stack = StackLayout()
        text_var = 0

        for row in range(self.rows):
            row_list = []
            for cell in range(self.cols):

                padding = [self.spacing * 0.5] * 4
                if row == 0:
                    padding[1] = 0
                if row == self.rows - 1:
                    padding[3] = 0
                if cell == 0:
                    padding[0] = 0
                if cell == self.cols - 1:
                    padding[2] = 0

                button_box = BoxLayout(
                    size_hint_x=1 / self.cols,
                    size_hint_y=1 / self.rows,
                    padding=padding,
                )
                button = MButton(font_size=self.font_size,
                                 text=self.text_list[text_var])
                text_var += 1
                if button.text == "rm":
                    continue
                button_box.add_widget(button)
                self.stack.add_widget(button_box)
                row_list.append(button)

            self.buttons.append(row_list)

        for index_, button_ in enumerate(self.buttons):
            for index, button in enumerate(button_):
                if button.text == "db":
                    button.disabled = True
                    button.text = ""
                elif button.text in ["and", "between"]:
                    button.hover = False
                    button.ripple = False
                elif "include" in button.text:
                    button.toggle_state = True
                elif button.text in ["INV", "RAD"]:
                    button.toggle_state = True
                    if (config_data["inverse"] and button.text == "INV") or (
                            config_data["radian"] and button.text == "RAD"):
                        button.state = "down"
                        button.color = button.hover_color
                    if button.text == 'RAD':

                        button.bind(on_release=lambda button: setattr(
                            button, 'text', 'RAD'
                            if button.text == 'DEG' else 'DEG'))
                    if button.text == 'INV':
                        button.bind(on_release=self.inverse_change)
                else:
                    if button.text not in [" ", "..."]:
                        button.bind(on_release=lambda button=button: self.
                                    parent.entry.insert_text(button.text))

        self.options = ModalView(size_hint=(0.4, 0.6))
        self.options_layout = MyBoxLayout(orientation="vertical")
        for options_button_text in config_data["page_list"]:
            if options_button_text["mode"] != current_page:
                options_button = MButton(text=options_button_text["mode"],
                                         modal_button=True)
                self.options_layout.add_widget(options_button)
                options_button.bind(
                    on_release=lambda options_button=options_button: self.
                    options_select(options_button))
        self.options.add_widget(self.options_layout)
        self.options.bind(on_dismiss=lambda button: self.parent.parent.parent.
                          parent.parent.options_close(button))

        self.buttons[0][0].bind(on_release=self.options.open)
        self.buttons[0][0].bind(on_release=lambda button: self.parent.parent.
                                parent.parent.parent.options_open(button))

        self.buttons[-1][0].bind(
            on_release=lambda button: self.parent.parent.parent.parent.parent.
            effect_layout.settings.open())
        self.buttons[-1][0].bind(on_release=lambda button: self.parent.parent.
                                 parent.parent.parent.options_open(button))
        self.spacing = 0

        self.quantity_drop = Drop(title="quantity",
                                  values=convert_quantities,
                                  size_hint=(0.6, 0.6))
        self.from_drop = Drop(
            title="from",
            values=eval("convert_unit_" + convert_quantities[0]),
            size_hint=(0.6, 0.6),
        )

        self.to_drop = Drop(
            title="to",
            values=eval("convert_unit_" + convert_quantities[0]),
            default=eval("convert_unit_" + convert_quantities[0])[1],
            size_hint=(0.6, 0.6))

        self.quantity_drop.bind(
            on_dismiss=lambda button: self.drop_close(button))

        self.from_drop.bind(on_dismiss=lambda button: self.drop_close(button))
        self.to_drop.bind(on_dismiss=lambda button: self.drop_close(button))
        self.add_widget(self.stack)
예제 #6
0
class ButtonStack(MyBoxLayout):
    rows = NumericProperty(1)
    cols = NumericProperty(1)
    buttons = ListProperty()
    font_size = NumericProperty()
    text_list = ListProperty()

    def drop_close(self, button):
        self.parent.parent.parent.parent.parent.options_close(button)
        if button == self.quantity_drop:
            self.buttons[0][1].text = self.parent.entry.quantity = button.value
            self.from_drop.values = self.to_drop.values = eval(
                "convert_unit_" + button.value)
            self.from_drop.refresh()
            self.to_drop.refresh()
            self.buttons[1][1].text = self.from_drop.values[0]
            self.buttons[1][3].text = self.to_drop.values[1]
        elif button == self.from_drop:
            self.buttons[1][
                1].text = self.parent.entry.from_unit = button.value
        elif button == self.to_drop:
            self.buttons[1][3].text = self.parent.entry.to_unit = button.value

    def size_change(self, row, column, new):
        self.buttons[row][column].parent.size_hint_x *= new

    def options_select(self, button, *args, **kwargs):
        global current_page
        self.options.dismiss()
        current_page[0] = button.text
        self.parent.parent.parent.page_change(button)

    def inverse_change(self, button):

        if button.state == 'down':
            text = config_data['page_list'][1]['inv_text']
        else:
            text = config_data['page_list'][1]['text']

        c = 1
        for index, row in enumerate(self.buttons):
            for index_, cell in enumerate(row):
                if (index == 0 and index_ == 0) or index > 3:
                    c += 1
                    continue
                elif cell.text == 'log' and text == config_data['page_list'][
                        1]['inv_text']:
                    cell.text = str(config_data['base']) + '\u00aa'
                    c += 1
                    continue
                cell.text = text[c] if text[c] not in ['rm', ' '] else text[c +
                                                                            1]
                c += 1

    def __init__(self, **kwargs):
        super(ButtonStack, self).__init__(**kwargs)
        self.stack = StackLayout()
        text_var = 0

        for row in range(self.rows):
            row_list = []
            for cell in range(self.cols):

                padding = [self.spacing * 0.5] * 4
                if row == 0:
                    padding[1] = 0
                if row == self.rows - 1:
                    padding[3] = 0
                if cell == 0:
                    padding[0] = 0
                if cell == self.cols - 1:
                    padding[2] = 0

                button_box = BoxLayout(
                    size_hint_x=1 / self.cols,
                    size_hint_y=1 / self.rows,
                    padding=padding,
                )
                button = MButton(font_size=self.font_size,
                                 text=self.text_list[text_var])
                text_var += 1
                if button.text == "rm":
                    continue
                button_box.add_widget(button)
                self.stack.add_widget(button_box)
                row_list.append(button)

            self.buttons.append(row_list)

        for index_, button_ in enumerate(self.buttons):
            for index, button in enumerate(button_):
                if button.text == "db":
                    button.disabled = True
                    button.text = ""
                elif button.text in ["and", "between"]:
                    button.hover = False
                    button.ripple = False
                elif "include" in button.text:
                    button.toggle_state = True
                elif button.text in ["INV", "RAD"]:
                    button.toggle_state = True
                    if (config_data["inverse"] and button.text == "INV") or (
                            config_data["radian"] and button.text == "RAD"):
                        button.state = "down"
                        button.color = button.hover_color
                    if button.text == 'RAD':

                        button.bind(on_release=lambda button: setattr(
                            button, 'text', 'RAD'
                            if button.text == 'DEG' else 'DEG'))
                    if button.text == 'INV':
                        button.bind(on_release=self.inverse_change)
                else:
                    if button.text not in [" ", "..."]:
                        button.bind(on_release=lambda button=button: self.
                                    parent.entry.insert_text(button.text))

        self.options = ModalView(size_hint=(0.4, 0.6))
        self.options_layout = MyBoxLayout(orientation="vertical")
        for options_button_text in config_data["page_list"]:
            if options_button_text["mode"] != current_page:
                options_button = MButton(text=options_button_text["mode"],
                                         modal_button=True)
                self.options_layout.add_widget(options_button)
                options_button.bind(
                    on_release=lambda options_button=options_button: self.
                    options_select(options_button))
        self.options.add_widget(self.options_layout)
        self.options.bind(on_dismiss=lambda button: self.parent.parent.parent.
                          parent.parent.options_close(button))

        self.buttons[0][0].bind(on_release=self.options.open)
        self.buttons[0][0].bind(on_release=lambda button: self.parent.parent.
                                parent.parent.parent.options_open(button))

        self.buttons[-1][0].bind(
            on_release=lambda button: self.parent.parent.parent.parent.parent.
            effect_layout.settings.open())
        self.buttons[-1][0].bind(on_release=lambda button: self.parent.parent.
                                 parent.parent.parent.options_open(button))
        self.spacing = 0

        self.quantity_drop = Drop(title="quantity",
                                  values=convert_quantities,
                                  size_hint=(0.6, 0.6))
        self.from_drop = Drop(
            title="from",
            values=eval("convert_unit_" + convert_quantities[0]),
            size_hint=(0.6, 0.6),
        )

        self.to_drop = Drop(
            title="to",
            values=eval("convert_unit_" + convert_quantities[0]),
            default=eval("convert_unit_" + convert_quantities[0])[1],
            size_hint=(0.6, 0.6))

        self.quantity_drop.bind(
            on_dismiss=lambda button: self.drop_close(button))

        self.from_drop.bind(on_dismiss=lambda button: self.drop_close(button))
        self.to_drop.bind(on_dismiss=lambda button: self.drop_close(button))
        self.add_widget(self.stack)
예제 #7
0
    def __init__(self, **kwargs):
        super(About, self).__init__(**kwargs)
        self.padding = [75, 30]
        self.header = MLabel(
            text="Calculator",
            valign="top",
            bold=True,
            font_size=dp(self.font_size*1.5),
            size_hint_y=0.6,
        )
        first_line = "This project was made keeping the power of [ref=https://www.python.org/][b]Python[/b][/ref] and flexibillity of open source software in mind. "
        second_line = "We have strived to bring you the richness of [ref=https://material.io/design][b]Google's Material Design[/b][/ref] via [ref=https://kivy.org/#home][b]Kivy[/b][/ref] and [ref=https://kivymd.readthedocs.io/en/latest/][b]KivyMD[/b][/ref] "
        third_line = "alongwith the good old [ref=https://python-pillow.org/][b]Pillow[/b][/ref] and [ref=https://docs.python.org/3/library/math.html][b]Math[/b][/ref] libraries. "
        fourth_line = "\n\nHope you have a great time with this completely free and open source application! "
        self.body1 = MLabel(
            text=first_line+second_line+third_line+fourth_line,
            markup=True,
            font_size=dp(self.font_size*1),
            halign='justify',
            valign="top"
        )

        self.footer = MyBoxLayout()
        credit_text1 = "[ref=https://www.pexels.com/photo/black-and-grey-casio-scientific-calculator-showing-formula-220301/][b]splash image[/b][/ref] by [ref=https://www.pexels.com/@pixabay][b]Pixabay[/b][/ref] from [ref=https://www.pexels.com/][b]Pexels[/b][/ref]"
        credit_text2 = "[ref=https://www.iconarchive.com/show/button-ui-system-apps-icons-by-blackvariant/Calculator-icon.html][b]icon[/b][/ref] by [ref=https://www.iconarchive.com/artist/blackvariant.html][b]BlackVariant[/b][/ref] from [ref=https://www.iconarchive.com/][b]IconArchive[/b][/ref]"
        credit_text3 = "conversion rates by [ref=https://www.fxexchangerate.com/][b]FxexchangeRate[/b][/ref]"
        self.footer.splash_credit = MLabel(

            text=credit_text1+'\n'+credit_text2+'\n'+credit_text3,
            markup=True,
            font_size=dp(self.font_size*0.8),
            valign="bottom",
            halign="left",
            size_hint=(0.4, 1),
        )

        self.footer.source_code = MLabel(
            text="[ref=https://www.github.com/shreyash/project-calculator][b]source code here[/b][/ref]",
            font_size=dp(self.font_size*0.9),
            valign="bottom",
            halign="center",
            markup=True,
            size_hint=(0.2, 1)
        )
        self.footer.credits = MLabel(
            text="Aman Singh (XII-E)\nShreyash Singh (XII-D)\nSuyash Kumar (XII-D)\nVineet Pratap Singh (XII-D)\n[ref=http://dpseldeco.com/][b]Delhi Public School Eldeco[/b][/ref]",
            markup=True,
            font_size=dp(self.font_size*0.9),
            halign="right",
            valign="bottom",
            size_hint=(0.4, 1),
        )

        self.footer.add_widget(self.footer.splash_credit)
        self.footer.add_widget(self.footer.source_code)
        self.footer.add_widget(self.footer.credits)

        self.footer.source_code.bind(
            on_ref_press=lambda args, args1: webbrowser.get().open_new_tab(args1)
        )
        self.footer.splash_credit.bind(
            on_ref_press=lambda args, args1: webbrowser.get().open_new_tab(args1)
        )
        self.body1.bind(
            on_ref_press=lambda args, args1: webbrowser.get().open_new_tab(args1)
        )
        self.footer.credits.bind(
            on_ref_press=lambda args, args1: webbrowser.get().open_new_tab(args1)
        )

        self.add_widget(self.header)
        self.add_widget(self.body1)
        self.add_widget(self.footer)
예제 #8
0
class Themes(MyBoxLayout):
    theme_check = ListProperty()
    active_theme = ObjectProperty()
    items = ListProperty()

    def on_theme_swipe(self, *args):

        for item in self.items:

            if item == args[0].get_current_item():
                item.hover = True
                item.layout.image_container.elevation = 5
                item.on_enter()
                Clock.schedule_once(item.on_leave, 1.5)
            else:
                item.on_leave()
                item.layout.image_container.elevation = 0
                item.hover = False

    def theme(self, *args):
        c = 0
        
        for x in self.theme_check:
            if x.state == "down":
                c += 1
        if c != 1:
            self.active_theme.state = "down"
        elif c == 1:
            for x in self.theme_check:
                if x.state == "down":
                    self.active_theme = x

    def __init__(self, **kwargs):
        super(Themes, self).__init__(**kwargs)
        self.orientation = "vertical"
        self.selector = MyBoxLayout(padding=dp(10))
        self.image_item = MDSwiper(
            swipe_distance=dp(40), size_hint_y=None, height=dp(200), width_mult=6
        )
        self.image_item.bind(on_swipe=lambda a: self.on_theme_swipe(a))
        for x, name in enumerate([j for j in theme_image]):
            self.item = Swiper(source=str(x + 1), title=name)
            if name == config_data["theme"]:
                self.item.layout.select.active = self.item.hover = True

            self.theme_check.append(self.item.layout.select)
            self.image_item.add_widget(self.item)
        self.theme()
        self.items = self.image_item.get_items()
        self.selector.add_widget(self.image_item)

        self.add_widget(MyBoxLayout(size_hint_x=0.1))
        self.add_widget(self.selector)
        self.image_item.set_current(list(theme_image.keys()).index(config_data["theme"]))

        self.theme_active = MLabel(
            text=f"{self.active_theme.parent.parent.title} is applied!"
        )
        self.add_widget(self.theme_active)

        self.restart_text = MLabel(size_hint_y=0.4)
        self.add_widget(self.restart_text)
        Window.bind(
            on_key_up=lambda *args: self.image_item.swipe_left()
            if args[2] == 80
            else self.image_item.swipe_right()
        )
예제 #9
0
    def __init__(self, **kwargs):
        super(General, self).__init__(**kwargs)
        for index, option_tuple in enumerate(
            (
                (
                    "math-compass",
                    "Set the base",
                    "for logarithmic calculations",
                    "base",
                ),
                (
                    "math-sin",
                    "Inverse on start",
                    "keep Inverse toggle on when starting the application",
                ),
                (
                    "angle-acute",
                    "Radian on start",
                    "keep Radian toggle on when starting the application",
                ),
                (
                    "history",
                    "History length",
                    "the latest entry will replace the oldest entry",
                    "history_length",
                ),
                (
                    "image-outline",
                    "Splash screen",
                    "turning this off won't affect the loading time",
                    "splash",
                ),
            )
        ):

            container = Container(
                padding=[0, 0, dp(20), 0] if index in [1, 2, 4] else [0] * 4
            )
            if index in [1, 2, 4]:
                container.add_widget(
                    SwitchText(
                        index=index,
                        down=True
                        if self.selected[list(self.selected.keys())[index]] == 1
                        else False)
                )
            else:
                container.add_widget(
                    TextField(
                        text=str(self.selected[option_tuple[3]]),
                        title=option_tuple[3],
                        halign="center",
                        multiline=False
                    )
                )
                input = container.children[0]
                input.bind(
                    on_text_validate=lambda input=input, **kwargs: self.selected.update(
                        {input.title: input.text}
                    )
                )

            self.setting_option = ListItem(
                icon=option_tuple[0],
                text=option_tuple[1],
                secondary_text=option_tuple[2],
                container=container,
                width_mult=0.5 if index in [1, 2, 4] else 0.6,
            )

            self.setting_option.add_widget(container)
            self.add_widget(self.setting_option)

        self.add_widget(MyBoxLayout(size_hint_y=0.3))