示例#1
0
 def _create_ui(self):
     self._sbh = ScrollbarHelper(self)
     self._sbh.grid(row=0, column=0, sticky='we')
     self._text = text = tk.Text(self._sbh, width=20, height=3)
     self._sbh.add_child(self._text)
     self.rowconfigure(0, weight=1)
     self.columnconfigure(0, weight=1)
     text.bind('<FocusOut>', self._on_variable_changed)
示例#2
0
    def create_treeview_widget_list(self, treelist):
        # sbhelper widget
        sbhelper = ScrollbarHelper(self.widgetlist, scrolltype='both')

        # widgetlisttv widget
        widgetlisttv = ttk.Treeview(sbhelper)
        widgetlisttv.configure(selectmode='browse', show='tree')
        widgetlisttv.grid(column='0', row='0', sticky='nsew')

        sbhelper.add_child(widgetlisttv)
        sbhelper.configure(usemousewheel='true')
        sbhelper.grid(column='0', row='0', sticky='nsew')

        #Default widget image:
        default_image = ''
        try:
            default_image = StockImage.get('22x22-tk.default')
        except StockImageException as e:
            pass

        #Start building widget tree selector
        roots = {}
        sections = {}
        for key, wc in treelist:
            root, section = key.split('>')
            #insert root
            if root not in roots:
                roots[root] = widgetlisttv.insert('', 'end', text=root)
            #insert section
            if key not in sections:
                sections[key] = widgetlisttv.insert(roots[root],
                                                    'end',
                                                    text=section)
            #insert widget
            w_image = default_image
            try:
                w_image = StockImage.get('22x22-{0}'.format(wc.classname))
            except StockImageException as e:
                pass

            widgetlisttv.insert(sections[key],
                                'end',
                                text=wc.label,
                                image=w_image,
                                tags='widget',
                                values=(wc.classname, ))
        widgetlisttv.tag_bind('widget', '<Double-1>',
                              self.on_widgetlist_dclick)

        #Expand prefered widget set
        hidews = 'tk'
        prefws = get_option('widget_set')
        if hidews == prefws:
            hidews = 'ttk'
        widgetlisttv.item(roots[hidews], open=False)
        widgetlisttv.item(roots[prefws], open=True)
        for child in widgetlisttv.get_children(roots[prefws]):
            widgetlisttv.item(child, open=True)
示例#3
0
 def _create_ui(self):
     self._sbh = ScrollbarHelper(self)
     self._sbh.grid(row=0, column=0, sticky='we')
     self._text = text = tk.Text(self._sbh, width=20, height=3)
     self._sbh.add_child(self._text)
     self.rowconfigure(0, weight=1)
     self.columnconfigure(0, weight=1)
     text.bind('<FocusOut>', self._on_variable_changed)
示例#4
0
class TextPropertyEditor(PropertyEditor):
    def _create_ui(self):
        self._sbh = ScrollbarHelper(self)
        self._sbh.grid(row=0, column=0, sticky='we')
        self._text = text = tk.Text(self._sbh, width=20, height=3)
        self._sbh.add_child(self._text)
        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)
        text.bind('<FocusOut>', self._on_variable_changed)

    def _get_value(self):
        value = self._text.get('0.0', tk.END)
        if value.endswith('\n'):
            value = value[:-1]
        return value

    def _set_value(self, value):
        self._text.delete('0.0', tk.END)
        self._text.insert('0.0', value)
示例#5
0
class TextPropertyEditor(PropertyEditor):
    def _create_ui(self):
        self._sbh = ScrollbarHelper(self)
        self._sbh.grid(row=0, column=0, sticky='we')
        self._text = text = tk.Text(self._sbh, width=20, height=3)
        self._sbh.add_child(self._text)
        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)
        text.bind('<FocusOut>', self._on_variable_changed)

    def _get_value(self):
        value = self._text.get('0.0', tk.END)
        if value.endswith('\n'):
            value = value[:-1]
        return value

    def _set_value(self, value):
        self._text.delete('0.0', tk.END)
        self._text.insert('0.0', value)
示例#6
0
    def __init__(self, master=None):
        # build ui
        # self.configuracao = Dialog(master)
        self.frame_5 = ttk.Frame(master)
        self.label_6 = ttk.Label(self.frame_5)
        self.label_6.config(anchor='center',
                            font='{Arial} 20 {bold}',
                            text='Configurações')
        self.label_6.place(anchor='nw', relx='0.29', rely='0.04', x='0', y='0')
        self.notebook_2 = ttk.Notebook(self.frame_5)
        self.frame_6 = ttk.Frame(self.notebook_2)
        self.n_chamado = ttk.Entry(self.frame_6)
        self.n_chamado.config(justify='center')
        self.n_chamado.place(anchor='nw',
                             relx='0.23',
                             rely='0.05',
                             width='30',
                             x='0',
                             y='0')
        self.n_assunto = ttk.Entry(self.frame_6)
        self.n_assunto.config(justify='center')
        self.n_assunto.place(anchor='nw',
                             relx='0.55',
                             rely='0.05',
                             width='30',
                             x='0',
                             y='0')
        self.n_email = ttk.Entry(self.frame_6)
        self.n_email.config(justify='center')
        self.n_email.place(anchor='nw',
                           relx='0.89',
                           rely='0.05',
                           width='30',
                           x='0',
                           y='0')
        self.label_7 = ttk.Label(self.frame_6)
        self.label_7.config(text='Coluna Chamado')
        self.label_7.place(anchor='nw', relx='0.01', rely='0.05', x='0', y='0')
        self.label_8 = ttk.Label(self.frame_6)
        self.label_8.config(text='Coluna E-mail')
        self.label_8.place(anchor='nw', relx='0.7', rely='0.05', x='0', y='0')
        self.label_9 = ttk.Label(self.frame_6)
        self.label_9.config(text='Coluna Assunto')
        self.label_9.place(anchor='nw', relx='0.35', rely='0.05', x='0', y='0')
        self.scrollbarhelper_3 = ScrollbarHelper(self.frame_6,
                                                 scrolltype='both')
        self.treeview_1 = ttk.Treeview(self.scrollbarhelper_3.container)
        self.treeview_1.pack(side='top')
        self.scrollbarhelper_3.add_child(self.treeview_1)
        # TODO - self.scrollbarhelper_3: code for custom option 'usemousewheel' not implemented.
        self.scrollbarhelper_3.place(anchor='nw',
                                     relx='0.01',
                                     rely='0.15',
                                     width='480',
                                     x='0',
                                     y='0')
        self.frame_6.config(height='150', width='150')
        self.frame_6.place(anchor='nw', relx='0.0', x='0', y='0')
        self.notebook_2.add(self.frame_6, text='Planilha')
        self.frame_7 = ttk.Frame(self.notebook_2)
        self.notebook_1_2 = ttk.Notebook(self.frame_7)
        self.frame_1 = ttk.Frame(self.notebook_1_2)
        self.campo_de = ttk.Entry(self.frame_1)
        self.campo_de.place(anchor='nw',
                            relx='0.21',
                            rely='0.06',
                            width='250',
                            x='0',
                            y='0')
        self.label_1 = ttk.Label(self.frame_1)
        self.label_1.config(text='De\Remetente:')
        self.label_1.place(anchor='nw', relx='0.01', rely='0.06', x='0', y='0')
        self.label_2 = ttk.Label(self.frame_1)
        self.label_2.config(text='Assunto:')
        self.label_2.place(anchor='nw', relx='0.08', rely='0.18', x='0', y='0')
        self.campo_assunto = ttk.Entry(self.frame_1)
        self.campo_assunto.place(anchor='nw',
                                 relx='0.21',
                                 rely='0.18',
                                 width='250',
                                 x='0',
                                 y='0')
        self.frame_1.config(height='200', width='200')
        self.frame_1.pack(side='top')
        self.notebook_1_2.add(self.frame_1, text='Envio')
        self.frame_2 = ttk.Frame(self.notebook_1_2)
        self.text_msg = tk.Text(self.frame_2)
        self.text_msg.config(blockcursor='false',
                             cursor='arrow',
                             font='TkDefaultFont',
                             height='10')
        self.text_msg.config(insertunfocussed='none',
                             setgrid='false',
                             takefocus=False,
                             width='50')
        self.text_msg.place(anchor='nw',
                            height='235',
                            relx='0.01',
                            rely='0.01',
                            width='460',
                            x='0',
                            y='0')
        self.frame_2.config(height='200', width='200')
        self.frame_2.pack(side='top')
        self.notebook_1_2.add(self.frame_2, text='Texto')
        self.frame_3 = ttk.Frame(self.notebook_1_2)
        self.text_ass = tk.Text(self.frame_3)
        self.text_ass.config(height='10', width='50')
        self.text_ass.place(anchor='nw',
                            height='180',
                            relx='0.01',
                            rely='0.01',
                            width='460',
                            x='0',
                            y='0')
        self.editor_online = ttk.Button(self.frame_3)
        self.editor_online.config(text='Editor Online')
        self.editor_online.place(anchor='nw',
                                 relx='0.81',
                                 rely='0.82',
                                 x='0',
                                 y='0')
        self.button_config_copy = ttk.Button(self.frame_3)
        self.button_config_copy.config(compound='top', text='Copiar')
        self.button_config_copy.place(anchor='nw',
                                      relx='0.64',
                                      rely='0.82',
                                      x='0',
                                      y='0')
        self.frame_3.config(height='200', width='200')
        self.frame_3.pack(side='top')
        self.notebook_1_2.add(self.frame_3, text='Assinatura')
        self.notebook_1_2.config(height='260', width='475')
        self.notebook_1_2.place(anchor='nw',
                                relx='0.01',
                                rely='0.05',
                                x='0',
                                y='0')
        self.frame_7.config(height='200', width='200')
        self.frame_7.pack(side='top')
        self.notebook_2.add(self.frame_7, state='normal', text='E-mail')
        self.notebook_2.config(height='280', width='490')
        self.notebook_2.place(anchor='center',
                              relx='0.50',
                              rely='0.52',
                              x='0',
                              y='0')
        self.button_config_ok = ttk.Button(self.frame_5)
        self.button_config_ok.config(text='OK')
        self.button_config_ok.place(anchor='nw',
                                    relx='0.81',
                                    rely='0.93',
                                    x='0',
                                    y='0')
        self.button_preview = ttk.Button(self.frame_5)
        self.button_preview.config(text='Preview')
        self.button_preview.place(anchor='nw',
                                  relx='0.02',
                                  rely='0.93',
                                  x='0',
                                  y='0')
        self.button_save = ttk.Button(self.frame_5)
        self.button_save.config(text='Save')
        self.button_save.place(anchor='nw',
                               relx='0.64',
                               rely='0.93',
                               x='0',
                               y='0')
        self.frame_5.config(height='400', width='500')
        self.frame_5.pack(side='top')
        # self.configuracao.config(height='100', modal='false', width='200')

        # Main widget
        self.mainwindow = self.frame_5
