Esempio n. 1
0
    def _translator(self, _text=None, _lang="en"):
        if _text == None:
            return None

        try:
            _translated = self.__translator.translate(_text, dest=_lang)
            _translated = self.__translator.translate(_text, dest="en")
            _text = _translated.text
        except:
            try:
                _text = self.__google_translator.translate(_text,
                                                           lang_tgt=_lang)
                _text = self.__google_translator.translate(_text,
                                                           lang_tgt="en")
            except:
                try:
                    _gs = goslate.Goslate()
                    _text = _gs.translate(_text, 'en')
                except:
                    _translator = trans(to_lang="en")
                    _text = _translator.translate(_text)

        txtBlob = TextBlob(_text)
        _text = str(txtBlob.correct())
        try:
            _text = str(txtBlob.translate(to='en'))
        except:
            _text = _text
        return _text
Esempio n. 2
0
def extract_chinese(path):
    for file in os.listdir(path):
        current_file = os.path.join(path, file)
        if not any(value in current_file
                   for value in (".DS_Store", "scss", "fonts", "mock",
                                 "assets", "script", "img", "protobuf")):
            if (os.path.isfile(current_file)):
                module_name = get_module_name(current_file)
                with open(current_file, "rb") as r:
                    lineslist = r.readlines()
                with open(current_file, "w") as w:
                    for l in lineslist:
                        chn = []
                        origin_l = l.decode('utf8')
                        l = l.decode('utf8')

                        llist = list(l)
                        for char in llist:
                            m = re.findall(u"[\u4e00-\u9fa5]", char)
                            if len(m):
                                chn.append(m[0])
                            else:
                                if len(chn):
                                    chn_str = ''.join(chn)
                                    eng_str = trans([chn_str])[0]
                                    final_key = get_key(module_name, eng_str)
                                    get_rows(final_key, chn_str, eng_str,
                                             origin_l)
                                    l = l.replace(chn_str,
                                                  'intl("' + final_key + '")')
                                    print(l)
                                    chn = []
                        w.write(l)
            else:
                extract_chinese(current_file)
Esempio n. 3
0
 def _translator(self, _text=None, _lang="en"):
     if _text == None:
         return None
     print("Translating...")
     txtBlob = TextBlob(_text)
     _text = str(txtBlob.correct())
     sleep(self.sleep_time)  #short Time
     try:
         _translated = self.__translator.translate(_text, dest=_lang)
         sleep(self.sleep_time)  #short Time
         _translated = self.__translator.translate(_text, dest="en")
         _text = _translated.text
     except:
         try:
             _text = self.__google_translator.translate(_text,
                                                        lang_tgt=_lang)
             sleep(self.sleep_time)  #short Time
             _text = self.__google_translator.translate(_text,
                                                        lang_tgt="en")
         except:
             try:
                 _gs = goslate.Goslate()
                 _text = _gs.translate(_text, 'en')
             except:
                 try:
                     _translator = trans(to_lang="en")
                     _text = _translator.translate(_text)
                 except:
                     try:
                         _text = str(txtBlob.translate(to='en'))
                     except:
                         _text = None
     _text = str(txtBlob.correct())
     print("Translating Completed.")
     return _text
Esempio n. 4
0
    def start(self, text):
        text = text.strip()

        if text.startswith(calc_keys):
            text = text.replace(calc_keys, '')
            text = text.strip()
            cal.cal(text)

        elif text.startswith(wiki_keys):
            text = text.replace(translate_keys, '')
            text = text.strip()
            textargs = text.split("-")
            text0 = textargs[1].replace('-', '')
            text0 = text0.strip()
            w.wikicall(text0)

        elif text.startswith(translate_keys):
            text = text.replace(translate_keys, '')
            text = text.strip()
            textargs = text.split("-")
            text0 = textargs[1].replace('-', '')
            text0 = text0.strip()
            text1 = textargs[2].replace('-', '')
            text1 = text1.strip()
            t.trans(text0, text1)

        elif text.startswith(create_keys):
            text = text.replace(create_keys, '')
            text = text.strip()
            textargs = text.split("-")
            text0 = textargs[1].replace('-', '')
            text0 = text0.strip()
            text1 = textargs[2].replace('-', '')
            text1 = text1.strip()
            cr.create(text0, text1)

        elif text.startswith(google_keys):
            text = text.replace(google_keys, '')
            text = text.strip()
            textargs = text.split("-")
            b.search_net(textargs[1])

        elif text.startswith(time_keys):
            ti.telltime()

        else:
            sg.popup('Sorry', "Something went wrong!\nTry again please!")
