Exemple #1
0
class OptionsBox(ScrollView):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.list = MDList()
        self.add_widget(self.list)

    @property
    def selected_option(self):
        for option in self.list.children:
            if option.selected:
                return option
        else:
            return None

    @property
    def selected_option_index(self):
        for i, option in enumerate(self.list.children):
            if option.selected:
                return i
        else:
            return None

    def select_next(self):
        try:
            self.select_option(self.selected_option_index - 1)
        except Exception:
            self.select_option(0)

    def select_previous(self):
        try:
            self.select_option(self.selected_option_index + 1)
        except Exception:
            self.select_option(0)

    def select_option(self, index):
        if len(self.list.children) + 1 < index:
            return
        [option.deselect() for option in self.list.children if option.selected]
        self.list.children[index].select()

    def refresh_options(self, items):
        self.remove_items()
        self.add_items(items)
        if len(items):
            self.select_option(len(items) - 1)

    def add_items(self, items):
        for idx, item in enumerate(items):
            i = SingleOption(text=item['title'],
                             secondary_text=item.get('subtitle', ''),
                             command=item.get('command', None))
            self.list.add_widget(i)

    def remove_items(self):
        self.list.clear_widgets()
class ProductPopup(Popup):
    def __init__(self, product, MDlist, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.title = f"{product.name}"
        self.MDlist = MDlist
        self.product = product
        self.size_hint = (0.7, 0.9)

        layout = BoxLayout()
        layout.orientation = "vertical"

        layout.add_widget(
            Label(text=f"Product: {product.name}", size_hint=(1, 0.3)))
        layout.add_widget(
            Label(text=f"Cost: £{round(product.cost, 2)}", size_hint=(1, 0.3)))

        scroll = ScrollView()
        self.Mlist = MDList()
        self.build_list()

        scroll.add_widget(self.Mlist)
        layout.add_widget(scroll)

        btn_layout = BoxLayout(size_hint=(1, 0.3))
        btn_layout.add_widget(
            MDRectangleFlatButton(text="Return", on_release=self.dismiss))
        btn_layout.add_widget(
            MDRectangleFlatButton(text="Discard",
                                  on_release=self.discard_product))
        layout.add_widget(btn_layout)
        self.content = layout

    def discard_product(self, td):
        app = MDApp.get_running_app()
        app.customconfig.remove_product(self.product.name)
        self.MDlist()
        self.dismiss()

    def build_list(self):
        self.Mlist.clear_widgets()
        app = MDApp.get_running_app()
        for i in self.product.materials:
            item = MaterialListItem(i, self.build_list)
            item.text = f"{i.name}"
            item.secondary_text = f"Cost: £{round(i.unit_price, 2)}"
            icon = IconRightWidget(icon="layers-outline")
            icon.bind(on_release=item.show_popup)
            item.add_widget(icon)
            item.bind(on_release=item.show_popup)
            self.Mlist.add_widget(item)
Exemple #3
0
class ListScrollApp(MDApp):

    def __init__(self, **kwargs):
        super(ListScrollApp, self).__init__(**kwargs)
        self.Main_Win    = MDFloatLayout()
        self.Rel_Win     = RelativeLayout()
        self.List_Scr    = ScrollView()
        self.The_List    = MDList()
        return

    def build(self):
        #######################################
        self.Main_Win.size = Window.size
        Xc = int(self.Main_Win.width * 0.5)
        Yc = int(self.Main_Win.height * 0.5)
        #######################################
        self.Rel_Win.size_hint = (None, None)
        self.Rel_Win.width     = int(self.Main_Win.width * 0.3)
        self.Rel_Win.height    = int(self.Main_Win.height * 0.5)
        self.Rel_Win.x         = Xc - int(self.Rel_Win.width * 0.5)
        self.Rel_Win.y         = Yc - int(self.Rel_Win.height * 0.5)
        #######################################
        self.List_Scr.bar_inactive_color = (0.4, 0, 0, 1)
        self.List_Scr.bar_color   = (1, 0.15, 0.15, 1)
        self.List_Scr.bar_margin  = 5
        self.List_Scr.bar_width   = int(self.Rel_Win.width * 0.10)
        self.List_Scr.bar_pos_y   = 'right'
        # self.List_Scr.scroll_type = ['content']
        # self.List_Scr.scroll_type = ['bars']
        self.List_Scr.scroll_type = ['content', 'bars']
        #######################################
        Height1 = int(self.Rel_Win.height / 10)
        self.The_List.clear_widgets()
        for i in range(100):
            self.The_List.add_widget(Button(text=f"Button Number {i}", \
                                            size_hint = (None, None), \
                                            width = self.Rel_Win.width, \
                                            height = Height1))
        #######################################
        if(self.The_List.parent == None):
            self.List_Scr.add_widget(self.The_List)
        if(self.List_Scr.parent == None):
            self.Rel_Win.add_widget(self.List_Scr)
        if(self.Rel_Win.parent == None):
            self.Main_Win.add_widget(self.Rel_Win)
        #######################################
        self.List_Scr.scroll_x    = 1
        self.List_Scr.scroll_y    = 1
        #######################################
        return self.Main_Win
Exemple #4
0
class Soliders(BoxLayout):
    def __init__(self, *args, **kwargs):
        super(Soliders, self).__init__(orientation="vertical")
        global app
        app = App.get_running_app()
        scrollview = ScrollView()
        self.list = MDList()
        self.database = Db(dbtype='sqlite', dbname='soliders.db')
        self.rewrite_list()
        scrollview.add_widget(self.list)
        self.add_widget(scrollview)
        button_box = BoxLayout(orientation='horizontal')

        new_solider_btn = MDRectangleFlatButton()
        new_solider_btn.text = "Zapsat vojáka"
        new_solider_btn.icon_color = [0.9, 0.9, 0.9, 1]
        new_solider_btn.md_bg_color = [0, 0.5, 0.8, 1]
        new_solider_btn.pos_hint = {"center_x": .5}
        new_solider_btn.on_release = self.on_create_solider
        button_box.add_widget(new_solider_btn)
        self.add_widget(button_box)

    def rewrite_list(self):
        self.list.clear_widgets()
        soliders = self.database.read_all()
        for x in soliders:
            print(vars(x))
            self.list.add_widget(MyItem(item=vars(x)))

    def on_create_solider(self, *args):
        self.dialog = SoliderDialog(id=None)
        self.dialog.open()

    def create(self, solider):
        create_solider = Solider()
        create_solider.name = solider['name']
        self.database.create(create_solider)
        self.rewrite_list()

    def update(self, solider):
        update_solider = self.database.read_by_id(solider['id'])
        update_solider.name = solider['name']
        self.database.update()
        self.rewrite_list()

    def delete(self, id):
        self.database.delete(id)
        self.rewrite_list()
Exemple #5
0
class Employees(BoxLayout):
    def __init__(self, *args, **kwargs):
        super(Employees, self).__init__(orientation="vertical")
        # kontent aplikace
        global app
        app = App.get_running_app()
        rolovaci = ScrollView()
        self.list = MDList()
        self.db = Database(dbtype='sqlite', dbname='firmy.db')
        self.vypis_prepis()
        rolovaci.add_widget(self.list)
        self.add_widget(rolovaci)

        #Tlačítko pro vytvoření nové firmy
        button1 = MDFlatButton()
        button1.text = "NOVÁ FIRMA"
        button1.size_hint = (0, .1)
        button1.font_style = "Button"
        button1.on_release = self.create_firma
        self.add_widget(button1)

        button2 = MDFlatButton()
        button2.text = "NOVÝ ZAMĚSTNANEC"
        button2.size_hint = (0, .1)
        button2.font_style = "Button"
        button2.on_release = self.create_zamestnanec
        self.add_widget(button2)

    def vypis_prepis(self):
        self.list.clear_widgets()
        zamestnanci = self.db.read_all()
        print(zamestnanci)
        for i in zamestnanci:
            self.list.add_widget(MyItem(item=i))

    def create_firma(self):
        self.dialog = FirmaDialog(id=None)
        self.dialog.open()

    def create_zamestnanec(self):
        self.dialog = DialogZamestnance(id=None)
        self.dialog.open()

    def delete_zam(self, id):
        self.db.delete_zamestnanec(id)
        self.vypis_prepis()
class ProductsScreen(Screen):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        app = MDApp.get_running_app()
        scroll = ScrollView()
        self.Mlist = MDList()
        self.build_list()

        layout = BoxLayout()
        layout.orientation = "vertical"
        toolbar = MDToolbar(title="Products")
        toolbar.left_action_items = [["menu", lambda x: self.openNav()]]
        layout.add_widget(toolbar)
        scroll.add_widget(self.Mlist)
        layout.add_widget(scroll)
        self.action_popup = ProductActionPopup(self.build_list)
        self.action = MDFloatingActionButton(icon="plus",
                                             pos_hint={"center_x": 0.5},
                                             on_release=self.action_popup.open)
        layout.add_widget(self.action)
        self.add_widget(layout)

    def build_list(self):
        self.Mlist.clear_widgets()
        app = MDApp.get_running_app()
        for i in app.customconfig.load_products():
            item = ProductListItem(i, self.build_list)
            item.text = f"{i.name}"
            item.secondary_text = f"Raw Cost: £{round(i.cost, 2)}"
            icon = IconRightWidget(icon="layers-outline")
            icon.bind(on_release=item.show_popup)
            item.add_widget(icon)
            item.bind(on_release=item.show_popup)
            self.Mlist.add_widget(item)

    def openNav(self):
        app = MDApp.get_running_app()
        app.root.ids.nav_drawer.toggle_nav_drawer()
class TessprofilesController(Controller):
    """ Controller class to manage tessprofiles screen """
    def __init__(self, screen, **kwargs):
        self.screen = screen
        self.layout = MDList()

    def set_profiles(self, text="", search=False):
        """ Lists all tesseract profiles """
        def add_profile(profile, profileparam, profileparamstr):
            item = TwoLineAvatarIconListItem(
                text=profile,
                secondary_text="Settings: " + profileparamstr,
                on_release=partial(self.load_profile, profileparam),
            )
            item.add_widget(
                IconRightWidget(icon="trash-can",
                                on_release=partial(self.remove_profile,
                                                   profile)))
            if 'default' in profileparam and profileparam['default'] == False:
                item.add_widget(
                    IconLeftWidget(icon="star-outline",
                                   on_release=partial(self.set_to_default,
                                                      profile)))
            else:
                item.add_widget(
                    IconLeftWidget(icon="star",
                                   on_release=partial(self.unset_default,
                                                      profile)))
            self.layout.add_widget(item)

        self.layout.clear_widgets()
        self.screen.tessprofilelist.clear_widgets()
        for profilename, profileparam in get_app().tessprofiles.items():
            profileparamstr = ", ".join(
                [f"{k}:{v}" for k, v in profileparam.items()])
            if search:
                if self.screen.exact_match_chk.active:
                    if text == profilename[:len(text)]:
                        add_profile(profilename, profileparam, profileparamstr)
                else:
                    textparts = text.split(" ")
                    if sum([
                            True if textpart.lower() in profilename.lower() +
                            " " + profileparamstr.lower() else False
                            for textpart in textparts
                    ]) == len(textparts):
                        add_profile(profilename, profileparam, profileparamstr)
            else:
                add_profile(profilename, profileparam, profileparamstr)
        self.screen.tessprofilelist.add_widget(self.layout)

    def load_profile(self, profileparam, *args):
        """ Apply all settings of the choosen profile to the main window"""
        get_app().tesseract_controller.load_tessprofile(profileparam)
        get_app().switch_screen('tesseract_xplore')

    def set_to_default(self, sel_profile, *args):
        """ Set selected profile as default profile"""
        for profile, profileparam in get_app().tessprofiles.items():
            if profile == sel_profile:
                profileparam['default'] = True
            else:
                profileparam['default'] = False
        write_tessprofiles(get_app().tessprofiles)
        self.set_profiles(text=self.screen.search_field.text)

    def unset_default(self, sel_profile, *args):
        """ Unset default profile"""
        get_app().tessprofiles[sel_profile]['default'] = False
        write_tessprofiles(get_app().tessprofiles)
        self.set_profiles(text=self.screen.search_field.text)

    def remove_profile(self, profile, *args):
        """ Deletes a profile from the tessprofileslist """
        logger.info(f'TESSPROFILE: Delete {profile}')
        del get_app().tessprofiles[profile]
        write_tessprofiles(get_app().tessprofiles)
        self.set_profiles(text=self.screen.search_field.text)
Exemple #8
0
class BlueDevicesScreen(MDScreen):
    def __init__(self, **kw):
        self.devices = []
        self.list_of_devices = None
        self.toolbar = None
        self.choosen_color = None
        self.app = MDApp.get_running_app()
        self.number_of_devices = 0
        self.count_animations = 0

        if platform == 'android':
            self.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
            if not self.bluetoothAdapter:
                android_toast("This device doesn't support bluetooth", True)
        else:
            self.bluetoothAdapter = None

        Clock.schedule_once(self.post_init, 0)
        super().__init__(**kw)

    def post_init(self, dt):

        scroll = ScrollView(always_overscroll=False)
        self.list_of_devices = MDList()
        scroll.add_widget(self.list_of_devices)
        box = BoxLayout()
        box.add_widget(scroll)

        self.refresh_btn = MDFloatingActionButton(
            icon='refresh',
            pos_hint={
                'center_x': .5,
                'center_y': .5
            },
            md_bg_color=self.app.theme_cls.primary_color,
            opacity=0)
        self.refresh_btn.bind(on_release=self.get_bluetooth_devices)
        btn_layout = FloatLayout(size_hint_y=None, height=dp(100))
        btn_layout.add_widget(self.refresh_btn)

        self.container = BoxLayout(orientation='vertical')
        self.toolbar = MDToolbar(pos_hint={'top': 1})
        self.toolbar.left_action_items = [
            'chevron-left', lambda x: self.switch_screen()
        ],
        self.toolbar.right_action_items = [
            'bluetooth-off', lambda x: self.clear_device()
        ],
        self.container.add_widget(self.toolbar)
        self.container.add_widget(box)
        self.container.add_widget(btn_layout)

        self.add_widget(self.container)

    def enable_bluetooth(self):
        enableAdapter = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
        mActivity.startActivityForResult(enableAdapter, 0)

    def post_background_permissions(self):
        if self.bluetoothAdapter:
            if not self.bluetoothAdapter.isEnabled():
                self.enable_bluetooth()
                return
            self.get_bluetooth_devices()
        Clock.schedule_once(self.animate_button_colors, 0)

    def on_enter(self, *args):

        if platform == 'android':
            granted = self.app.check_background()
            if granted:
                self.post_background_permissions()
            else:
                self.app.root.ids.sm.current = 'scr 1'

        return super().on_enter(*args)

    def on_leave(self, *args):
        self.devices = []
        self.number_of_devices = 0
        self.list_of_devices.clear_widgets()
        Clock.schedule_once(self.app.save_theme, 0)
        Animation.cancel_all(self.refresh_btn)
        Animation.cancel_all(self.toolbar)
        self.toolbar.md_bg_color = self.app.theme_cls.primary_color
        self.refresh_btn.md_bg_color = self.app.theme_cls.primary_color
        return super().on_leave(*args)

    def on_pre_enter(self, *args):
        Animation(opacity=1, d=1.5).start(self.refresh_btn)
        return super().on_pre_enter(*args)

    def on_pre_leave(self, *args):
        self.app.set_decorations()
        self.refresh_btn.opacity = 0
        return super().on_pre_leave(*args)

    def get_bluetooth_devices(self, *_):

        if self.bluetoothAdapter:
            if self.bluetoothAdapter.isEnabled():
                results = self.bluetoothAdapter.getBondedDevices()
                self.devices = results.toArray()
                self.list_of_devices.clear_widgets()

                for device in self.devices:
                    name = OneLineListItem(text=device.getName(), opacity=0)
                    name.bind(on_release=self.save_device_name)
                    self.list_of_devices.add_widget(name)

                self.count_animations = len(self.list_of_devices.children)
                Clock.schedule_once(self.animate_items_opacity, 0)
            else:
                self.enable_bluetooth()

    def save_device_name(self, widget):

        self.app.paired_car = widget.text

        self.app.root.ids.content_drawer\
            .ids.md_list.children[0].text = widget.text

        android_toast(f'Listening for {widget.text}', True)

    def switch_screen(self):
        self.app.root.ids.sm.current = 'scr 1'

    def clear_device(self):
        self.app.paired_car = ''
        self.app.root.ids.content_drawer\
            .ids.md_list.children[0].text = 'Choose car'

    def change_decorations(self, *_):

        if platform == 'android':
            statusbar = get_hex_from_color(self.choosen_color[:-1])
            navbar = get_hex_from_color(self.choosen_color[:-1])
            self.app.statusbar(statusbar, navbar)

    def animate_button_colors(self, *_):
        self.choosen_color = choice(DECORATION_COLORS)
        a = Animation(md_bg_color=self.choosen_color, d=.3)
        b = Animation(md_bg_color=self.choosen_color, d=.3)
        a.bind(on_start=self.change_decorations)
        a.start(self.refresh_btn)
        b.start(self.toolbar)

    def animate_items_opacity(self, *_):
        try:
            a = Animation(opacity=1, d=.25, t='out_bounce')
            a.bind(on_complete=self.decrease_children)
            a.start(self.list_of_devices.children[self.count_animations - 1])
        except IndexError as e:
            print(e)
            for child in self.list_of_devices.children:
                child.opacity = 1

    def decrease_children(self, *_):
        self.count_animations -= 1
        if self.count_animations < 0:
            self.count_animations = 0
            return
        self.animate_items_opacity()
Exemple #9
0
class Persons(BoxLayout):
    def __init__(self, *args, **kwargs):
        super(Persons, self).__init__(orientation="vertical")
        # Globální proměnná - obsahuje kontext aplikace
        global app
        app = App.get_running_app()
        # Vytvoření rolovacího seznamu
        scrollview = ScrollView()
        self.list = MDList()
        # Volání metody, která načte seznam osob ze souboru JSON
        self.person_list = self.read()
        # Volání metody, která načte přepíše seznam osob na obrazovku
        self.rewrite_list()
        scrollview.add_widget(self.list)
        self.add_widget(scrollview)
        # Přidání tlačítka pro vložení nového záznamu
        self.add_widget(
            MDFillRoundFlatIconButton(text="Nový záznam",
                                      icon="plus",
                                      icon_color=[0.9, 0.9, 0.9, 1],
                                      text_color=[0.9, 0.9, 0.9, 1],
                                      md_bg_color=[0, 0.5, 0.8, 1],
                                      font_style="Button",
                                      pos_hint={"center_x": .5},
                                      on_release=self.on_create))

    def rewrite_list(self):
        """
        Metoda přepíše seznam osob na obrazovce
        """
        self.list.clear_widgets()
        # Pro všechny osoby v seznamu self.person_list vytváří widget MyItem
        for person in self.person_list:
            self.list.add_widget(MyItem(item=person))

    def on_create(self, *args):
        """
        Metoda reaguje na tlačítko Nový záznam a vyvolá dialogové okno MyDialog
        """
        self.dialog = MyDialog(id=None)
        self.dialog.open()

    def create(self, person):
        """
        Metoda vytvoří nový záznam
        """
        self.person_list.append({
            "id":
            self.person_list[len(self.person_list) - 1]["id"] + 1,
            "name":
            person["name"],
            "state":
            person["state"]
        })
        self.rewrite_list()
        self.save_data()

    def update(self, person):
        """
        Metoda aktualizuje záznam
        """
        update_person = next(
            (obj for obj in self.person_list if obj['id'] == person["id"]),
            None)
        update_person["name"] = person["name"]
        update_person["state"] = person["state"]
        self.rewrite_list()
        self.save_data()

    def read(self):
        """
        Metoda načítá data ze souboru JSON
        """
        with open('files/person.json', encoding='utf-8') as f:
            return json.load(f)

    def delete(self, id):
        """
        Metoda smaže záznam o osobě
        """
        person = next(
            (obj for obj in self.person_list if obj['id'] == int(id)), None)
        self.person_list.remove(person)
        self.rewrite_list()
        self.save_data()

    def save_data(self):
        """
        Metoda ukládá data do souboru JSON
        """
        with open('files/person.json', 'w', encoding='utf-8') as f:
            json.dump(self.person_list, f)
class ModelListController(Controller):
    """ Controller class to manage image metadata screen """
    def __init__(self, screen, **kwargs):
        self.screen = screen
        self.layout = MDList()
        self.checked_models = None
        self.modelinfos = {}
        self.screen.model_selection_button.bind(on_release=self.set_model_btn)
        self.screen.show_all_chk.bind(active=partial(self.thread_set_list))

    def thread_set_list(self, *args, text="", search=False):
        import threading
        # TODO: Why is threading still blocking the ui and the pb not working?
        if not args[0].active:
            self.layout.clear_widgets()
            self.screen.modellist.clear_widgets()
            self.screen.modellist.add_widget(self.layout)
            return
        self.ocr_single_event = threading.Thread(target=self.process_set_list,
                                                 args=(args),
                                                 kwargs={
                                                     'text': text,
                                                     'search': search
                                                 })
        self.ocr_single_event.setDaemon(True)
        self.ocr_single_event.start()
        return

    def process_set_list(self, *args, text="", search=False):
        from kivymd.uix.progressbar import MDProgressBar
        pb = MDProgressBar(type="determinate",
                           running_duration=1,
                           catching_duration=1.5)
        status_bar = get_app().modellist_controller.screen.status_bar
        status_bar.clear_widgets()
        status_bar.add_widget(pb)
        pb.start()
        Clock.schedule_once(
            partial(self.set_list, self, *args, text=text, search=search))
        pb.stop()

    def set_list(self, *args, text="", search=False):
        ''' Lists all installed models '''
        def add_item(model):
            description = self.modelinfos.get(model).get('description', '')
            description = 'No description' if description == '' else description
            item = TwoLineAvatarIconListItem(text=model,
                                             secondary_text=description,
                                             on_release=partial(
                                                 self.set_model, model),
                                             size_hint=(None, None),
                                             size=(600, 1))
            if model not in self.checked_models:
                self.checked_models[model] = False
            item.add_widget(LeftCheckbox(active=self.checked_models[model]))
            item.add_widget(
                IconRightWidget(icon='file-edit',
                                on_release=partial(self.edit_description,
                                                   model, description)))
            self.layout.add_widget(item)

        if self.checked_models is None:
            self.checked_models = {}
            for model in list(
                    get_app().modelinformations.get_modelinfos().keys()):
                self.checked_models[model] = False
        else:
            self.chk_active_models()
        self.layout.clear_widgets()
        self.screen.modellist.clear_widgets()
        self.modelinfos = get_app().modelinformations.get_modelinfos()

        for model in list(self.modelinfos.keys()):
            if model == "osd": continue
            if self.screen.show_all_chk.active and len(text) == 0:
                add_item(model)
            if search and len(text) > 1:
                if self.screen.exact_match_chk.active:
                    if text == model[:len(text)]:
                        add_item(model)
                else:
                    textparts = text.split(" ")
                    if sum([
                            True
                            if textpart.lower() in model.lower() else False
                            for textpart in textparts
                    ]) == len(textparts):
                        add_item(model)
                    elif sum([
                            True if textpart.lower() in " ".join(
                                self.modelinfos.get(model).get(
                                    'tags', [''])).lower() else False
                            for textpart in textparts
                    ]) == len(textparts):
                        add_item(model)
        self.screen.modellist.add_widget(self.layout)

    def edit_description(self, model, description, instance, *args):
        def close_dialog(instance, *args):
            instance.parent.parent.parent.parent.dismiss()

        dialog = MDDialog(
            title=f"Edit the description of {model}",
            type='custom',
            auto_dismiss=False,
            content_cls=MDTextField(text=description, mode="rectangle"),
            buttons=[
                MDFlatButton(text="SAVE",
                             on_release=partial(self.save_description, model,
                                                instance)),
                MDFlatButton(text="DISCARD", on_release=close_dialog),
            ],
        )
        if get_app()._platform not in ['win32', 'win64']:
            # TODO: Focus function seems buggy in win
            dialog.content_cls.focused = True
        dialog.open()

    def save_description(self, model, model_instance, dialog_instance, *args):
        dialog_instance.parent.parent.parent.parent.dismiss()
        model_instance.parent.parent.children[2].children[
            1].text = dialog_instance.parent.parent.parent.children[
                2].children[0].text
        modelinfo = get_app().modelinformations.get_modelinfos().get(model)
        modelinfo[
            'description'] = dialog_instance.parent.parent.parent.children[
                2].children[0].text
        get_app().modelinformations.update_modelinformations(model, modelinfo)
        get_app().modelinformations.write_modelinfos()

    def chk_active_models(self):
        for model in self.layout.children:
            self.checked_models[model.children[2].children[2].
                                text] = model.children[1].children[0].active

    def set_model_btn(self, instance, *args):
        self.set_model("")

    def set_model(self, model, *args):
        selected_models = []
        if model != "": selected_models.append(model)
        self.chk_active_models()
        for chk_model, state in self.checked_models.items():
            if state and chk_model != model:
                selected_models.append(chk_model)
        if get_app().home_screen == HOME_SCREEN_ONLINE:
            get_app().tesseract_online_controller.screen.model.set_item(
                'Model: ' + '+'.join(selected_models))
        else:
            get_app().tesseract_controller.screen.model.set_item(
                'Model: ' + '+'.join(selected_models))
        get_app().switch_screen(get_app().home_screen)
Exemple #11
0
class Books(BoxLayout):
    def __init__(self, *args, **kwargs):
        super(Books, self).__init__(orientation="vertical")
        global app
        app = App.get_running_app()
        scrollview = ScrollView()
        self.list = MDList()
        self.database = Db(dbtype='sqlite', dbname='books.db')
        self.rewrite_list()
        scrollview.add_widget(self.list)
        self.add_widget(scrollview)
        button_box = BoxLayout(orientation='horizontal', size_hint_y=0.1)
        new_book_btn = MDFillRoundFlatIconButton()
        new_book_btn.text = "Nová kniha"
        new_book_btn.icon = "plus"
        new_book_btn.icon_color = [0.9, 0.9, 0.9, 1]
        new_book_btn.text_color = [0.9, 0.9, 0.9, 1]
        new_book_btn.md_bg_color = [0, 0.5, 0.8, 1]
        new_book_btn.font_style = "Button"
        new_book_btn.pos_hint = {"center_x": .5}
        new_book_btn.on_release = self.on_create_book
        button_box.add_widget(new_book_btn)

        new_author_btn = MDFillRoundFlatIconButton()
        new_author_btn.text = "Nový autor"
        new_author_btn.icon = "plus"
        new_author_btn.icon_color = [0.9, 0.9, 0.9, 1]
        new_author_btn.text_color = [0.9, 0.9, 0.9, 1]
        new_author_btn.md_bg_color = [0.8, 0.5, 0, 1]
        new_author_btn.font_style = "Button"
        new_author_btn.pos_hint = {"center_x": .6}
        new_author_btn.on_release = self.on_create_author
        button_box.add_widget(new_author_btn)

        new_genre_btn = MDFillRoundFlatIconButton()
        new_genre_btn.text = "Nový žánr"
        new_genre_btn.icon = "plus"
        new_genre_btn.icon_color = [0.9, 0.9, 0.9, 1]
        new_genre_btn.text_color = [0.9, 0.9, 0.9, 1]
        new_genre_btn.md_bg_color = [0.8, 0.5, 0, 1]
        new_genre_btn.font_style = "Button"
        new_genre_btn.pos_hint = {"center_x": .6}
        new_genre_btn.on_release = self.on_create_genre
        button_box.add_widget(new_genre_btn)
        self.add_widget(button_box)

    def rewrite_list(self):
        self.list.clear_widgets()
        books = self.database.read_all()
        for book in books:
            print(vars(book))
            self.list.add_widget(MyItem(item=vars(book)))

    def on_create_book(self, *args):
        self.dialog = BookDialog(id=None)
        self.dialog.open()

    def on_create_author(self, *args):
        self.dialog = AuthorDialog()
        self.dialog.open()

    def on_create_genre(self, *args):
        self.dialog = GenreDialog()
        self.dialog.open()

    def create(self, book):
        create_book = Book()
        create_book.name = book['name']
        create_book.author = book['author']
        self.database.create(create_book)
        self.rewrite_list()

    def update(self, book):
        update_book = self.database.read_by_id(book['id'])
        update_book.name = book['name']
        update_book.author = book['author']
        self.database.update()
        self.rewrite_list()

    def delete(self, id):
        self.database.delete(id)
        self.rewrite_list()
Exemple #12
0
class ModelListController(Controller):
    """ Controller class to manage image metadata screen """
    def __init__(self, screen, **kwargs):
        self.screen = screen
        self.layout = MDList()
        self.checked_models = None
        self.screen['model_selection_button'].bind(
            on_release=self.set_model_btn)

    def set_list(self, text="", search=False):
        '''Lists all installed models '''
        def add_item(model):
            item = OneLineAvatarIconListItem(
                text=model,
                secondary_text="",
                on_release=partial(self.set_model, model),
            )
            item.add_widget(LeftCheckbox(active=self.checked_models[model]))
            self.layout.add_widget(item)

        if self.checked_models is None:
            self.checked_models = {}
            for model in get_app().tesseract_controller.models:
                self.checked_models[model] = False
        else:
            self.chk_active_models()
        self.layout.clear_widgets()
        self.screen.modellist.clear_widgets()
        for model in get_app().tesseract_controller.models:
            if search:
                if self.screen.exact_match_chk.active:
                    if text == model[:len(text)]:
                        add_item(model)
                else:
                    textparts = text.split(" ")
                    if sum([
                            True
                            if textpart.lower() in model.lower() else False
                            for textpart in textparts
                    ]) == len(textparts):
                        add_item(model)
            else:
                add_item(model)
        self.screen.modellist.add_widget(self.layout)

    def chk_active_models(self):
        for model in self.layout.children:
            self.checked_models[model.children[2].children[2].
                                text] = model.children[1].children[0].active

    def set_model_btn(self, instance, *args):
        self.set_model("")

    def set_model(self, model, *args):
        selected_models = []
        if model != "": selected_models.append(model)
        self.chk_active_models()
        for chk_model, state in self.checked_models.items():
            if state and chk_model != model:
                selected_models.append(chk_model)
        get_app().tesseract_controller.screen.model.set_item(
            'Model: ' + '+'.join(selected_models))
        get_app().switch_screen('tesseract_xplore')
class ProductActionPopup(Popup):
    def __init__(self, Mlist, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.app = MDApp.get_running_app()
        self.title = f"New Product"
        self.P_list = Mlist
        self.size_hint = (0.7, 0.9)
        self.materials_list = self.app.customconfig.load_materials()

        self.selected_materials_list = []
        app = MDApp.get_running_app()

        vlayout = BoxLayout()
        vlayout.orientation = "vertical"

        # name
        namerow = BoxLayout(size_hint=(1, 0.25))
        namerow.orientation = "horizontal"
        namerow.add_widget(Label(text="Product name: "))
        self.name_widget = MDTextField()
        namerow.add_widget(self.name_widget)

        scroll = ScrollView()
        self.Mlist = MDList()
        self.build_list()

        scroll.add_widget(self.Mlist)

        material_chooser_layout = BoxLayout()
        material_chooser_layout.orientation = "horizontal"
        material_chooser_layout.size_hint = (1, 0.2)

        self.menu_items = self.build_material_chooser_list()

        self.add_material_btn = MDRectangleFlatIconButton()
        self.add_material_btn.text = "Material"
        self.add_material_btn.icon = "plus"
        self.add_material_menu = MDDropdownMenu(
            items=self.menu_items,
            width_mult=4,
            caller=self.add_material_btn,
            callback=self.add_material_callback)
        self.add_material_btn.on_release = self.add_material_menu.open

        self.remove_material_btn = MDRectangleFlatIconButton()
        self.remove_material_btn.text = "Material"
        self.remove_material_btn.icon = "minus"
        self.remove_material_menu = MDDropdownMenu(
            items=self.menu_items,
            width_mult=4,
            caller=self.remove_material_btn,
            callback=self.remove_material_callback)
        self.remove_material_btn.on_release = self.remove_material_menu.open

        material_chooser_layout.add_widget(self.add_material_btn)
        material_chooser_layout.add_widget(self.remove_material_btn)

        vlayout.add_widget(namerow)
        vlayout.add_widget(material_chooser_layout)
        vlayout.add_widget(scroll)

        buttonlayout = BoxLayout()
        buttonlayout.orientation = "horizontal"
        buttonlayout.size_hint = (1, 0.2)
        buttonlayout.add_widget(
            MDRectangleFlatButton(text="Discard", on_release=self.dismiss))
        buttonlayout.add_widget(
            MDRectangleFlatButton(text="Save", on_release=self.save))
        vlayout.add_widget(buttonlayout)
        self.content = vlayout

    def on_dismiss(self):
        self.Mlist.clear_widgets()
        self.selected_materials_list = []
        self.P_list()
        self.name_widget.text = ""

    def add_material_callback(self, item):
        for i in self.materials_list:
            if i.name == item.text:
                self.selected_materials_list.append(i)
        self.build_list()
        self.add_material_menu.dismiss()

    def remove_material_callback(self, item):
        try:
            for i in self.materials_list:
                if i.name == item.text:
                    self.selected_materials_list.remove(i)
        except ValueError:
            # Material not in product
            pass
        self.build_list()
        self.remove_material_menu.dismiss()

    def build_material_chooser_list(self):
        tmp = []
        for i in self.materials_list:
            tmp.append({"text": i.name})
        return tmp

    def build_list(self):
        self.Mlist.clear_widgets()
        app = MDApp.get_running_app()
        for i in self.selected_materials_list:
            item = MaterialListItem(i, self.build_list)
            item.text = f"{i.name}"
            item.secondary_text = f"Cost: £{round(i.unit_price, 2)}"
            icon = IconRightWidget(icon="layers-outline")
            icon.bind(on_release=item.show_popup)
            item.add_widget(icon)
            item.bind(on_release=item.show_popup)
            self.Mlist.add_widget(item)

    def save(self, td):
        app = MDApp.get_running_app()
        app.customconfig.new_product(
            self.name_widget.text,
            [i.name for i in self.selected_materials_list])
        self.P_list()
        self.dismiss()
Exemple #14
0
class Games(BoxLayout):
    def __init__(self, *args, **kwargs):
        super(Games, self).__init__(orientation="vertical")
        global app
        app = App.get_running_app()
        scrollview = ScrollView()
        self.list = MDList()
        self.database = Db(dbtype='sqlite', dbname='games.db')
        self.rewrite_list()
        scrollview.add_widget(self.list)
        self.add_widget(scrollview)
        button_box = BoxLayout(orientation='horizontal', size_hint_y=0.1)
        new_game_btn = MDFillRoundFlatIconButton()
        new_game_btn.text = "Nová hra"
        new_game_btn.icon = "plus"
        new_game_btn.icon_color = [0.9, 0.9, 0.9, 1]
        new_game_btn.text_color = [0.9, 0.9, 0.9, 1]
        new_game_btn.md_bg_color = [0, 0.5, 0.8, 1]
        new_game_btn.font_style = "Button"
        new_game_btn.pos_hint = {"center_x": .5}
        new_game_btn.on_release = self.on_create_game
        button_box.add_widget(new_game_btn)
        new_platform_btn = MDFillRoundFlatIconButton()
        new_platform_btn.text = "Nová platforma"
        new_platform_btn.icon = "plus"
        new_platform_btn.icon_color = [0.9, 0.9, 0.9, 1]
        new_platform_btn.text_color = [0.9, 0.9, 0.9, 1]
        new_platform_btn.md_bg_color = [0.8, 0.5, 0, 1]
        new_platform_btn.font_style = "Button"
        new_platform_btn.pos_hint = {"center_x": .6}
        new_platform_btn.on_release = self.on_create_platform
        button_box.add_widget(new_platform_btn)
        self.add_widget(button_box)

    def rewrite_list(self):
        self.list.clear_widgets()
        games = self.database.read_all()
        for game in games:
            print(vars(game))
            self.list.add_widget(MyItem(item=vars(game)))

    def on_create_game(self, *args):
        self.dialog = GameDialog(id=None)
        self.dialog.open()

    def on_create_platform(self, *args):
        self.dialog = PlatformDialog()
        self.dialog.open()

    def create(self, game):
        create_game = Game()
        create_game.name = game['name']
        create_game.platform1 = game['platform1']
        self.database.create(create_game)
        self.rewrite_list()

    def update(self, game):
        update_game = self.database.read_by_id(game['id'])
        update_game.name = game['name']
        update_game.platform1 = game['platform1']
        self.database.update()
        self.rewrite_list()

    def delete(self, id):
        self.database.delete(id)
        self.rewrite_list()
Exemple #15
0
class Persons(BoxLayout):
    # Metoda konstruktoru
    def __init__(self, *args, **kwargs):
        super(Persons, self).__init__(orientation="vertical")
        global app
        app = App.get_running_app()
        scrollview = ScrollView()
        self.list = MDList()
        self.database = Db(dbtype='sqlite', dbname='persons.db')
        self.rewrite_list()
        scrollview.add_widget(self.list)
        self.add_widget(scrollview)
        button_box = BoxLayout(orientation='horizontal', size_hint_y=0.1)
        new_person_btn = MDFillRoundFlatIconButton()
        new_person_btn.text = "Nová osoba"
        new_person_btn.icon = "plus"
        new_person_btn.icon_color = [0.9, 0.9, 0.9, 1]
        new_person_btn.text_color = [0.9, 0.9, 0.9, 1]
        new_person_btn.md_bg_color = [0, 0.5, 0.8, 1]
        new_person_btn.font_style = "Button"
        new_person_btn.pos_hint = {"center_x": .5}
        new_person_btn.on_release = self.on_create_person
        button_box.add_widget(new_person_btn)

        new_state_btn = MDFillRoundFlatIconButton()
        new_state_btn.text = "Nový stát"
        new_state_btn.icon = "plus"
        new_state_btn.icon_color = [0.9, 0.9, 0.9, 1]
        new_state_btn.text_color = [0.9, 0.9, 0.9, 1]
        new_state_btn.md_bg_color = [0.8, 0.5, 0, 1]
        new_state_btn.font_style = "Button"
        new_state_btn.pos_hint = {"center_x": .6}
        new_state_btn.on_release = self.on_create_state
        button_box.add_widget(new_state_btn)

        new_city_btn = MDFillRoundFlatIconButton()
        new_city_btn.text = "Nové město"
        new_city_btn.icon = "plus"
        new_city_btn.icon_color = [0.9, 0.9, 0.9, 1]
        new_city_btn.text_color = [0.9, 0.9, 0.9, 1]
        new_city_btn.md_bg_color = [0.8, 0.5, 0.5, 1]
        new_city_btn.font_style = "Button"
        new_city_btn.pos_hint = {"center_x": 1}
        new_city_btn.on_release = self.on_create_city
        button_box.add_widget(new_city_btn)
        self.add_widget(button_box)

    #funkce
    def rewrite_list(self):
        self.list.clear_widgets()
        persons = self.database.read_all()
        for person in persons:
            print(vars(person))
            self.list.add_widget(MyItem(item=vars(person)))

    def on_create_person(self, *args):
        self.dialog = PersonDialog(id=None)
        self.dialog.open()

    def on_create_state(self, *args):
        self.dialog = StateDialog()
        self.dialog.open()

    def on_create_city(self, *args):
        self.dialog = CityDialog()
        self.dialog.open()

    def create(self, person):
        create_person = Person()
        create_person.name = person['name']
        create_person.state_short = person['state_short']
        create_person.city = person['city']
        self.database.create(create_person)
        self.rewrite_list()

    def create_test_data(self):

        create_person = Person()
        create_person.name = "testovací jméno"
        create_person.state_short = "testovací stát"
        create_person.city = "testovací město"
        self.database.create(create_person)
        self.rewrite_list()

    def update(self, person):

        update_person = self.database.read_by_id(person['id'])
        update_person.name = person['name']
        update_person.state_short = person['state_short']
        self.database.update()
        self.rewrite_list()

    def delete(self, id):

        self.database.delete(id)
        self.rewrite_list()
Exemple #16
0
class Animals(BoxLayout):
    def __init__(self, *args, **kwargs):
        super(Animals, self).__init__(orientation="vertical")
        global app
        app = App.get_running_app()
        scrollview = ScrollView()
        self.list = MDList()
        self.database = Database(dbtype='sqlite', dbname='animals.db')
        self.rewrite_list()
        scrollview.add_widget(self.list)
        self.add_widget(scrollview)
        button_box = BoxLayout(orientation='horizontal', size_hint_y=0.1)

        #button 1
        btn_animal = MDFlatButton()
        btn_animal.text = "Add new animal"
        btn_animal.font_style = "Button"
        btn_animal.on_release = self.on_create_animal

        # button 2
        btn_type = MDFlatButton()
        btn_type.text = "Add new animal type"
        btn_type.font_style = "Button"
        btn_type.on_release = self.on_create_type

        button_box.add_widget(btn_animal)
        button_box.add_widget(btn_type)
        self.add_widget(button_box)

    def rewrite_list(self):
        self.list.clear_widgets()

        animals = self.database.read_all()

        for animal in animals:
            print(vars(animal))
            self.list.add_widget(MyItem(item=vars(animal)))

    def on_create_animal(self, *args):

        self.dialog = AnimalDialog(id=None)
        self.dialog.open()

    def on_create_type(self, *args):

        self.dialog = TypeDialog()
        self.dialog.open()

    def create(self, animal):

        cr_animal = Animal()
        cr_animal.name = animal['name']
        cr_animal.typee = animal['typee']
        # cr_animal.info = animal['info']
        # cr_animal.photoo = animal['photoo']
        self.database.create_animal(cr_animal)
        self.rewrite_list()

    def update(self, animal):

        up_animal = self.database.read_animal_by_id(animal['id'])
        up_animal.name = animal['name']
        up_animal.typee = animal['typee']
        # up_animal.info = animal['info']
        # up_animal.photoo = animal['photoo']
        self.database.update()
        self.rewrite_list()

    def delete(self, id):

        self.database.delete_animal(id)
        self.rewrite_list()
Exemple #17
0
class EventContent(MDScreen):
    def build(self):
        return Builder.load_string(kv)

    def create(self, year, month, day):
        self.build()

        country = driver().getCity()['countryCode']
        iso = datetime(int(year), int(month), int(day))

        key = getstrftime('%A, %B {S}, %Y', iso)
        islamic_date = getDict()[key].split(',')[1].strip()

        hijri = convert.Gregorian(year, month, day).to_hijri().datetuple()
        hijri_iso = f"{hijri[2]}-{hijri[1]}"
        islamic = []

        self.label = MDLabel()
        self.label.size_hint_y = .05
        self.label.font_size = "35px"
        self.label.halign = "center"
        self.label.text = islamic_date

        tabs = Tabs()
        tabs.on_tab_switch = self.on_tab_switch

        events = Screen(name='events')
        namaz = Screen(name='namaz')

        personal_events = getPersonal(str(iso).split()[0])

        layout = MDBoxLayout(orientation='vertical')
        eventslayout = MDBoxLayout(orientation='vertical')

        self.sm = ScreenManager()

        events.add_widget(eventslayout)

        self.sm.add_widget(events)
        self.sm.add_widget(namaz)

        tabs.add_widget(Tab(text="Events"))
        tabs.add_widget(Tab(text="Namaz Times"))
        personalscreen = PersonalEvents()
        world = WorldEvents()

        scroll = ScrollView()

        self.nrv = MDList()
        self.wrv = world.ids.wrv
        self.prv = personalscreen.ids.prv

        self.holidays = json.loads(
            requests.get(
                f'https://calendarific.com/api/v2/holidays?&api_key={APIKEY}&country={country}&year={year}'
            ).text)

        self.holidays['year'] = year

        with open('./lib/data/islamic.json', 'r', encoding="utf-8") as file:
            data = json.loads(str(file.read()))

        for key in data.keys():
            if key == hijri_iso:
                islamic.append(data[key]["event"])

        holidays = (Holidays().getHoliday(day, month, year, self.holidays))

        self.wrv.add_widget(OneLineListItem(text="No Events"))
        self.prv.add_widget(OneLineListItem(text="No Events"))

        if holidays or islamic:
            self.wrv.clear_widgets()

        for i in holidays + islamic:
            text = str(i)
            description = None

            if type(i) == dict:
                text = str(i['name'])
                description = str(i['description'])

            item = EventItem(text=str(text), description=str(description))
            self.wrv.add_widget(item)

        if personal_events:
            self.prv.clear_widgets()

        for x in personal_events:
            item = OneLineListItem(text=str(x))
            self.prv.add_widget(item)

        self.namaz_times = driver().getSalaatTimesForDate(iso)

        for item in self.namaz_times.keys():
            self.nrv.add_widget(
                TwoLineListItem(text=str(item),
                                secondary_text=str(self.namaz_times[item]),
                                height=dp(50)))

        scroll.add_widget(self.nrv)

        layout.add_widget(self.label)
        layout.add_widget(tabs)
        layout.add_widget(self.sm)

        eventslayout.add_widget(world)
        eventslayout.add_widget(personalscreen)

        namaz.add_widget(scroll)

        self.sm.current = "events"
        self.add_widget(layout)

        return self

    def switch_year(self, year):
        thread = threading.Thread(target=self.setHoliday, args=(year, ))
        thread.start()

        return self.holidays

    def setHoliday(self, year):
        country = driver().getCity()['countryCode']
        self.holidays = json.loads(
            requests.get(
                f'https://calendarific.com/api/v2/holidays?&api_key={APIKEY}&country={country}&year={year}'
            ).text)

    def switch_dates(self, year, month, day):
        iso = datetime(int(year), int(month), int(day))

        key = getstrftime('%A, %B {S}, %Y', iso)
        islamic_date = getDict()[key].split(',')[1].strip()
        self.label.text = islamic_date

        thread = threading.Thread(target=self.setNamaz, args=(iso, ))
        thread.start()

        hijri = convert.Gregorian(year, month, day).to_hijri().datetuple()
        hijri_iso = f"{hijri[2]}-{hijri[1]}"
        islamic = []

        personal_events = getPersonal(str(iso).split()[0])

        with open('./lib/data/islamic.json', 'r', encoding="utf-8") as file:
            data = json.loads(str(file.read()))

        for key in data.keys():
            if key == hijri_iso:
                islamic.append(data[key]["event"])

        self.wrv.clear_widgets()
        self.prv.clear_widgets()

        holidays = (Holidays().getHoliday(day, month, year, self.holidays))

        self.wrv.add_widget(OneLineListItem(text="No Events"))
        self.prv.add_widget(OneLineListItem(text="No Events"))

        if holidays or islamic:
            self.wrv.clear_widgets()

        for i in holidays + islamic:
            text = str(i)
            description = None

            if type(i) == dict:
                text = str(i['name'])
                description = str(i['description'])

            item = EventItem(text=str(text), description=str(description))
            self.wrv.add_widget(item)

        if personal_events:
            self.prv.clear_widgets()

        for x in personal_events:
            item = OneLineListItem(text=str(x))
            self.prv.add_widget(item)

    def on_tab_switch(self, *args):
        if args[2] == "Events":
            self.sm.transition.direction = 'right'
            self.sm.current = "events"

        elif args[2] == "Namaz Times":
            self.sm.transition.direction = 'left'
            self.sm.current = "namaz"

    def setNamaz(self, iso):
        self.namaz_times = driver().getSalaatTimesForDate(str(iso).split()[0])

        self.nrv.clear_widgets()

        for item in self.namaz_times.keys():
            self.nrv.add_widget(
                TwoLineListItem(text=str(item),
                                secondary_text=str(self.namaz_times[item]),
                                height=dp(60)))