示例#7
0
    def __init__(self, master=None):
        # build ui
        self.base_ds = ttk.Frame(master)
        self.forms_link = ttk.Entry(self.base_ds)
        self.forms_link.place(anchor='nw',
                              relx='0.01',
                              rely='0.05',
                              width='400',
                              x='0',
                              y='0')
        self.mail_control = ttk.Entry(self.base_ds)
        self.mail_control.config(exportselection='true')
        self.mail_control.place(anchor='nw',
                                relx='0.01',
                                rely='0.21',
                                width='400',
                                x='0',
                                y='0')
        self.label_forms = ttk.Label(self.base_ds)
        self.label_forms.config(text='Link Forms')
        self.label_forms.place(anchor='nw', relx='0.01', x='0', y='0')
        self.label_mail = ttk.Label(self.base_ds)
        self.label_mail.config(text='E-mails para relatórios')
        self.label_mail.place(anchor='nw',
                              relx='0.01',
                              rely='0.16',
                              x='0',
                              y='0')
        self.separator_2 = ttk.Separator(self.base_ds)
        self.separator_2.config(orient='horizontal')
        self.separator_2.place(anchor='nw',
                               relx='0.0',
                               rely='0.47',
                               width='600',
                               y='0')
        self.arquivo_ch = PathChooserInput(self.base_ds)
        self.arquivo_ch.config(type='file')
        self.arquivo_ch.place(anchor='nw',
                              relx='0.01',
                              rely='0.38',
                              width='465',
                              x='0',
                              y='0')
        self.label_arquivo = ttk.Label(self.base_ds)
        self.label_arquivo.config(text='Excel com chamados')
        self.label_arquivo.place(anchor='nw',
                                 relx='0.01',
                                 rely='0.33',
                                 x='0',
                                 y='0')
        self.progressbar_1 = ttk.Progressbar(self.base_ds)
        self.progressbar_1.config(maximum='100', orient='vertical', value='0')
        self.progressbar_1.place(anchor='nw',
                                 height='190',
                                 relx='0.61',
                                 rely='0.51',
                                 width='15',
                                 x='0',
                                 y='0')
        self.button_ok = ttk.Button(self.base_ds)
        self.button_ok.config(text='OK')
        self.button_ok.place(anchor='nw',
                             relx='0.86',
                             rely='0.92',
                             x='0',
                             y='0')
        self.button_enviar = ttk.Button(self.base_ds)
        self.button_enviar.config(text='Enviar')
        self.button_enviar.place(anchor='nw',
                                 height='80',
                                 relx='0.75',
                                 rely='0.56',
                                 width='80',
                                 y='0')
        self.progressbar_2 = ttk.Progressbar(self.base_ds)
        self.progressbar_2.config(maximum='100', orient='horizontal')
        self.progressbar_2.place(anchor='nw',
                                 height='6',
                                 relx='0.75',
                                 rely='0.77',
                                 width='80',
                                 x='0',
                                 y='0')
        self.button_config = ttk.Button(self.base_ds)
        self.button_config.config(text='Configurações')
        self.button_config.place(anchor='nw',
                                 relx='0.66',
                                 rely='0.92',
                                 x='0',
                                 y='0')
        self.button_config.bind('<1>', self.callback, add='')
        self.forms_colar = ttk.Button(self.base_ds)
        self.forms_colar.config(text='Colar Inteligente')
        self.forms_colar.place(anchor='nw',
                               relx='0.82',
                               rely='0.38',
                               x='0',
                               y='0')
        self.scrollbarhelper_2 = ScrollbarHelper(self.base_ds,
                                                 scrolltype='both')
        self.output = tk.Text(self.scrollbarhelper_2.container)
        self.output.config(height='10',
                           relief='flat',
                           state='normal',
                           undo='false')
        self.output.config(width='50')

        self.output.place(anchor='nw', width='120', x='0', y='0')
        self.scrollbarhelper_2.add_child(self.output)
        self.scrollbarhelper_2.place(anchor='nw',
                                     height='190',
                                     relx='0.01',
                                     rely='0.51',
                                     width='355',
                                     x='0',
                                     y='0')
        self.base_ds.config(height='400', relief='flat', width='600')
        self.base_ds.pack(anchor='center', expand='false', side='top')
        self.base_ds.pack_propagate(0)

        # Main widget
        self.mainwindow = self.base_ds

        #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        #                                   INICIALIZAÇÃO
        #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        self.forms_link.insert(0, link_forms)
        self.mail_control.insert(0, email_controle)

        self.button_enviar.config(state='disabled')

        #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
        #                                       CHAMANDO FUNÇÕES
        #///////////////////////////////////////////////////////////////////////////////////////////

        self.button_ok.config(command=self.sair)
        self.button_config.config(command=self.setting)

        self.button_enviar.config(command=self.enviar)

        self.arquivo_ch.bind('<<PathChooserPathChanged>>', self.arquivo_excel)
示例#8
0
class Automail:
    def __init__(self, master=None):
        # build ui
        self.base_ds = ttk.Frame(master)
        self.forms_link = ttk.Entry(self.base_ds)
        self.forms_link.place(anchor='nw',
                              relx='0.01',
                              rely='0.05',
                              width='400',
                              x='0',
                              y='0')
        self.mail_control = ttk.Entry(self.base_ds)
        self.mail_control.config(exportselection='true')
        self.mail_control.place(anchor='nw',
                                relx='0.01',
                                rely='0.21',
                                width='400',
                                x='0',
                                y='0')
        self.label_forms = ttk.Label(self.base_ds)
        self.label_forms.config(text='Link Forms')
        self.label_forms.place(anchor='nw', relx='0.01', x='0', y='0')
        self.label_mail = ttk.Label(self.base_ds)
        self.label_mail.config(text='E-mails para relatórios')
        self.label_mail.place(anchor='nw',
                              relx='0.01',
                              rely='0.16',
                              x='0',
                              y='0')
        self.separator_2 = ttk.Separator(self.base_ds)
        self.separator_2.config(orient='horizontal')
        self.separator_2.place(anchor='nw',
                               relx='0.0',
                               rely='0.47',
                               width='600',
                               y='0')
        self.arquivo_ch = PathChooserInput(self.base_ds)
        self.arquivo_ch.config(type='file')
        self.arquivo_ch.place(anchor='nw',
                              relx='0.01',
                              rely='0.38',
                              width='465',
                              x='0',
                              y='0')
        self.label_arquivo = ttk.Label(self.base_ds)
        self.label_arquivo.config(text='Excel com chamados')
        self.label_arquivo.place(anchor='nw',
                                 relx='0.01',
                                 rely='0.33',
                                 x='0',
                                 y='0')
        self.progressbar_1 = ttk.Progressbar(self.base_ds)
        self.progressbar_1.config(maximum='100', orient='vertical', value='0')
        self.progressbar_1.place(anchor='nw',
                                 height='190',
                                 relx='0.61',
                                 rely='0.51',
                                 width='15',
                                 x='0',
                                 y='0')
        self.button_ok = ttk.Button(self.base_ds)
        self.button_ok.config(text='OK')
        self.button_ok.place(anchor='nw',
                             relx='0.86',
                             rely='0.92',
                             x='0',
                             y='0')
        self.button_enviar = ttk.Button(self.base_ds)
        self.button_enviar.config(text='Enviar')
        self.button_enviar.place(anchor='nw',
                                 height='80',
                                 relx='0.75',
                                 rely='0.56',
                                 width='80',
                                 y='0')
        self.progressbar_2 = ttk.Progressbar(self.base_ds)
        self.progressbar_2.config(maximum='100', orient='horizontal')
        self.progressbar_2.place(anchor='nw',
                                 height='6',
                                 relx='0.75',
                                 rely='0.77',
                                 width='80',
                                 x='0',
                                 y='0')
        self.button_config = ttk.Button(self.base_ds)
        self.button_config.config(text='Configurações')
        self.button_config.place(anchor='nw',
                                 relx='0.66',
                                 rely='0.92',
                                 x='0',
                                 y='0')
        self.button_config.bind('<1>', self.callback, add='')
        self.forms_colar = ttk.Button(self.base_ds)
        self.forms_colar.config(text='Colar Inteligente')
        self.forms_colar.place(anchor='nw',
                               relx='0.82',
                               rely='0.38',
                               x='0',
                               y='0')
        self.scrollbarhelper_2 = ScrollbarHelper(self.base_ds,
                                                 scrolltype='both')
        self.output = tk.Text(self.scrollbarhelper_2.container)
        self.output.config(height='10',
                           relief='flat',
                           state='normal',
                           undo='false')
        self.output.config(width='50')

        self.output.place(anchor='nw', width='120', x='0', y='0')
        self.scrollbarhelper_2.add_child(self.output)
        self.scrollbarhelper_2.place(anchor='nw',
                                     height='190',
                                     relx='0.01',
                                     rely='0.51',
                                     width='355',
                                     x='0',
                                     y='0')
        self.base_ds.config(height='400', relief='flat', width='600')
        self.base_ds.pack(anchor='center', expand='false', side='top')
        self.base_ds.pack_propagate(0)

        # Main widget
        self.mainwindow = self.base_ds

        #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        #                                   INICIALIZAÇÃO
        #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        self.forms_link.insert(0, link_forms)
        self.mail_control.insert(0, email_controle)

        self.button_enviar.config(state='disabled')

        #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
        #                                       CHAMANDO FUNÇÕES
        #///////////////////////////////////////////////////////////////////////////////////////////

        self.button_ok.config(command=self.sair)
        self.button_config.config(command=self.setting)

        self.button_enviar.config(command=self.enviar)

        self.arquivo_ch.bind('<<PathChooserPathChanged>>', self.arquivo_excel)

#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#////////////////////////////////////////////////////////////////////////////////////////////

    def callback(self, event=None):
        pass

    def run(self):
        self.mainwindow.mainloop()

#--------------------------------------------------------------------------------------------
#                                           FUNÇÕES
#---------------------------------------------------------------------------------------------

    def sair(self):
        root.destroy()
        if obs == 1:
            root_config.destroy()

##############################################################################
#!!! EMAIL

    def enviar(self):
        global corpo_email, excel
        excel['Envio email'] = "nan"
        ncolunas = len(excel.columns)
        nlinhas = len(excel.index)

        ## TRATAMENTO DOS DADOS
        for i in range(nlinhas):

            # Pegando valores da base dados
            campo_chamado = excel.columns[int(coluna_chamado)]
            try:
                numero_chamado = int(excel.loc[i][int(coluna_chamado)])
            except:
                excel.iat[i, ncolunas] = "Falta n° chamado"
                continue

            nome_chamado = excel.loc[i][int(coluna_assunto)]

            #cliente = excel.loc[i][13]

            responsavel = excel.loc[i][int(coluna_responsavel_chm)]

            email_destino = excel.loc[i][int(coluna_email)]

            if str(nome_chamado) == 'nan':
                excel.iat[i, ncolunas] = "Falta Assunto do chamado"
                recusa.append(" {};".format(numero_chamado))
                continue

            if str(email_destino) == "nan":
                excel.iat[i, ncolunas] = "Falta email"
                recusa.append(" {};".format(numero_chamado))
                continue
            else:
                excel.iat[i, ncolunas] = "Em preparação"

            # filtrando os reponsaveis pelos chamados
            if not resp:
                resp.append(responsavel)
            elif responsavel not in resp:
                resp.append(responsavel)

            corpo_emailhtml = corpo_email.replace('\n', '<br>')
            assinatura_emailhtml = assinatura_email.replace('\n', '<br>')
            outlook = win32com.client.Dispatch('Outlook.Application')
            email = outlook.CreateItem(0)

            email.BodyFormat = 2
            email.Subject = assunto_email
            email.To = email_destino

            email.HTMLBody = (corpo_emailhtml + "<p>" + assinatura_emailhtml +
                              "<\p>")
            if email_remetente == "":
                pass
            else:
                email.SentOnBehalfOfName = email_remetente

            email.Display(False)

            # self.output.insert("0.0", corpo_email)

##############################################################################

    def arquivo_excel(self, event=None):
        global excel, colunas, X, excel_config, bz
        bz = 0
        excel = self.arquivo_ch.cget('path')
        try:
            excel_config = pd.read_excel(excel)
            excel = pd.read_excel(excel)
            colunas = list(excel_config)
            X = 1
            print('Arquivo carregado')
            self.button_enviar.config(state='enabled')
            self.output.insert("end", "Arquivo carregado\n-----------------\n")
        except:
            self.arquivo_ch.configure(path="")
            if bz == 0:
                print("Arquivo não pode ser carregado")
                self.output.insert(
                    "end",
                    "Arquivo não pode ser carregado, extensão não suportada, extensão necessária: XLSX\n------------------------------\n"
                )

                X = 0
                # self.arquivo_ch.configure(path="")
                self.button_enviar.config(state='disabled')
                bz = 1

    def clean(self):
        self.arquivo_ch.configure(path="")