def reply(msg):
    global Name
    if msg['Text'] == '翻译' and msg['FromUserName'] not in Name:
        Name.append(msg['FromUserName'])
        itchat.send_msg(msg='进入翻译,请输入英文', toUserName=msg['FromUserName'])
        return
    if msg['FromUserName'] in Name and msg['Text'] != '退出':
        result = trans(msg['Text'])
        itchat.send_msg(msg=result, toUserName=msg['FromUserName'])
        return
    if msg['Text'] == '退出' and msg['FromUserName'] in Name:
        Name.remove(msg['FromUserName'])
        return
Esempio n. 6
0
async def translate(context):
    """ PagerMaid universal translator. """
    translator = Translator()
    reply = await context.get_reply_message()
    message = context.arguments
    ap_lang = config['application_language']
    if message:
        pass
    elif reply:
        message = reply.text
    else:
        await context.edit(lang('arg_error'))
        return

    try:
        if not silent:
            await context.edit(lang('translate_processing'))
        try:
            result = translator.translate(clear_emojis(message), dest=ap_lang)
        except:
            from translate import Translator as trans
            result = trans(to_lang=ap_lang.replace('zh-cn', 'zh')).translate(
                clear_emojis(message))
    except ValueError:
        await context.edit(lang('translate_ValueError'))
        return
    try:
        source_lang = result.src
        source_text = result.origin
        trans_lang = result.dest
    except AttributeError:
        await context.edit(lang('google_connection_error'))
        return
    result = f"**{lang('translate_hits')}**\n{lang('translate_original_lang')}: {source_lang}\n{source_text} -> {result.text}"

    if len(result) > 4096:
        await context.edit(lang('translate_tg_limit_uploading_file'))
        await attach_log(result, context.chat_id, "translation.txt",
                         context.id)
        return
    await context.edit(result)
    if len(result) <= 4096:
        await log(
            f"{lang('translate_get')}: `{source_text}` \n{lang('translate_from')} {source_lang} {lang('translate_to')} {trans_lang}"
        )
    else:
        await log(
            f"{lang('translate_get')}{translate('translate_from')} {source_lang} {lang('translate_to')} {trans_lang}."
        )
Esempio n. 7
0
 def tran():
     if drop_t.get() == 'ಕನ್ನಡ':
         new_array = translate.trans(array_trans, 'en', 'kn')
         name_label.configure(text=new_array[0].text)
         email_label.configure(text=new_array[1].text)
         number_label.configure(text=new_array[2].text)
         pw_label.configure(text=new_array[3].text)
         radio_label.configure(text=new_array[4].text)
         drop_label.configure(text=new_array[5].text)
     elif drop_t.get() == "हिंदी":
         new_array = translate.trans(array_trans, 'en', 'hi')
         name_label.configure(text=new_array[0].text)
         email_label.configure(text=new_array[1].text)
         number_label.configure(text=new_array[2].text)
         pw_label.configure(text=new_array[3].text)
         radio_label.configure(text=new_array[4].text)
         drop_label.configure(text=new_array[5].text)
     else:
         name_label.configure(text=array_trans[0])
         email_label.configure(text=array_trans[1])
         number_label.configure(text=array_trans[2])
         pw_label.configure(text=array_trans[3])
         radio_label.configure(text=array_trans[4])
         drop_label.configure(text=array_trans[5])
Esempio n. 8
0
def wit_parser(resp):
    print 'resp from WIT'
    print ''
    print resp
    print ''
    try:
        for entity in resp['entities']:
            if (entity == 'phrase_to_translate'):
                _text = resp['entities']['phrase_to_translate'][0]['value']
                _lang = resp['_text'].split()[-1]
                return ("'" + str(_text) + "'" + ' in ' + str(_lang) +
                        ' is => \n' + str(translate.trans(_text, _lang)))
            elif (entity == 'hotel'):
                _destination = resp['entities']['location'][0]['value']
                return hotels.hotel_in(_destination)
            elif (entity == 'pnr'):
                _pnr = resp['entities']['number'][0]['value']
                return trains.pnr_status(_pnr)
            elif (entity == 'live_status'):
                _train_num = resp['entities']['number'][0]['value']
                return trains.live_train_status(_train_num)
            elif (entity == 'travel_mode'):
                date = None
                if ('datetime' in resp['entities']):
                    _date = resp['entities']['datetime'][0]['values'][0][
                        'value']
                    date = (str(_date)[0:10].replace('-', ''))
                _travel_mode = resp['entities'][entity][0]['value']
                _source = resp['entities']['location'][0]['value']
                _destination = resp['entities']['location'][1]['value']
                if (_travel_mode == 'train'):
                    return trains.train_between(_source, _destination, date)
                elif (_travel_mode == 'bus'):
                    return buses.bus_between(_source, _destination, date)
                elif (_travel_mode == 'flight'):
                    _adults = '1'
                    if ('number' in resp['entities']):
                        _adults = resp['entities']['number'][0]['value']
                    return flights.flight_between(_source, _destination, date,
                                                  _adults)

    except Exception as e:
        return 'app.py error: ' + str(e)
    return "Sorry! I'm not smart enough yet!"
Esempio n. 9
0
def wit_parser(resp):
    print 'resp from WIT'
    print ''
    print resp
    print ''
    for entity in resp['entities']:
        if (entity == 'phrase_to_translate'):
            _text = resp['entities']['phrase_to_translate'][0]['value']
            _lang = resp['_text'].split()[-1]
            return str(translate.trans(_text, _lang))
        elif (entity == 'hotel'):
            _destination = resp['entities']['location'][0]['value']
            return hotels.hotel_in(_destination)
        elif (entity == 'pnr'):
            _pnr = resp['entities']['number'][0]['value']
            return trains.pnr_status(_pnr)
        elif (entity == 'live_status'):
            _train_num = resp['entities']['number'][0]['value']
            return trains.live_train_status(_train_num)
        elif (entity == 'travel_mode'):
            date = None
            if ('datetime' in resp['entities']):
                _date = resp['entities']['datetime'][0]['values'][0]['value']
                datex = (str(_date)[0:10].replace('-', ''))
                print datetime.datetime.strptime(datex,
                                                 '%Y%m%d').strftime('%d-%m-%Y')
            _travel_mode = resp['entities'][entity][0]['value']
            _source = resp['entities']['location'][0]['value']
            _destination = resp['entities']['location'][1]['value']
            if (_travel_mode == 'train'):
                return trains.train_between(_source, _destination, date)
            elif (_travel_mode == 'bus'):
                return buses.bus_between(_source, _destination, date)
            elif (_travel_mode == 'flight'):
                _adults = '1'
                if ('number' in resp['entities']):
                    _adults = resp['entities']['number'][0]['value']
                return flights.flight_between(_source, _destination, date,
                                              _adults)
Esempio n. 10
0
async def translate(context):
    """ PagerMaid universal translator. """
    translator = Translator()
    reply = await context.get_reply_message()
    message = context.arguments
    lang = config['application_language']
    if message:
        pass
    elif reply:
        message = reply.text
    else:
        await context.edit("出错了呜呜呜 ~ 无效的参数。")
        return

    try:
        await context.edit("正在生成翻译中 . . .")
        try:
            result = translator.translate(clear_emojis(message), dest=lang)
        except:
            from translate import Translator as trans
            result = trans(to_lang=lang.replace('zh-cn', 'zh')).translate(clear_emojis(message))
    except ValueError:
        await context.edit("出错了呜呜呜 ~ 找不到目标语言,请更正配置文件中的错误。")
        return

    source_lang = LANGUAGES[f'{result.src.lower()}']
    trans_lang = LANGUAGES[f'{result.dest.lower()}']
    result = f"**文本翻译** 源语言 {source_lang.title()}:\n{result.text}"

    if len(result) > 4096:
        await context.edit("输出超出 TG 限制,正在尝试上传文件。")
        await attach_log(result, context.chat_id, "translation.txt", context.id)
        return
    await context.edit(result)
    if len(result) <= 4096:
        await log(f"把 `{message}` 从 {source_lang} 翻译到了 {trans_lang}")
    else:
        await log(f"把一条消息从 {source_lang} 翻译到了 {trans_lang}.")
Esempio n. 11
0
def callsubprog(progCmd):
    global forceStop
    global serverid
    global id
    global status_ui
    forceStop = False
    recognizer = aiy.cloudspeech.get_recognizer()
    if progCmd in ['冰箱有什麼', '冰箱裡有什麼']:
        result = msgsend.sender('icebox', id, serverid, 'request', (), None,
                                'todolist').sendmsg()
        itemtext = ''
        for key, value in result[5].items():
            itemtext += str(value) + ' ' + str(key) + ','
        chitems = trans(itemtext)
        if chitems != '':
            say('冰箱裡有' + chitems)
        elif result[3] == 'error':
            say('遠端沒有回應')
        else:
            say('冰箱裡好像沒東西喔')
        print(result)
    elif progCmd in ['有人在家嗎', '家裡有人嗎']:
        result = msgsend.sender('monitorhome', id, serverid, 'request', (),
                                None, 'todolist').sendmsg()
        if result[5].get('person') != None:
            recognizer = aiy.cloudspeech.get_recognizer()
            say('家裡有' + str(result[5]['person']) + '個人, 要開啟對話嗎?')
            print('Listening...')
            text = recognizer.recognize()
            while text is None:
                text = recognizer.recognize()
            print(text)
            if text not in ['不是', '不好', '不要', '不用']:
                print('connecting')
                response = msgsend.sender('talker', id, serverid, 'request',
                                          (), None, 'todolist').sendmsg()
                if response[5] == 'connected':
                    talker(serverid, id, id, serverid)
        elif result[3] == 'error':
            say('遠端沒有回應')
        else:
            say('我沒看到家裡有人喔')
    elif progCmd in ['打回家', '大回家', '帶回家', '回家']:
        response = msgsend.sender('talker', id, serverid, 'request', (), None,
                                  'todolist').sendmsg()
        if response[5] == 'connected':
            talker(serverid, id, id, serverid)
        elif response[3] == 'error':
            say('遠端沒有回應')
    elif progCmd.lower() in ['google', 'google小姐']:
        say('那接下來就交給google小姐了')
        recognizer = aiy.cloudspeech.get_recognizer()
        status_ui.status('ready')
        gathr = Thread(target=ga, args=(status_ui, ))
        gathr.setDaemon(True)
        gathr.start()
        text = ''
        while text != '結束' and not forceStop:
            text = recognizer.recognize()
            time.sleep(1)
            print(text, forceStop)
        say('小助理回來了,想我嗎?')
        return
    elif progCmd in ['email']:
        say('想寄給誰呢?')
        text = None
        while text is None:
            text = recognizer.recognize()
        emaillist = {'自己': '*****@*****.**'}
        print(emaillist.items())
        if emaillist.get(text) == None:
            say(text + '不在通訊錄內')
        else:
            say('想對他說什麼呢?')
            content = None
            while content is None:
                content = recognizer.recognize()
            say('信件內容為:' + content + '要寄出嗎?')
            text = None
            while text is None:
                text = recognizer.recognize()
            if text not in ['不是', '不好', '不要', '不用']:
                send = uploadAndSendEmail.sendPic()
                send.uploadAndSendEmail(
                    ["*****@*****.**", "*****@*****.**"],
                    './README.md', content)
                say('已將信件送出')
            else:
                say('已取消')
    else:
        say('ba歉,我還不會' + progCmd)
    translated_text_en = ""
    translated_text_zh_cn = ""
    a = ""
    print("URL        : %s" % url)
    print("content    : %s" % content)
    print("lastupdated: %s\n" % lastupdated)
    #content = content.replace("\"","")
    #content = content.replace("\'","")
    if ('\"' in content):
        print("Yes, content has \"\n")
        a = re.sub('[^A-Za-z0-9\.\"\?\s\w]+', ' ', content)
        print("a = %s" % a)
        input("Press Enter to continue...")
    elif ('\'' in content):
        print("Yes, content has \'\n")
        a = re.sub('[^A-Za-z0-9\.\"\?\s\w]+', ' ', content)
        #a = re.sub(r'[\'|"|“|\|\[|]}“]',r'',content)
        #a = a.replace('`', '')
        print("a = %s" % a)
        input("Press Enter to continue...")
    else:
        a = content
    #print ("content    : %s" % a)
    translated_text_en = trans(a, "en")
    print("content_en : %s" % translated_text_en)
    translated_text_zh_cn = trans(a, "zh-cn")
    print("content_ch : %s" % translated_text_zh_cn)
    input("Press Enter to continue...")
