def create_obj(self, data: dict): course_name = data['course_name'] course_name = Application.decode_value(course_name) course = site.get_course(course_name) student_name = data['student_name'] student_name = Application.decode_value(student_name) student = site.get_student(student_name) course.add_student(student)
def create_obj(self, data: dict): name = data['name'] name = Application.decode_value(name) new_obj = site.create_user('student', name) site.students.append(new_obj) new_obj.mark_new() UnitOfWork.get_current().commit()
def create_obj(self, data: dict): name = data['name'] name = Application.decode_value(name) category_id = data.get('category_id') category = None if category_id: category = site.find_category_by_id(int(category_id)) new_category = site.create_category(name, category) site.categories.append(new_category)
def copy_course(request): request_params = request['request_params'] name = request_params['name'] name = Application.decode_value(name) old_course = site.get_course(name) if old_course: new_name = f'copy_{name}' new_course = old_course.clone() new_course.name = new_name site.courses.append(new_course) return '200 OK', render('course_list.html', objects_list=site.courses)
def create_course(request): if request['method'] == 'POST': data = request['data'] name = data['name'] name = Application.decode_value(name) category_id = data.get('category_id') category = None if category_id: category = site.find_category_by_id(int(category_id)) course = site.create_course('record', name, category) course.observers.append(email_notifier) course.observers.append(sms_notifier) site.courses.append(course) categories = site.categories return '200 OK', render('create_course.html', categories=categories) else: categories = site.categories return '200 OK', render('create_course.html', categories=categories)
def setup_class(cls): cls.app = Application() rnd_numbers = str(random.randint(1, 10000000)) cls.rnd_subject = ComposePopUp.subject_sender + rnd_numbers + '_automation' cls.rnd_body = ComposePopUp.body_of_letter_sender + rnd_numbers + '_automation'
from framework.templates import render_from_file from framework.utils import parse_body_json from settings import urls, middleware from framework.application import Application, MockApplication, DebugApplication app = Application(urls, middleware) # app = DebugApplication(urls, middleware) # app = MockApplication(urls, middleware) @app.add_route('/') def index(request): page = render_from_file('index.html', request) return '200 OK', page @app.add_route('/contacts/') def contacts(request): if request['METHOD'] == 'GET': page = render_from_file('contacts.html', request) return '200 OK', page if request['METHOD'] == 'POST': body = parse_body_json(request) print(body) if body['topic'] and body['msg'] and body['email']: print( f'User with email {body["email"]} had sent a message. Topic {body["topic"]}: \n {body["msg"]}' )
def __init__(self): self.colors = {} # self.colors['light green'] = 'light green' # self.colors['red'] = 'red' # self.colors['light grey'] = 'light grey' self.colors['light green'] = '#C5E6A6' self.colors['green'] = '#7FB069' self.colors['red'] = '#DA4167' self.colors['light grey'] = '#9B9B9B' self.colors['white'] = 'white' self.colors['dark grey'] = '#5f6363' self.colors['black'] = 'black' self._root = Tk() self._root.geometry("1900x1000+0+0") self._root.title("Owczarek Test System (OTS) for Capelon") self._root.configure(background='white') self._style = ttk.Style() self._style.configure('TFrame', background='white') self._style.configure('TLabel', background=self.colors['light grey'], foreground=self.colors['white'], font=('Arial', 16, 'bold')) self._style.configure('WhiteBg.TLabel', background=self.colors['white'], foreground='black') self._style.configure('TButton', background='white') self._style.configure('TreeView', background='white') comboboxListFont = ("Arial", 16) self._root.option_add("*TCombobox*Listbox*Font", comboboxListFont) self._frames = {} self._widgets = {} self._style = ttk.Style() self._frames['header'] = ttk.Frame(self._root) self._frames['content'] = ttk.Frame(self._root) self._frames['header'].pack() self._frames['content'].pack() self._frames['content'].grid_columnconfigure(0, minsize=400) self._frames['content'].grid_columnconfigure(1, minsize=20) self._frames['content'].grid_columnconfigure(2, minsize=500) self._frames['content'].grid_columnconfigure(3, minsize=20) self._frames['content'].grid_columnconfigure(4, minsize=300) # header subframes self._frames['logo'] = ttk.Frame(self._frames['header']) self._frames['menuButtons'] = ttk.Frame(self._frames['header']) self._frames['logo'].grid(row=0, column=0, padx=30, pady=30) self._frames['menuButtons'].grid(row=0, column=1) # header widgets self._widgets['logo.image'] = PhotoImage(file='docs/logo2.PNG') self._widgets['logo.logo'] = ttk.Label( self._frames['logo'], image=self._widgets['logo.image'], style='WhiteBg.TLabel') self._widgets['logo.name'] = ttk.Label(self._frames['logo'], text='TEST STATION', font=['Arial', 18, 'bold'], foreground='grey', style='WhiteBg.TLabel') self._widgets['menuButtons.settingsButton'] = \ ttk.Button(self._frames['menuButtons'], text='SETTINGS', command=lambda: self.callback_settingsButtonClick()) self._widgets['menuButtons.hardwareConfigurationButton'] = \ ttk.Button(self._frames['menuButtons'], text='HARDWARE CONFIGURATION', command=lambda: self.callback_hardwareConfigurationButtonClick()) self._widgets['menuButtons.dataManagementButton'] = \ ttk.Button(self._frames['menuButtons'], text='DATA MANAGEMENT', command=lambda: self.callback_dataManagementButtonClick()) self._widgets['menuButtons.exitButton'] = \ ttk.Button(self._frames['menuButtons'], text='EXIT', command=lambda: self.callback_exitButtonClick()) self._widgets['logo.logo'].grid(row=0, column=0) self._widgets['logo.name'].grid(row=1, column=0) # self._widgets['menuButtons.settingsButton'].grid(row=0, column=0) # self._widgets['menuButtons.hardwareConfigurationButton'].grid(row=0, column=1) # self._widgets['menuButtons.dataManagementButton'].grid(row=0, column=2) # self._widgets['menuButtons.exitButton'].grid(row=0, column=3) # content subframes self._frames['user'] = Frame(self._frames['content'], background=self.colors['light grey']) self._frames['interactive'] = Frame( self._frames['content'], background=self.colors['light grey']) self._frames['message'] = Frame(self._frames['content'], background='white') self._frames['customFrame'] = Frame(self._frames['content'], background='white') self._frames['authentication'] = Frame(self._frames['content'], background='white') self._frames['resultList'] = Frame( self._frames['content'], borderwidth=2, background=self.colors['light grey'], padx=10, pady=5) self._frames['logs'] = LabelFrame(self._frames['content'], background='white', text='Logs', pady=10, padx=10) self._frames['statistics'] = Frame(self._frames['content'], background='white') self._frames['testStatus'] = Frame( self._frames['content'], background=self.colors['light grey']) self._frames['user'].grid(row=0, column=0, sticky='nwe') self._frames['user'].grid_columnconfigure(0, weight=1) self._frames['user'].grid_remove() self._frames['authentication'].grid(row=0, column=0, sticky='new', padx=0, pady=0) self._frames['message'].grid(row=1, column=0, sticky='nsew') self._frames['resultList'].grid(row=0, column=2, rowspan=5) #self._frames['logs'].grid(row=4, column=0, rowspan=2) self._frames['statistics'].grid(row=0, column=4, sticky='nsew', rowspan=3) self._frames['testStatus'].grid(row=5, column=2, sticky='nsew') self._frames['content'].grid_columnconfigure(2, minsize=30, weight=1) # content widgets self._widgets['user.user'] = Label( self._frames['user'], background=self.colors['light grey'], text='NO USER LOGGED IN', font=('Arial', 14, 'bold'), foreground='white', padx=30, pady=10) self._widgets['user.logout'] = Button( self._frames['user'], text='Log out', command=lambda: self.callback_logoutButtonClick(), background=self.colors['dark grey'], foreground=self.colors['white'], font=('Arial', 14, 'bold')) self._widgets['message.message'] = \ ttk.Label(self._frames['message'], text='', font=('Arial', 20), anchor='center', wraplength=400, style='WhiteBg.TLabel', justify='center') self._widgets['logs.logs'] = \ scrolledtext.ScrolledText(self._frames['logs'], height=10, width=80, state='disabled', bd=0, highlightthickness=0, relief='ridge') self._widgets['resultList.tree'] = self.initializeResultListTree() self._widgets['logs.logs'].configure(font=('TkFixedFont', 7)) self._widgets['testStatus.currentStatus'] = \ ttk.Label(self._frames['testStatus'], text='', font=('Arial', 18, 'bold'), background=self.colors['light grey'], anchor=CENTER) self._widgets['testStatus.currentStatusButton'] = \ Button(self._frames['testStatus'], text='TERMINATE', command=lambda: self.callback_terminateButtonClick(), background=self.colors['dark grey'], foreground=self.colors['white'], font=('Arial', 14, 'bold')) self.initializeStatisticsFrame() self.initializeSequenceChoiceFrame() self._widgets['customFrame.message'] = ttk.Label( self._frames['customFrame'], text='', font=('Arial', 20), anchor='center', wraplength=400, justify='center', style='WhiteBg.TLabel') self._widgets['customFrame.image'] = PhotoImage(file='docs/wait.png') self._widgets['customFrame.imageContainer'] = ttk.Label( self._frames['customFrame'], anchor='center', justify='center', image=self._widgets['customFrame.image'], style='WhiteBg.TLabel') self.initializeAuthenticationFrame() self._widgets['user.user'].grid(column=0, row=0, sticky='nsew') self._widgets['user.logout'].grid(column=1, row=0, sticky='nsew', padx=10, pady=20) self._widgets['message.message'].pack() self._widgets['logs.logs'].pack() self._frames['testStatus'].grid_rowconfigure(0, weight=1, minsize=60) self._frames['testStatus'].grid_columnconfigure(0, weight=4) self._frames['testStatus'].grid_columnconfigure(1, weight=1) self._widgets['testStatus.currentStatus'].grid(row=0, column=0, sticky='wnse', ipadx=10, ipady=10) self._widgets['testStatus.currentStatusButton'].grid(row=0, column=1, sticky='nse', padx=10, pady=10) self._widgets['resultList.tree'].grid(row=0, column=0) self._widgets['customFrame.message'].grid(row=0, column=0, pady=(0, 30)) self._widgets['customFrame.imageContainer'].grid(row=1, column=0) # textHandler = TextHandler(self._widgets['logs.logs']) # logger = logging.getLogger() # logger.addHandler(textHandler) from framework.application import Application self.ots = Application('settings.ini', 'hardware_configuration.ini', 'users.txt') self._widgets['interactive.sequenceList'].configure( value=list(self.ots.sequences.keys())) self.init()
class Gui: def __init__(self): self.colors = {} # self.colors['light green'] = 'light green' # self.colors['red'] = 'red' # self.colors['light grey'] = 'light grey' self.colors['light green'] = '#C5E6A6' self.colors['green'] = '#7FB069' self.colors['red'] = '#DA4167' self.colors['light grey'] = '#9B9B9B' self.colors['white'] = 'white' self.colors['dark grey'] = '#5f6363' self.colors['black'] = 'black' self._root = Tk() self._root.geometry("1900x1000+0+0") self._root.title("Owczarek Test System (OTS) for Capelon") self._root.configure(background='white') self._style = ttk.Style() self._style.configure('TFrame', background='white') self._style.configure('TLabel', background=self.colors['light grey'], foreground=self.colors['white'], font=('Arial', 16, 'bold')) self._style.configure('WhiteBg.TLabel', background=self.colors['white'], foreground='black') self._style.configure('TButton', background='white') self._style.configure('TreeView', background='white') comboboxListFont = ("Arial", 16) self._root.option_add("*TCombobox*Listbox*Font", comboboxListFont) self._frames = {} self._widgets = {} self._style = ttk.Style() self._frames['header'] = ttk.Frame(self._root) self._frames['content'] = ttk.Frame(self._root) self._frames['header'].pack() self._frames['content'].pack() self._frames['content'].grid_columnconfigure(0, minsize=400) self._frames['content'].grid_columnconfigure(1, minsize=20) self._frames['content'].grid_columnconfigure(2, minsize=500) self._frames['content'].grid_columnconfigure(3, minsize=20) self._frames['content'].grid_columnconfigure(4, minsize=300) # header subframes self._frames['logo'] = ttk.Frame(self._frames['header']) self._frames['menuButtons'] = ttk.Frame(self._frames['header']) self._frames['logo'].grid(row=0, column=0, padx=30, pady=30) self._frames['menuButtons'].grid(row=0, column=1) # header widgets self._widgets['logo.image'] = PhotoImage(file='docs/logo2.PNG') self._widgets['logo.logo'] = ttk.Label( self._frames['logo'], image=self._widgets['logo.image'], style='WhiteBg.TLabel') self._widgets['logo.name'] = ttk.Label(self._frames['logo'], text='TEST STATION', font=['Arial', 18, 'bold'], foreground='grey', style='WhiteBg.TLabel') self._widgets['menuButtons.settingsButton'] = \ ttk.Button(self._frames['menuButtons'], text='SETTINGS', command=lambda: self.callback_settingsButtonClick()) self._widgets['menuButtons.hardwareConfigurationButton'] = \ ttk.Button(self._frames['menuButtons'], text='HARDWARE CONFIGURATION', command=lambda: self.callback_hardwareConfigurationButtonClick()) self._widgets['menuButtons.dataManagementButton'] = \ ttk.Button(self._frames['menuButtons'], text='DATA MANAGEMENT', command=lambda: self.callback_dataManagementButtonClick()) self._widgets['menuButtons.exitButton'] = \ ttk.Button(self._frames['menuButtons'], text='EXIT', command=lambda: self.callback_exitButtonClick()) self._widgets['logo.logo'].grid(row=0, column=0) self._widgets['logo.name'].grid(row=1, column=0) # self._widgets['menuButtons.settingsButton'].grid(row=0, column=0) # self._widgets['menuButtons.hardwareConfigurationButton'].grid(row=0, column=1) # self._widgets['menuButtons.dataManagementButton'].grid(row=0, column=2) # self._widgets['menuButtons.exitButton'].grid(row=0, column=3) # content subframes self._frames['user'] = Frame(self._frames['content'], background=self.colors['light grey']) self._frames['interactive'] = Frame( self._frames['content'], background=self.colors['light grey']) self._frames['message'] = Frame(self._frames['content'], background='white') self._frames['customFrame'] = Frame(self._frames['content'], background='white') self._frames['authentication'] = Frame(self._frames['content'], background='white') self._frames['resultList'] = Frame( self._frames['content'], borderwidth=2, background=self.colors['light grey'], padx=10, pady=5) self._frames['logs'] = LabelFrame(self._frames['content'], background='white', text='Logs', pady=10, padx=10) self._frames['statistics'] = Frame(self._frames['content'], background='white') self._frames['testStatus'] = Frame( self._frames['content'], background=self.colors['light grey']) self._frames['user'].grid(row=0, column=0, sticky='nwe') self._frames['user'].grid_columnconfigure(0, weight=1) self._frames['user'].grid_remove() self._frames['authentication'].grid(row=0, column=0, sticky='new', padx=0, pady=0) self._frames['message'].grid(row=1, column=0, sticky='nsew') self._frames['resultList'].grid(row=0, column=2, rowspan=5) #self._frames['logs'].grid(row=4, column=0, rowspan=2) self._frames['statistics'].grid(row=0, column=4, sticky='nsew', rowspan=3) self._frames['testStatus'].grid(row=5, column=2, sticky='nsew') self._frames['content'].grid_columnconfigure(2, minsize=30, weight=1) # content widgets self._widgets['user.user'] = Label( self._frames['user'], background=self.colors['light grey'], text='NO USER LOGGED IN', font=('Arial', 14, 'bold'), foreground='white', padx=30, pady=10) self._widgets['user.logout'] = Button( self._frames['user'], text='Log out', command=lambda: self.callback_logoutButtonClick(), background=self.colors['dark grey'], foreground=self.colors['white'], font=('Arial', 14, 'bold')) self._widgets['message.message'] = \ ttk.Label(self._frames['message'], text='', font=('Arial', 20), anchor='center', wraplength=400, style='WhiteBg.TLabel', justify='center') self._widgets['logs.logs'] = \ scrolledtext.ScrolledText(self._frames['logs'], height=10, width=80, state='disabled', bd=0, highlightthickness=0, relief='ridge') self._widgets['resultList.tree'] = self.initializeResultListTree() self._widgets['logs.logs'].configure(font=('TkFixedFont', 7)) self._widgets['testStatus.currentStatus'] = \ ttk.Label(self._frames['testStatus'], text='', font=('Arial', 18, 'bold'), background=self.colors['light grey'], anchor=CENTER) self._widgets['testStatus.currentStatusButton'] = \ Button(self._frames['testStatus'], text='TERMINATE', command=lambda: self.callback_terminateButtonClick(), background=self.colors['dark grey'], foreground=self.colors['white'], font=('Arial', 14, 'bold')) self.initializeStatisticsFrame() self.initializeSequenceChoiceFrame() self._widgets['customFrame.message'] = ttk.Label( self._frames['customFrame'], text='', font=('Arial', 20), anchor='center', wraplength=400, justify='center', style='WhiteBg.TLabel') self._widgets['customFrame.image'] = PhotoImage(file='docs/wait.png') self._widgets['customFrame.imageContainer'] = ttk.Label( self._frames['customFrame'], anchor='center', justify='center', image=self._widgets['customFrame.image'], style='WhiteBg.TLabel') self.initializeAuthenticationFrame() self._widgets['user.user'].grid(column=0, row=0, sticky='nsew') self._widgets['user.logout'].grid(column=1, row=0, sticky='nsew', padx=10, pady=20) self._widgets['message.message'].pack() self._widgets['logs.logs'].pack() self._frames['testStatus'].grid_rowconfigure(0, weight=1, minsize=60) self._frames['testStatus'].grid_columnconfigure(0, weight=4) self._frames['testStatus'].grid_columnconfigure(1, weight=1) self._widgets['testStatus.currentStatus'].grid(row=0, column=0, sticky='wnse', ipadx=10, ipady=10) self._widgets['testStatus.currentStatusButton'].grid(row=0, column=1, sticky='nse', padx=10, pady=10) self._widgets['resultList.tree'].grid(row=0, column=0) self._widgets['customFrame.message'].grid(row=0, column=0, pady=(0, 30)) self._widgets['customFrame.imageContainer'].grid(row=1, column=0) # textHandler = TextHandler(self._widgets['logs.logs']) # logger = logging.getLogger() # logger.addHandler(textHandler) from framework.application import Application self.ots = Application('settings.ini', 'hardware_configuration.ini', 'users.txt') self._widgets['interactive.sequenceList'].configure( value=list(self.ots.sequences.keys())) self.init() def init(self): # TODO dynamic import of values self.updateTestStatus('', '', False) if self.ots.loggedUser: self._loginSuccess() def initializeSequenceChoiceFrame(self): self._widgets['interactive.sequenceList'] = \ ttk.Combobox(self._frames['interactive'], font=('Arial', 16, 'bold'), justify='center', foreground=self.colors['dark grey'], state='readonly', width=30) self._widgets['interactive.sequenceListLabel'] = \ ttk.Label(self._frames['interactive'], text='Choose test sequence:', foreground=self.colors['white'], justify='center') self._widgets['interactive.batchNumber'] = \ Entry(self._frames['interactive'], font=('Arial', 16, 'bold'), foreground=self.colors['dark grey'], justify='center', highlightbackground=self.colors['light grey'], highlightcolor=self.colors['light grey'], highlightthickness=0) self._widgets['interactive.batchNumberLabel'] = \ ttk.Label(self._frames['interactive'], text='Enter batch number:', justify='center') self._widgets['interactive.okButton'] = \ Button(self._frames['interactive'], text='OK', command=lambda: self.callback_okButtonClick(), background=self.colors['dark grey'], foreground=self.colors['white'], font=('Arial', 14, 'bold')) self._widgets['interactive.okButtonLabel'] = ttk.Label( self._frames['interactive'], justify='center', wraplength=350) self._widgets['interactive.closeBatchButtonLabel'] = ttk.Label( self._frames['interactive'], justify='center') self._widgets['interactive.closeBatchButton'] = \ Button(self._frames['interactive'], text='FINISH TEST SESSION', command=lambda: self.callback_closeBatchButtonClick(), background=self.colors['dark grey'], foreground=self.colors['white'], font=('Arial', 14, 'bold')) self._widgets['interactive.sequenceListLabel'].grid(row=0, column=0, pady=(20, 0)) self._widgets['interactive.sequenceList'].grid(row=1, column=0, pady=5) self._widgets['interactive.batchNumberLabel'].grid(row=2, column=0, pady=(30, 0)) self._widgets['interactive.batchNumber'].grid(row=3, column=0, pady=5) self._widgets['interactive.closeBatchButtonLabel'].grid(row=6, column=0, padx=0, pady=(30, 0)) self._widgets['interactive.closeBatchButton'].grid(row=7, column=0, padx=50, pady=(5, 20)) self._widgets['interactive.okButtonLabel'].grid(row=4, column=0, padx=30, pady=(30, 0)) self._widgets['interactive.okButton'].grid(row=5, column=0, padx=0, pady=(5, 20)) def initializeResultListTree(self): self._style.element_create("Custom.Treeheading.border", "from", "default") self._style.layout("Custom.Treeview.Heading", [ ("Custom.Treeheading.cell", { 'sticky': 'nswe' }), ("Custom.Treeheading.border", { 'sticky': 'nswe', 'children': [("Custom.Treeheading.padding", { 'sticky': 'nswe', 'children': [("Custom.Treeheading.image", { 'side': 'right', 'sticky': '' }), ("Custom.Treeheading.text", { 'sticky': 'we' })] })] }), ]) self._style.layout("Treeview", [('Treeview.treearea', { 'sticky': 'nswe' })]) self._style.configure("Custom.Treeview.Heading", background=self.colors['light grey'], foreground="white", relief="flat", font=('Arial', 10, 'bold')) self._style.map("Custom.Treeview.Heading", relief=[('active', 'groove'), ('pressed', 'sunken')]) self._style.configure('Treeview', rowheight=25, borderwidth=10, bordercolor='black') resultListTree = ttk.Treeview(self._frames['resultList'], style='Custom.Treeview') resultListTree.config(columns=('stepName', 'stepType', 'value', 'limits', 'result', 'timestamp'), height=24) resultListTree.heading('#0', text='') resultListTree.heading('stepName', text='Step Name') resultListTree.heading('stepType', text='Type') resultListTree.heading('value', text='Value') resultListTree.heading('limits', text='Limits') resultListTree.heading('result', text='Result') resultListTree.heading('timestamp', text='Time') resultListTree['show'] = 'headings' resultListTree["displaycolumns"] = ( "stepName", "value", 'result', ) resultListTree.column('#0', width=0) resultListTree.column('stepName', width=280, anchor='center') resultListTree.column('stepType', width=60, anchor='center') resultListTree.column('value', width=250, anchor='center') resultListTree.column('limits', width=140, anchor='center') resultListTree.column('result', width=80, anchor='center') resultListTree.column('timestamp', width=120, anchor='center') resultListTree.tag_configure('PASSED', background=self.colors['light green']) resultListTree.tag_configure('FAILED', background=self.colors['red']) resultListTree.tag_configure('DONE', background=self.colors['light green']) resultListTree.tag_configure('result', font=('Arial', 14), foreground=self.colors['dark grey']) return resultListTree def initializeStatisticsFrame(self): left = 50 top = 100 diameter = 60 gap = 60 text_gap = 50 text_width = 100 self._widgets['statistics.canvas'] = Canvas( self._frames['statistics'], width=left + diameter + text_gap + text_width, height=(top + 4 * diameter + 3 * gap + 10), background='white', bd=0, highlightthickness=0, relief='ridge') ypos = 0 self._widgets['statistics.passed'] = self._widgets[ 'statistics.canvas'].create_oval(left, top + ypos * (diameter + gap), left + diameter, top + diameter + ypos * (gap + diameter), outline=self.colors['green'], fill=self.colors['green']) self._widgets['statistics.passedCount'] = self._widgets[ 'statistics.canvas'].create_text(left + diameter / 2, top + ypos * (diameter + gap) + diameter / 2, fill="white", font=('Arial', 20, 'bold'), text="0") self._widgets['statistics.passedLabel'] = self._widgets[ 'statistics.canvas'].create_text(left + diameter + text_gap, top + ypos * (diameter + gap) + diameter / 2, fill=self.colors['green'], font=('Arial', 20, 'bold'), text="OK") ypos = 1 self._widgets['statistics.failed'] = self._widgets[ 'statistics.canvas'].create_oval(left, top + ypos * (diameter + gap), left + diameter, top + diameter + ypos * (gap + diameter), outline=self.colors['red'], fill=self.colors['red']) self._widgets['statistics.failedCount'] = self._widgets[ 'statistics.canvas'].create_text(left + diameter / 2, top + ypos * (diameter + gap) + diameter / 2, fill="white", font=('Arial', 20, 'bold'), text="0") self._widgets['statistics.failedLabel'] = self._widgets[ 'statistics.canvas'].create_text(left + diameter + text_gap, top + ypos * (diameter + gap) + diameter / 2, fill=self.colors['red'], font=('Arial', 20, 'bold'), text="NOK") ypos = 2 self._widgets['statistics.total'] = self._widgets[ 'statistics.canvas'].create_oval(left, top + ypos * (diameter + gap), left + diameter, top + diameter + ypos * (gap + diameter), outline=self.colors['light grey'], fill=self.colors['light grey']) self._widgets['statistics.totalCount'] = self._widgets[ 'statistics.canvas'].create_text(left + diameter / 2, top + ypos * (diameter + gap) + diameter / 2, fill="white", font=('Arial', 20, 'bold'), text="0") self._widgets['statistics.totalLabel'] = self._widgets[ 'statistics.canvas'].create_text(left + diameter + text_gap, top + ypos * (diameter + gap) + diameter / 2, fill=self.colors['light grey'], font=('Arial', 20, 'bold'), text="Total") ypos = 3 self._widgets['statistics.time'] = self._widgets[ 'statistics.canvas'].create_oval(left, top + ypos * (diameter + gap), left + diameter, top + diameter + ypos * (gap + diameter), outline=self.colors['dark grey'], fill=self.colors['white'], width=5) self._widgets['statistics.timeCount'] = self._widgets[ 'statistics.canvas'].create_text(left + diameter / 2, top + ypos * (diameter + gap) + diameter / 2, fill=self.colors['dark grey'], font=('Arial', 20, 'bold'), text="0") self._widgets['statistics.timeLabel'] = self._widgets[ 'statistics.canvas'].create_text(left + diameter + text_gap, top + ypos * (diameter + gap) + diameter / 2, fill=self.colors['dark grey'], font=('Arial', 20, 'bold'), text="Time") self._widgets['statistics.canvas'].grid(row=0, column=0) self._frames['statistics'].grid_rowconfigure(0, weight=1) self._frames['statistics'].grid_columnconfigure(0, weight=1) self._frames['statistics'].grid_rowconfigure(1, weight=1, minsize=100) self._frames['statistics'].grid_rowconfigure(2, weight=1) def initializeAuthenticationFrame(self): self._frames['authentication'].configure( background=self.colors['light grey']) self._widgets['authentication.loginLabel'] = Label( self._frames['authentication'], text='Login', font=('Arial', 16), background=self.colors['light grey'], foreground='white') self._widgets['authentication.login'] = Entry( self._frames['authentication'], font=('Arial', 16), relief='flat', width=15) self._widgets['authentication.passwordLabel'] = Label( self._frames['authentication'], text='Password', font=('Arial', 16), background=self.colors['light grey'], foreground='white') self._widgets['authentication.password'] = Entry( self._frames['authentication'], font=('Arial', 16), relief='flat', show='*', width=15) self._widgets['authentication.loginButton'] = \ Button(self._frames['authentication'], text='Log in', command=self.callback_loginButtonClick, background=self.colors['dark grey'], foreground=self.colors['white'], font=('Arial', 14, 'bold')) self._widgets['authentication.loginLabel'].grid(row=0, column=0, sticky='e', pady=(10, 0)) self._widgets['authentication.login'].grid(row=0, column=2, pady=(10, 0), sticky='w') self._widgets['authentication.passwordLabel'].grid(row=1, column=0, sticky='e', pady=(10, 0)) self._widgets['authentication.password'].grid(row=1, column=2, pady=(10, 0), sticky='w') self._widgets['authentication.loginButton'].grid(row=2, column=0, columnspan=3, ipadx=10, pady=(20, 20)) self._frames['authentication'].grid_rowconfigure(0, weight=1) self._frames['authentication'].grid_rowconfigure(1, weight=1) self._frames['authentication'].grid_rowconfigure(2, weight=1) self._frames['authentication'].grid_columnconfigure(0, weight=1) self._frames['authentication'].grid_columnconfigure(1, weight=1, minsize=5) self._frames['authentication'].grid_columnconfigure(2, weight=1) def updateTestTime(self, time): self._widgets['statistics.canvas'].itemconfigure( self._widgets['statistics.timeCount'], text=str(round(time))) def callback_okButtonClick(self): sequenceName = self._widgets['interactive.sequenceList'].get() if not sequenceName: self._widgets['message.message']['text'] = 'No sequence selected' return self._widgets['message.message']['text'] = '' logging.debug('Sequence: \'{}\''.format(sequenceName)) from framework.gui_result_list import GuiResultList self._resultList = GuiResultList() self._resultList.bindGui(self, self._widgets['resultList.tree']) sequenceData = self.ots.sequences[sequenceName] sequence1 = sequenceData['sequence'](self.ots.station, sequenceName, self._resultList, self, sequenceData['stepsFilepath'], sequenceData['configFilepath']) self._resultList.bindSequence(sequence1) from framework.test import Test from framework.batch import Batch if not self.ots.batch: self.ots.batch = Batch( self._widgets['interactive.batchNumber'].get()) self.ots.test = Test(sequence1, self._resultList) for widget in self._frames['interactive'].winfo_children(): widget.grid_remove() self.ots.station.drivers['PowerRelay1'].switchOff(0.5) self._widgets['interactive.okButtonLabel'].grid() self._widgets['interactive.okButtonLabel'][ 'text'] = 'Attach new test object and click' self._widgets['interactive.okButton'].config( command=lambda: self.callback_startButtonClick()) self._widgets['interactive.okButton']['text'] = 'START TEST RUN' self._widgets['interactive.okButton'].grid() self._widgets['interactive.closeBatchButtonLabel'].grid() self._widgets['interactive.closeBatchButtonLabel'][ 'text'] = 'To finish the test session, click' self._widgets['interactive.closeBatchButton'].grid() # self.displayMemo('Attach the test device and click START TEST') def callback_startButtonClick(self): self._frames['interactive'].grid_remove() self.ots.testThread = threading.Thread( target=lambda: self.ots.test.run()) self.ots.testThread.start() self.displayMemo('') def callback_quitButtonClick(self): if messagebox.askokcancel("Quit", "Do you want to quit?"): if self.ots.testThread and self.ots.testThread.isAlive(): logging.debug("Exiting while test thread is active") self.ots.test.sequence.requestTerminate() self.ots.logout() time.sleep(1) self._root.destroy() self._root = None def callback_terminateButtonClick(self): self.ots.test.sequence.requestTerminate() def callback_closeBatchButtonClick(self): self.ots.batch.close() self.ots.batch = None self.displaySequenceChoice() def callback_loginButtonClick(self): user = self.ots.login(self._widgets['authentication.login'].get(), self._widgets['authentication.password'].get()) if user: self._loginSuccess() else: self._loginFailed() def callback_logoutButtonClick(self): if self.ots.test and self.ots.test.sequence.status == SequenceStatusEnum.RUNNING: messagebox.showinfo( "Action not allowed", "You cannot log out while the test is in progress. \nFinish test session to log out!" ) else: user = self.ots.logout() self._logout() self.initializeAuthenticationFrame() def _loginSuccess(self): self._frames['authentication'].grid_remove() self._frames['user'].grid() self._widgets['message.message']['text'] = '' self.displaySequenceChoice() self._widgets['user.user']['text'] = 'User: '******'name'] def _logout(self): self._frames['user'].grid_remove() self._frames['interactive'].grid_remove() self._frames['authentication'].grid() self._widgets['message.message']['text'] = '' def _loginFailed(self): self._widgets['message.message']['text'] = 'Wrong login or password' def displaySequenceChoice(self): if self._root: self._widgets['user.logout'].grid() self._frames['customFrame'].grid_remove() self._frames['interactive'].grid(row=2, column=0, columnspan=1, sticky='nwe') self._frames['interactive'].grid_columnconfigure(0, weight=1) if self.ots.batch and self.ots.batch.batchNumber: for widget in self._frames['interactive'].winfo_children(): widget.grid_remove() self._widgets['interactive.okButtonLabel'].grid() self._widgets['interactive.okButtonLabel'][ 'text'] = 'Attach new test object and click' self._widgets['interactive.okButton'][ 'text'] = 'START TEST RUN' self._widgets['interactive.okButton'].grid() self._widgets['interactive.closeBatchButtonLabel'].grid() self._widgets['interactive.closeBatchButtonLabel'][ 'text'] = 'To finish the test session, click' self._widgets['interactive.closeBatchButton'].grid() # self.displayMemo('Attach next test device and click START NEXT TEST') self._widgets['interactive.okButton'].config( command=lambda: self.callback_startButtonClick()) else: self._widgets['interactive.sequenceListLabel'][ 'text'] = '1. Choose test sequence:' self._widgets['interactive.sequenceListLabel'].grid() self._widgets['interactive.sequenceList'].grid() self._widgets['interactive.batchNumberLabel'][ 'text'] = '2. Enter batch number:' self._widgets['interactive.batchNumberLabel'].grid() self._widgets['interactive.batchNumber'].grid() self._widgets['interactive.okButtonLabel'].grid() self._widgets['interactive.okButtonLabel'][ 'text'] = '3. Click OK' self._widgets['interactive.okButton'].grid() self._widgets['interactive.closeBatchButton'].grid_remove() self._widgets['interactive.closeBatchButtonLabel'].grid_remove( ) self._widgets['interactive.okButton'].config( command=lambda: self.callback_okButtonClick()) def displayMemo(self, text): self._widgets['message.message']['text'] = text def displayCustomMessage(self, type, displayText): if self._root: self._widgets['customFrame.message'].config(text=displayText) self._frames['interactive'].grid_remove() self._frames['customFrame'].grid(row=1, column=0, columnspan=2) def updateTestStatus(self, text, bgcolor=None, showTerminateButton=False): if self._root: self._widgets['testStatus.currentStatus']['text'] = text if bgcolor: self._widgets['testStatus.currentStatus'].config( background=bgcolor, foreground='white') self._frames['testStatus'].config(background=bgcolor) self._frames['resultList'].config(background=bgcolor) self._style.configure("Custom.Treeview.Heading", background=bgcolor) if showTerminateButton: self._widgets['testStatus.currentStatusButton'].grid() else: self._widgets['testStatus.currentStatusButton'].grid_remove( ) # grid will remember the position def incrementStatistics(self, widgetName): actual = int(self._widgets['statistics.canvas'].itemcget( self._widgets[widgetName], 'text')) self._widgets['statistics.canvas'].itemconfigure( self._widgets[widgetName], text=str(actual + 1)) def incrementPassedStatistics(self): self.incrementStatistics('statistics.passedCount') self.incrementStatistics('statistics.totalCount') def incrementFailedStatistics(self): self.incrementStatistics('statistics.failedCount') self.incrementStatistics('statistics.totalCount')
def main(): framework_root = os.path.dirname(os.path.realpath(__file__)) app = Application(framework_root) app.run()
student_name = Application.decode_value(student_name) student = site.get_student(student_name) course.add_student(student) urls = { '/': main_view, '/create-course/': create_course, '/create-category/': CategoryCreateView(), '/category-list/': CategoryListView(), '/student-list/': StudentListView(), '/create-student/': StudentCreateView(), '/add-student/': AddStudentByCourseCreateView(), } application = Application(urls, front_controllers) @application.add_route('/copy-course/') @debug def copy_course(request): request_params = request['request_params'] name = request_params['name'] name = Application.decode_value(name) old_course = site.get_course(name) if old_course: new_name = f'copy_{name}' new_course = old_course.clone() new_course.name = new_name site.courses.append(new_course)
from framework.gui import * from framework.application import * from framework.application import Application from framework.result_list import ResultList ots = Application('settings.ini', 'hardware_configuration.ini') ots.station.addDriver(MqttClient("MqttClient1")) ots.station.addDriver(JLinkExe("JLinkExe1")) from framework.gui_result_list import GuiResultList resultList = ResultList() sequence = ots.sequences['OLC NEMA PP - full test'](ots.station, 'OLC NEMA PP - full test', resultList, None, 'sequences/full_test.csv', 'sequences/full_test.ini') resultList.bindSequence(sequence) from framework.test import Test from framework.batch import Batch if not ots.batch: ots.batch = Batch("12345") ots.test = Test(sequence, resultList) ots.testThread = threading.Thread(target=lambda: ots.test.run()) ots.testThread.start()
async def on_startup(app): # you may query here actual db, but for example let's just use simple set. app.db = { 'john_doe', } async def log_middleware(request, handler): print(f'Received request to {request.url.raw_path}') return await handler(request) async def handler(request): username = request.match_info['username'] if username not in request.app.db: raise HTTPNotFound(reason=f'No such user with as {username} :(') return Response(f'Welcome, {username}') app = Application(middlewares=[log_middleware]) app.on_startup.append(on_startup) app.router.add_route('GET', '/{username}', handler) if __name__ == '__main__': run_app(app)
#!/usr/bin/env python import sys from framework.application import Application if __name__ == '__main__': app = Application(sys.argv) sys.exit(app.run())
self.npc_icon.image = Loader.get_image( "data/DialogWindow/woodcutter_icon.png") Renderer.submit(self.dialog, False) Renderer.submit(self.npc_icon, False) Renderer.submit(self.cancel_btn, False) if self.quest not in [2, 4]: Renderer.submit(self.accept_btn, False) for i in self.plot["woodcutter"][str(self.quest)]: plot = [ self.plot["woodcutter"][i] for i in [j for j in list(self.plot["woodcutter"])] ][self.quest - 1] text = f.render(i, 1, (160, 135, 132)) Renderer.submit((text, [320, 480 + (plot.index(i) * 40)] - Renderer.cameraTranslation)) if self.quest == 2: text = f.render("Wood: " + str(self.wood) + "/3", 1, (255, 120, 104)) Renderer.submit((text, [100, 100] - Renderer.cameraTranslation)) Renderer.present() if Developer_mode: Renderer.check(self.posit) return Trans.Pass if __name__ == "__main__": app = Application(MainMenu(), "Game", 1080, 720) app.run()