Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import curses
- import os
- from curses import wrapper
- class EndConsole:
- def __init__(self):
- self.generate_dims()
- self.create_records()
- self.set_record(ab(5, 17))
- self.init_params()
- self.init_screen()
- self.create_colors()
- self.last_list_record = None
- def start(self):
- self.start_loop()
- def set_record(self, record):
- self.record = record
- self.cursor = (record[0], record[1])
- self.other_recs = []
- def create_records(self, e_span=(-200,200), n_span=(-100,100), x_lim=(50)):
- self.record_dic = self.create_records_inner(e_span=e_span, n_span=n_span, x_lim=x_lim)
- def create_records_inner(self, e_span=(-200,200), n_span=(-100,100), x_lim=(50)):
- dic = {}
- e_w = e_span[1] - e_span[0]
- for e in range(*e_span):
- if e % (e_w/10) == 0:
- print('.\n')
- for n in range(*n_span):
- for x in range(-x_lim, x_lim):
- x_test = 2*x + e%2
- if in_enx(e,n,x_test):
- rec = enx(e,n,x_test)
- if e not in dic.keys():
- dic[e] = {}
- if n not in dic[e].keys():
- dic[e][n] = []
- dic[e][n].append(rec)
- return dic
- def populate_dictionary(self):
- E, N = self.cursor
- ee = (E - self.map_width, E + self.map_width)
- nn = (N - self.map_width, N + self.map_width)
- x_lim = self.list_x_search_depth
- more_recs = self.create_records_inner(ee, nn, x_lim)
- cur_dic = self.record_dic
- for e in more_recs.keys():
- if e not in cur_dic.keys():
- cur_dic[e] = {}
- for n in more_recs[e].keys():
- if n not in cur_dic[e].keys():
- cur_dic[e][n] = []
- cur_dic[e][n].extend(more_recs[e][n])
- def in_dic(self, e, n):
- return e in self.record_dic.keys() and n in self.record_dic[e].keys()
- #record must be set before calling this
- def init_params(self):
- self.show_pos_d = False
- self.show_neg_d = False
- self.show_pos_x = False
- self.show_neg_x = False
- self.show_pos_a = False
- self.show_neg_a = False
- self.show_pos_b = False
- self.show_neg_b = False
- self.show_all_recs = True
- self.highlight_axis = False
- self.highlight_cursor = True
- self.highlight_first_entry = True
- self.highlight_marked = True
- self.highlight_followed = True
- self.list_x_search_depth = 100
- self.jump_shift = 5
- self.list_jump_shift = 3
- self.other_recs = []
- self.marked_coords = []
- self.cur_indexer = self.record[3]
- self.grids_to_highlight = []
- self.grid_highlight_colors = [15, 16, 13, 12, 14]
- self.show_highlighted_grids = True
- def generate_dims(self):
- #This is designed to work so that if you only
- #modify these two values, it will all workout
- wind = True
- if wind:
- self.max_width = 240
- self.max_height = 60
- else:
- self.max_width = 185
- self.max_height = 50
- #detail view:
- #this is the bottom view panel where you can track records
- self.column_detail_width = 12
- self.detail_strings = ['ID','e','n','d','x','a','b','c','t','f','(d+n)','(x+n)']
- self.detail_ids = ['%','0','1','2','3','4','5','6','7','8','9','Z','Y','W','V','U','T','S','R','Q']
- self.detail_row_height = len(self.detail_strings)
- self.max_detail_row_entries = 160 / self.column_detail_width
- self.detail_total_width = self.max_width
- self.detail_total_height = self.detail_row_height # * self.detail_row_count
- #list view (right side)
- self.list_view_strings = self.detail_strings[1:]
- self.list_cell_width = 6 # num of digits to show in right list
- self.list_cell_max_width = 8
- self.list_view_height = self.max_height - self.detail_total_height
- self.list_view_values = self.detail_strings #likely to change
- # The +1 below is to account for the '|' splitting the cells apart -1 for removing ID
- self.list_view_width = (self.list_cell_max_width + 1) * (len(self.list_view_values)- 1)
- self.map_width = self.max_width - self.list_view_width
- self.map_height = self.list_view_height
- def init_screen(self):
- self.screen = curses.initscr()
- self.map_pad = curses.newpad(self.map_height, self.map_width)
- self.list_pad = curses.newpad(self.list_view_height, self.list_view_width)
- self.detail_pad = curses.newpad(self.detail_total_height, self.detail_total_width)
- self.screen.keypad(True)
- self.screen.immedok(True)
- curses.noecho()
- curses.cbreak()
- curses.resizeterm(self.max_height, self.max_width)
- def parse_words(self):
- curses.echo()
- input_words = self.screen.getstr().split()
- if not input_words:
- return
- try:
- prompt = input_words[0].lower()
- rest = input_words[1:]
- if prompt == 'help':
- if rest:
- self.do_help(rest[0])
- else:
- self.do_help('basic')
- elif prompt == 'hl':
- if str(rest[0]).lower() in ('d','x','a','c','f','(d+n)','(x+n)','x+n','d+n','e','n','t'):
- self.grids_to_highlight.append((rest[0], int(rest[1])))
- else:
- rest = [int(ttt) for ttt in input_words[1:]]
- if prompt == 'ab':
- self.set_record(ab(*[int(x) for x in rest[:2]]))
- elif prompt == 'end' and all([isinstance(x, int) for x in rest[:2]]):
- self.set_record(end(*rest[:3]))
- elif prompt == 'enx' and all([isinstance(x, int) for x in rest[:2]]):
- self.set_record(enx(*rest[:3]))
- elif prompt == 'abd' and all([isinstance(x, int) for x in rest[:2]]):
- self.set_record(abd(*rest[:3]))
- elif prompt == 'ena' and all([isinstance(x, int) for x in rest[:2]]):
- self.set_record(ena(*rest[:3]))
- elif prompt == 'mj':
- neww = rest[0]
- if isinstance(neww, int):
- self.jump_shift = neww
- elif prompt == 'lj':
- neww = rest[0]
- if isinstance(neww, int):
- self.list_jump_shift = neww
- elif prompt == 'xm':
- if isinstance(rest[0], int):
- self.list_x_search_depth = rest[0]
- elif prompt == 'quit':
- self.quit()
- elif prompt == 'en':
- new_curs = [int(mmm) for mmm in rest[:2]]
- self.cursor = new_curs
- except Exception as e:
- print('Something happened. Try again')
- pass
- curses.noecho()
- def in_marked_grids(self, E, N):
- for i in range(len(self.grids_to_highlight)):
- string, val = self.grids_to_highlight[i]
- if self.in_grid_from_things(E, N, string, val):
- return i
- return -1
- def in_grid_from_things(self, e, n, grid_string, value):
- value = int(value)
- grid_string = grid_string.lower()
- if grid_string == 'd':
- return in_end(e, n, value)
- elif grid_string == 'x':
- return in_enx(e, n, value)
- elif grid_string == 'a':
- return in_ena(e, n, value)
- elif grid_string in ('(d+n)', 'd+n'):
- d = value - n
- return in_end(e, n, d)
- elif grid_string in ('(x+n)', 'x+n'):
- x = value - n
- return in_enx(e, n, x)
- elif grid_string == 'e':
- return e == value
- elif grid_string == 'n':
- return n == value
- elif grid_string == 't':
- x = x_from_t(value, e)
- if n==0:
- return x*x + e == 0
- else:
- return in_enx(e, n, x_from_t(value, e))
- elif grid_string == 'f':
- # f = 2d + 1 - e
- # f + e - 1 = 2d
- d2 = value + e - 1
- if not d2 % 2:
- d = d2 / 2
- return in_end(e, n, d)
- elif grid_string == 'c':
- dd = value - e
- if is_square(dd):
- d = int_sqrt(dd)
- return in_end(e, n, d)
- def do_help(self, arg):
- self.map_pad.clear()
- if arg == 'basic':
- lines = ['Type "help" followed by one of these ',
- 'keywords to learn more:', '',
- 'gestalt - basic gestalt',
- 'move - about movement',
- 'detail - about the bottom view',
- 'map - about map settings',
- 'commands - about terminal',
- 'press any button to return',
- '(tutorial step 1) >> gestalt'
- ]
- elif arg == 'gestalt':
- lines = ['So I made this because VQC organized the numbers in this grid',
- 'he put them in a grid for a reason and so I wanted to make',
- 'a way to study the grid',
- ' ',
- 'The area this message is taking up is',
- 'the map view. It shows the records based',
- 'on their e,n coordinates.',
- ' ',
- 'The area on the right is the list view ',
- 'this shows all of the records in the cell',
- 'that your cursor is on',
- ' ',
- 'The bottom area is the detail view. Here you',
- 'can select and save records here as you explore the map',
- ' ',
- '(tutorial step 2) >> commands'
- ]
- elif arg == 'commands':
- lines = ["To enter command mode, type '!' ",
- 'once in this mode you can do a number of things:',
- 'abd A B D - will change your current record to the record',
- ' with those coordinates',
- 'ab A B - similar to A B D',
- 'enx E N X',
- 'end E N D',
- 'ena E N A',
- 'en E N - will move your cursor to that spot',
- 'xm J - will change the max x depth that the program searches',
- ' for the list view with the pop command',
- 'mj J - changes the jump size to J for shift wasd',
- 'lj J - changes the list jump size to J for shift jk'
- ' ',
- ' (tutorial step 3) >> move'
- ]
- elif arg == 'move':
- lines = ['-Use WASD to navigate the map',
- "-use JK to navigate the list view",
- "-If you hold shift while moving with these, it ",
- ' increases the movement size'
- "-To change either of these sizes use:",
- " 'mj' to change the map jump size",
- " 'lj' to change the list jump size",
- "-'f' will increase the current d value by one",
- " while shift+'f' will decrease it by one",
- "-'e' will go to e+2n, 'q' to e-2n",
- "-'H' returns your cursor to the starting record",
- " (tutorial step 4) >> detail"
- ]
- elif arg == 'detail':
- lines = [
- 'Your starting record is on the bottom left',
- 'You must have a starting record and it is set by default',
- 'h - sets the starting record to the current record',
- ' highlighted in the list view',
- 'i - adds the current highlighted record to the detail',
- ' view. shift + i will delete the last one added',
- 'enx, ena, end, abd, ab - will all change the starting',
- ' record to whichever is created from these coordinates',
- ' (tutorial step 5) >> map'
- ]
- elif arg == 'map':
- lines = [
- 'The view this is taking up is the map',
- 'o - mark a spot',
- 'O - unmark last marked spot. If you want to',
- ' unmark a different spot, mark it again, then unmark',
- 'm - toggle highlight marked spots',
- 'M - toggle highlight records in detail view',
- 'c - toggle highlight records in map with same ',
- ' d value as the starting record (C does -d)',
- 'v - toggle highlight records in map with same ',
- ' a value as the starting record (V does -a)',
- 'x - toggle highlight records on map with same ',
- ' x value as the starting record (X does -x)',
- 'z - toggle highlight all records',
- 'Z - toggle highlighted grids',
- 't - toggle highlight axis',
- 'T - toggle highlight cursor',
- 'p - refresh the map',
- 'hl X Y - will highlight records with the X value as Y',
- " ex: 'hl d 7' would highlight records with the",
- ' d value equal to 7. Values you can use are:',
- " (e, n, d, x, a, b, c, f, t,'(d+n)','(x+n)') ",
- "'-' - will delete the most recent highlighted grid",
- ' (tutorial done)'
- ]
- for i in range(len(lines)):
- self.map_pad.addstr(i+2, 5, lines[i])
- self.map_pad.refresh(0, 0, 0, 0, self.map_height, self.map_width)
- self.screen.getch()
- def create_colors(self):
- curses.start_color()
- # 0 1 2 3
- self.colors = [curses.COLOR_WHITE, curses.COLOR_BLACK, curses.COLOR_RED, curses.COLOR_GREEN,
- curses.COLOR_BLUE, curses.COLOR_CYAN, curses.COLOR_MAGENTA, curses.COLOR_YELLOW]
- curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK) # Basic
- curses.init_pair(10, curses.COLOR_BLACK, curses.COLOR_WHITE) # Invert
- curses.init_pair(31, curses.COLOR_GREEN, curses.COLOR_BLACK) # Green On Black
- curses.init_pair(13, curses.COLOR_BLACK, curses.COLOR_GREEN) # Black on Green
- curses.init_pair(21, curses.COLOR_RED, curses.COLOR_BLACK) # Red on Black
- curses.init_pair(12, curses.COLOR_BLACK, curses.COLOR_RED) #Black on Red
- curses.init_pair(51, curses.COLOR_CYAN, curses.COLOR_BLACK) # Cyan on Black
- curses.init_pair(15, curses.COLOR_BLACK, curses.COLOR_CYAN) # Black on Cyan
- curses.init_pair(71, curses.COLOR_YELLOW, curses.COLOR_BLACK) # Yellow on Black
- curses.init_pair(17, curses.COLOR_BLACK, curses.COLOR_YELLOW) # Black on Yellow
- curses.init_pair(67, curses.COLOR_MAGENTA, curses.COLOR_YELLOW) # Magenta on Yellow
- curses.init_pair(76, curses.COLOR_YELLOW, curses.COLOR_MAGENTA) # Yellow on Magenta
- curses.init_pair(57, curses.COLOR_CYAN, curses.COLOR_YELLOW) # Cyan on Yellow
- curses.init_pair(75, curses.COLOR_YELLOW, curses.COLOR_CYAN) # Yellow on Cyan
- curses.init_pair(61, curses.COLOR_MAGENTA, curses.COLOR_BLACK) # Magenta on Black
- curses.init_pair(16, curses.COLOR_BLACK, curses.COLOR_MAGENTA) # Black on Magenta
- curses.init_pair(41, curses.COLOR_BLUE, curses.COLOR_BLACK)
- self.color_dic = {
- 'basic' : 1,
- 'd_grid' : 31,
- 'x_grid' : 61,
- 'a_grid' : 21,
- 'b_grid' : 51,
- 'highlight': 16,
- 'list_view_highlight': 16,
- 'cursor' : 75,
- 'highlight_marked': 17
- }
- def invert_color(self, color):
- modten = color % 10
- tens = (color - modten)/10
- return 10*modten + tens
- def start_loop(self):
- while True:
- c = self.screen.getch()
- if c == ord('w'):
- self.cursor = self.cursor[0], self.cursor[1]-1
- elif c == ord('s'):
- self.cursor = self.cursor[0], self.cursor[1]+1
- elif c == ord('a'):
- self.cursor = self.cursor[0]-1, self.cursor[1]
- elif c == ord('d'):
- self.cursor = self.cursor[0]+1, self.cursor[1]
- elif c == ord('W'):
- self.cursor = self.cursor[0], self.cursor[1]-self.jump_shift
- elif c == ord('S'):
- self.cursor = self.cursor[0], self.cursor[1]+self.jump_shift
- elif c == ord('A'):
- self.cursor = self.cursor[0]-self.jump_shift, self.cursor[1]
- elif c == ord('D'):
- self.cursor = self.cursor[0]+self.jump_shift, self.cursor[1]
- ## GRIDS ##
- elif c == ord('x'):
- self.show_pos_x = not self.show_pos_x
- elif c == ord('X'):
- self.show_neg_x = not self.show_neg_x
- elif c == ord('c'):
- self.show_pos_d = not self.show_pos_d
- elif c == ord('C'):
- self.show_neg_d = not self.show_neg_d
- elif c == ord('v'):
- self.show_pos_a = not self.show_pos_a
- elif c == ord('V'):
- self.show_neg_a = not self.show_neg_a
- ## ## ## ##
- elif c == ord('t'):
- self.highlight_axis = not self.highlight_axis
- elif c == ord('T'):
- self.highlight_cursor = not self.highlight_cursor
- elif c == ord('M'):
- self.highlight_followed = not self.highlight_followed
- elif c == ord('m'):
- self.highlight_marked = not self.highlight_marked
- elif c == ord('o'):
- new_spot = self.cursor
- if self.cursor in self.marked_coords:
- self.marked_coords.remove(new_spot)
- self.marked_coords.append(self.cursor)
- elif c == ord('O'):
- self.marked_coords = self.marked_coords[:-1]
- elif c == ord('j'):
- self.move_record_in_list(True, 1)
- elif c == ord('k'):
- self.move_record_in_list(False, 1)
- elif c == ord('J'):
- self.move_record_in_list(True, self.list_jump_shift)
- elif c == ord('K'):
- self.move_record_in_list(False, self.list_jump_shift)
- elif c == ord('h'):
- self.set_record_from_list()
- elif c == ord('i'):
- self.add_record_from_list()
- elif c == ord('I'):
- self.other_recs = self.other_recs[:-1]
- elif c == ord('z'):
- self.show_all_recs = not self.show_all_recs
- elif c == ord('Z'):
- self.show_highlighted_grids = not self.show_highlighted_grids
- elif c == ord('H'):
- self.cursor = self.record[:2]
- elif c == ord('-'):
- self.grids_to_highlight = self.grids_to_highlight[:-1]
- elif c == ord('f'):
- N = self.cursor[1]
- record = self.get_current_list_record()
- new_rec = abd(self.record[4], self.record[5], self.record[2]+1)
- self.cursor = new_rec[:2]
- if N != 0:
- self.cur_indexer += 1
- elif c == ord('F'):
- N = self.cursor[1]
- record = self.get_current_list_record()
- new_rec = abd(record[4], record[5], record[2]+1)
- self.cursor = new_rec[:2]
- if N != 0:
- self.cur_indexer -= 1
- elif c == ord('e'):
- E, N = self.cursor
- self.cursor = E + 2*N, N
- elif c == ord('q'):
- E,N = cursor
- self.cursor = E - 2*N, N
- elif c == ord('p'):
- self.populate_dictionary()
- elif c == ord('r'):
- self.cursor = -self.cursor[0], self.cursor[1]
- elif c == ord('R'):
- self.cursor = self.cursor[0], - self.cursor[1]
- elif c == ord('!'):
- self.parse_words()
- self.refresh_all()
- def refresh_all(self):
- self.refresh_map()
- self.refresh_list()
- self.refresh_detail()
- def refresh_map(self):
- self.map_pad.clear()
- e_start = self.cursor[0] - self.map_width / 2
- n_start = self.cursor[1] - self.map_height / 2
- marked_indexes = [(rec[0], rec[1]) for rec in self.other_recs]
- marked_spots = self.marked_coords
- for e_s in range(self.map_width):
- e = e_start + e_s
- for n_s in range(self.map_height):
- n = n_start + n_s
- char = False
- if self.highlight_cursor and e == self.cursor[0] and n == self.cursor[1]:
- col_num = self.color_dic['cursor']
- character = '@'
- elif self.highlight_first_entry and e == self.record[0] and n == self.record[1]:
- col_num = self.color_dic['highlight']
- character = '%'
- elif self.highlight_followed and (e,n) in marked_indexes:
- col_num = self.color_dic['highlight']
- idx = marked_indexes.index((e,n))
- character = self.detail_ids[1:][idx]
- elif self.highlight_marked and (e,n) in marked_spots:
- col_num = self.color_dic['highlight_marked']
- character = '#'
- elif self.show_pos_d and in_end(e, n, self.record[2]):
- col_num = self.color_dic['d_grid']
- character = 'D'
- elif self.show_neg_d and in_end(e, n, -self.record[2]):
- col_num = self.color_dic['d_grid']
- character = 'd'
- elif self.show_pos_a and in_ena(e, n, self.record[4]):
- col_num = self.color_dic['a_grid']
- character = 'A'
- elif self.show_neg_a and in_ena(e, n, -self.record[4]):
- col_num = self.color_dic['a_grid']
- character = 'a'
- elif self.show_pos_x and in_enx(e, n, self.record[3]):
- col_num = self.color_dic['x_grid']
- character = 'X'
- elif self.show_neg_x and in_enx(e, n, -self.record[3]):
- col_num = self.color_dic['x_grid']
- character = 'x'
- elif self.show_highlighted_grids and self.in_marked_grids(e,n) != -1:
- iddd = self.in_marked_grids(e,n)
- col_num = self.grid_highlight_colors[iddd%len(self.grid_highlight_colors)]
- character = '='
- elif self.show_all_recs and self.in_dic(e, n):
- col_num = self.color_dic['basic']
- character = '+'
- else:
- col_num = self.color_dic['basic']
- character = ' '
- if self.highlight_axis and (e == 0 or n == 0):
- col_num = self.invert_color(col_num)
- try:
- self.map_pad.addch(n_s, e_s, ord(character), curses.color_pair(col_num))
- except:
- pass
- self.map_pad.box()
- refresh_args = (0, 0, 0, 0, self.map_height, self.map_width)
- self.map_pad.refresh(*refresh_args)
- def refresh_list(self):
- self.list_pad.clear()
- cells = []
- E, N = self.cursor
- list_strings = self.list_view_strings
- now_in_n0 = is_square(-E) and N==0
- if self.cur_indexer == None:
- self.cur_indexer = self.record[3]
- if now_in_n0:
- check_func = in_ena
- gen_func = ena
- shift_amt = 1
- else:
- check_func = in_enx
- gen_func = enx
- if self.cur_indexer % 2 != E % 2:
- if E%2:
- self.cur_indexer += 1
- else:
- self.cur_indexer -= 1
- shift_amt = 2
- search_depth = self.list_x_search_depth
- cells = []
- record_limit = self.list_view_height - 1
- good_index = 0
- doing_pos = True
- doing_neg = True
- i = 1
- good_spot = self.list_view_height / 2
- dracula = 0
- while(good_index != good_spot):
- t_shift_a = i * shift_amt
- if check_func(E, N, self.cur_indexer - t_shift_a):
- cells = [gen_func(E, N, self.cur_indexer - t_shift_a)] + cells
- good_index += 1
- dracula += 1
- i += 1
- if len(cells) == record_limit / 2 or dracula > self.list_x_search_depth:
- break
- dracula = 0
- i = 0
- while(len(cells) != record_limit and dracula < self.list_x_search_depth):
- t_shift_a = i * shift_amt
- if check_func(E, N, self.cur_indexer + t_shift_a):
- cells = cells + [gen_func(E, N, self.cur_indexer + t_shift_a)]
- dracula += 1
- i += 1
- #cells is now all the records we want to show with good_index being the index of the highlighted one
- words = self.lines_from_list(cells)
- for h in range(len(words)):
- try:
- if h == good_index + 1 or h == 0:
- self.list_pad.addstr(h, 0, str(words[h]), curses.color_pair(13))
- else:
- self.list_pad.addstr(h, 0, str(words[h]), curses.color_pair(1))
- except:
- pass
- refresh_args = (0, 0, 0, self.map_width, self.map_height, self.max_width)
- self.list_pad.refresh(*refresh_args)
- def lines_from_list(self, entries):
- words = self.list_view_strings
- str_rows = [words]
- for entry in entries:
- try:
- row_strs = self.values_from_record(entry, words)
- except:
- raise Exception(str(words))
- str_rows.append(row_strs)
- #str_rows = [words] + [self.values_from_record(entry, words) for entry in entries]
- def_width = self.list_cell_width
- max_widths = []
- for i in range(len(words)):
- max_w = len(words[i]) if len(words[i]) > def_width else def_width
- for str_row in str_rows:
- len_piece = str_row[i]
- if len(len_piece) > max_w:
- max_w = len(len_piece)
- max_widths.append(max_w)
- for i in range(len(max_widths)):
- if max_widths[i] > self.list_cell_max_width:
- max_widths[i] = self.list_cell_max_width
- disp_strings = []
- for row in str_rows:
- row_final = ''
- for i in range(len(words)):
- piece = row[i]
- row_final += ' '*(max_widths[i] - len(piece)+1) + piece + '|'
- disp_strings.append(row_final)
- return disp_strings
- def move_record_in_list(self, up=True, big=False):
- if big == 0:
- self.refresh_list()
- return
- E,N = self.cursor
- now_in_n0 = is_square(-E) and N==0
- if big == False:
- big = 1
- if self.cur_indexer == None:
- if now_in_n0:
- self.cur_indexer = self.record[4]
- else:
- self.cur_indexer = self.record[3]
- shifter = self.cur_indexer
- if up:
- mult = 1
- else:
- mult = -1
- if now_in_n0:
- check_func = in_ena
- shift_amt = 1 * mult
- else:
- check_func = in_enx
- if shifter % 2 != E % 2:
- if E%2:
- shifter += 1
- else:
- shifter -= 1
- shift_amt = 2 * mult
- shifter += shift_amt
- count = 0
- while(not check_func(E, N, shifter)):
- shifter += shift_amt
- count += 1
- if count > 100:
- return
- self.cur_indexer = shifter
- if big:
- self.move_record_in_list(up=up, big=big-1)
- def get_current_list_record(self):
- E, N = self.cursor
- if self.cur_indexer:
- if is_square(-E) and N==0:
- return ena(E, N, self.cur_indexer)
- else:
- return enx(E, N, self.cur_indexer)
- def set_record_from_list(self):
- b = self.get_current_list_record()
- if b:
- self.record = b
- self.other_recs = []
- self.refresh_detail()
- def add_record_from_list(self):
- b = self.get_current_list_record()
- if b:
- if len(self.other_recs) == self.max_detail_row_entries:
- return
- self.other_recs.append(b)
- self.refresh_detail()
- def values_from_record(self, record, words):
- try:
- e,n,d,x,a,b = record
- except:
- raise Exception(str(record))
- ret_val = []
- for wordd in words:
- word = wordd.lower()
- if word == 'e':
- ret_val.append(str(e))
- elif word == 'n':
- ret_val.append(str(n))
- elif word == 'd':
- ret_val.append(str(d))
- elif word == 'x':
- ret_val.append(str(x))
- elif word == 'a':
- ret_val.append(str(a))
- elif word == 'b':
- ret_val.append(str(b))
- elif word == 'c':
- ret_val.append(str(a*b))
- elif word == 'f':
- ret_val.append(str(2*d + 1 - e))
- elif word in ('d+n', '(d+n)'):
- ret_val.append(str(d + n))
- elif word in ('x+n', '(x+n)'):
- ret_val.append(str(x + n))
- elif word == 't':
- ret_val.append(str(t_from_x(x)))
- else:
- ret_val.append(word)
- return ret_val
- def refresh_detail(self):
- self.detail_pad.clear()
- cur_rec = self.record
- recs = self.other_recs
- all_recs = [cur_rec] + recs
- ids = self.detail_ids[:len(all_recs)]
- vals_to_calc = self.detail_strings[1:] #cant calculate the id so it just goes off here
- values = []
- for i in range(len(all_recs)):
- rec = all_recs[i]
- strs = [ids[i]] + self.values_from_record(rec, vals_to_calc)
- values.append(strs)
- row_strings = []
- for i in range(len(self.detail_strings)):
- max_width = max([len(x) for x in self.detail_strings])
- ddddd = str(self.detail_strings[i]) + ' '*(max_width + 1 - len(str(self.detail_strings[i])))
- row_strings.append(ddddd)
- for value in values:
- max_width = max([len(x) for x in value])
- if max_width < self.column_detail_width:
- max_width = self.column_detail_width
- for i in range(len(row_strings)):
- row_strings[i] += ' '*(max_width + 1 - len(str(value[i]))) + str(value[i]) + '|'
- for i in range(len(row_strings)):
- try:
- color = 1
- if i == 0:
- color = 16
- self.detail_pad.addstr(i, 0, row_strings[i], curses.color_pair(color))
- except:
- pass
- refresh_args = (0, 0, self.map_height, 0, self.max_height, self.detail_total_width)
- self.detail_pad.refresh(*refresh_args)
- def x_from_t(t, e):
- if e%2==0:
- x = (t - 1) * 2
- else:
- x = t*2 - 1
- return x
- def t_from_x(x):
- if x%2:
- return x/2 + 1
- else:
- return (x+1)/2
- def int_sqrt(n):
- x = n
- y = (x + 1) // 2
- while y < x:
- x = y
- y = (x + n // x) // 2
- return x
- def is_square(n):
- r = int_sqrt(n)
- return n == r*r
- #### RECORD CREATION ####
- def in_enx(e,n,x):
- if n == 0:
- return e + x*x == 0
- else:
- return (x*x + e) % (2*n) == 0
- def enx(e,n,x):
- if n == 0:
- a = 0
- else:
- a = (x*x + e) / (2*n)
- b = a + 2*x + 2*n
- c = a * b
- d = a + x
- return (e,n,d,x,a,b)
- def in_end(e,n,d):
- c = d*d + e
- #dn*dn - xn*xn = c
- #dn*dn - c = xn*xn
- xpn_s = (d+n)**2 - c
- root = int_sqrt(xpn_s)
- return root*root == xpn_s
- def end(e,n,d):
- c = d*d + e
- x = int_sqrt((d+n)**2 - c) - n
- a = d - x
- b = a + 2*x + 2*n
- return (e,n,d,x,a,b)
- def in_ena(e,n,a):
- xx = 2*n*a - e
- root = int_sqrt(xx)
- return xx == root*root
- def ena(e,n,a):
- xx = 2*n*a - e
- x = int_sqrt(xx)
- d = a + x
- b = a + 2*x + 2*n
- return (e,n,d,x,a,b)
- def abd(a,b,d):
- c = a * b
- e = c - d*d
- x = d - a
- n = (b - a)/2 - x
- return (e,n,d,x,a,b)
- def ab(a,b):
- c = a * b
- d = int_sqrt(c)
- e = c - d*d
- n = (b+a)/2 - d
- x = d - a
- return (e,n,d,x,a,b)
- '''
- SDOFSDFLJKSDF
- SDfaSDF
- SDFSDf
- asdfasdfas
- asdfasdfas
- a*bsdfasd
- failsdf
- asdfasdfas
- '''
- if __name__ == '__main__':
- x = EndConsole()
- wrapper(x.start())
- x = wrapper(EndConsole())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement