def setup_dht(self, n): ''' Asks server for n-1 other free users then constructs a ring structure and builds a DHT amongst the n nodes. Parameters ---------- n : int Number of nodes in the DHT, cannot exceed number of free users. ''' response = self.send_segment( sn(command='setup-dht', args=sn(n=int(n), )), self.host_addr) if response.status == SUCCESS: n = len(response.body) self.set_id(0, n, response.body[-1 % n], response.body[1]) for i in range(1, n): payload = sn(command='set-id', args=sn(i=i, n=n, prev=response.body[(i - 1) % n], next=response.body[(i + 1) % n])) self.sock.sendto(pickle.dumps(payload), response.body[i].recv_addr) # Read Stats File with open(self.stat_file) as f: reader = csv.DictReader(f) for row in reader: self.store(dict(row)) # All done self.send_segment(sn(command='dht-complete', args=None), self.host_addr)
def entry(arg, style, align, text, name="", password=False, keyboard=False): stylevar = styles.setup() arg.hprops.__dict__[arg.curpage].__dict__[name] = sn(**{"bind": sn(**{})}) if align == "left": anchor = tk.LEFT elif align == "right": anchor = tk.RIGHT elif align == "center": anchor = tk.CENTER if password: toShow = "*" arg.hprops.__dict__[arg.curpage].__dict__[name].bind.password = True else: toShow = "" obj = ttk.Entry( arg.master, font=(stylevar.lookup(style + ".TEntry", "font")), # style = style + ".TEntry", justify=anchor, show=toShow) obj.delete(0, tk.END) obj.insert(0, text) if keyboard: arg.hprops.__dict__[arg.curpage].__dict__[name].bind.keyboard = True return obj
def query(self, long_name, u_addr): ''' If the id computed by the hash is our id then send it back to the user that queried, otherwise the command will be sent along the chain. Parameters ---------- long_name : str Long Name of Country to query DHT. u_addr : tuple Address of the user who issued the query. ''' id = self.hash_table.hash_func(long_name) % self.n if self.i == id: record = self.hash_table.lookup(long_name) if record is not None: self.sock.sendto(pickle.dumps(sn(status=SUCCESS, body=record)), u_addr) else: err_msg = f'Long name, {long_name}, could not be found in the DHT.' self.sock.sendto( pickle.dumps(sn(status=FAILURE, body=err_msg)), u_addr) else: payload = sn(command='query', args=sn(long_name=long_name, u_addr=u_addr)) self.sock.sendto(pickle.dumps(payload), self.next.recv_addr)
def hpropsobjs(arg, h): ## Objects for hname in arg.hobjs.__dict__[arg.curpage].__dict__: if arg.hobjs.__dict__[ arg.curpage].__dict__[hname].obj.winfo_class() == "TScrollbar": h.__dict__[hname + "_scroll"] = arg.hobjs.__dict__[ arg.curpage].__dict__[hname] h.__dict__[hname + "_scroll"].pos = sn( **{ "x": h.__dict__[hname].pos.x + h.__dict__[hname].pos.w - g.scrollWidth, "y": h.__dict__[hname].pos.y, "w": g.scrollWidth, "h": h.__dict__[hname].pos.h }) ## Properties and Variables for hname in h.__dict__: # print(arg.curpage, hname) if h.__dict__[hname].obj.winfo_class() == "TEntry": h.__dict__[hname].bind = sn(**{}) if "password" in arg.hprops.__dict__[ arg.curpage].__dict__[hname].bind.__dict__: h.__dict__[hname].bind.password = True if "keyboard" in arg.hprops.__dict__[ arg.curpage].__dict__[hname].bind.__dict__: h.__dict__[hname].bind.keyboard = True
def teardown_dht(self): ''' Tears down the DHT completely for all users. ''' response = self.send_segment(sn(command='teardown-dht', args=None), self.host_addr) if response.status == SUCCESS: payload = sn(command='teardown', args=None) self.send_segment(payload, self.next.recv_addr) # All done self.send_segment(sn(command='teardown-complete', args=None), self.host_addr)
def teardown(self): ''' Message send around the DHT deleting all DHT attributes until it gets back to the leader. ''' if self.i == 0: self.sock.sendto(pickle.dumps(sn(status=SUCCESS, body=None)), self.sock.getsockname()) else: payload = sn(command='teardown', args=None) self.sock.sendto(pickle.dumps(payload), self.next.recv_addr) self.del_dht_attrs()
def test_posiible_workflows_with_backlog(): issue = sn(fields=sn(status=sn(name='Backlog'))) issues = {} issues['issue_obj'] = issue issues['workflow'] = { 'Return to Backlog': '131', 'Selected for development': '51', 'Declare done': '171', 'Flag': '181' } assert MainController(None).get_possible_workflows(issues) == [ 'Return to Backlog', 'Selected for development', 'Declare done', 'Flag' ]
def reset_id(self, i, n): ''' Updates i and n values and sends message around the ring until it comes back to the user that is leaving. ''' self.i = i self.n = n self.hash_table = HashTable(size=HASH_SIZE) # If the next the user is leaving the DHT if i == n - 1: self.sock.sendto(pickle.dumps(sn(status=SUCCESS, body=None)), self.next.out_addr) else: payload = sn(command='reset-id', args=sn(i=i + 1, n=n)) self.sock.sendto(pickle.dumps(payload), self.next.recv_addr)
def store(self, record): ''' If the id computed by the hash is our id then the record will be added to the hash table, otherwise it will be sent along the chain. Parameters ---------- record : dict dictionary mapping each field associated with a particular country to its value. ''' id = self.hash_table.hash_func(record['Long Name']) % self.n if self.i == id: self.hash_table.add(record) else: payload = sn(command='store', args=sn(record=record)) self.sock.sendto(pickle.dumps(payload), self.next.recv_addr)
def setupPages(arg): ######## Main Handle Variable that contains All GUI Elements ######## pages = glob.glob("pages/pg_*.py") for ctr in range(0, len(pages)): ## Remove .py pages[ctr] = pages[ctr][6:-3] ## IMPORT AND GENERATE HANDLES AND FUNCTION HOLDERS ##################### Acces to Page Functions ##################### # fcn = sn(**{}) handles = sn(**{}) for pagename in pages: arg.curpage = pagename handles.__dict__[pagename] = importlib.import_module( "pages." + pagename).page(arg) fcnFilename = "fcn_" + pagename[3:] arg.__dict__[fcnFilename] = importlib.import_module("functions." + fcnFilename) # fcn.__dict__[fcnFilename] = importlib.import_module("functions." + fcnFilename) # arg.fcn = fcn arg.handles = handles
def deregister(self): ''' If the server allows the user to deregister, terminate the application. ''' response = self.send_segment(sn(command='deregister', args=None), self.host_addr) if response.status == SUCCESS: sys.exit(0)
def query_dht(self, long_name): ''' Sends request to server to query, on a successful response it will go around the ring looking for who has the long_name that was queried. If found it will be printed. Parameters ---------- long_name : str Long Name of Country to query DHT. ''' response = self.send_segment(sn(command='query-dht', args=None), self.host_addr) if response.status == SUCCESS: payload = sn(command='query', args=sn(long_name=long_name, u_addr=self.sock.getsockname())) record = self.send_segment(payload, response.body.recv_addr).body print(record)
def register(self, user_name, port): ''' Registers a new user with the server with the desired user_name and port. After a successful response from the server, a thread will be spawned to listen on the chosen port. user_name and port should be unique across all Clients. Parameters ---------- user_name : string Name of client, must be less than 16 characters. port : int Reasonable port that is not already in use, must be less than 65535. ''' payload = sn(command='register', args=sn(user_name=user_name, port=int(port))) response = self.send_segment(payload, self.host_addr) if response.status == SUCCESS: start_new_thread(self.listen, (int(port), ))
def table(arg, style="", align="", header=[], data=[], name=""): ## Style Pending h = ttk.Treeview(arg.master) arg.hvars.__dict__[arg.curpage].__dict__[name] = sn(**{ "header": header, "data": data, }) return h
def success(self, body=None): ''' Sends a SUCCESS response to self.out_addr. Parameters ---------- body : any Data relevant to response. ''' self.sock.sendto(pickle.dumps(sn(status=SUCCESS, body=body)), self.out_addr)
def margin(self, value): if isinstance(value, numbers.Number): value = (value, value, value, value) elif len(value) == 3: value = (value[0], value[1], value[2], value[1]) elif len(value) == 2: value = (value[0], value[1], value[0], value[1]) value = sn( top=value[0], right=value[1], bottom=value[2], left=value[3]) if value != self._margin: self._margin = value self.set_needs_display()
def page(arg): ## SAVE PROPERTIES arg.hprops = sn(**{}) arg.hobjs = sn(**{}) arg.hvars = sn(**{}) arg.hprops.__dict__[arg.curpage] = sn(**{}) arg.hobjs.__dict__[arg.curpage] = sn(**{}) arg.hvars.__dict__[arg.curpage] = sn(**{}) h = sn(**{}) ####################### GUI ELEMENTS START ######################### ####################### GUI ELEMENTS END ######################### gui.hpropsobjs(arg, h) return h
def listbox(arg, data, name): obj = tk.Listbox(arg.master) obj.delete(0, tk.END) ## If data is List if isinstance(data, list): for d in data: obj.insert(tk.END, d) else: ## If data is scalar obj.insert(tk.END, data) arg.hobjs.__dict__[arg.curpage].__dict__[name] = sn(**{ "obj": ttk.Scrollbar(arg.master, orient="vertical", command=obj.yview), }) return obj
def __init__(self, margin=None, **kwargs): super().__init__(**kwargs) self._margin = sn(top=5, right=5, bottom=5, left=5) self.touch_enabled = False if margin: self.margin = margin
def stage_zip(dbhost, dbname, schema, username, password, zip_file): conn = psycopg2.connect(f"""user='******' password='******' host='{dbhost}' port='{5432}' dbname='{dbname}'""") cur = conn.cursor() entries = [] columns = None cur.execute(f'CREATE SCHEMA IF NOT EXISTS {schema}') def process_step_init(entry): entry.tbl_name = entry.filename[0:-4] entry.name = schema +'.'+ entry.tbl_name entry.is_dim = entry.filename.startswith('D_') if entry.is_dim: cur.execute( f'create table if not exists {entry.name}({entry.header[0]} text PRIMARY KEY, {entry.header[1]} text)') for col in entry.header[2:]: cur.execute(f'ALTER TABLE {entry.name} ADD COLUMN IF NOT EXISTS {col} text') entry.meta = columns.get(entry.tbl_name[2:], []) for col in entry.meta: cur.execute(f'alter table {entry.name} drop constraint if exists ' + col['ColumnId'] + '_MFK') else: entry.val_col = entry.header[-1] cur.execute(f'create table if not exists {entry.name}({entry.val_col} numeric)') for col in entry.header[:-1]: cur.execute(f'ALTER TABLE {entry.name} ADD COLUMN IF NOT EXISTS {col} text') cur.execute(f'ALTER TABLE {entry.name} DROP CONSTRAINT if exists {col}_FK') cur.execute(f'alter table {entry.name} drop constraint if exists {entry.tbl_name}_pkey') cur.execute(f'alter table {entry.name} ADD PRIMARY KEY (' + ','.join(entry.header[:-1]) + ')') def process_step_load(entry, data): cur.execute(f'truncate table {entry.name}') insert = 'insert into ' + entry.name + '(' + ','.join(entry.header) + ') values %s' psycopg2.extras.execute_values (cur, insert, data) def process_step_finish(entry): if entry.is_dim: for meta_info in entry.meta: if meta_info['Type']=='Reference': cur.execute(f'alter table {entry.name} add constraint ' + meta_info['ColumnId'] + '_MFK FOREIGN KEY (' + meta_info['ColumnHeader'] + ') REFERENCES ' + schema + '.d_' + meta_info['ReferencedTable'] + ' (' + meta_info['ReferencedTable'] + '_ID)') else: for col in entry.header[:-1]: cur.execute(f"""ALTER TABLE {entry.name} ADD CONSTRAINT {col}_FK FOREIGN KEY ({col}) REFERENCES {schema}.d_{col[:-3]} ({col})""") def get_reader(zip_entry): return csv.reader(io.TextIOWrapper(zip_entry, encoding='utf-8-sig'), delimiter='\t', quotechar='"') with zipfile.ZipFile(zip_file) as zip_file: with zip_file.open('columns.json') as zip_entry: columns = json.load(zip_entry) for text_file in zip_file.infolist(): if text_file.filename.endswith('.csv'): with zip_file.open(text_file.filename) as zip_entry: entries.append(sn(filename=text_file.filename, header=next(get_reader(zip_entry)))) print("creating tables") for entry in entries: process_step_init(entry) conn.commit(); for entry in entries: print(f"staging table {entry.name} ({('dimension' if entry.is_dim else 'fact')}): ", end='') with zip_file.open(entry.filename) as zip_entry: reader = get_reader(zip_entry) next(reader) # skip header count = 0 def process_rows(): nonlocal count for line in reader: count += 1 yield [(None if v == '' else v) for v in line] process_step_load(entry, process_rows()) print(f'{count} row(s) loaded') conn.commit(); print("setting up key constraints") for entry in entries: process_step_finish(entry) conn.commit(); cur.close() conn.close() print('done')
def page(arg): ## SAVE PROPERTIES arg.hprops = sn(**{}) arg.hobjs = sn(**{}) arg.hvars = sn(**{}) arg.hprops.__dict__[arg.curpage] = sn(**{}) arg.hobjs.__dict__[arg.curpage] = sn(**{}) arg.hvars.__dict__[arg.curpage] = sn(**{}) h = sn(**{}) ####################### GUI ELEMENTS START ######################### h.myEntry = sn( ** { ## gui.entry(arg,"style","align","text", name="entryName" ,password=True, keyboard=True, type=number), "obj": gui.entry(arg, "entryMedium", "center", "Edit me!", name="myEntry", password=True, keyboard=True), "pos": sn(**{ "x": 10, "y": 10, "w": 150, "h": 30, }) }) h.label1 = sn( **{ ## gui.label(arg,"style","align","text") "obj": gui.label(arg, "labelSmall", "center", "Hello There!"), "pos": sn(**{ "x": 100, "y": 300, "w": 100, "h": 40, }) }) # h.checkbox = sn(**{ ## gui.checkbox(arg,"yourText", lambda: test(arg)), # "obj": gui.checkbox(arg,"yourText", lambda: test(arg)), # "pos": sn(**{ # "x": 10, # "y": 10, # "w": 150, # "h": 30, # }) # }) h.checkbox = sn( **{ ## gui.checkbox(arg,"yourText", lambda: test(arg)), "obj": gui.checkbox(arg, "yourText", lambda: test(arg, 1)), "pos": sn(**{ "x": 10, "y": 40, "w": 150, "h": 30, }) }) optionList1 = ('a', 'a', 'b', 'c') h.combobox = sn( ** { ## ttk.OptionMenu(arg.master,v1,*optionList1, command=lambda selected:test123123(selected)) "obj": gui.combobox(arg, optionList1, lambda selected_val: test(arg, selected_val)), "pos": sn(**{ "x": 10, "y": 80, "w": 150, "h": 30, }) }) h.progress = sn( ** { ## tttk.Progressbar(arg.master, orient = orient, length = length, mode = mode) "obj": gui.progressbar(arg), "pos": sn(**{ "x": 10, "y": 120, "w": 150, "h": 30, }) }) h.radiobutton = sn( ** { ## Radiobutton(arg.master,text="t",padx = 20, variable=v, command=command,value=value).pack(anchor=tk.W) "obj": gui.radiobutton(arg, text="option1", variable=radiobutton_var, value=1, command=lambda: test(arg, 1)), "pos": sn(**{ "x": 10, "y": 160, "w": 150, "h": 30, }) }) h.radiobutton2 = sn( ** { ## Radiobutton(arg.master,text="t",padx = 20, variable=v, command=command,value=value).pack(anchor=tk.W) "obj": gui.radiobutton(arg, text="option1", variable=radiobutton_var, value=2, command=lambda: test(arg, 1)), "pos": sn(**{ "x": 10, "y": 200, "w": 150, "h": 30, }) }) ####################### GUI ELEMENTS END ######################### gui.hpropsobjs(arg, h) return h
def leave_dht(self): ''' Asks the server to leave, Tells all the other nodes to reset their ids, reconnects left and right neighbors, rebuilds dht, tells the server. ''' response = self.send_segment(sn(command='leave-dht', args=None), self.host_addr) if response.status == SUCCESS: # Restucture DHT self.send_segment( sn(command='reset-id', args=sn(i=0, n=self.n - 1)), self.next.recv_addr) self.sock.sendto( pickle.dumps( sn(command='reset-left', args=sn(next_user=self.next))), self.prev.recv_addr) self.sock.sendto( pickle.dumps( sn(command='reset-right', args=sn(prev_user=self.prev))), self.next.recv_addr) # Rebuild the DHT with open(self.stat_file) as f: reader = csv.DictReader(f) for row in reader: self.sock.sendto( pickle.dumps( sn(command='store', args=sn(record=dict(row)))), self.next.recv_addr) # Tell the server who the new leader is self.send_segment( sn(command='dht-rebuilt', args=sn(leader=self.next)), self.host_addr) self.del_dht_attrs()
def page(arg): ## Name of this Page # print(arg.curpage) ## SAVE PROPERTIES arg.hprops = sn(**{}) arg.hobjs = sn(**{}) arg.hvars = sn(**{}) arg.hprops.__dict__[arg.curpage] = sn(**{}) arg.hobjs.__dict__[arg.curpage] = sn(**{}) arg.hvars.__dict__[arg.curpage] = sn(**{}) ####################### GUI ELEMENTS ######################### h = sn(**{}) ## Optional Variables for Guided Positioning margin = 30 spacing = 10 small = 150 medium = 225 large = 300 height = 40 h.bg = sn( **{ ## gui.image(arg,"imagename", "image.jpg", (w,h))) "obj": gui.image(arg, "pg_1-bg", "bg.jpg", (g.frameWidth, g.frameHeight)), "pos": sn(**{ "x": 0, "y": 0, "w": g.frameWidth, "h": g.frameHeight, }) }) ### LABEL h.label1 = sn( **{ ## gui.label(arg,"style","align","text") "obj": gui.label(arg, "labelSmall", "center", "Hello There!"), "pos": sn(**{ "x": margin, "y": 300, "w": medium, "h": height, }) }) ### ENTRY h.myEntry = sn( ** { ## gui.entry(arg,"style","align","text", name="entryName" ,password=True, keyboard=True, type=number), "obj": gui.entry(arg, "entryMedium", "center", "Edit me!", name="myEntry", password=True, keyboard=True), "pos": sn(**{ "x": 10, "y": 10, "w": 150, "h": 30, }) }) h.btnTest1 = sn( **{ ## gui.button(arg,"style","unused","text",lambda: fcn(arg)), ## Function Wont Work on Quick View "obj": gui.button(arg, "btnBig", "center", "Push Me!", lambda: arg.fcn_main.testFcn(arg)), "pos": sn(**{ "x": margin, "y": 200, "w": medium, "h": height, }) }) h.btnTest2 = sn( **{ ## gui.button(arg,"style","unused","text",lambda: fcn(arg)), "obj": gui.button(arg, "btnBig", "center", "NEXT PAGE", lambda: gui.showPage(arg, "pg_testing")), "pos": sn( **{ "x": margin, "y": h.btnTest1.pos.y + h.btnTest1.pos.h + spacing, "w": medium, "h": height, }) }) # data = ["Entry1", "fsfs"] ## ["Entry 1" , "Entry 2"] h.listbox1 = sn( **{ "obj": gui.listbox(arg, data, "listbox1"), "pos": sn( **{ "x": margin + medium + spacing, "y": margin, "w": large, "h": 300, }) }) data = ["Entry 1", "Entry 2"] h.dropdown1 = sn( **{ "obj": gui.dropdown(arg, "ddstyle", "center", data, "dropdown1"), "pos": sn(**{ "x": 600, "y": 20, "w": 180, "h": 35, }) }) rsp = db(arg, "getPathologist") data = [] for dt in rsp: data.append([dt["name"], dt["status"]]) h.table1 = sn( **{ "obj": gui.ttk.Treeview(arg.master), "pos": sn(**{ "x": 70, "y": 180, "w": 650, "h": 200, }), "table": sn( **{ "columns": [ sn(**{ "title": "Name", "width": 500 }), sn(**{ "title": "Status", "width": 150 }), # sn(**{"title" : "Brand", "width" : 150}), # sn(**{"title" : "Equipment", "width" : 200}), # sn(**{"title" : "Tag", "width" : 100}), ], "data": [[]], }), }) # For Scrollbar h.table1Scroll = sn( **{ "obj": gui.ttk.Scrollbar( arg.master, orient="vertical", command=h.table1.obj.yview), "pos": sn(**{ "x": 725, "y": 180, "w": 25, "h": 200, }) }) h.table1.obj.configure(yscrollcommand=h.table1Scroll.obj.set) # self.canvas.bind('<Button-1>', self.clicked) # self.canvas.bind('<Double-1>', self.double_click) # self.canvas.bind('<ButtonRelease-1>', self.button_released) # self.canvas.bind('<B1-Motion>', self.moved) # Bind double click even on table1 data/row. h.table1.obj.bind( '<Double-1>', lambda event, t=h.table1.obj: arg.fcn_gui3.table1Double_ClickEven(arg)) # "data" : [ # ["Felipe Templo Jr, MD","ON-DUTY"], # ["Jeffrey S. So, MD, DPSP","OFF-DUTY"], # ["Francis G. Moria, MD, MSc FPSP","OFF-DUTY"], # ["Jose Maria C. Avila, MD","ON-DUTY"], # ["Michelle Anne M. Latoy, MD","ON-DUTY"], # ["Aida Isabel Mendoza, MD","OFF-DUTY"], # ["Charles Harris, MD","OFF-DUTY"], # ["Felipe Templo Jr, MD","ON-DUTY"], # ["Jeffrey S. So, MD, DPSP","OFF-DUTY"], # ["Francis G. Moria, MD, MSc FPSP","OFF-DUTY"], # ["Jose Maria C. Avila, MD","ON-DUTY"], # ["Michelle Anne M. Latoy, MD","ON-DUTY"], # ["Aida Isabel Mendoza, MD","OFF-DUTY"], # ["Charles Harris, MD","OFF-DUTY"], # ], # h.scrollAlone = sn(**{ # "obj": gui.scroll(arg,"scrollstyle","center"), # "pos": sn(**{ # "x": h.listbox1.pos.x + h.listbox1.pos.w + spacing, # "y": margin, # "w": 50, # "h": 300, # }) # }) # data = ["Entry1 - ON-DUTY","fsfs - OFF-DUTY"] ## ["Entry 1" , "Entry 2"] # h.listbox1 = sn(**{ # "obj" : gui.listbox(arg,data,"listbox1"), # "pos": sn(**{ # "x": 70, # "y": 180, # "w": 645, # "h": 200, # }) # }) # For Scrollbar # h.listScroll = sn(**{ # "obj" : ttk.Scrollbar(master, orient="vertical", # # command=handle["listbox1"]["element"].yview), # command=h.listbox1.obj.yview), # "pos" : sn(**{ # "x": 200, # "y": 50, # "w": 40, # "h": 720, # }) # }) # ##### SUB PROPERTIES OF THE ABOVE HANDLES # h.listbox1.obj.configure(yscrollcommand=h.listScroll.obj.set); h.checkbox = sn( **{ ## gui.checkbox(arg,"yourText", lambda: test(arg)), "obj": gui.checkbox(arg, "yourText", lambda: test(arg)), "pos": sn(**{ "x": 10, "y": 10, "w": 150, "h": 30, }) }) # array 0 is the default value. optionList1 = ('a', 'a', 'b', 'c') h.combobox = sn( ** { ## ttk.OptionMenu(arg.master,v1,*optionList1, command=lambda selected:test123123(selected)) "obj": gui.combobox(arg, optionList1, lambda selected_val: test(selected_val)), "pos": sn(**{ "x": 50, "y": 10, "w": 150, "h": 30, }) }) h.progressbar = sn( ** { ## tttk.Progressbar(arg.master, orient = orient, length = length, mode = mode) "obj": gui.progressbar(arg), "pos": sn(**{ "x": 100, "y": 10, "w": 150, "h": 30, }) }) gui.hpropsobjs(arg, h) return h
def msgbox( arg, message="", MessageBoxButtons="ok", MessageBoxIcon="info", title=g.defaultMessageBoxTitle, ): obj = messagebox._show(message=message, _type=MessageBoxButtons, _icon=MessageBoxIcon, title=title) return obj msgtype = sn(**{}) # types msgtype.ABORTRETRYIGNORE = "abortretryignore" # RETURN retry, ignore, abort msgtype.OK = "ok" # RETURN YES OR NO msgtype.OKCANCEL = "okcancel" # RETURN TRUE OR FALSE msgtype.RETRYCANCEL = "retrycancel" # RETURN TRUE OR FALSE msgtype.YESNO = "yesno" # RETURN TRUE OR FALSE msgtype.YESNOCANCEL = "yesnocancel" # RETURN Cancel=None Yes=True No=False msgicon = sn(**{}) # icons msgicon.ERROR = "error" msgicon.INFO = "info" msgicon.QUESTION = "question" msgicon.WARNING = "warning"
def page(arg): master = arg.master handle = sn(**{ # KEYBOARD PAGE##################################### "label": sn(**{ "obj": ttk.Label(master, \ text="", style="keyboard.TLabel", anchor=tk.CENTER), "pos": sn(**{ "x": 0, "y": 0, "w": 15, "h": 1, }), "number" : True, }), # "~": sn(**{ # "obj": ttk.Button(master, \ # text="~", \ # style="keyboard.TButton", \ # command=lambda: gui.keyboardInput(arg, "~")), # "pos": sn(**{ # "x": 0, # "y": 1, # "w": 1, # "h": 1, # }), # "shift": "`", # # }), "1": sn(**{ "obj": ttk.Button(master, \ text="1", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "1")), "pos": sn(**{ "x": 1, "y": 1, "w": 1, "h": 1, }), "shift": "1", "number": True, }), "2": sn(**{ "obj": ttk.Button(master, \ text="2", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "2")), "pos": sn(**{ "x": 2, "y": 1, "w": 1, "h": 1, }), "shift": "2", "number": True, }), "3": sn(**{ "obj": ttk.Button(master, \ text="3", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "3")), "pos": sn(**{ "x": 3, "y": 1, "w": 1, "h": 1, }), "shift": "3", "number": True, }), "4": sn(**{ "obj": ttk.Button(master, \ text="4", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "4")), "pos": sn(**{ "x": 4, "y": 1, "w": 1, "h": 1, }), "shift": "4", "number": True, }), "5": sn(**{ "obj": ttk.Button(master, \ text="5", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "5")), "pos": sn(**{ "x": 5, "y": 1, "w": 1, "h": 1, }), "shift": "5", "number": True, }), "6": sn(**{ "obj": ttk.Button(master, \ text="6", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "6")), "pos": sn(**{ "x": 6, "y": 1, "w": 1, "h": 1, }), "shift": "6", "number": True, }), "7": sn(**{ "obj": ttk.Button(master, \ text="7", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "7")), "pos": sn(**{ "x": 7, "y": 1, "w": 1, "h": 1, }), "shift": "7", "number": True, }), "8": sn(**{ "obj": ttk.Button(master, \ text="8", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "8")), "pos": sn(**{ "x": 8, "y": 1, "w": 1, "h": 1, }), "shift": "8", "number": True, }), "9": sn(**{ "obj": ttk.Button(master, \ text="9", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "9")), "pos": sn(**{ "x": 9, "y": 1, "w": 1, "h": 1, }), "shift": "9", "number": True, }), "0": sn(**{ "obj": ttk.Button(master, \ text="0", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "0")), "pos": sn(**{ "x": 10, "y": 1, "w": 1, "h": 1, }), "shift": "0", "number": True, }), "-": sn(**{ "obj": ttk.Button(master, \ text="-", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "-")), "pos": sn(**{ "x": 11, "y": 1, "w": 1, "h": 1, }), "shift": "_", "date": True, }), # "=": sn(**{ # "obj": ttk.Button(master, \ # text="=", \ # style="keyboard.TButton", \ # command=lambda: gui.keyboardInput(arg, "=")), # "pos": sn(**{ # "x": 12, # "y": 1, # "w": 1, # "h": 1, # }), # "shift": "+", # }), "backspace": sn(**{ "obj": ttk.Button(master, \ text="←", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "backspace")), "pos": sn(**{ "x": 13, "y": 1, "w": 2, "h": 1, }), "number" : True, }), "q": sn(**{ "obj": ttk.Button(master, \ text="q", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "q")), "pos": sn(**{ "x": 1.5, "y": 2, "w": 1, "h": 1, }), "shift": "Q", }), "w": sn(**{ "obj": ttk.Button(master, \ text="w", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "w")), "pos": sn(**{ "x": 2.5, "y": 2, "w": 1, "h": 1, }), "shift": "W", }), "e": sn(**{ "obj": ttk.Button(master, \ text="e", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "e")), "pos": sn(**{ "x": 3.5, "y": 2, "w": 1, "h": 1, }), "shift": "E", }), "r": sn(**{ "obj": ttk.Button(master, \ text="r", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "r")), "pos": sn(**{ "x": 4.5, "y": 2, "w": 1, "h": 1, }), "shift": "R", }), "t": sn(**{ "obj": ttk.Button(master, \ text="t", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "t")), "pos": sn(**{ "x": 5.5, "y": 2, "w": 1, "h": 1, }), "shift": "T", }), "y": sn(**{ "obj": ttk.Button(master, \ text="y", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "y")), "pos": sn(**{ "x": 6.5, "y": 2, "w": 1, "h": 1, }), "shift": "Y", }), "u": sn(**{ "obj": ttk.Button(master, \ text="u", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "u")), "pos": sn(**{ "x": 7.5, "y": 2, "w": 1, "h": 1, }), "shift": "U", }), "i": sn(**{ "obj": ttk.Button(master, \ text="i", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "i")), "pos": sn(**{ "x": 8.5, "y": 2, "w": 1, "h": 1, }), "shift": "I", }), "o": sn(**{ "obj": ttk.Button(master, \ text="o", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "o")), "pos": sn(**{ "x": 9.5, "y": 2, "w": 1, "h": 1, }), "shift": "O", }), "p": sn(**{ "obj": ttk.Button(master, \ text="p", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "p")), "pos": sn(**{ "x": 10.5, "y": 2, "w": 1, "h": 1, }), "shift": "P", }), # "[" : sn(**{ # "obj" : ttk.Button(master, \ # text="[", \ # style="keyboard.TButton", \ # command=lambda: gui.keyboardInput(master,handles,"[")), # "pos" : sn(**{ # "x" : 11.5, # "y" : 2, # "w" : 1, # "h" : 1, # }), # "shift" : "{", # }), # "]" : sn(**{ # "obj" : ttk.Button(master, \ # text="]", \ # style="keyboard.TButton", \ # command=lambda: gui.keyboardInput(master,handles,"]")), # "pos" : sn(**{ # "x" : 12.5, # "y" : 2, # "w" : 1, # "h" : 1, # }), # "shift" : "}", # }), # "\\" : sn(**{ # "obj" : ttk.Button(master, \ # text="\\", \ # style="keyboard.TButton", \ # command=lambda: gui.keyboardInput(master,handles,"\\")), # "pos" : sn(**{ # "x" : 13.5, # "y" : 2, # "w" : 1.5, # "h" : 1, # }), # "shift" : "|", # }), "a": sn(**{ "obj": ttk.Button(master, \ text="a", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "a")), "pos": sn(**{ "x": 2, "y": 3, "w": 1, "h": 1, }), "shift": "A", }), "s": sn(**{ "obj": ttk.Button(master, \ text="s", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "s")), "pos": sn(**{ "x": 3, "y": 3, "w": 1, "h": 1, }), "shift": "S", }), "d": sn(**{ "obj": ttk.Button(master, \ text="d", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "d")), "pos": sn(**{ "x": 4, "y": 3, "w": 1, "h": 1, }), "shift": "D", }), "f": sn(**{ "obj": ttk.Button(master, \ text="f", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "f")), "pos": sn(**{ "x": 5, "y": 3, "w": 1, "h": 1, }), "shift": "F", }), "g": sn(**{ "obj": ttk.Button(master, \ text="g", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "g")), "pos": sn(**{ "x": 6, "y": 3, "w": 1, "h": 1, }), "shift": "G", }), "h": sn(**{ "obj": ttk.Button(master, \ text="h", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "h")), "pos": sn(**{ "x": 7, "y": 3, "w": 1, "h": 1, }), "shift": "H", }), "j": sn(**{ "obj": ttk.Button(master, \ text="j", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "j")), "pos": sn(**{ "x": 8, "y": 3, "w": 1, "h": 1, }), "shift": "J", }), "k": sn(**{ "obj": ttk.Button(master, \ text="k", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "k")), "pos": sn(**{ "x": 9, "y": 3, "w": 1, "h": 1, }), "shift": "K", }), "l": sn(**{ "obj": ttk.Button(master, \ text="l", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "l")), "pos": sn(**{ "x": 10, "y": 3, "w": 1, "h": 1, }), "shift": "L", }), ":" : sn(**{ "obj" : ttk.Button(master, \ text=":", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg,":")), "pos" : sn(**{ "x" : 11, "y" : 3, "w" : 1, "h" : 1, }), "shift" : ":", "time": True, }), # "'" : sn(**{ # "obj" : ttk.Button(master, \ # text="'", \ # style="keyboard.TButton", \ # command=lambda: gui.keyboardInput(master,handles,"'")), # "pos" : sn(**{ # "x" : 12, # "y" : 3, # "w" : 1, # "h" : 1, # }), # "shift" : "\"", # }), "enter": sn(**{ "obj": ttk.Button(master, \ text="OK", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "ok")), "pos": sn(**{ "x": 13, "y": 3, "w": 2, "h": 1, }), "number" : True, }), "lshift": sn(**{ "obj": ttk.Button(master, \ text="SHIFT", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "shift")), "pos": sn(**{ "x": 0, "y": 4, "w": 2.5, "h": 1, }), }), "z": sn(**{ "obj": ttk.Button(master, \ text="z", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "z")), "pos": sn(**{ "x": 2.5, "y": 4, "w": 1, "h": 1, }), "shift": "Z", }), "x": sn(**{ "obj": ttk.Button(master, \ text="x", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "x")), "pos": sn(**{ "x": 3.5, "y": 4, "w": 1, "h": 1, }), "shift": "X", }), "c": sn(**{ "obj": ttk.Button(master, \ text="c", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "c")), "pos": sn(**{ "x": 4.5, "y": 4, "w": 1, "h": 1, }), "shift": "C", }), "v": sn(**{ "obj": ttk.Button(master, \ text="v", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "v")), "pos": sn(**{ "x": 5.5, "y": 4, "w": 1, "h": 1, }), "shift": "V", }), "b": sn(**{ "obj": ttk.Button(master, \ text="b", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "b")), "pos": sn(**{ "x": 6.5, "y": 4, "w": 1, "h": 1, }), "shift": "B", }), "n": sn(**{ "obj": ttk.Button(master, \ text="n", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "n")), "pos": sn(**{ "x": 7.5, "y": 4, "w": 1, "h": 1, }), "shift": "N", }), "m": sn(**{ "obj": ttk.Button(master, \ text="m", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "m")), "pos": sn(**{ "x": 8.5, "y": 4, "w": 1, "h": 1, }), "shift": "M", }), ",": sn(**{ "obj": ttk.Button(master, \ text=",", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, ",")), "pos": sn(**{ "x": 9.5, "y": 4, "w": 1, "h": 1, }), "shift": ",", }), ".": sn(**{ "obj": ttk.Button(master, \ text=".", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, ".")), "pos": sn(**{ "x": 10.5, "y": 4, "w": 1, "h": 1, }), "shift": ".", }), # "/" : sn(**{ # "obj" : ttk.Button(master, \ # text="/", \ # style="keyboard.TButton", \ # command=lambda: gui.keyboardInput(master,handles,"/")), # "pos" : sn(**{ # "x" : 11.5, # "y" : 4, # "w" : 1, # "h" : 1, # }), # "shift" : "?", # }), "rshift": sn(**{ "obj": ttk.Button(master, \ text="SHIFT", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "shift")), "pos": sn(**{ "x": 12.5, "y": 4, "w": 2.5, "h": 1, }), }), "space": sn(**{ "obj": ttk.Button(master, \ text="", \ style="keyboard.TButton", \ command=lambda: gui.keyboardInput(arg, "space")), "pos": sn(**{ "x": 4, "y": 5, "w": 7, "h": 1, }), }), }) return handle
def failure(self): ''' Sends a FAILURE response to self.out_addr. ''' self.sock.sendto(pickle.dumps(sn(status=FAILURE, body=None)), self.out_addr)
h = arg.handles.pg_history while arg.thread_trig.historytime: x = datetime.datetime.now() curtime = x.strftime("%I:%M:%S %p") curdate = x.strftime("%m / %d / %y") print(curdate, curtime) gui.set_val(arg, h.lblTime.obj, "Time: " + curtime) gui.set_val(arg, h.lblDate.obj, "Date: " + curdate) arg.master.update() time.sleep(1) ### RUN THIS FILE FOR QUICK VIEWING ### if __name__ == "__main__": arg = sn(**{}) arg.quickpreview = True arg.curpage = os.path.basename(__file__)[0:-3] fcnFilename = "fcn_" + arg.curpage[3:] gui.setupMaster(arg) styles.setup() arg.handles = sn(**{arg.curpage: page(arg)}) arg.__dict__[fcnFilename] = importlib.import_module("functions." + fcnFilename) print(arg.__dict__) fcn = arg.__dict__[fcnFilename].preshow(arg) gui.dbgview(arg, fcn, preshow=True)
def test_get_remaining_estimate(self): issue = sn(fields=sn(timetracking=sn(raw={'remainingEstimate': '1h'}))) self.assertEqual(JiraClient.get_remaining_estimate(issue), '1h')
import csv import os import pony from collections import Counter import numpy as np from scipy.io import wavfile as wavf from scipy.interpolate import interp1d, InterpolatedUnivariateSpline import matplotlib.pyplot as plt from bisect import bisect as bs import json import geopy.distance from types import SimpleNamespace as sn with open('settings.json') as settings_file: settings = json.loads(settings_file.read(), object_hook=lambda d: sn(**d)) tracks = [] class Point: def __init__(self, t, gFx, gFy, gFz, lat, lng, s, dfs=0): self.time = t self.gfx = gFx self.gfy = gFy self.gfz = gFz self.lat = lat self.lng = lng self.speed = s self.dfromstart = dfs def equals(self, other):
def test_get_remaining_estimate_empty(self): issue = sn(fields=sn(timetracking=sn(raw={}))) self.assertEqual(JiraClient.get_remaining_estimate(issue), '0m')