示例#1
0
    def __init__(self, parent, **kw):
        BaseClass.__init__(self)
        Toplevel.__init__(self, parent)

        self._parent = parent
        self['bg'] = 'white'
        self.geometry('350x100')
        if 'data' in kw: self._data = kw['data']

        for i in range(0, 2):
            Grid.columnconfigure(self, i, weight=1)
            Grid.rowconfigure(self, i, weight=1)

        self._button_cancel = CustomButton(self,
                                           view='normal_red',
                                           text='Cancel')
        self._button_cancel.grid(row=1, column=0)
        self._button_cancel.bind('<Button-1>', self._on_button_cancel_click)

        self._button_apply = CustomButton(self,
                                          view='normal_green',
                                          text='Accept')
        self._button_apply.grid(row=1, column=1)
        self._button_apply.bind('<Button-1>', self._on_button_apply_click)

        self._label_text = CustomLabel(
            self, text='Are you shure you want to delete this product?')
        self._label_text.grid(row=0, column=0, columnspan=2)
    def __init__(self, parent):
        Frame.__init__(self, parent)
        BaseClass.__init__(self)

        self.parent = parent
        self['bg'] = 'white smoke'

        Grid.rowconfigure(self, 0, weight=1)
        Grid.columnconfigure(self, 0, weight=1)
        Grid.columnconfigure(self, 1, weight=1)
        Grid.columnconfigure(self, 2, weight=1)

        self._button_switcher = CustomButton(self,
                                             view='border_green',
                                             text='Show Available',
                                             font=(self.default_font, 14,
                                                   'normal', 'bold'),
                                             height=1,
                                             width=14)
        self._button_switcher.grid(column=0, row=0)

        self._label_search = CustomLabel(self,
                                         text='Search: ',
                                         bg='white smoke',
                                         font=('Halvetica', 12, 'normal',
                                               'normal'))
        self._label_search.grid(column=1, row=0, sticky=E)

        self._entry_search = CustomEntry(self, text='Text', width=50)
        self._entry_search.grid(column=2, row=0, padx=(0, 40), sticky=W)
        self._entry_search.bind('<Key>', self._on_entry_search_key)
        self.get_root().bind('<Button-1>', self._remove_focus)
class Product(Frame, BaseClass):
    def __init__(self, parent, *args, **kw):
        Frame.__init__(self, parent)
        BaseClass.__init__(self)

        if kw['picture']: self._picture = kw['picture']
        if kw['name']: self._name = kw['name']
        self['bg'] = 'white'

        Grid.columnconfigure(self, 1, weight=1)

        self._picture_product = CustomPicture(self,
                                              picture=self._picture,
                                              size=70)
        self._picture_product.grid(column=0, row=1, pady=(0, 10), padx=(10, 0))

        self._label_product_name = CustomLabel(self,
                                               font=(self.default_font, 11,
                                                     'bold'),
                                               text=self._name)
        self._label_product_name.grid(column=1,
                                      row=1,
                                      sticky=W,
                                      padx=(10, 0),
                                      pady=(0, 10))

        self._button_delete_product = CustomButton(
            self,
            view='normal_red',
            text='Delete',
            command=self._on_button_delete_product_click)
        self._button_delete_product.grid(column=0,
                                         row=0,
                                         sticky=W,
                                         pady=(10, 5),
                                         padx=(15, 0))

        self._button_edit_product = CustomButton(
            self,
            view='normal_green',
            text='Edit',
            command=self._on_button_edit_product_click)
        self._button_edit_product.grid(column=1,
                                       row=0,
                                       sticky=E,
                                       pady=(10, 5),
                                       padx=(0, 15))

    def _on_button_delete_product_click(self):
        ProductDialogDelete(self, data=self._name)

    def _on_button_edit_product_click(self):
        pass