#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

    class AutomailConfig:
        def __init__(self, master=None):
            # build ui

            self.frame_5 = ttk.Frame(master)
            self.label_6 = ttk.Label(self.frame_5)
            self.label_6.config(anchor='center',
                                font='{Arial} 20 {bold}',
                                text='Configurações')
            self.label_6.place(anchor='nw',
                               relx='0.29',
                               rely='0.04',
                               x='0',
                               y='0')
            self.notebook_2 = ttk.Notebook(self.frame_5)
            self.frame_6 = ttk.Frame(self.notebook_2)
            self.n_chamado = ttk.Entry(self.frame_6)
            self.n_chamado.config(justify='center')
            self.n_chamado.place(anchor='nw',
                                 relx='0.23',
                                 rely='0.05',
                                 width='30',
                                 x='0',
                                 y='0')
            self.n_assunto = ttk.Entry(self.frame_6)
            self.n_assunto.config(justify='center')
            self.n_assunto.place(anchor='nw',
                                 relx='0.55',
                                 rely='0.05',
                                 width='30',
                                 x='0',
                                 y='0')
            self.n_email = ttk.Entry(self.frame_6)
            self.n_email.config(justify='center')
            self.n_email.place(anchor='nw',
                               relx='0.89',
                               rely='0.05',
                               width='30',
                               x='0',
                               y='0')
            self.label_7 = ttk.Label(self.frame_6)
            self.label_7.config(text='Coluna Chamado')
            self.label_7.place(anchor='nw',
                               relx='0.01',
                               rely='0.05',
                               x='0',
                               y='0')
            self.label_8 = ttk.Label(self.frame_6)
            self.label_8.config(text='Coluna E-mail')
            self.label_8.place(anchor='nw',
                               relx='0.7',
                               rely='0.05',
                               x='0',
                               y='0')
            self.label_9 = ttk.Label(self.frame_6)
            self.label_9.config(text='Coluna Assunto')
            self.label_9.place(anchor='nw',
                               relx='0.35',
                               rely='0.05',
                               x='0',
                               y='0')
            self.scrollbarhelper_3 = ScrollbarHelper(self.frame_6,
                                                     scrolltype='both')
            self.treeview_1 = ttk.Treeview(self.scrollbarhelper_3.container)
            self.treeview_1.pack(side='top')
            self.scrollbarhelper_3.add_child(self.treeview_1)
            self.scrollbarhelper_3.place(anchor='nw',
                                         relx='0.01',
                                         rely='0.15',
                                         width='480',
                                         x='0',
                                         y='0')
            self.frame_6.config(height='150', width='150')
            self.frame_6.place(anchor='nw', relx='0.0', x='0', y='0')
            self.notebook_2.add(self.frame_6, text='Planilha')
            self.frame_7 = ttk.Frame(self.notebook_2)
            self.notebook_1_2 = ttk.Notebook(self.frame_7)
            self.frame_1 = ttk.Frame(self.notebook_1_2)
            self.campo_de = ttk.Entry(self.frame_1)
            self.campo_de.place(anchor='nw',
                                relx='0.21',
                                rely='0.06',
                                width='250',
                                x='0',
                                y='0')
            self.label_1 = ttk.Label(self.frame_1)
            self.label_1.config(text='De\Remetente:')
            self.label_1.place(anchor='nw',
                               relx='0.01',
                               rely='0.06',
                               x='0',
                               y='0')
            self.label_2 = ttk.Label(self.frame_1)
            self.label_2.config(text='Assunto:')
            self.label_2.place(anchor='nw',
                               relx='0.08',
                               rely='0.18',
                               x='0',
                               y='0')
            self.campo_assunto = ttk.Entry(self.frame_1)
            self.campo_assunto.place(anchor='nw',
                                     relx='0.21',
                                     rely='0.18',
                                     width='250',
                                     x='0',
                                     y='0')
            self.frame_1.config(height='200', width='200')
            self.frame_1.pack(side='top')
            self.notebook_1_2.add(self.frame_1, text='Envio')
            self.frame_2 = ttk.Frame(self.notebook_1_2)
            self.text_msg = tk.Text(self.frame_2)
            self.text_msg.config(blockcursor='false',
                                 cursor='arrow',
                                 font='TkDefaultFont',
                                 height='10')
            self.text_msg.config(insertunfocussed='none',
                                 setgrid='false',
                                 takefocus=False,
                                 width='50')
            self.text_msg.place(anchor='nw',
                                height='235',
                                relx='0.01',
                                rely='0.01',
                                width='460',
                                x='0',
                                y='0')
            self.frame_2.config(height='200', width='200')
            self.frame_2.pack(side='top')
            self.notebook_1_2.add(self.frame_2, text='Texto')
            self.frame_3 = ttk.Frame(self.notebook_1_2)
            self.text_ass = tk.Text(self.frame_3)
            self.text_ass.config(height='10', width='50')
            self.text_ass.place(anchor='nw',
                                height='180',
                                relx='0.01',
                                rely='0.01',
                                width='460',
                                x='0',
                                y='0')
            self.editor_online = ttk.Button(self.frame_3)
            self.editor_online.config(text='Editor Online')
            self.editor_online.place(anchor='nw',
                                     relx='0.81',
                                     rely='0.82',
                                     x='0',
                                     y='0')
            self.button_config_copy = ttk.Button(self.frame_3)
            self.button_config_copy.config(compound='top', text='Copiar')
            self.button_config_copy.place(anchor='nw',
                                          relx='0.64',
                                          rely='0.82',
                                          x='0',
                                          y='0')
            self.frame_3.config(height='200', width='200')
            self.frame_3.pack(side='top')
            self.notebook_1_2.add(self.frame_3, text='Assinatura')
            self.notebook_1_2.config(height='260', width='475')
            self.notebook_1_2.place(anchor='nw',
                                    relx='0.01',
                                    rely='0.05',
                                    x='0',
                                    y='0')
            self.frame_7.config(height='200', width='200')
            self.frame_7.pack(side='top')
            self.notebook_2.add(self.frame_7, state='normal', text='E-mail')
            self.notebook_2.config(height='280', width='490')
            self.notebook_2.place(anchor='center',
                                  relx='0.50',
                                  rely='0.52',
                                  x='0',
                                  y='0')
            self.button_config_ok = ttk.Button(self.frame_5)
            self.button_config_ok.config(text='OK')
            self.button_config_ok.place(anchor='nw',
                                        relx='0.81',
                                        rely='0.93',
                                        x='0',
                                        y='0')
            self.button_preview = ttk.Button(self.frame_5)
            self.button_preview.config(text='Preview')
            self.button_preview.place(anchor='nw',
                                      relx='0.02',
                                      rely='0.93',
                                      x='0',
                                      y='0')
            self.button_save = ttk.Button(self.frame_5)
            self.button_save.config(text='Save')
            self.button_save.place(anchor='nw',
                                   relx='0.64',
                                   rely='0.93',
                                   x='0',
                                   y='0')
            self.frame_5.config(height='400', width='500')
            self.frame_5.pack(side='top')

            # Main widget
            self.mainwindow = self.frame_5
            #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
            #                                       CHAMANDO FUNÇÕES
            #///////////////////////////////////////////////////////////////////////////////////////////

            self.button_save.config(command=self.save)

            self.button_config_ok.config(command=self.ok_config)

            self.button_preview.config(command=self.preview)

            # self.mainwindow.protocol("WM_DELETE_WINDOW",self.sair_config)

            #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            #                                INICIALIZAÇÃO
            #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

            self.n_chamado.insert(0, coluna_chamado)
            self.n_assunto.insert(0, coluna_assunto)
            self.n_email.insert(0, coluna_email)

            self.campo_assunto.insert(0, assunto_email)
            self.campo_de.insert(0, email_remetente)

            self.text_msg.insert("0.0", corpo_email)
            self.text_ass.insert("0.0", assinatura_email)

            global excel_config, colunas, X

            if not X == 0:
                index_c = list(range(1, (1 + (len(excel_config.columns)))))
                colunas_excel = list(index_c)

                self.treeview_1.config(selectmode="none")
                self.treeview_1['columns'] = colunas_excel

                for i in colunas_excel:
                    self.treeview_1.column(i, width=100, anchor='n')
                    self.treeview_1.heading(i, text=i)

                self.treeview_1.insert("", 'end', text=0, values=colunas)

                for index, row in excel_config.iterrows():
                    self.treeview_1.insert("",
                                           'end',
                                           text=(index + 1),
                                           values=list(row))

                # definindo largura da coluna de INDEX
                self.treeview_1.column('#0', width=30)

        def run(self):
            self.mainwindow.mainloop()

#---------------------------------------------------------------------------------
#                               FUNÇÕES CONFIGURAÇÕES
#--------------------------------------------------------------------------------

        def sair_config():
            global obs
            obs = 0
            print('Fechou')

        def save(self):
            global obs, coluna_chamado, coluna_assunto, coluna_email
            global assunto_email, email_remetente, corpo_email, assinatura_email

            coluna_chamado = self.n_chamado.get()
            coluna_assunto = self.n_assunto.get()
            coluna_email = self.n_email.get()

            assunto_email = self.campo_assunto.get()
            email_remetente = self.campo_de.get()

            corpo_email = self.text_msg.get("0.0", 'end-1c')
            assinatura_email = self.text_ass.get("0.0", 'end-1c')

            # Janela Principal
            padrao['link_forms'] = link_forms
            padrao_email['controle'] = email_controle
            # # Janela Configuraçoes
            padrao_email['remetente'] = self.campo_de.get()
            padrao_email['assunto'] = self.campo_assunto.get()
            padrao_email['corpo'] = self.text_msg.get("0.0", 'end-1c')
            padrao_email['assinatura'] = self.text_ass.get("0.0", 'end-1c')

            padrao_planilha['colunaChamados'] = self.n_chamado.get()
            padrao_planilha['colunaEmails'] = self.n_email.get()
            padrao_planilha['colunaAssuntos'] = self.n_assunto.get()
            #Salvando arquivo config
            with open('Configuracao.ini', 'w') as stg:
                default.write(stg)

        def ok_config(self):
            global obs, coluna_chamado, coluna_assunto, coluna_email
            global assunto_email, email_remetente, corpo_email, assinatura_email
            coluna_chamado = self.n_chamado.get()
            coluna_assunto = self.n_assunto.get()
            coluna_email = self.n_email.get()

            assunto_email = self.campo_assunto.get()
            email_remetente = self.campo_de.get()

            corpo_email = self.text_msg.get("0.0", 'end-1c')
            assinatura_email = self.text_ass.get("0.0", 'end-1c')

            root_config.destroy()
            obs = 0

        def preview(self):
            global corpo_email, assunto_email, email_remetente
            corpo_emailhtml = corpo_email.replace('\n', '<br>')
            assinatura_emailhtml = assinatura_email.replace('\n', '<br>')
            outlook = win32com.client.Dispatch('Outlook.Application')
            email = outlook.CreateItem(0)

            email.BodyFormat = 2
            email.Subject = assunto_email

            email.HTMLBody = (corpo_emailhtml + "<p>" + assinatura_emailhtml +
                              "<\p>")
            if email_remetente == "":
                pass
            else:
                email.SentOnBehalfOfName = email_remetente

            email.Display(False)

            # self.output.insert("end", (corpo_email+"\n------------\n"))

    def setting(self):
        global root_config, link_forms, obs, email_controle
        print('ok')

        if obs == 0:
            root_config = tk.Tk()

            w2 = 550
            h2 = 300
            ws = root.winfo_screenwidth()
            hs = root.winfo_screenheight()
            x2 = (ws / 2) - (w2 / 2)
            y2 = (hs / 2) - (h2 / 2)
            root_config.geometry('+%d+%d' % (x2, y2))

            self.AutomailConfig(root_config)
            obs = 1

            ## HINT Get informações
            link_forms = self.forms_link.get()
            print(link_forms)
            email_controle = self.mail_control.get()

            def sair_config():
                global obs
                obs = 0
                print('Fechou')
                root_config.destroy()

            # try:
            root_config.protocol("WM_DELETE_WINDOW", sair_config)