cursor.close()
connection.close()
Esempio n. 13
0
def fun():
    if variable.get() == "हिंदी":
        new_array = translate.trans(trans_array, 'en', 'hi')
        main_canvas.itemconfig(title, text=new_array[0].text)
        main_canvas.itemconfig(head_top, text=new_array[1].text)
        main_canvas.itemconfig(head_bottom, text=new_array[2].text + '?')
        main_canvas.itemconfig(sub_head_one,
                               text=new_array[3].text + '  -  ' +
                               new_array[4].text + '.')
        main_canvas.itemconfig(sub_head_two,
                               text=new_array[5].text + '  -  ' +
                               new_array[6].text + '.')
        main_canvas.itemconfig(
            about_text,
            text=new_array[7].text + '\n' + new_array[8].text + '\n' +
            new_array[9].text + '.\n\n' + new_array[10].text + '\n' +
            new_array[11].text + '\n' + new_array[12].text + '\n' +
            new_array[13].text + '.\n\n' + new_array[14].text + '\n' +
            new_array[15].text + '\n' + new_array[16].text + '\n' +
            new_array[17].text + '\n' + new_array[18].text + '.\n\n' +
            new_array[19].text + '\n' + new_array[20].text + '\n' +
            new_array[21].text + '\n' + new_array[22].text,
            font=('monospace', 11))
    elif variable.get() == "ಕನ್ನಡ":
        new_array = translate.trans(trans_array, 'en', 'kn')
        main_canvas.itemconfig(title, text=new_array[0].text)
        main_canvas.itemconfig(head_top, text=new_array[1].text)
        main_canvas.itemconfig(head_bottom, text=new_array[2].text + '?')
        main_canvas.itemconfig(sub_head_one,
                               text=new_array[3].text + '  -  ' +
                               new_array[4].text + '.')
        main_canvas.itemconfig(sub_head_two,
                               text=new_array[5].text + '  -  ' +
                               new_array[6].text + '.')
        main_canvas.itemconfig(
            about_text,
            text=new_array[7].text + '\n' + new_array[8].text + '\n' +
            new_array[9].text + '.\n\n\n' + new_array[14].text + '\n' +
            new_array[15].text + '\n' + new_array[16].text + '\n' +
            new_array[17].text + '\n' + new_array[18].text + '.\n\n\n' +
            new_array[19].text + '\n' + new_array[20].text + '\n' +
            new_array[21].text + '\n' + new_array[22].text,
            font=('monospace', 11))
    else:
        main_canvas.itemconfig(title, text=trans_array[0])
        main_canvas.itemconfig(head_top, text=trans_array[1])
        main_canvas.itemconfig(head_bottom, text=trans_array[2] + '?')
        main_canvas.itemconfig(sub_head_one,
                               text=trans_array[3] + '  -  ' + trans_array[4] +
                               '.')
        main_canvas.itemconfig(sub_head_two,
                               text=trans_array[5] + '  -  ' + trans_array[6] +
                               '.')
        main_canvas.itemconfig(
            about_text,
            text=trans_array[7] + '\n' + trans_array[8] + '\n' +
            trans_array[9] + '.\n\n' + trans_array[10] + '\n' +
            trans_array[11] + '\n' + trans_array[12] + '\n' + trans_array[13] +
            '.\n\n' + trans_array[14] + '\n' + trans_array[15] + '\n' +
            trans_array[16] + '\n' + trans_array[17] + '\n' + trans_array[18] +
            '.\n\n' + trans_array[19] + '\n' + trans_array[20] + '\n' +
            trans_array[21] + '\n' + trans_array[22])
