Example #1
0
    def setupUI(self):
        frame_group_option = Frame(self)
        frame_group_option.grid(row=0, column=0)

        self.var_frame_group_option = IntVar()
        self.var_frame_group_option.set(1)  # set UI for app

        icon_unsplash = PhotoImage(file='icon/photo-camera.png')
        radiobutton_unsplash_ui = Radiobutton(
            frame_group_option,
            text='Unsplash',
            image=icon_unsplash,
            variable=self.var_frame_group_option,
            value=1,
            command=self.set_ui,
            compound='left')
        radiobutton_unsplash_ui.image = icon_unsplash

        icon_graphicriver = ImageTk.PhotoImage(file='icon/graphicriver.png')
        radiobutton_graphicriver_ui = Radiobutton(frame_group_option)
        radiobutton_graphicriver_ui['text'] = 'GraphicRiver'
        radiobutton_graphicriver_ui['image'] = icon_graphicriver
        radiobutton_graphicriver_ui.image = icon_graphicriver
        radiobutton_graphicriver_ui['compound'] = 'left'
        radiobutton_graphicriver_ui['variable'] = self.var_frame_group_option
        radiobutton_graphicriver_ui['value'] = 2
        radiobutton_graphicriver_ui['command'] = self.set_ui

        radiobutton_unsplash_ui.pack(side='left')
        radiobutton_graphicriver_ui.pack(side='left')

        self.unsplash_ui = UnsplashUI(self)
        self.unsplash_ui.grid(row=1, column=0, sticky='w')
Example #2
0
    def render(self, question: Question):
        '''render the question object'''

        logging.info(f'render question {question.index}')

        # delete the previous question if any
        for widget in self.grid_slaves():
            widget.destroy()

        # render question
        self.label_question = Label(self)
        self.label_question['text'] = str(
            question.index) + '. ' + question.content
        self.label_question.grid(row=0, column=0, sticky='w')

        # get list of answers
        self.list_radiobutton = []
        for answer in question.answers:
            ans = Radiobutton(self)
            ans['text'] = answer.content
            ans['compound'] = 'bottom'
            ans['value'] = answer.name
            ans['variable'] = question.choice
            ans['command'] = self.callback
            if os.path.exists(answer.image):
                i = Image.open(answer.image)
                width = 100
                height = int(width * i.height / i.width)
                i = i.resize((width, height), Image.ANTIALIAS)
                photo = ImageTk.PhotoImage(i)
                ans['image'] = photo
                ans.image = photo
            self.list_radiobutton.append(ans)

        # render answers
        for i in range(len(self.list_radiobutton)):
            # +1 because question's row is 0
            self.list_radiobutton[i].grid(row=i + 1, column=0, sticky='w')

        # render frame which contains images of question
        if allIs(True, [os.path.exists(i['path']) for i in question.images]):
            self.frame_images_of_question = ImageQuestionContainer(
                self, question.images)
            location_column_frame_images_of_question = len(self.grid_slaves())
            self.frame_images_of_question.grid(
                row=0,
                column=1,
                rowspan=location_column_frame_images_of_question)

        self.button_sure = Button(self)
        self.button_sure['text'] = 'Sure this question'
        icon_tick = PhotoImage(file='icon/tick-24.png')
        self.button_sure['image'] = icon_tick
        self.button_sure.image = icon_tick
        self.button_sure['compound'] = 'left'
        self.button_sure['command'] = self.sureCallback

        # determind location of sure button, this button will be end of the frame
        location_row = len(self.grid_slaves())
        self.button_sure.grid(row=location_row, column=0)

        # render the disabled question
        if question.state == 'sure':
            self.label_question['state'] = 'disabled'
            for radiobutton in self.list_radiobutton:
                radiobutton['state'] = 'disabled'
            self.button_sure['state'] = 'disabled'