示例#9
0
        def __init__(self, master=None):
            # build ui

            self.frame_5 = ttk.Frame(master)
            self.label_6 = ttk.Label(self.frame_5)
            self.label_6.config(anchor='center',
                                font='{Arial} 20 {bold}',
                                text='Configurações')
            self.label_6.place(anchor='nw',
                               relx='0.29',
                               rely='0.04',
                               x='0',
                               y='0')
            self.notebook_2 = ttk.Notebook(self.frame_5)
            self.frame_6 = ttk.Frame(self.notebook_2)
            self.n_chamado = ttk.Entry(self.frame_6)
            self.n_chamado.config(justify='center')
            self.n_chamado.place(anchor='nw',
                                 relx='0.23',
                                 rely='0.05',
                                 width='30',
                                 x='0',
                                 y='0')
            self.n_assunto = ttk.Entry(self.frame_6)
            self.n_assunto.config(justify='center')
            self.n_assunto.place(anchor='nw',
                                 relx='0.55',
                                 rely='0.05',
                                 width='30',
                                 x='0',
                                 y='0')
            self.n_email = ttk.Entry(self.frame_6)
            self.n_email.config(justify='center')
            self.n_email.place(anchor='nw',
                               relx='0.89',
                               rely='0.05',
                               width='30',
                               x='0',
                               y='0')
            self.label_7 = ttk.Label(self.frame_6)
            self.label_7.config(text='Coluna Chamado')
            self.label_7.place(anchor='nw',
                               relx='0.01',
                               rely='0.05',
                               x='0',
                               y='0')
            self.label_8 = ttk.Label(self.frame_6)
            self.label_8.config(text='Coluna E-mail')
            self.label_8.place(anchor='nw',
                               relx='0.7',
                               rely='0.05',
                               x='0',
                               y='0')
            self.label_9 = ttk.Label(self.frame_6)
            self.label_9.config(text='Coluna Assunto')
            self.label_9.place(anchor='nw',
                               relx='0.35',
                               rely='0.05',
                               x='0',
                               y='0')
            self.scrollbarhelper_3 = ScrollbarHelper(self.frame_6,
                                                     scrolltype='both')
            self.treeview_1 = ttk.Treeview(self.scrollbarhelper_3.container)
            self.treeview_1.pack(side='top')
            self.scrollbarhelper_3.add_child(self.treeview_1)
            self.scrollbarhelper_3.place(anchor='nw',
                                         relx='0.01',
                                         rely='0.15',
                                         width='480',
                                         x='0',
                                         y='0')
            self.frame_6.config(height='150', width='150')
            self.frame_6.place(anchor='nw', relx='0.0', x='0', y='0')
            self.notebook_2.add(self.frame_6, text='Planilha')
            self.frame_7 = ttk.Frame(self.notebook_2)
            self.notebook_1_2 = ttk.Notebook(self.frame_7)
            self.frame_1 = ttk.Frame(self.notebook_1_2)
            self.campo_de = ttk.Entry(self.frame_1)
            self.campo_de.place(anchor='nw',
                                relx='0.21',
                                rely='0.06',
                                width='250',
                                x='0',
                                y='0')
            self.label_1 = ttk.Label(self.frame_1)
            self.label_1.config(text='De\Remetente:')
            self.label_1.place(anchor='nw',
                               relx='0.01',
                               rely='0.06',
                               x='0',
                               y='0')
            self.label_2 = ttk.Label(self.frame_1)
            self.label_2.config(text='Assunto:')
            self.label_2.place(anchor='nw',
                               relx='0.08',
                               rely='0.18',
                               x='0',
                               y='0')
            self.campo_assunto = ttk.Entry(self.frame_1)
            self.campo_assunto.place(anchor='nw',
                                     relx='0.21',
                                     rely='0.18',
                                     width='250',
                                     x='0',
                                     y='0')
            self.frame_1.config(height='200', width='200')
            self.frame_1.pack(side='top')
            self.notebook_1_2.add(self.frame_1, text='Envio')
            self.frame_2 = ttk.Frame(self.notebook_1_2)
            self.text_msg = tk.Text(self.frame_2)
            self.text_msg.config(blockcursor='false',
                                 cursor='arrow',
                                 font='TkDefaultFont',
                                 height='10')
            self.text_msg.config(insertunfocussed='none',
                                 setgrid='false',
                                 takefocus=False,
                                 width='50')
            self.text_msg.place(anchor='nw',
                                height='235',
                                relx='0.01',
                                rely='0.01',
                                width='460',
                                x='0',
                                y='0')
            self.frame_2.config(height='200', width='200')
            self.frame_2.pack(side='top')
            self.notebook_1_2.add(self.frame_2, text='Texto')
            self.frame_3 = ttk.Frame(self.notebook_1_2)
            self.text_ass = tk.Text(self.frame_3)
            self.text_ass.config(height='10', width='50')
            self.text_ass.place(anchor='nw',
                                height='180',
                                relx='0.01',
                                rely='0.01',
                                width='460',
                                x='0',
                                y='0')
            self.editor_online = ttk.Button(self.frame_3)
            self.editor_online.config(text='Editor Online')
            self.editor_online.place(anchor='nw',
                                     relx='0.81',
                                     rely='0.82',
                                     x='0',
                                     y='0')
            self.button_config_copy = ttk.Button(self.frame_3)
            self.button_config_copy.config(compound='top', text='Copiar')
            self.button_config_copy.place(anchor='nw',
                                          relx='0.64',
                                          rely='0.82',
                                          x='0',
                                          y='0')
            self.frame_3.config(height='200', width='200')
            self.frame_3.pack(side='top')
            self.notebook_1_2.add(self.frame_3, text='Assinatura')
            self.notebook_1_2.config(height='260', width='475')
            self.notebook_1_2.place(anchor='nw',
                                    relx='0.01',
                                    rely='0.05',
                                    x='0',
                                    y='0')
            self.frame_7.config(height='200', width='200')
            self.frame_7.pack(side='top')
            self.notebook_2.add(self.frame_7, state='normal', text='E-mail')
            self.notebook_2.config(height='280', width='490')
            self.notebook_2.place(anchor='center',
                                  relx='0.50',
                                  rely='0.52',
                                  x='0',
                                  y='0')
            self.button_config_ok = ttk.Button(self.frame_5)
            self.button_config_ok.config(text='OK')
            self.button_config_ok.place(anchor='nw',
                                        relx='0.81',
                                        rely='0.93',
                                        x='0',
                                        y='0')
            self.button_preview = ttk.Button(self.frame_5)
            self.button_preview.config(text='Preview')
            self.button_preview.place(anchor='nw',
                                      relx='0.02',
                                      rely='0.93',
                                      x='0',
                                      y='0')
            self.button_save = ttk.Button(self.frame_5)
            self.button_save.config(text='Save')
            self.button_save.place(anchor='nw',
                                   relx='0.64',
                                   rely='0.93',
                                   x='0',
                                   y='0')
            self.frame_5.config(height='400', width='500')
            self.frame_5.pack(side='top')

            # Main widget
            self.mainwindow = self.frame_5
            #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
            #                                       CHAMANDO FUNÇÕES
            #///////////////////////////////////////////////////////////////////////////////////////////

            self.button_save.config(command=self.save)

            self.button_config_ok.config(command=self.ok_config)

            self.button_preview.config(command=self.preview)

            # self.mainwindow.protocol("WM_DELETE_WINDOW",self.sair_config)

            #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            #                                INICIALIZAÇÃO
            #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

            self.n_chamado.insert(0, coluna_chamado)
            self.n_assunto.insert(0, coluna_assunto)
            self.n_email.insert(0, coluna_email)

            self.campo_assunto.insert(0, assunto_email)
            self.campo_de.insert(0, email_remetente)

            self.text_msg.insert("0.0", corpo_email)
            self.text_ass.insert("0.0", assinatura_email)

            global excel_config, colunas, X

            if not X == 0:
                index_c = list(range(1, (1 + (len(excel_config.columns)))))
                colunas_excel = list(index_c)

                self.treeview_1.config(selectmode="none")
                self.treeview_1['columns'] = colunas_excel

                for i in colunas_excel:
                    self.treeview_1.column(i, width=100, anchor='n')
                    self.treeview_1.heading(i, text=i)

                self.treeview_1.insert("", 'end', text=0, values=colunas)

                for index, row in excel_config.iterrows():
                    self.treeview_1.insert("",
                                           'end',
                                           text=(index + 1),
                                           values=list(row))

                # definindo largura da coluna de INDEX
                self.treeview_1.column('#0', width=30)
