def __init__(self): super().__init__() self.setupUi(self) self.serial_port = QtSerialPort.QSerialPort() self.port_settings: data_types.ComSettings = data_types.ComSettings() self.text_settings: data_types.TextSettings = data_types.TextSettings() self.all_macros: List[data_types.MacroSet] = list() self.current_macros: data_types.MacroSet = data_types.MacroSet( name="", macros=list()) self.load_macros() self.counter: int = 0 self.time_shown = False self.tail = "" self.file_to_send = "" self.graph_form = Optional[terminal_graph.MainWindow] self.graph = False self.start_time = datetime.datetime.now() self.settings_form: Optional[settings.Settings] = None self.macros_form: Optional[macros.Macros] = None self.ascii_form: Optional[ASCII_table.ASCIITable] = None self.help_form: Optional[help.Help] = None self.var_form: Optional[variables.Variables] = variables.Variables() self.var_form.send_signal[str].connect(self.var_signal_send) self.current_font = QtGui.QFont("Consolas", 10) self.apply_styles() self.macros_btns_list = list() self.macros_ui() self.load_settings() self.serial_port_ui() self.set_transmitzone_ui() self.create_connections() self.init_timer_data()
def __init__(self, lie_type, rank): self.lie_type = lie_type self.rank = rank self.label = self.lie_type + str(self.rank) self.rootsystem = rs.RootSystem(self) self.dim = self.rootsystem.nr_roots + self.rank self.weyl = wg.Weyl(self) self.parabolics = pa.Parabolics(self) self.constants = cs.Constants(self) nr = self.rootsystem.nr_roots self.var = vr.Variables(2 * nr, 2 * nr, 2 * self.rank) self.group = gr.Group(self) self.lie = la.LieAlgebra(self) self.ad_action = ad.AdAction(self) self.bruhat = br.Bruhat(self) self.deodhar = dr.Deodhar(self) if self.label == "a2": self.curtis = CurtisA2(self) if self.label == "b2": self.curtis = CurtisB2(self) if self.label == "g2": self.curtis = CurtisG2(self)
def var_pressed(self): """ var form show :return: """ self.var_form = variables.Variables() self.var_form.send_signal[str].connect(self.var_signal_send) self.var_form.show()
# Run this file for combined verbal experiment (longVerbal+shortverbal+longVerbal+shortVerbal) #-------------------imports-------------------------------------------------------------------- import Short_Verbal, Long_Verbal, doodle, setup, variables,newPoints import os, datetime, json from psychopy import event import functions as fc import SQL_call as sql #-------------make necessary objects------------------------------ myPoints = newPoints.NewPoints() var = variables.Variables() doo = doodle.Doodle() dbc = fc.dbconnect() mouse = event.Mouse(setup.mywin) #---------------Main Function------------------------------------- def verbal_odd(var,doo,mouse,myPoints,dbc): expName = os.path.basename(__file__)[:-3] # get expName of this file expDate = datetime.datetime.now().strftime("%Y-%m-%d_T%H_%M_%S") # get expDate [rate_ans, dt_ans, chhist_ans]=fc.survey(doo) # survey subjects' recent time and money scarcity d = {'answer': rate_ans, 'decisionTime': dt_ans, 'choiceHistory': chhist_ans} # record the survey result to database quest = json.dumps(d) fc.about_to_start(doo) # show the get ready instruction var.points = 0 # set total points to 0 for short verbal experiments p_net,points_short1,trials_short1,trialsCorrect_short1 = Short_Verbal.ShortVerbal(var,doo,myPoints,dbc,mouse) # run short verbal session #1 p_num = sql.r_subjid(dbc,p_net) # connect to next session in database fc.block_break(var,doo) # show the break instruction to subject p_net,pick1,pay_delay1,pay_num1,trials_long1,points_long1 = Long_Verbal.LongVerbal(var,doo,myPoints,dbc,mouse,getName=False,sub_id=p_net,gettrialn=0) # run the first long verbal session and record the returned info ses1id = sql.r_sessid(dbc,p_num) numl1 = sql.r_countChoice(dbc,ses1id) # count the number of trials in the first long verbal session fc.block_break(var,doo) # show the break instruction to subject Short_Verbal.ShortVerbal(var,doo,myPoints,dbc,mouse,getName=False,sub_id=p_net,pre_points=points_short1,pre_trials=trials_short1,pre_trialsCorrect=trialsCorrect_short1) # run short verbal session #1 fc.block_break(var,doo) # show the break instruction to subject
# -*- coding: utf-8 -*- import urllib2 from bs4 import BeautifulSoup import variables import sqlite3 import datetime import time import langdetect import hashlib from unidecode import unidecode vars = variables.Variables() topics = vars.topics def connect_db(db_path=vars.db_path): connection = sqlite3.connect(db_path) cursor = connection.cursor() return connection, cursor def create_tbl(cursor, name): cursor.execute(""" DROP TABLE IF EXISTS %s """ % name) cursor.execute(vars.create_tbl_sql[name]) return def parse_timestamp(ts): ts = ts.replace('Januar', 'January').replace('Februar', 'February') ts = ts.replace(u'März', 'March').replace('Mai', 'May') ts = ts.replace('Juni', 'June').replace('Juli', 'July')
def requests_list(message, chat_id, r_json): ''' Foo takes message and chat_id from Teleram server and make an answer to user. There are 4 main levels, every level means a certain step in work of Telegram Bot. This foo is more like a distributor of functions, that realy have a weight, do action. Also first lines of foo check authorization of user in Telegram Bot. ''' try: if checking_chat_id(chat_id) == False and "@" in message: try: print(chat_id, message) print("UPDATE users SET telegram_id='{}', user_level='start password' \ WHERE email='{}'". format(chat_id, str(message))) config_file.db_update("UPDATE users SET telegram_id='{}', user_level='start password' \ WHERE email='{}'". format(chat_id, str(message))) telegram_api_request.ButtonCreate(message_text='Теперь напиши пароль', chat_id=chat_id, texts_of_button=['']).return_button() except: telegram_api_request.ButtonCreate(message_text='Что-то пошло не так. напиши почту, ' + \ 'которую ты зарегистрировал на сайте. Именно почту.\n' + \ 'Если не зарегистрирован на сайте, то следуте зарегистрироваться сначала. ' + \ 'Ссылка на сайт: https://telegrampyvocab.herokuapp.com/registration', chat_id=chat_id, texts_of_button=['']).\ return_button() elif checking_chat_id(chat_id) == False and "@" not in message: telegram_api_request.ButtonCreate(message_text='Напиши почту, на которую зарегистрирован аккаунт на сайте. ' + \ 'Пожалуйста, не ошибись при записи :) ', chat_id=chat_id, texts_of_button=['']).\ return_button() else: pk_of_user_in_db = config_file.db_select("SELECT id from users where telegram_id={}".format(chat_id))[0][0] message_list = ['Добавить новое слово', 'Удалить слова', 'Внести изменения в словарь', 'Проверять слова!' ] if message in message_list: if message=='Добавить новое слово': variables.Variables(message,chat_id,pk_of_user_in_db).add_word() elif message=='Удалить слова': variables.Variables(message, chat_id, pk_of_user_in_db).delete_word() elif message=='Внести изменения в словарь': variables.Variables(message, chat_id,pk_of_user_in_db).modif_dict() elif message=='Проверять слова!': variables.Variables(message, chat_id, pk_of_user_in_db).check_word() else: level = config_file.db_select("SELECT user_level FROM users \ WHERE telegram_id = {}".format(chat_id))[0][0] if level == 'start password': try: tg_password = hash.hashing(str(message)) if tg_password == config_file.db_select("SELECT user_password FROM users \ WHERE telegram_id = {}".format(chat_id))[0][0]: modificate_level(pk_of_user_in_db, 'default') telegram_api_request.ButtonCreate(message_text='Ты авторизован! Теперь добавь первое слово. ' + \ 'Нажми кнопку.', chat_id=chat_id, texts_of_button=['Добавить новое слово']).\ return_button() else: modificate_level(pk_of_user_in_db, 'default') telegram_api_request.ButtonCreate(message_text='Пароль не тот :(\nПопробуй еще раз, пожалуйста. ' + \ 'Напиши почту сначала. ', chat_id=chat_id, texts_of_button=['']).\ return_button() except: telegram_api_request.ButtonCreate(message_text='Что-то пошло не так. Посмотри внимательно свой пароль. ' + \ 'Напиши снова почту', chat_id=chat_id, texts_of_button=['']).\ return_button() elif level == 'adding word': config_file.db_update("INSERT INTO whole_vocab (word_in_whole, user_id, status_of_word_in_whole) \ VALUES('{}', {}, 'doing')". format(message.rstrip()[::-1].rstrip()[::-1], pk_of_user_in_db)) modificate_level(pk_of_user_in_db, 'adding_definition') telegram_api_request.ButtonCreate(message_text='Напиши дефиницию или перевод данного слова.', chat_id=chat_id, texts_of_button=['Добавить новое слово', 'Удалить слова', 'Внести изменения в словарь']).\ return_button() elif level == 'adding_definition': config_file.db_update("UPDATE whole_vocab SET definition_of_word = '{}', status_of_word_in_whole = 'not done' \ WHERE user_id = {} AND status_of_word_in_whole='doing' ". format(message.rstrip()[::-1].rstrip()[::-1], pk_of_user_in_db)) modificate_level(pk_of_user_in_db, 'default') telegram_api_request.ButtonCreate(message_text='Новое слово добавлено.', chat_id=chat_id, texts_of_button=['Добавить новое слово', 'Проверять слова!', 'Внести изменения в словарь', 'Удалить слова'], )\ .return_button() elif level == 'default': bul, word = operations.checking_word(message, pk_of_user_in_db) if bul == True: telegram_api_request.ButtonCreate(message_text='Правильно. ' + '\n\n' + operations.show_word(pk_of_user_in_db), chat_id=chat_id, texts_of_button=['Добавить новое слово', 'Внести изменения в словарь', 'Удалить слова', 'Проверять слова!']).\ return_button() else: telegram_api_request.ButtonCreate(message_text='Неправильно.\nПравильно так: ' + word + '\n\n' + \ operations.show_word(pk_of_user_in_db), chat_id=chat_id, texts_of_button=['Добавить новое слово', 'Внести изменения в словарь', 'Удалить слова', 'Проверять слова!']).\ return_button() elif level == 'deleting': if len(config_file.db_select("SELECT * FROM whole_vocab WHERE user_id={}".format(pk_of_user_in_db))) > 0: delete_message = operations.delete_word(numbers=message,pk_of_user_in_db=pk_of_user_in_db) if delete_message == 'Пожалуйста, не используйте буквы, предпочтительно использовать такой формат: \n\n 1, 2, 3': telegram_api_request.ButtonCreate(message_text='Пожалуйста, не используйте буквы, ' + \ 'предпочтительно использовать такой формат: \n\n 1, 2, 3', chat_id=chat_id, texts_of_button=['Добавить новое слово', 'Проверять слова!', 'Внести изменения в словарь']).\ return_button() else: telegram_api_request.ButtonCreate(message_text='Удалено!', chat_id=chat_id, texts_of_button=['Добавить новое слово', 'Проверять слова!', 'Внести изменения в словарь', 'Удалить слова']).\ return_button() else: telegram_api_request.ButtonCreate(message_text='Словарь в данный момент пустой.\n\nНеловко это сообщать, ' + \ 'но сначала следует добавить слова прежде, чем удалять их :) ', chat_id=chat_id, texts_of_button=['Добавить новое слово', 'Проверять слова!', 'Внести изменения в словарь', 'Удалить слова']).\ return_button() elif level == 'modificate word': definition = operations.modificate_word(message, pk_of_user_in_db) if definition == 'Что-то пошло не так. Попробуй, пожалуйста, набрать только номер, без других символов. \ Возможно, в этом дело' \ or definition == 'Что-то пошло не так. Попробуй еще разок именно в формате таком: \n 1. Слово. ': telegram_api_request.ButtonCreate(message_text=definition, chat_id=chat_id, texts_of_button=['']).return_button() else: modificate_level(pk_of_user_in_db, 'modificate definition') telegram_api_request.ButtonCreate(message_text=definition, chat_id=chat_id, texts_of_button=['Добавить новое слово','Удалить слова','Проверять слова!', 'Внести изменения в словарь']).\ return_button() elif level == 'modificate definition': result_of_operation = operations.modificate_definition(message, pk_of_user_in_db) telegram_api_request.ButtonCreate(message_text=result_of_operation, chat_id=chat_id, texts_of_button=['Добавить новое слово','Удалить слова', 'Проверять слова!', 'Внести изменения в словарь']).\ return_button() except Exception as ex: config_file.db_select("SELECT user_level FROM users WHERE telegram_id={}".format(chat_id)) telegram_api_request.ButtonCreate(message_text='Что-то пошло не так. Затруднительно сказать на каком именно этапе произошла ошибка. ' + \ '\n\nПередай информаци Диме, сообщив ошибку., ошибка такая{}'. format(str(ex)), chat_id=chat_id, texts_of_button=['']).\ return_button()