Esempio n. 14
0
def f(name, location, email, number, pref_lan):
    # function to return a list of all the crops selected
    trans_arr = [
        'Sow', 'Harvest', 'Sell', 'Welcome', 'WHAT ARE YOU SELLING', 'Peas',
        'Wheat', 'Turmeric', 'Maize', 'Paddy', 'Millet', 'Groundnut', 'Sesame',
        'Barley', 'Cotton', 'Investment cost', 'Previous profit'
    ]
    if pref_lan == "हिंदी":
        new_arr = translate.trans(trans_arr, 'en', 'hi')
        for i in range(0, len(new_arr)):
            trans_arr[i] = new_arr[i].text
    elif pref_lan == "ಕನ್ನಡ":
        new_arr = translate.trans(trans_arr, 'en', 'kn')
        for i in range(0, len(new_arr)):
            trans_arr[i] = new_arr[i].text

    def crop_list():
        total = []
        crop = []
        invest = []
        profit = []
        if var_pea.get() == 1:
            crop.append('peas')
            invest.append(inv_peas.get())
            profit.append(pro_peas.get())
        if var_wheat.get() == 1:
            crop.append('wheat')
            invest.append(inv_wheat.get())
            profit.append(pro_wheat.get())
        if var_tur.get() == 1:
            crop.append('turmeric')
            invest.append(inv_tur.get())
            profit.append(pro_tur.get())
        if var_maize.get() == 1:
            crop.append('maize')
            invest.append(inv_maize.get())
            profit.append(pro_maize.get())
        if var_pad.get() == 1:
            crop.append('paddy')
            invest.append(inv_paddy.get())
            profit.append(pro_paddy.get())
        if var_mil.get() == 1:
            crop.append('millet')
            invest.append(inv_mil.get())
            profit.append(pro_mil.get())
        if var_gn.get() == 1:
            crop.append('groundnut')
            invest.append(inv_gn.get())
            profit.append(pro_gn.get())
        if var_ses.get() == 1:
            crop.append('sesame')
            invest.append(inv_ses.get())
            profit.append(pro_ses.get())
        if var_bar.get() == 1:
            crop.append('barley')
            invest.append(inv_bar.get())
            profit.append(pro_bar.get())
        if var_cot.get() == 1:
            crop.append('cotton')
            invest.append(inv_cot.get())
            profit.append(pro_cot.get())

        total.append(crop)
        total.append(invest)
        total.append(profit)

        return total

    # For storing the data taken in
    def store():

        total = crop_list()

        crop = total[0]
        invest = total[1]
        profit = total[2]

        if location == 'Bijapur':
            index = []
            conn = sqlite3.connect('crop.db')
            c = conn.cursor()
            c.execute("SELECT id FROM bijapur")
            for x in c.fetchall():
                index.append(x)
            if len(index) == 0:
                index_b = 0
            else:
                index_b = len(index)
            for i in range(0, len(crop)):

                c.execute(
                    "INSERT INTO bijapur VALUES (:id, :name, :email, :number, :crop, :investment, :profit, :price)",
                    {
                        'id': index_b,
                        'name': name,
                        'email': email,
                        'number': number,
                        'crop': crop[i],
                        'investment': invest[i],
                        'profit': profit[i],
                        'price': 0.0
                    })
                index_b = index_b + 1
            c.execute("SELECT * FROM bijapur")
            print(c.fetchall())
            conn.commit()
            conn.close()

        elif location == 'Udupi':
            index = []
            conn = sqlite3.connect('crop.db')
            c = conn.cursor()
            c.execute("SELECT id FROM udupi")
            for x in c.fetchall():
                index.append(x)
            if len(index) == 0:
                index_u = 0
            else:
                index_u = len(index)

            for i in range(0, len(crop)):
                c.execute(
                    "INSERT INTO udupi VALUES (:id, :name, :email, :number, :crop, :investment, :profit, :price)",
                    {
                        'id': index_u,
                        'name': name,
                        'email': email,
                        'number': number,
                        'crop': crop[i],
                        'investment': invest[i],
                        'profit': profit[i],
                        'price': 0.0
                    })
                index_u = index_u + 1
            c.execute("SELECT * FROM udupi")
            print(c.fetchall())
            conn.commit()
            conn.close()

        else:
            index = []
            conn = sqlite3.connect('crop.db')
            c = conn.cursor()
            c.execute("SELECT id FROM bangalore")
            for x in c.fetchall():
                index.append(x)
            if len(index) == 0:
                index_br = 0
            else:
                index_br = len(index)
            for i in range(0, len(crop)):
                c.execute(
                    "INSERT INTO bangalore VALUES (:id, :name, :email, :number, :crop, :investment, :profit, :price)",
                    {
                        'id': index_br,
                        'name': name,
                        'email': email,
                        'number': number,
                        'crop': crop[i],
                        'investment': invest[i],
                        'profit': profit[i],
                        'price': 0.0
                    })
                index_br = index_br + 1
            c.execute("SELECT * FROM bangalore")
            print(c.fetchall())
            conn.commit()
            conn.close()

        final_label = Label(farm,
                            text='Data registered successfully.',
                            bg='white',
                            fg='black',
                            font=('Calibri', 14))
        final_label.place(x=1100, y=370)

        # clearing the entries
        inv_peas.delete(0, END)
        inv_cot.delete(0, END)

        inv_bar.delete(0, END)
        inv_ses.delete(0, END)
        inv_wheat.delete(0, END)
        inv_mil.delete(0, END)
        inv_maize.delete(0, END)
        inv_paddy.delete(0, END)
        inv_tur.delete(0, END)
        inv_gn.delete(0, END)

        # clearing profit entries
        pro_peas.delete(0, END)
        pro_cot.delete(0, END)
        pro_bar.delete(0, END)
        pro_ses.delete(0, END)
        pro_gn.delete(0, END)
        pro_paddy.delete(0, END)
        pro_maize.delete(0, END)
        pro_wheat.delete(0, END)
        pro_tur.delete(0, END)
        pro_mil.delete(0, END)

    def investment_repeat(x1, x2, y2):

        # entries
        inv_entry = Entry(farm, width=8)
        inv_entry.place(x=x2, y=y2)

        # labels
        inv_label = Label(farm,
                          text=trans_arr[15],
                          font=('Calibri', 12),
                          bg="white",
                          fg="black")
        inv_label.place(x=x1, y=y2)

        return inv_entry

    def profit_repeat(x1, x2, y2):

        # Labels
        profit_label = Label(farm,
                             text=trans_arr[16],
                             font=('Calibri', 12),
                             bg="white",
                             fg="black")
        profit_label.place(x=x1, y=y2)

        # entries
        profit_entry = Entry(farm, width=8)
        profit_entry.place(x=x2, y=y2)

        return profit_entry

    farm = Toplevel()
    farm.geometry('2000x1000')
    farm.state('zoomed')
    farm.resizable(0, 0)
    farm.config(bg='#ffffff')
    bg = PhotoImage(
        file=r"C:\Users\Riya Savant\PycharmProjects\ADA\image\green.png")
    label = Label(farm, image=bg)
    label.image = bg
    label.pack()

    title = Label(farm,
                  text=trans_arr[0] + "." + "    " + trans_arr[1] + "." +
                  "    " + trans_arr[2] + ".",
                  font=('Britannic Bold', 60),
                  bg='#09baa7',
                  fg='grey')
    title.place(x=300, y=80)

    # name = 'Test Name'
    message = trans_arr[3] + ", " + name + "!"
    name_label = Label(farm,
                       text=message,
                       font=('Calibri', 14),
                       bg='#09baa7',
                       fg='black')
    name_label.place(x=1200, y=20)

    # setting up icon image
    icon = PhotoImage(
        file=r"C:\Users\Riya Savant\PycharmProjects\ADA\image\sr.png")
    label_icon = Label(farm, image=icon, bg='#09baa7')
    label_icon.image = icon
    label_icon.place(x=700, y=200)

    # intro line
    intro = Label(farm,
                  text=trans_arr[4] + '?',
                  font=('Britannic Bold', 18),
                  bg='#ffffff',
                  fg='grey')
    intro.place(x=600, y=380)

    # variables for checkbox
    var_pea = IntVar(farm)
    var_wheat = IntVar(farm)
    var_tur = IntVar(farm)
    var_maize = IntVar(farm)
    var_pad = IntVar(farm)
    var_mil = IntVar(farm)
    var_gn = IntVar(farm)
    var_ses = IntVar(farm)
    var_bar = IntVar(farm)
    var_cot = IntVar(farm)

    # images for checkboxes
    pea = PhotoImage(
        file=r"C:\Users\Riya Savant\PycharmProjects\ADA\image\peas.png")
    wheat = PhotoImage(
        file=r"C:\Users\Riya Savant\PycharmProjects\ADA\image\wheat.png")
    tur = PhotoImage(
        file=r"C:\Users\Riya Savant\PycharmProjects\ADA\image\turmeric.png")
    maize = PhotoImage(
        file=r"C:\Users\Riya Savant\PycharmProjects\ADA\image\maize.png")
    pad = PhotoImage(
        file=r"C:\Users\Riya Savant\PycharmProjects\ADA\image\paddy.png")
    millet = PhotoImage(
        file=r"C:\Users\Riya Savant\PycharmProjects\ADA\image\millet.png")
    gn = PhotoImage(
        file=r"C:\Users\Riya Savant\PycharmProjects\ADA\image\gn.png")
    sesame = PhotoImage(
        file=r"C:\Users\Riya Savant\PycharmProjects\ADA\image\sesame.png")
    barley = PhotoImage(
        file=r"C:\Users\Riya Savant\PycharmProjects\ADA\image\barley.png")
    cotton = PhotoImage(
        file=r"C:\Users\Riya Savant\PycharmProjects\ADA\image\cotton.png")

    # checkboxes
    c1 = Checkbutton(farm,
                     text=trans_arr[5],
                     image=pea,
                     compound='left',
                     bg='#ffffff',
                     variable=var_pea)
    c1.image = pea
    c1.place(x=50, y=430)
    c3 = Checkbutton(farm,
                     text=trans_arr[6],
                     image=wheat,
                     compound='left',
                     bg='#ffffff',
                     variable=var_wheat)
    c3.image = wheat
    c3.place(x=350, y=430)
    c4 = Checkbutton(farm,
                     text=trans_arr[7],
                     image=tur,
                     compound='left',
                     bg='#ffffff',
                     variable=var_tur)
    c4.image = tur
    c4.place(x=650, y=430)
    c5 = Checkbutton(farm,
                     text=trans_arr[8],
                     image=maize,
                     compound='left',
                     bg='#ffffff',
                     variable=var_maize)
    c5.iamge = maize
    c5.place(x=950, y=430)
    c7 = Checkbutton(farm,
                     text=trans_arr[9],
                     image=pad,
                     compound='left',
                     bg='#ffffff',
                     variable=var_pad)
    c7.image = pad
    c7.place(x=1250, y=430)
    c8 = Checkbutton(farm,
                     text=trans_arr[10],
                     image=millet,
                     compound='left',
                     bg='#ffffff',
                     variable=var_mil)
    c8.image = millet
    c8.place(x=50, y=620)
    c9 = Checkbutton(farm,
                     text=trans_arr[11],
                     image=gn,
                     compound='left',
                     bg='#ffffff',
                     variable=var_gn)
    c9.image = gn
    c9.place(x=350, y=620)
    c11 = Checkbutton(farm,
                      text=trans_arr[12],
                      image=sesame,
                      compound='left',
                      bg='#ffffff',
                      variable=var_ses)
    c11.image = sesame
    c11.place(x=650, y=620)
    c12 = Checkbutton(farm,
                      text=trans_arr[13],
                      image=barley,
                      compound='left',
                      bg='#ffffff',
                      variable=var_bar)
    c12.image = barley
    c12.place(x=950, y=620)
    c14 = Checkbutton(farm,
                      text=trans_arr[14],
                      image=cotton,
                      compound='left',
                      bg='#ffffff',
                      variable=var_cot)
    c14.image = cotton
    c14.place(x=1250, y=620)

    # Variables for investment and profit
    inv_peas = investment_repeat(30, 150, 540)
    pro_peas = profit_repeat(30, 150, 570)
    inv_wheat = investment_repeat(330, 450, 540)
    pro_wheat = profit_repeat(330, 450, 570)
    inv_tur = investment_repeat(630, 750, 540)
    pro_tur = profit_repeat(630, 750, 570)
    inv_maize = investment_repeat(930, 1050, 540)
    pro_maize = profit_repeat(930, 1050, 570)
    inv_paddy = investment_repeat(1230, 1350, 540)
    pro_paddy = profit_repeat(1230, 1350, 570)

    # Second row variables
    inv_mil = investment_repeat(30, 150, 730)
    pro_mil = profit_repeat(30, 150, 770)
    inv_gn = investment_repeat(330, 450, 730)
    pro_gn = profit_repeat(330, 450, 770)
    inv_ses = investment_repeat(630, 750, 730)
    pro_ses = profit_repeat(630, 750, 770)
    inv_bar = investment_repeat(930, 1050, 730)
    pro_bar = profit_repeat(930, 1050, 770)
    inv_cot = investment_repeat(1230, 1350, 730)
    pro_cot = profit_repeat(1230, 1350, 770)

    # Button
    Butt = Button(farm,
                  text="Submit Info",
                  font=('Calibri', 15),
                  width=15,
                  command=store)
    Butt.configure(bg='#84a9ac', fg='#ffffff')
    Butt.place(x=900, y=370)

    def log_out():
        farm.destroy()

    # Logout Button
    logout = Button(farm, text='Log out', command=log_out, width=10)
    logout.place(x=1400, y=20)

    farm.mainloop()
Esempio n. 15
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author: Sizepeng Zhao

from PyQt5 import QtCore, QtGui, QtWidgets
from translate import trans

#创建一个翻译类的对象
tran = trans()


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(726, 569)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(542, 260, 131, 31))
        self.pushButton.setObjectName("pushButton")
        self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
        self.textBrowser.setGeometry(QtCore.QRect(50, 300, 621, 192))
        self.textBrowser.setObjectName("textBrowser")
        self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(50, 60, 621, 191))
        self.textEdit.setObjectName("textEdit")
        self.comboBox = QtWidgets.QComboBox(self.centralwidget)
        self.comboBox.setGeometry(QtCore.QRect(50, 30, 141, 22))
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
Esempio n. 16
0
def paper_keyword_expand(keyword):
    '''
    expand keyword from single language into bilingual
    '''
    trans_keyword = trans(keyword)
    return [keyword, trans_keyword]