示例#10
0
    class AutomailConfig:
        def __init__(self, master=None):
            # build ui

            self.frame_5 = ttk.Frame(master)
            self.label_6 = ttk.Label(self.frame_5)
            self.label_6.config(anchor='center',
                                font='{Arial} 20 {bold}',
                                text='Configurações')
            self.label_6.place(anchor='nw',
                               relx='0.29',
                               rely='0.04',
                               x='0',
                               y='0')
            self.notebook_2 = ttk.Notebook(self.frame_5)
            self.frame_6 = ttk.Frame(self.notebook_2)
            self.n_chamado = ttk.Entry(self.frame_6)
            self.n_chamado.config(justify='center')
            self.n_chamado.place(anchor='nw',
                                 relx='0.23',
                                 rely='0.05',
                                 width='30',
                                 x='0',
                                 y='0')
            self.n_assunto = ttk.Entry(self.frame_6)
            self.n_assunto.config(justify='center')
            self.n_assunto.place(anchor='nw',
                                 relx='0.55',
                                 rely='0.05',
                                 width='30',
                                 x='0',
                                 y='0')
            self.n_email = ttk.Entry(self.frame_6)
            self.n_email.config(justify='center')
            self.n_email.place(anchor='nw',
                               relx='0.89',
                               rely='0.05',
                               width='30',
                               x='0',
                               y='0')
            self.label_7 = ttk.Label(self.frame_6)
            self.label_7.config(text='Coluna Chamado')
            self.label_7.place(anchor='nw',
                               relx='0.01',
                               rely='0.05',
                               x='0',
                               y='0')
            self.label_8 = ttk.Label(self.frame_6)
            self.label_8.config(text='Coluna E-mail')
            self.label_8.place(anchor='nw',
                               relx='0.7',
                               rely='0.05',
                               x='0',
                               y='0')
            self.label_9 = ttk.Label(self.frame_6)
            self.label_9.config(text='Coluna Assunto')
            self.label_9.place(anchor='nw',
                               relx='0.35',
                               rely='0.05',
                               x='0',
                               y='0')
            self.scrollbarhelper_3 = ScrollbarHelper(self.frame_6,
                                                     scrolltype='both')
            self.treeview_1 = ttk.Treeview(self.scrollbarhelper_3.container)
            self.treeview_1.pack(side='top')
            self.scrollbarhelper_3.add_child(self.treeview_1)
            self.scrollbarhelper_3.place(anchor='nw',
                                         relx='0.01',
                                         rely='0.15',
                                         width='480',
                                         x='0',
                                         y='0')
            self.frame_6.config(height='150', width='150')
            self.frame_6.place(anchor='nw', relx='0.0', x='0', y='0')
            self.notebook_2.add(self.frame_6, text='Planilha')
            self.frame_7 = ttk.Frame(self.notebook_2)
            self.notebook_1_2 = ttk.Notebook(self.frame_7)
            self.frame_1 = ttk.Frame(self.notebook_1_2)
            self.campo_de = ttk.Entry(self.frame_1)
            self.campo_de.place(anchor='nw',
                                relx='0.21',
                                rely='0.06',
                                width='250',
                                x='0',
                                y='0')
            self.label_1 = ttk.Label(self.frame_1)
            self.label_1.config(text='De\Remetente:')
            self.label_1.place(anchor='nw',
                               relx='0.01',
                               rely='0.06',
                               x='0',
                               y='0')
            self.label_2 = ttk.Label(self.frame_1)
            self.label_2.config(text='Assunto:')
            self.label_2.place(anchor='nw',
                               relx='0.08',
                               rely='0.18',
                               x='0',
                               y='0')
            self.campo_assunto = ttk.Entry(self.frame_1)
            self.campo_assunto.place(anchor='nw',
                                     relx='0.21',
                                     rely='0.18',
                                     width='250',
                                     x='0',
                                     y='0')
            self.frame_1.config(height='200', width='200')
            self.frame_1.pack(side='top')
            self.notebook_1_2.add(self.frame_1, text='Envio')
            self.frame_2 = ttk.Frame(self.notebook_1_2)
            self.text_msg = tk.Text(self.frame_2)
            self.text_msg.config(blockcursor='false',
                                 cursor='arrow',
                                 font='TkDefaultFont',
                                 height='10')
            self.text_msg.config(insertunfocussed='none',
                                 setgrid='false',
                                 takefocus=False,
                                 width='50')
            self.text_msg.place(anchor='nw',
                                height='235',
                                relx='0.01',
                                rely='0.01',
                                width='460',
                                x='0',
                                y='0')
            self.frame_2.config(height='200', width='200')
            self.frame_2.pack(side='top')
            self.notebook_1_2.add(self.frame_2, text='Texto')
            self.frame_3 = ttk.Frame(self.notebook_1_2)
            self.text_ass = tk.Text(self.frame_3)
            self.text_ass.config(height='10', width='50')
            self.text_ass.place(anchor='nw',
                                height='180',
                                relx='0.01',
                                rely='0.01',
                                width='460',
                                x='0',
                                y='0')
            self.editor_online = ttk.Button(self.frame_3)
            self.editor_online.config(text='Editor Online')
            self.editor_online.place(anchor='nw',
                                     relx='0.81',
                                     rely='0.82',
                                     x='0',
                                     y='0')
            self.button_config_copy = ttk.Button(self.frame_3)
            self.button_config_copy.config(compound='top', text='Copiar')
            self.button_config_copy.place(anchor='nw',
                                          relx='0.64',
                                          rely='0.82',
                                          x='0',
                                          y='0')
            self.frame_3.config(height='200', width='200')
            self.frame_3.pack(side='top')
            self.notebook_1_2.add(self.frame_3, text='Assinatura')
            self.notebook_1_2.config(height='260', width='475')
            self.notebook_1_2.place(anchor='nw',
                                    relx='0.01',
                                    rely='0.05',
                                    x='0',
                                    y='0')
            self.frame_7.config(height='200', width='200')
            self.frame_7.pack(side='top')
            self.notebook_2.add(self.frame_7, state='normal', text='E-mail')
            self.notebook_2.config(height='280', width='490')
            self.notebook_2.place(anchor='center',
                                  relx='0.50',
                                  rely='0.52',
                                  x='0',
                                  y='0')
            self.button_config_ok = ttk.Button(self.frame_5)
            self.button_config_ok.config(text='OK')
            self.button_config_ok.place(anchor='nw',
                                        relx='0.81',
                                        rely='0.93',
                                        x='0',
                                        y='0')
            self.button_preview = ttk.Button(self.frame_5)
            self.button_preview.config(text='Preview')
            self.button_preview.place(anchor='nw',
                                      relx='0.02',
                                      rely='0.93',
                                      x='0',
                                      y='0')
            self.button_save = ttk.Button(self.frame_5)
            self.button_save.config(text='Save')
            self.button_save.place(anchor='nw',
                                   relx='0.64',
                                   rely='0.93',
                                   x='0',
                                   y='0')
            self.frame_5.config(height='400', width='500')
            self.frame_5.pack(side='top')

            # Main widget
            self.mainwindow = self.frame_5
            #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
            #                                       CHAMANDO FUNÇÕES
            #///////////////////////////////////////////////////////////////////////////////////////////

            self.button_save.config(command=self.save)

            self.button_config_ok.config(command=self.ok_config)

            self.button_preview.config(command=self.preview)

            # self.mainwindow.protocol("WM_DELETE_WINDOW",self.sair_config)

            #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            #                                INICIALIZAÇÃO
            #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

            self.n_chamado.insert(0, coluna_chamado)
            self.n_assunto.insert(0, coluna_assunto)
            self.n_email.insert(0, coluna_email)

            self.campo_assunto.insert(0, assunto_email)
            self.campo_de.insert(0, email_remetente)

            self.text_msg.insert("0.0", corpo_email)
            self.text_ass.insert("0.0", assinatura_email)

            global excel_config, colunas, X

            if not X == 0:
                index_c = list(range(1, (1 + (len(excel_config.columns)))))
                colunas_excel = list(index_c)

                self.treeview_1.config(selectmode="none")
                self.treeview_1['columns'] = colunas_excel

                for i in colunas_excel:
                    self.treeview_1.column(i, width=100, anchor='n')
                    self.treeview_1.heading(i, text=i)

                self.treeview_1.insert("", 'end', text=0, values=colunas)

                for index, row in excel_config.iterrows():
                    self.treeview_1.insert("",
                                           'end',
                                           text=(index + 1),
                                           values=list(row))

                # definindo largura da coluna de INDEX
                self.treeview_1.column('#0', width=30)

        def run(self):
            self.mainwindow.mainloop()

#---------------------------------------------------------------------------------
#                               FUNÇÕES CONFIGURAÇÕES
#--------------------------------------------------------------------------------

        def sair_config():
            global obs
            obs = 0
            print('Fechou')

        def save(self):
            global obs, coluna_chamado, coluna_assunto, coluna_email
            global assunto_email, email_remetente, corpo_email, assinatura_email

            coluna_chamado = self.n_chamado.get()
            coluna_assunto = self.n_assunto.get()
            coluna_email = self.n_email.get()

            assunto_email = self.campo_assunto.get()
            email_remetente = self.campo_de.get()

            corpo_email = self.text_msg.get("0.0", 'end-1c')
            assinatura_email = self.text_ass.get("0.0", 'end-1c')

            # Janela Principal
            padrao['link_forms'] = link_forms
            padrao_email['controle'] = email_controle
            # # Janela Configuraçoes
            padrao_email['remetente'] = self.campo_de.get()
            padrao_email['assunto'] = self.campo_assunto.get()
            padrao_email['corpo'] = self.text_msg.get("0.0", 'end-1c')
            padrao_email['assinatura'] = self.text_ass.get("0.0", 'end-1c')

            padrao_planilha['colunaChamados'] = self.n_chamado.get()
            padrao_planilha['colunaEmails'] = self.n_email.get()
            padrao_planilha['colunaAssuntos'] = self.n_assunto.get()
            #Salvando arquivo config
            with open('Configuracao.ini', 'w') as stg:
                default.write(stg)

        def ok_config(self):
            global obs, coluna_chamado, coluna_assunto, coluna_email
            global assunto_email, email_remetente, corpo_email, assinatura_email
            coluna_chamado = self.n_chamado.get()
            coluna_assunto = self.n_assunto.get()
            coluna_email = self.n_email.get()

            assunto_email = self.campo_assunto.get()
            email_remetente = self.campo_de.get()

            corpo_email = self.text_msg.get("0.0", 'end-1c')
            assinatura_email = self.text_ass.get("0.0", 'end-1c')

            root_config.destroy()
            obs = 0

        def preview(self):
            global corpo_email, assunto_email, email_remetente
            corpo_emailhtml = corpo_email.replace('\n', '<br>')
            assinatura_emailhtml = assinatura_email.replace('\n', '<br>')
            outlook = win32com.client.Dispatch('Outlook.Application')
            email = outlook.CreateItem(0)

            email.BodyFormat = 2
            email.Subject = assunto_email

            email.HTMLBody = (corpo_emailhtml + "<p>" + assinatura_emailhtml +
                              "<\p>")
            if email_remetente == "":
                pass
            else:
                email.SentOnBehalfOfName = email_remetente

            email.Display(False)