示例#4
0
    def _expand(self, event):
        self.event_dispatcher.dispatch_event(
            RecipeExpandEvent(RecipeExpandEvent.ASK, self))

        self._label_description_title = CustomLabel(self,
                                                    text='Recipe:',
                                                    font=(self.default_font,
                                                          14, 'bold'))
        self._label_description_title.grid(row=2, column=0, columnspan=2)

        self._label_description = CustomLabel(self,
                                              text=self._description,
                                              wraplength=(self.winfo_width() -
                                                          40),
                                              justify=LEFT)
        self._label_description.grid(row=3, column=0, columnspan=2)
    def __init__(self, parent, **kw):
        BaseClass.__init__(self)
        Toplevel.__init__(self, parent)

        self.parent = parent
        self['bg'] = 'white'

        self.geometry('500x350')

        for i in range(0, 4):
            Grid.columnconfigure(self, i, weight=1)
            Grid.rowconfigure(self, i, weight=1)

        self._bottom_padding = 20

        self._button_exit = CustomButton(self,
                                         view='normal_red',
                                         text='Cancel',
                                         command=self._on_button_exit_click)
        self._button_exit.grid(row=4, column=0, pady=(0, self._bottom_padding))

        self._button_apply = CustomButton(self,
                                          view='normal_green',
                                          text='Apply',
                                          command=self._on_button_apply_click)
        self._button_apply.grid(row=4,
                                column=2,
                                pady=(0, self._bottom_padding))

        self._button_change_picture = CustomButton(
            self,
            view='normal_blue',
            text='Change Picture',
            command=self._on_button_change_picture_click)
        self._button_change_picture.grid(row=1, column=1, sticky=N)

        self._picture = CustomPicture(self,
                                      picture=self._get_placeholder(),
                                      size=150)
        self._picture.grid(column=1, row=0, pady=(20, 0))

        self._entry_name = CustomEntry(self, width=25)
        self._entry_name.grid(row=2, column=1, columnspan=2, sticky=W + E)

        self._label_name = CustomLabel(self, text='Product Name: ')
        self._label_name.grid(row=2, column=0, sticky=W + E)
class ProductDialogNew(Toplevel, BaseClass):
    def __init__(self, parent, **kw):
        BaseClass.__init__(self)
        Toplevel.__init__(self, parent)

        self.parent = parent
        self['bg'] = 'white'

        self.geometry('500x350')

        for i in range(0, 4):
            Grid.columnconfigure(self, i, weight=1)
            Grid.rowconfigure(self, i, weight=1)

        self._bottom_padding = 20

        self._button_exit = CustomButton(self,
                                         view='normal_red',
                                         text='Cancel',
                                         command=self._on_button_exit_click)
        self._button_exit.grid(row=4, column=0, pady=(0, self._bottom_padding))

        self._button_apply = CustomButton(self,
                                          view='normal_green',
                                          text='Apply',
                                          command=self._on_button_apply_click)
        self._button_apply.grid(row=4,
                                column=2,
                                pady=(0, self._bottom_padding))

        self._button_change_picture = CustomButton(
            self,
            view='normal_blue',
            text='Change Picture',
            command=self._on_button_change_picture_click)
        self._button_change_picture.grid(row=1, column=1, sticky=N)

        self._picture = CustomPicture(self,
                                      picture=self._get_placeholder(),
                                      size=150)
        self._picture.grid(column=1, row=0, pady=(20, 0))

        self._entry_name = CustomEntry(self, width=25)
        self._entry_name.grid(row=2, column=1, columnspan=2, sticky=W + E)

        self._label_name = CustomLabel(self, text='Product Name: ')
        self._label_name.grid(row=2, column=0, sticky=W + E)

    def _on_button_change_picture_click(self):
        picture_path = filedialog.askopenfilename()

        the_file = open(picture_path, 'rb')
        self._new_picture = the_file.read()

        the_file.close()

        self._picture.set_picture(self._new_picture)

    def _get_placeholder(self):
        self.database.query(
            'select `blob` from meta where text = "placeholder"')
        return self.database.fetch_one()[0]

    def _on_button_exit_click(self):
        self.destroy()

    def _on_button_apply_click(self):
        if self._entry_name.get() == "" or not hasattr(self, '_new_picture'):
            return

        self.database.query(
            'insert into products (name, picture) values (?, ?)',
            [self._entry_name.get(), self._new_picture])

        data = dict()
        data['name'] = self._entry_name.get()
        data['picture'] = self._new_picture

        self.event_dispatcher.dispatch_event(
            NewProductEvent(NewProductEvent.ASK, data))

        self.destroy()
示例#7
0
class Recipe(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        BaseClass.__init__(self)

        self.parent = parent
        self['bg'] = 'white'
        self._ingredients = list()
        self._description = """
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.

Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim pellentesque felis.

Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu. Cras consequat.

Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.
        """

        self._button_delete = CustomButton(self,
                                           view='normal_red',
                                           text='Delete')
        self._button_delete.grid(row=0,
                                 column=0,
                                 pady=(10, 10),
                                 padx=(10, 0),
                                 sticky=W)

        self._button_edit = CustomButton(self,
                                         view='normal_green',
                                         text='Edit')
        self._button_edit.grid(row=0,
                               column=1,
                               pady=(10, 10),
                               padx=(0, 10),
                               sticky=E)

        self._picture = CustomPicture(self,
                                      picture=self._get_placeholder(),
                                      size=150)
        self._picture.grid(column=0, row=1, pady=(0, 10), padx=(10, 0))

        Grid.columnconfigure(self, 1, weight=1)

        self._frame_text = Frame(self, bg='white')
        self._frame_text.grid(row=1, column=1, sticky=N + E + W + S)

        Grid.columnconfigure(self._frame_text, 0, weight=1)
        Grid.columnconfigure(self._frame_text, 1, weight=1)

        self._label_name = CustomLabel(self._frame_text,
                                       text='Cake',
                                       font=(self.default_font, 14, 'normal',
                                             'bold'))
        self._label_name.grid(row=0,
                              column=0,
                              columnspan=2,
                              sticky=W,
                              padx=(50, 0))

        self._label_ingredients_column_1 = CustomLabel(self._frame_text,
                                                       text='''
            1. Яицо куриное
            2. Пшеничная мука
            3. Сливки 33%-ные 
            4. Сыр маскарпоне
            5. Молочный шоколад
            6. Вишневый компот
            ''',
                                                       justify=LEFT)
        self._label_ingredients_column_1.grid(row=1, column=0, sticky=W + N)

        self._label_ingredients_column_2 = CustomLabel(self._frame_text,
                                                       text='''
            7. Топленое сливочное масло
            8. Шоколадное печенье
            9. Клубника
            10. Клубничный йогурт
            11. Мягкий творог
            12. Сахар
            ''',
                                                       justify=LEFT)
        self._label_ingredients_column_2.grid(row=1,
                                              column=1,
                                              sticky=W + N,
                                              padx=(0, 50))

        self._label_name.bind('<Button-1>', self._expand)
        self._picture.bind('<Button-1>', self._expand)
        self._label_ingredients_column_1.bind('<Button-1>', self._expand)
        self._label_ingredients_column_2.bind('<Button-1>', self._expand)

        self.event_dispatcher.add_event_listener(RecipeExpandEvent.ASK,
                                                 self._shrink)

    def _shrink(self, event):
        data = event.data
        if data == self: return
        else:
            if hasattr(self, '_label_description') and self._label_description:
                self._label_description.grid_forget()
                self._label_description.destroy()
                self._label_description = None
                self._label_description_title.grid_forget()
                self._label_description_title.destroy()
                self._label_description_title = None

    def _expand(self, event):
        self.event_dispatcher.dispatch_event(
            RecipeExpandEvent(RecipeExpandEvent.ASK, self))

        self._label_description_title = CustomLabel(self,
                                                    text='Recipe:',
                                                    font=(self.default_font,
                                                          14, 'bold'))
        self._label_description_title.grid(row=2, column=0, columnspan=2)

        self._label_description = CustomLabel(self,
                                              text=self._description,
                                              wraplength=(self.winfo_width() -
                                                          40),
                                              justify=LEFT)
        self._label_description.grid(row=3, column=0, columnspan=2)

    def _get_placeholder(self):
        self.database.query(
            'select picture from products where name = "{}"'.format('Banana'))
        return self.database.fetch_one()[0]
示例#8
0
class RecipeDialogNew(Toplevel, BaseClass):
    def __init__(self, parent, **kw):
        BaseClass.__init__(self)
        Toplevel.__init__(self, parent)

        self.parent = parent
        self['bg'] = 'white'
        self.geometry('480x650')

        self._vertical_padding = 20
        self._horizontal_padding = 20

        for i in range(0, 8):
            Grid.columnconfigure(self, i, weight=1)
            Grid.rowconfigure(self, i, weight=1)

        self._label_name = CustomLabel(self, text="Name: ")
        self._label_name.grid(row=0, column=1, sticky=S + W)

        self._entry_name = CustomEntry(self, width=35)
        self._entry_name.grid(row=1, column=1, sticky=N)

        self._label_ingredients = CustomLabel(self, text='Ingredients:')
        self._label_ingredients.grid(row=2, column=1, sticky=S + W)

        self._frame_ingredients = Frame(self)
        self._frame_ingredients.grid(row=3, column=1, sticky=N + E + W + S)

        self._scrollbar_ingredients = Scrollbar(self._frame_ingredients,
                                                orient=VERTICAL)

        self._listbox_ingredients = Listbox(
            self._frame_ingredients,
            selectmode=EXTENDED,
            yscrollcommand=self._scrollbar_ingredients.set)
        self._scrollbar_ingredients.config(
            command=self._listbox_ingredients.yview)
        self._listbox_ingredients.pack(side=LEFT, fill=BOTH, expand=1)
        self._scrollbar_ingredients.pack(side=RIGHT, fill=BOTH)

        for item in self._get_all_ingredients():
            self._listbox_ingredients.insert(END, item[0])

        self._label_description = CustomLabel(self, text='Description:')
        self._label_description.grid(row=4, column=1, sticky=S + W)

        self._entry_description = Text(self, height=10, width=50)
        self._entry_description.grid(row=5, column=1, sticky=N)

        self._picture = CustomPicture(self,
                                      picture=self._get_placeholder(),
                                      size=100)
        self._picture.grid(row=6, column=1)

        self._button_picture = CustomButton(self,
                                            view='normal_blue',
                                            text='Change Picture')
        self._button_picture.grid(row=7, column=1, sticky=N)
        self._button_picture.bind('<Button-1>', self._on_button_picture_click)

        self._button_exit = CustomButton(self,
                                         view='normal_red',
                                         text='Cancel')
        self._button_exit.grid(row=8,
                               column=0,
                               sticky=N + E + W + S,
                               pady=(0, self._vertical_padding),
                               padx=(self._horizontal_padding, 0))
        self._button_exit.bind('<Button-1>', self._on_button_exit_click)

        self._button_apply = CustomButton(self,
                                          view='normal_green',
                                          text='Apply')
        self._button_apply.grid(row=8,
                                column=2,
                                sticky=N + E + W + S,
                                pady=(0, self._vertical_padding),
                                padx=(0, self._horizontal_padding))
        self._button_apply.bind('<Button-1>', self._on_button_apply_click)

    def _on_button_apply_click(self, event):
        if self._entry_description.get(
                1.0, END) == '' or not hasattr(self, '_new_picture'):
            return

        ingredients_indexes = self._listbox_ingredients.curselection()
        ingredients_string = ''
        for i in ingredients_indexes:
            ingredients_string += '|' + self._listbox_ingredients.get(i) + '|'

        self.database.query(
            'insert into recipes (name, description, picture, ingredients) values (?, ?, ?, ?)',
            [
                self._entry_name.get(),
                self._entry_description.get(1.0, END), self._new_picture,
                ingredients_string
            ])

        data = dict()
        data['name'] = self._entry_name.get()
        data['description'] = self._entry_description.get(1.0, END)
        data['picture'] = self._new_picture
        data['ingredients'] = ingredients_string

        self.event_dispatcher.dispatch_event(
            NewRecipeEvent(NewRecipeEvent.ASK, data))

        self.destroy()

    def _on_button_exit_click(self, event):
        self.destroy()

    def _get_placeholder(self):
        self.database.query(
            'select `blob` from meta where text = "placeholder"')
        return self.database.fetch_one()[0]

    def _get_all_ingredients(self):
        self.database.query('select `name` from products')
        self._ingredients = self.database.fetch_all()
        return self._ingredients

    def _on_button_picture_click(self, event):
        picture_path = filedialog.askopenfilename()

        the_file = open(picture_path, 'rb')
        self._new_picture = the_file.read()

        the_file.close()

        self._picture.set_picture(self._new_picture)
示例#9
0
    def __init__(self, parent, **kw):
        BaseClass.__init__(self)
        Toplevel.__init__(self, parent)

        self.parent = parent
        self['bg'] = 'white'
        self.geometry('480x650')

        self._vertical_padding = 20
        self._horizontal_padding = 20

        for i in range(0, 8):
            Grid.columnconfigure(self, i, weight=1)
            Grid.rowconfigure(self, i, weight=1)

        self._label_name = CustomLabel(self, text="Name: ")
        self._label_name.grid(row=0, column=1, sticky=S + W)

        self._entry_name = CustomEntry(self, width=35)
        self._entry_name.grid(row=1, column=1, sticky=N)

        self._label_ingredients = CustomLabel(self, text='Ingredients:')
        self._label_ingredients.grid(row=2, column=1, sticky=S + W)

        self._frame_ingredients = Frame(self)
        self._frame_ingredients.grid(row=3, column=1, sticky=N + E + W + S)

        self._scrollbar_ingredients = Scrollbar(self._frame_ingredients,
                                                orient=VERTICAL)

        self._listbox_ingredients = Listbox(
            self._frame_ingredients,
            selectmode=EXTENDED,
            yscrollcommand=self._scrollbar_ingredients.set)
        self._scrollbar_ingredients.config(
            command=self._listbox_ingredients.yview)
        self._listbox_ingredients.pack(side=LEFT, fill=BOTH, expand=1)
        self._scrollbar_ingredients.pack(side=RIGHT, fill=BOTH)

        for item in self._get_all_ingredients():
            self._listbox_ingredients.insert(END, item[0])

        self._label_description = CustomLabel(self, text='Description:')
        self._label_description.grid(row=4, column=1, sticky=S + W)

        self._entry_description = Text(self, height=10, width=50)
        self._entry_description.grid(row=5, column=1, sticky=N)

        self._picture = CustomPicture(self,
                                      picture=self._get_placeholder(),
                                      size=100)
        self._picture.grid(row=6, column=1)

        self._button_picture = CustomButton(self,
                                            view='normal_blue',
                                            text='Change Picture')
        self._button_picture.grid(row=7, column=1, sticky=N)
        self._button_picture.bind('<Button-1>', self._on_button_picture_click)

        self._button_exit = CustomButton(self,
                                         view='normal_red',
                                         text='Cancel')
        self._button_exit.grid(row=8,
                               column=0,
                               sticky=N + E + W + S,
                               pady=(0, self._vertical_padding),
                               padx=(self._horizontal_padding, 0))
        self._button_exit.bind('<Button-1>', self._on_button_exit_click)

        self._button_apply = CustomButton(self,
                                          view='normal_green',
                                          text='Apply')
        self._button_apply.grid(row=8,
                                column=2,
                                sticky=N + E + W + S,
                                pady=(0, self._vertical_padding),
                                padx=(0, self._horizontal_padding))
        self._button_apply.bind('<Button-1>', self._on_button_apply_click)