示例#11
0
    def __init__(self, master=None):

        self._logger = getLogger(__name__)
        self._logger.addHandler(NullHandler())
        self._logger.setLevel(DEBUG)
        self._logger.propagate = True

        self.root = master
        self.root.title(NAME + ' ' + VERSION)
        # self.root.resizable(0, 0)
        self.controller = None
        self.poke_treeview = None
        self.keyPress = None
        self.keyboard = None
        '''
        ここから
        '''
        # build ui
        self.frame_1 = ttk.Frame(master)
        self.camera_lf = ttk.Labelframe(self.frame_1)
        self.label_1 = ttk.Label(self.camera_lf)
        self.label_1.config(anchor='center', text='Camera ID:')
        self.label_1.grid(padx='5', sticky='ew')
        self.camera_entry = ttk.Entry(self.camera_lf)
        self.camera_id = tk.IntVar()
        self.camera_entry.config(state='normal', textvariable=self.camera_id)
        self.camera_entry.grid(column='1', padx='5', row='0', sticky='ew')
        self.camera_entry.columnconfigure('1', uniform='0')
        self.reloadButton = ttk.Button(self.camera_lf)
        self.reloadButton.config(text='Reload Camera')
        self.reloadButton.grid(column='2', padx='5', row='0', sticky='ew')
        self.reloadButton.configure(command=self.openCamera)
        self.separator_1 = ttk.Separator(self.camera_lf)
        self.separator_1.config(orient='vertical')
        self.separator_1.grid(column='3', row='0', sticky='ns')
        self.cb1 = ttk.Checkbutton(self.camera_lf)
        self.is_show_realtime = tk.BooleanVar()
        self.cb1.config(text='Show Realtime', variable=self.is_show_realtime)
        self.cb1.grid(column='4', row='0')
        self.separator_2 = ttk.Separator(self.camera_lf)
        self.separator_2.config(orient='vertical')
        self.separator_2.grid(column='5', row='0', sticky='ns')
        self.captureButton = ttk.Button(self.camera_lf)
        self.captureButton.config(text='Capture')
        self.captureButton.grid(column='6', row='0')
        self.captureButton.configure(command=self.saveCapture)
        self.camera_f2 = ttk.Frame(self.camera_lf)
        self.label3 = ttk.Label(self.camera_f2)
        self.label3.config(text='FPS:')
        self.label3.grid(padx='5', sticky='ew')
        self.fps_cb = ttk.Combobox(self.camera_f2)
        self.fps = tk.StringVar()
        self.fps_cb.config(justify='right',
                           state='readonly',
                           textvariable=self.fps,
                           values=[60, 45, 30, 15, 5])
        self.fps_cb.config(width='5')
        self.fps_cb.grid(column='1', padx='10', row='0', sticky='ew')
        self.fps_cb.bind('<<ComboboxSelected>>', self.applyFps, add='')
        self.separator_3 = ttk.Separator(self.camera_f2)
        self.separator_3.config(orient='vertical')
        self.separator_3.grid(column='2', row='0', sticky='ns')
        self.show_size_label = ttk.Label(self.camera_f2)
        self.show_size_label.config(text='Show Size:')
        self.show_size_label.grid(column='3', padx='5', row='0', sticky='ew')
        self.show_size_cb = ttk.Combobox(self.camera_f2)
        self.show_size = tk.StringVar()
        self.show_size_cb.config(textvariable=self.show_size,
                                 state='readonly',
                                 values='640x360 1280x720 1920x1080')
        self.show_size_cb.grid(column='4', padx='10', row='0', sticky='ew')
        self.show_size_cb.bind('<<ComboboxSelected>>',
                               self.applyWindowSize,
                               add='')
        self.camera_f2.grid(column='0', columnspan='7', row='3', sticky='nsew')
        self.camera_name_l = ttk.Label(self.camera_lf)
        self.camera_name_l.config(anchor='center', text='Camera Name: ')
        self.camera_name_l.grid(column='0', padx='5', row='1', sticky='ew')
        self.Camera_Name = ttk.Combobox(self.camera_lf)
        self.camera_name_fromDLL = tk.StringVar()
        self.Camera_Name.config(state='normal',
                                textvariable=self.camera_name_fromDLL)
        self.Camera_Name.grid(column='1',
                              columnspan='6',
                              padx='5',
                              row='1',
                              sticky='ew')
        self.Camera_Name.bind('<<ComboboxSelected>>',
                              self.set_cameraid,
                              add='')
        self.frame_1_2 = ttk.Frame(self.camera_lf)
        self.frame_1_2.config(height='360', relief='groove', width='640')
        self.frame_1_2.grid(column='0', columnspan='7', row='2')
        self.camera_lf.config(height='200', text='Camera', width='200')
        self.camera_lf.grid(columnspan='3', padx='5', sticky='ew')
        self.serial_lf = ttk.Labelframe(self.frame_1)
        self.label2 = ttk.Label(self.serial_lf)
        self.label2.config(text='COM Port: ')
        self.label2.grid(padx='5', sticky='ew')
        self.label2.rowconfigure('0', uniform='None', weight='0')
        self.entry2 = ttk.Entry(self.serial_lf)
        self.com_port = tk.IntVar()
        self.entry2.config(textvariable=self.com_port, width='5')
        self.entry2.grid(column='1', padx='5', row='0', sticky='ew')
        self.entry2.rowconfigure('0', uniform='None', weight='0')
        self.reloadComPort = ttk.Button(self.serial_lf)
        self.reloadComPort.config(text='Reload Port')
        self.reloadComPort.grid(column='2', row='0')
        self.reloadComPort.rowconfigure('0', uniform='None', weight='0')
        self.reloadComPort.configure(command=self.activateSerial)
        self.separator_4 = ttk.Separator(self.serial_lf)
        self.separator_4.config(orient='vertical')
        self.separator_4.grid(column='3', padx='5', row='0', sticky='ns')
        self.separator_4.rowconfigure('0', uniform='None', weight='0')
        self.separator_4.columnconfigure('3', uniform='None', weight='0')
        self.checkbutton_2 = ttk.Checkbutton(self.serial_lf)
        self.is_show_serial = tk.BooleanVar()
        self.checkbutton_2.config(text='Show Serial',
                                  variable=self.is_show_serial)
        self.checkbutton_2.grid(column='4',
                                columnspan='2',
                                padx='5',
                                row='0',
                                sticky='ew')
        self.checkbutton_2.rowconfigure('0', uniform='None', weight='0')
        self.serial_lf.config(text='Serial Settings')
        self.serial_lf.grid(column='0',
                            columnspan='2',
                            padx='5',
                            row='1',
                            sticky='nsew')
        self.control_lf = ttk.Labelframe(self.frame_1)
        self.cb_use_keyboard = ttk.Checkbutton(self.control_lf)
        self.cb_left_stick_mouse = ttk.Checkbutton(self.control_lf)
        self.cb_right_stick_mouse = ttk.Checkbutton(self.control_lf)
        self.is_use_keyboard = tk.BooleanVar()
        self.camera_lf.is_use_left_stick_mouse = tk.BooleanVar()
        self.camera_lf.is_use_right_stick_mouse = tk.BooleanVar()
        self.cb_use_keyboard.config(text='Use Keyboard',
                                    variable=self.is_use_keyboard)
        self.cb_use_keyboard.grid(column='0', padx='10', pady='5', sticky='ew')
        self.cb_use_keyboard.rowconfigure('0', weight='1')
        self.cb_use_keyboard.columnconfigure('0', weight='1')
        self.cb_use_keyboard.configure(command=self.activateKeyboard)
        self.cb_left_stick_mouse.config(
            text='Use LStick Mouse',
            variable=self.camera_lf.is_use_left_stick_mouse)
        self.cb_left_stick_mouse.grid(column='1',
                                      row='0',
                                      padx='10',
                                      pady='5',
                                      sticky='ew')
        self.cb_left_stick_mouse.rowconfigure('0', weight='1')
        self.cb_left_stick_mouse.columnconfigure('0', weight='1')
        self.cb_left_stick_mouse.configure(
            command=self.activate_Left_stick_mouse)
        self.cb_right_stick_mouse.config(
            text='Use RStick Mouse',
            variable=self.camera_lf.is_use_right_stick_mouse)
        self.cb_right_stick_mouse.grid(column='1',
                                       row='1',
                                       padx='10',
                                       pady='5',
                                       sticky='ew')
        self.cb_right_stick_mouse.rowconfigure('0', weight='1')
        self.cb_right_stick_mouse.columnconfigure('0', weight='1')
        self.cb_right_stick_mouse.configure(
            command=self.activate_Right_stick_mouse)
        self.simpleConButton = ttk.Button(self.control_lf)
        self.simpleConButton.config(text='Controller')
        self.simpleConButton.grid(column='0',
                                  padx='10',
                                  pady='5',
                                  row='1',
                                  sticky='ew')
        self.simpleConButton.rowconfigure('1', weight='1')
        self.simpleConButton.columnconfigure('0', weight='1')
        self.simpleConButton.configure(command=self.createControllerWindow)
        self.control_lf.config(height='200', text='Controller')
        # self.control_lf.grid(column='0', padx='5', row='2', sticky='nsew')
        self.control_lf.grid(column='0',
                             padx='5',
                             row='2',
                             columnspan='2',
                             sticky='nsew')
        # self.Poke_statistic_lf = ttk.Labelframe(self.frame_1)
        # self.OpenPokeButton = ttk.Button(self.Poke_statistic_lf)
        # self.OpenPokeButton.config(text='技統計')
        # self.OpenPokeButton.grid(padx='10', pady='10', sticky='nsew')
        # self.OpenPokeButton.rowconfigure('0', pad='0', uniform='1', weight='1')
        # self.OpenPokeButton.columnconfigure('0', pad='0', uniform='1', weight='1')
        # self.OpenPokeButton.configure(command=self.createGetFromHomeWindow)
        # self.Poke_statistic_lf.config(height='200', text='PokemonHome連携', width='200')
        # self.Poke_statistic_lf.grid(column='1', padx='5', row='2', sticky='nsew')
        self.lf = ttk.Labelframe(self.frame_1)
        self.Command_nb = ttk.Notebook(self.lf)
        self.py_cb = ttk.Combobox(self.Command_nb)
        self.py_name = tk.StringVar()
        self.py_cb.config(state='readonly', textvariable=self.py_name)
        self.py_cb.pack(side='top')
        self.Command_nb.add(self.py_cb, padding='5', text='Python Command')
        self.mcu_cb = ttk.Combobox(self.Command_nb)
        self.mcu_name = tk.StringVar()
        self.mcu_cb.config(state='readonly', textvariable=self.mcu_name)
        self.mcu_cb.pack(side='top')
        self.Command_nb.add(self.mcu_cb, padding='5', text='Mcu Command')
        self.Command_nb.grid(column='0',
                             columnspan='2',
                             padx='5',
                             pady='5',
                             row='0',
                             sticky='ew')
        self.reloadCommandButton = ttk.Button(self.lf)
        self.reloadCommandButton.config(text='Reload')
        self.reloadCommandButton.grid(column='0',
                                      padx='5',
                                      pady='5',
                                      row='1',
                                      sticky='ew')
        self.reloadCommandButton.configure(command=self.reloadCommands)
        self.startButton = ttk.Button(self.lf)
        self.startButton.config(text='Start')
        self.startButton.grid(column='1',
                              padx='5',
                              pady='5',
                              row='1',
                              sticky='ew')
        self.startButton.configure(command=self.startPlay)
        self.lf.config(height='200', text='Command')
        self.lf.grid(column='2', padx='5', row='1', rowspan='2', sticky='nsew')
        self.log_scroll = ScrollbarHelper(self.frame_1, scrolltype='both')
        self.logArea = tk.Text(self.log_scroll.container)
        self.logArea.config(blockcursor='true',
                            height='10',
                            insertunfocussed='none',
                            maxundo='0')
        self.logArea.config(relief='flat',
                            state='disabled',
                            undo='false',
                            width='50')
        self.logArea.pack(expand='true', fill='both', side='top')
        self.log_scroll.add_child(self.logArea)
        self.log_scroll.config(borderwidth='1', padding='1', relief='sunken')
        # TODO - self.log_scroll: code for custom option 'usemousewheel' not implemented.
        self.log_scroll.grid(column='3',
                             padx='5',
                             pady='5',
                             row='0',
                             rowspan='3',
                             sticky='nsew')
        self.frame_1.config(height='720',
                            padding='5',
                            relief='flat',
                            width='1280')
        self.frame_1.pack(expand='true', fill='both', side='top')
        self.frame_1.columnconfigure('3', weight='1')
        '''
        ここまで
        '''

        # 仮置フレームを削除
        self.frame_1_2.destroy()

        # 標準出力をログにリダイレクト
        sys.stdout = StdoutRedirector(self.logArea)
        # load settings file
        self.loadSettings()
        # 各tk変数に設定値をセット(コピペ簡単のため)
        self.is_show_realtime.set(self.settings.is_show_realtime.get())
        self.is_show_serial.set(self.settings.is_show_serial.get())
        self.is_use_keyboard.set(self.settings.is_use_keyboard.get())
        self.fps.set(self.settings.fps.get())
        self.show_size.set(self.settings.show_size.get())
        self.com_port.set(self.settings.com_port.get())
        self.camera_id.set(self.settings.camera_id.get())
        # 各コンボボックスを現在の設定値に合わせて表示
        self.fps_cb.current(self.fps_cb['values'].index(self.fps.get()))
        self.show_size_cb.current(self.show_size_cb['values'].index(
            self.show_size.get()))

        if os.name == 'nt':
            try:
                self.locateCameraCmbbox()
                self.camera_entry.config(state='disable')
            except:
                # Locate an entry instead whenever dll is not imported successfully
                self.camera_name_fromDLL.set(
                    "An error occurred while displaying the camera names in NT environment."
                )
                self._logger.warning(
                    "An error occurred while displaying the camera names in NT environment."
                )
                self.Camera_Name.config(state='disable')
        else:
            self.camera_name_fromDLL.set(
                "Not nt environment so that cannot show Camera name.")
            self.Camera_Name.config(state='disable')
        # open up a camera
        self.camera = Camera(self.fps.get())
        self.openCamera()
        # activate serial communication
        self.ser = Sender.Sender(self.is_show_serial)
        self.activateSerial()
        self.activateKeyboard()
        self.preview = CaptureArea(
            self.camera, self.fps.get(), self.is_show_realtime, self.ser,
            self.camera_lf, *list(map(int,
                                      self.show_size.get().split("x"))))
        self.preview.config(cursor='crosshair')
        self.preview.grid(column='0',
                          columnspan='7',
                          row='2',
                          padx='5',
                          pady='5',
                          sticky=tk.NSEW)
        self.loadCommands()

        # Main widget
        self.mainwindow = self.frame_1

        self.root.protocol("WM_DELETE_WINDOW", self.exit)
        self.preview.startCapture()

        self.menu = PokeController_Menubar(self)
        self.root.config(menu=self.menu)
示例#12
0
class PokeControllerApp:
    def __init__(self, master=None):

        self._logger = getLogger(__name__)
        self._logger.addHandler(NullHandler())
        self._logger.setLevel(DEBUG)
        self._logger.propagate = True

        self.root = master
        self.root.title(NAME + ' ' + VERSION)
        # self.root.resizable(0, 0)
        self.controller = None
        self.poke_treeview = None
        self.keyPress = None
        self.keyboard = None
        '''
        ここから
        '''
        # build ui
        self.frame_1 = ttk.Frame(master)
        self.camera_lf = ttk.Labelframe(self.frame_1)
        self.label_1 = ttk.Label(self.camera_lf)
        self.label_1.config(anchor='center', text='Camera ID:')
        self.label_1.grid(padx='5', sticky='ew')
        self.camera_entry = ttk.Entry(self.camera_lf)
        self.camera_id = tk.IntVar()
        self.camera_entry.config(state='normal', textvariable=self.camera_id)
        self.camera_entry.grid(column='1', padx='5', row='0', sticky='ew')
        self.camera_entry.columnconfigure('1', uniform='0')
        self.reloadButton = ttk.Button(self.camera_lf)
        self.reloadButton.config(text='Reload Camera')
        self.reloadButton.grid(column='2', padx='5', row='0', sticky='ew')
        self.reloadButton.configure(command=self.openCamera)
        self.separator_1 = ttk.Separator(self.camera_lf)
        self.separator_1.config(orient='vertical')
        self.separator_1.grid(column='3', row='0', sticky='ns')
        self.cb1 = ttk.Checkbutton(self.camera_lf)
        self.is_show_realtime = tk.BooleanVar()
        self.cb1.config(text='Show Realtime', variable=self.is_show_realtime)
        self.cb1.grid(column='4', row='0')
        self.separator_2 = ttk.Separator(self.camera_lf)
        self.separator_2.config(orient='vertical')
        self.separator_2.grid(column='5', row='0', sticky='ns')
        self.captureButton = ttk.Button(self.camera_lf)
        self.captureButton.config(text='Capture')
        self.captureButton.grid(column='6', row='0')
        self.captureButton.configure(command=self.saveCapture)
        self.camera_f2 = ttk.Frame(self.camera_lf)
        self.label3 = ttk.Label(self.camera_f2)
        self.label3.config(text='FPS:')
        self.label3.grid(padx='5', sticky='ew')
        self.fps_cb = ttk.Combobox(self.camera_f2)
        self.fps = tk.StringVar()
        self.fps_cb.config(justify='right',
                           state='readonly',
                           textvariable=self.fps,
                           values=[60, 45, 30, 15, 5])
        self.fps_cb.config(width='5')
        self.fps_cb.grid(column='1', padx='10', row='0', sticky='ew')
        self.fps_cb.bind('<<ComboboxSelected>>', self.applyFps, add='')
        self.separator_3 = ttk.Separator(self.camera_f2)
        self.separator_3.config(orient='vertical')
        self.separator_3.grid(column='2', row='0', sticky='ns')
        self.show_size_label = ttk.Label(self.camera_f2)
        self.show_size_label.config(text='Show Size:')
        self.show_size_label.grid(column='3', padx='5', row='0', sticky='ew')
        self.show_size_cb = ttk.Combobox(self.camera_f2)
        self.show_size = tk.StringVar()
        self.show_size_cb.config(textvariable=self.show_size,
                                 state='readonly',
                                 values='640x360 1280x720 1920x1080')
        self.show_size_cb.grid(column='4', padx='10', row='0', sticky='ew')
        self.show_size_cb.bind('<<ComboboxSelected>>',
                               self.applyWindowSize,
                               add='')
        self.camera_f2.grid(column='0', columnspan='7', row='3', sticky='nsew')
        self.camera_name_l = ttk.Label(self.camera_lf)
        self.camera_name_l.config(anchor='center', text='Camera Name: ')
        self.camera_name_l.grid(column='0', padx='5', row='1', sticky='ew')
        self.Camera_Name = ttk.Combobox(self.camera_lf)
        self.camera_name_fromDLL = tk.StringVar()
        self.Camera_Name.config(state='normal',
                                textvariable=self.camera_name_fromDLL)
        self.Camera_Name.grid(column='1',
                              columnspan='6',
                              padx='5',
                              row='1',
                              sticky='ew')
        self.Camera_Name.bind('<<ComboboxSelected>>',
                              self.set_cameraid,
                              add='')
        self.frame_1_2 = ttk.Frame(self.camera_lf)
        self.frame_1_2.config(height='360', relief='groove', width='640')
        self.frame_1_2.grid(column='0', columnspan='7', row='2')
        self.camera_lf.config(height='200', text='Camera', width='200')
        self.camera_lf.grid(columnspan='3', padx='5', sticky='ew')
        self.serial_lf = ttk.Labelframe(self.frame_1)
        self.label2 = ttk.Label(self.serial_lf)
        self.label2.config(text='COM Port: ')
        self.label2.grid(padx='5', sticky='ew')
        self.label2.rowconfigure('0', uniform='None', weight='0')
        self.entry2 = ttk.Entry(self.serial_lf)
        self.com_port = tk.IntVar()
        self.entry2.config(textvariable=self.com_port, width='5')
        self.entry2.grid(column='1', padx='5', row='0', sticky='ew')
        self.entry2.rowconfigure('0', uniform='None', weight='0')
        self.reloadComPort = ttk.Button(self.serial_lf)
        self.reloadComPort.config(text='Reload Port')
        self.reloadComPort.grid(column='2', row='0')
        self.reloadComPort.rowconfigure('0', uniform='None', weight='0')
        self.reloadComPort.configure(command=self.activateSerial)
        self.separator_4 = ttk.Separator(self.serial_lf)
        self.separator_4.config(orient='vertical')
        self.separator_4.grid(column='3', padx='5', row='0', sticky='ns')
        self.separator_4.rowconfigure('0', uniform='None', weight='0')
        self.separator_4.columnconfigure('3', uniform='None', weight='0')
        self.checkbutton_2 = ttk.Checkbutton(self.serial_lf)
        self.is_show_serial = tk.BooleanVar()
        self.checkbutton_2.config(text='Show Serial',
                                  variable=self.is_show_serial)
        self.checkbutton_2.grid(column='4',
                                columnspan='2',
                                padx='5',
                                row='0',
                                sticky='ew')
        self.checkbutton_2.rowconfigure('0', uniform='None', weight='0')
        self.serial_lf.config(text='Serial Settings')
        self.serial_lf.grid(column='0',
                            columnspan='2',
                            padx='5',
                            row='1',
                            sticky='nsew')
        self.control_lf = ttk.Labelframe(self.frame_1)
        self.cb_use_keyboard = ttk.Checkbutton(self.control_lf)
        self.cb_left_stick_mouse = ttk.Checkbutton(self.control_lf)
        self.cb_right_stick_mouse = ttk.Checkbutton(self.control_lf)
        self.is_use_keyboard = tk.BooleanVar()
        self.camera_lf.is_use_left_stick_mouse = tk.BooleanVar()
        self.camera_lf.is_use_right_stick_mouse = tk.BooleanVar()
        self.cb_use_keyboard.config(text='Use Keyboard',
                                    variable=self.is_use_keyboard)
        self.cb_use_keyboard.grid(column='0', padx='10', pady='5', sticky='ew')
        self.cb_use_keyboard.rowconfigure('0', weight='1')
        self.cb_use_keyboard.columnconfigure('0', weight='1')
        self.cb_use_keyboard.configure(command=self.activateKeyboard)
        self.cb_left_stick_mouse.config(
            text='Use LStick Mouse',
            variable=self.camera_lf.is_use_left_stick_mouse)
        self.cb_left_stick_mouse.grid(column='1',
                                      row='0',
                                      padx='10',
                                      pady='5',
                                      sticky='ew')
        self.cb_left_stick_mouse.rowconfigure('0', weight='1')
        self.cb_left_stick_mouse.columnconfigure('0', weight='1')
        self.cb_left_stick_mouse.configure(
            command=self.activate_Left_stick_mouse)
        self.cb_right_stick_mouse.config(
            text='Use RStick Mouse',
            variable=self.camera_lf.is_use_right_stick_mouse)
        self.cb_right_stick_mouse.grid(column='1',
                                       row='1',
                                       padx='10',
                                       pady='5',
                                       sticky='ew')
        self.cb_right_stick_mouse.rowconfigure('0', weight='1')
        self.cb_right_stick_mouse.columnconfigure('0', weight='1')
        self.cb_right_stick_mouse.configure(
            command=self.activate_Right_stick_mouse)
        self.simpleConButton = ttk.Button(self.control_lf)
        self.simpleConButton.config(text='Controller')
        self.simpleConButton.grid(column='0',
                                  padx='10',
                                  pady='5',
                                  row='1',
                                  sticky='ew')
        self.simpleConButton.rowconfigure('1', weight='1')
        self.simpleConButton.columnconfigure('0', weight='1')
        self.simpleConButton.configure(command=self.createControllerWindow)
        self.control_lf.config(height='200', text='Controller')
        # self.control_lf.grid(column='0', padx='5', row='2', sticky='nsew')
        self.control_lf.grid(column='0',
                             padx='5',
                             row='2',
                             columnspan='2',
                             sticky='nsew')
        # self.Poke_statistic_lf = ttk.Labelframe(self.frame_1)
        # self.OpenPokeButton = ttk.Button(self.Poke_statistic_lf)
        # self.OpenPokeButton.config(text='技統計')
        # self.OpenPokeButton.grid(padx='10', pady='10', sticky='nsew')
        # self.OpenPokeButton.rowconfigure('0', pad='0', uniform='1', weight='1')
        # self.OpenPokeButton.columnconfigure('0', pad='0', uniform='1', weight='1')
        # self.OpenPokeButton.configure(command=self.createGetFromHomeWindow)
        # self.Poke_statistic_lf.config(height='200', text='PokemonHome連携', width='200')
        # self.Poke_statistic_lf.grid(column='1', padx='5', row='2', sticky='nsew')
        self.lf = ttk.Labelframe(self.frame_1)
        self.Command_nb = ttk.Notebook(self.lf)
        self.py_cb = ttk.Combobox(self.Command_nb)
        self.py_name = tk.StringVar()
        self.py_cb.config(state='readonly', textvariable=self.py_name)
        self.py_cb.pack(side='top')
        self.Command_nb.add(self.py_cb, padding='5', text='Python Command')
        self.mcu_cb = ttk.Combobox(self.Command_nb)
        self.mcu_name = tk.StringVar()
        self.mcu_cb.config(state='readonly', textvariable=self.mcu_name)
        self.mcu_cb.pack(side='top')
        self.Command_nb.add(self.mcu_cb, padding='5', text='Mcu Command')
        self.Command_nb.grid(column='0',
                             columnspan='2',
                             padx='5',
                             pady='5',
                             row='0',
                             sticky='ew')
        self.reloadCommandButton = ttk.Button(self.lf)
        self.reloadCommandButton.config(text='Reload')
        self.reloadCommandButton.grid(column='0',
                                      padx='5',
                                      pady='5',
                                      row='1',
                                      sticky='ew')
        self.reloadCommandButton.configure(command=self.reloadCommands)
        self.startButton = ttk.Button(self.lf)
        self.startButton.config(text='Start')
        self.startButton.grid(column='1',
                              padx='5',
                              pady='5',
                              row='1',
                              sticky='ew')
        self.startButton.configure(command=self.startPlay)
        self.lf.config(height='200', text='Command')
        self.lf.grid(column='2', padx='5', row='1', rowspan='2', sticky='nsew')
        self.log_scroll = ScrollbarHelper(self.frame_1, scrolltype='both')
        self.logArea = tk.Text(self.log_scroll.container)
        self.logArea.config(blockcursor='true',
                            height='10',
                            insertunfocussed='none',
                            maxundo='0')
        self.logArea.config(relief='flat',
                            state='disabled',
                            undo='false',
                            width='50')
        self.logArea.pack(expand='true', fill='both', side='top')
        self.log_scroll.add_child(self.logArea)
        self.log_scroll.config(borderwidth='1', padding='1', relief='sunken')
        # TODO - self.log_scroll: code for custom option 'usemousewheel' not implemented.
        self.log_scroll.grid(column='3',
                             padx='5',
                             pady='5',
                             row='0',
                             rowspan='3',
                             sticky='nsew')
        self.frame_1.config(height='720',
                            padding='5',
                            relief='flat',
                            width='1280')
        self.frame_1.pack(expand='true', fill='both', side='top')
        self.frame_1.columnconfigure('3', weight='1')
        '''
        ここまで
        '''

        # 仮置フレームを削除
        self.frame_1_2.destroy()

        # 標準出力をログにリダイレクト
        sys.stdout = StdoutRedirector(self.logArea)
        # load settings file
        self.loadSettings()
        # 各tk変数に設定値をセット(コピペ簡単のため)
        self.is_show_realtime.set(self.settings.is_show_realtime.get())
        self.is_show_serial.set(self.settings.is_show_serial.get())
        self.is_use_keyboard.set(self.settings.is_use_keyboard.get())
        self.fps.set(self.settings.fps.get())
        self.show_size.set(self.settings.show_size.get())
        self.com_port.set(self.settings.com_port.get())
        self.camera_id.set(self.settings.camera_id.get())
        # 各コンボボックスを現在の設定値に合わせて表示
        self.fps_cb.current(self.fps_cb['values'].index(self.fps.get()))
        self.show_size_cb.current(self.show_size_cb['values'].index(
            self.show_size.get()))

        if os.name == 'nt':
            try:
                self.locateCameraCmbbox()
                self.camera_entry.config(state='disable')
            except:
                # Locate an entry instead whenever dll is not imported successfully
                self.camera_name_fromDLL.set(
                    "An error occurred while displaying the camera names in NT environment."
                )
                self._logger.warning(
                    "An error occurred while displaying the camera names in NT environment."
                )
                self.Camera_Name.config(state='disable')
        else:
            self.camera_name_fromDLL.set(
                "Not nt environment so that cannot show Camera name.")
            self.Camera_Name.config(state='disable')
        # open up a camera
        self.camera = Camera(self.fps.get())
        self.openCamera()
        # activate serial communication
        self.ser = Sender.Sender(self.is_show_serial)
        self.activateSerial()
        self.activateKeyboard()
        self.preview = CaptureArea(
            self.camera, self.fps.get(), self.is_show_realtime, self.ser,
            self.camera_lf, *list(map(int,
                                      self.show_size.get().split("x"))))
        self.preview.config(cursor='crosshair')
        self.preview.grid(column='0',
                          columnspan='7',
                          row='2',
                          padx='5',
                          pady='5',
                          sticky=tk.NSEW)
        self.loadCommands()

        # Main widget
        self.mainwindow = self.frame_1

        self.root.protocol("WM_DELETE_WINDOW", self.exit)
        self.preview.startCapture()

        self.menu = PokeController_Menubar(self)
        self.root.config(menu=self.menu)

        # logging.debug(f'python version: {sys.version}')

    def openCamera(self):
        self.camera.openCamera(self.camera_id.get())

    def assignCamera(self, event):
        if os.name == 'nt':
            self.camera_name_fromDLL.set(self.camera_dic[self.camera_id.get()])

    def locateCameraCmbbox(self):
        import clr
        clr.AddReference(r"..\DirectShowLib\DirectShowLib-2005")
        from DirectShowLib import DsDevice, FilterCategory

        # Get names of detected camera devices
        captureDevices = DsDevice.GetDevicesOfCat(
            FilterCategory.VideoInputDevice)
        self.camera_dic = {
            cam_id: device.Name
            for cam_id, device in enumerate(captureDevices)
        }

        self.camera_dic[str(max(list(self.camera_dic.keys())) + 1)] = 'Disable'
        self.Camera_Name['values'] = [
            device for device in self.camera_dic.values()
        ]
        self._logger.debug(
            f"Camera list: {[device for device in self.camera_dic.values()]}")
        dev_num = len(self.camera_dic)

        if self.camera_id.get() > dev_num - 1:
            print('Inappropriate camera ID! -> set to 0')
            self._logger.debug('Inappropriate camera ID! -> set to 0')
            self.camera_id.set(0)
            if dev_num == 0:
                print('No camera devices can be found.')
                self._logger.debug('No camera devices can be found.')
        #
        self.camera_entry.bind('<KeyRelease>', self.assignCamera)
        self.Camera_Name.current(self.camera_id.get())

    def saveCapture(self):
        self.camera.saveCapture()

    def set_cameraid(self, event=None):
        keys = [
            k for k, v in self.camera_dic.items()
            if v == self.Camera_Name.get()
        ]
        if keys:
            ret = keys[0]
        else:
            ret = None
        self.camera_id.set(ret)

    def applyFps(self, event=None):
        print('changed FPS to: ' + self.fps.get() + ' [fps]')
        self.preview.setFps(self.fps.get())

    def applyWindowSize(self, event=None):
        width, height = map(int, self.show_size.get().split("x"))
        self.preview.setShowsize(height, width)

    def activateSerial(self):
        if self.ser.isOpened():
            print('Port is already opened and being closed.')
            self.ser.closeSerial()
            self.keyPress = None
            self.activateSerial()
        else:
            if self.ser.openSerial(self.com_port.get()):
                print('COM Port ' + str(self.com_port.get()) +
                      ' connected successfully')
                self._logger.debug('COM Port ' + str(self.com_port.get()) +
                                   ' connected successfully')
                self.keyPress = KeyPress(self.ser)

    def activateKeyboard(self):
        if self.is_use_keyboard.get():
            # enable Keyboard as controller
            if self.keyboard is None:
                self.keyboard = SwitchKeyboardController(self.keyPress)
                self.keyboard.listen()

            # bind focus
            if os.name == 'nt':
                self.root.bind("<FocusIn>", self.onFocusInController)
                self.root.bind("<FocusOut>", self.onFocusOutController)

        else:
            if os.name == 'nt':  # NOTE: Idk why but self.keyboard.stop() makes crash on Linux
                if self.keyboard is not None:
                    # stop listening to keyboard events
                    self.keyboard.stop()
                    self.keyboard = None

                self.root.bind("<FocusIn>", lambda _: None)
                self.root.bind("<FocusOut>", lambda _: None)

    def onFocusInController(self, event):
        # enable Keyboard as controller
        if event.widget == self.root and self.keyboard is None:
            self.keyboard = SwitchKeyboardController(self.keyPress)
            self.keyboard.listen()

    def onFocusOutController(self, event):
        # stop listening to keyboard events
        if event.widget == self.root and not self.keyboard is None:
            self.keyboard.stop()
            self.keyboard = None

    def createControllerWindow(self):
        if not self.controller is None:
            self.controller.focus_force()
            return

        window = ControllerGUI(self.root, self.ser)
        window.protocol("WM_DELETE_WINDOW", self.closingController)
        self.controller = window

    def activate_Left_stick_mouse(self):
        self.preview.ApplyLStickMouse()

    def activate_Right_stick_mouse(self):
        self.preview.ApplyRStickMouse()

    # def createGetFromHomeWindow(self):
    #     if self.poke_treeview is not None:
    #         self.poke_treeview.focus_force()
    #         return
    #
    #     window2 = GetFromHomeGUI(self.root, self.settings.season, self.settings.is_SingleBattle)
    #     window2.protocol("WM_DELETE_WINDOW", self.closingGetFromHome)
    #     self.poke_treeview = window2

    def loadCommands(self):
        self.py_loader = CommandLoader(
            util.ospath('Commands/PythonCommands'),
            PythonCommandBase.PythonCommand)  # コマンドの読み込み
        self.mcu_loader = CommandLoader(util.ospath('Commands/McuCommands'),
                                        McuCommandBase.McuCommand)
        self.py_classes = self.py_loader.load()
        self.mcu_classes = self.mcu_loader.load()
        self.setCommandItems()
        self.assignCommand()

    def setCommandItems(self):
        self.py_cb['values'] = [c.NAME for c in self.py_classes]
        self.py_cb.current(0)
        self.mcu_cb['values'] = [c.NAME for c in self.mcu_classes]
        self.mcu_cb.current(0)

    def assignCommand(self):
        # 選択されているコマンドを取得する
        self.mcu_cur_command = self.mcu_classes[
            self.mcu_cb.current()]()  # MCUコマンドについて

        # pythonコマンドは画像認識を使うかどうかで分岐している
        cmd_class = self.py_classes[self.py_cb.current()]
        if issubclass(cmd_class, PythonCommandBase.ImageProcPythonCommand):
            try:  # 画像認識の際に認識位置を表示する引数追加。互換性のため従来のはexceptに。
                self.py_cur_command = cmd_class(self.camera, self.preview)
            except TypeError:
                self.py_cur_command = cmd_class(self.camera)
            except:
                self.py_cur_command = cmd_class(self.camera)

        else:
            self.py_cur_command = cmd_class()

        if self.Command_nb.index(self.Command_nb.select()) == 0:
            self.cur_command = self.py_cur_command
        else:
            self.cur_command = self.mcu_cur_command

    def reloadCommands(self):
        # 表示しているタブを読み取って、どのコマンドを表示しているか取得、リロード後もそれが選択されるようにする
        oldval_mcu = self.mcu_cb.get()
        oldval_py = self.py_cb.get()

        self.py_classes = self.py_loader.reload()
        self.mcu_classes = self.mcu_loader.reload()

        # Restore the command selecting state if possible
        self.setCommandItems()
        if oldval_mcu in self.mcu_cb['values']:
            self.mcu_cb.set(oldval_mcu)
        if oldval_py in self.py_cb['values']:
            self.py_cb.set(oldval_py)
        self.assignCommand()
        print('Finished reloading command modules.')
        self._logger.info("Reloaded commands.")

    def startPlay(self):
        if self.cur_command is None:
            print('No commands have been assigned yet.')
            self._logger.info('No commands have been assigned yet.')

        # set and init selected command
        self.assignCommand()

        print(self.startButton["text"] + ' ' + self.cur_command.NAME)
        self._logger.info(self.startButton["text"] + ' ' +
                          self.cur_command.NAME)
        self.cur_command.start(self.ser, self.stopPlayPost)

        self.startButton["text"] = "Stop"
        self.startButton["command"] = self.stopPlay
        self.reloadCommandButton["state"] = "disabled"

    def stopPlay(self):
        print(self.startButton["text"] + ' ' + self.cur_command.NAME)
        self._logger.info(self.startButton["text"] + ' ' +
                          self.cur_command.NAME)
        self.startButton["state"] = "disabled"
        self.cur_command.end(self.ser)

    def stopPlayPost(self):
        self.startButton["text"] = "Start"
        self.startButton["command"] = self.startPlay
        self.startButton["state"] = "normal"
        self.reloadCommandButton["state"] = "normal"

    def run(self):
        self._logger.debug("Start Poke-Controller")
        self.mainwindow.mainloop()

    def exit(self):
        if self.ser.isOpened():
            self.ser.closeSerial()
            print("Serial disconnected")
            # self._logger.info("Serial disconnected")

        # stop listening to keyboard events
        if not self.keyboard is None:
            self.keyboard.stop()
            self.keyboard = None

        # save settings
        self.settings.is_show_realtime.set(self.is_show_realtime.get())
        self.settings.is_show_serial.set(self.is_show_serial.get())
        self.settings.is_use_keyboard.set(self.is_use_keyboard.get())
        self.settings.fps.set(self.fps.get())
        self.settings.show_size.set(self.show_size.get())
        self.settings.com_port.set(self.com_port.get())
        self.settings.camera_id.set(self.camera_id.get())

        self.settings.save()

        self.camera.destroy()
        cv2.destroyAllWindows()
        self._logger.debug("Stop Poke Controller")
        self.root.destroy()

    def closingController(self):
        self.controller.destroy()
        self.controller = None

    # def closingGetFromHome(self):
    #     self.poke_treeview.destroy()
    #     self.poke_treeview = None

    def loadSettings(self):
        self.settings = Settings.GuiSettings()
        self.settings.load()