def postfilter(merged, postwords, patterns, maxmember): """(dict, dict, dict, int) -> dict Return a filtered result KW dictionary by stoplist and patterns. Arguments: - merged: input dictionary of KWs - postwords: dict of tokens not allowed as individual KWs - patterns: dict of patterns not allowed in KWs - maxmember: maximum number of tokens allowed in complex KW """ out = {} for kw in merged: # check if KW matches forbidden pattern kwstring = repr(" ".join(kw)) if debug: print "KWSTRING:", kwstring if [ kwstring for fp in patterns.keys() if re.search(fp, kwstring, re.U) ]: if debug: print "MATCHED:", kwstring continue # check if one token KW is in forbidden list if len(kw) == 1 and kw[0] in postwords: if debug: print "POSTFILTERED:", kw[0] continue # check length limit if len(kw) > maxmember: continue out[kw] = merged[kw] return out
def addfiletype(self, filetype, added, removed): if self.filetypes.has_key(filetype): self.filetypes[filetype][self.ADDED] += added self.filetypes[filetype][self.REMOVED] += removed else: self.filetypes[filetype] = [added, removed] def addfile(self, filename, added, removed): self.files[filename] = [added, removed, max(added, removed)] def repr(self): return ('Patch', self.commit, self.author.repr(), 'Email', self.email) ns = {'n': 0} for key in patterns.keys(): ns[key] = 0 def parse_numstat(line, file_filter): global ns, InvertFilter """ Receive a line of text, determine if fits a numstat line and parse the added and removed lines as well as the file type. """ m = patterns['numstat'].match(line) ns['n'] += 1 if m: if 'numstat' not in ns: ns['numstat'] = 1 else:
def __init__(self, background): Scene.__init__(self, background) for i in xrange(0, WIDTH, BOX): self.lines.append({'color': (100,100,100), 'startx': i, 'starty': 0, 'endx': i, 'endy': HEIGHT, 'width': 1}) for i in xrange(0, HEIGHT, BOX): self.lines.append({'color': (100,100,100), 'startx': 0, 'starty': i, 'endx': WIDTH, 'endy': i, 'width': 1}) # zoom controls ''' self.buttons['out'] = Button('out', (WIDTH*.801,HEIGHT*.6), WIDTH*.07, HEIGHT*.07, (200,200,200), '-', (100,100,100,), 50, (WIDTH*.823, HEIGHT*.6), 'game', action='zoom_out') self.buttons['in'] = Button('in', (WIDTH*.876,HEIGHT*.6), WIDTH*.07, HEIGHT*.07, (200,200,200), '+', (100,100,100,), 50, (WIDTH*.898, HEIGHT*.598), 'game', action='zoom_in') ''' # speed controls self.buttons['slow'] = Button('slow', (WIDTH*.801,HEIGHT*.675), WIDTH*.04, WIDTH*.04, (200,200,200), '<<', (100,100,100,), 28, (WIDTH*.806,HEIGHT*.685), 'game', action='slow_down') self.buttons['normal'] = Button('normal', (WIDTH*.856,HEIGHT*.675), WIDTH*.04, WIDTH*.04, (200,200,200), '>', (100,100,100,), 28, (WIDTH*.869,HEIGHT*.685), 'game', action='normal_speed') self.buttons['fast'] = Button('fast', (WIDTH*.906,HEIGHT*.675), WIDTH*.04, WIDTH*.04, (200,200,200), '>>', (100,100,100,), 28, (WIDTH*.915,HEIGHT*.685), 'game', action='speed_up') # movement controls self.buttons['pause'] = Button('pause', (WIDTH*.801,HEIGHT*.75), WIDTH*.07, HEIGHT*.07, (200,200,200), 'PAUSE', (100,100,100,), 28, (WIDTH*.803, HEIGHT*.765), 'pause') # clear screen self.buttons['clear'] = Button('clear', (WIDTH*.876,HEIGHT*.75), WIDTH*.07, HEIGHT*.07, (200,200,200), 'CLEAR', (100,100,100,), 28, (WIDTH*.878, HEIGHT*.765), 'game', 'clear') # exit self.buttons['exit'] = Button('exit', (WIDTH*.801,HEIGHT*.825), WIDTH*.1445, HEIGHT*.07, (200,200,200), 'QUIT', (100,100,100,), 28, (WIDTH*.8475, HEIGHT*.839), 'exit') # patterns i = 0 for name in patterns.keys(): i = i + HEIGHT*.04 self.buttons[name] = Button(name, (WIDTH*.801, HEIGHT*.0012*i), WIDTH*.1445, HEIGHT*.035, (200,200,200), name, (100,100,100), 8, (WIDTH*.805, HEIGHT*.0012*i+7), 'game', action=name)
def __init__(self, background): Scene.__init__(self, background) for i in xrange(0, WIDTH, BOX): self.lines.append({ 'color': (100, 100, 100), 'startx': i, 'starty': 0, 'endx': i, 'endy': HEIGHT, 'width': 1 }) for i in xrange(0, HEIGHT, BOX): self.lines.append({ 'color': (100, 100, 100), 'startx': 0, 'starty': i, 'endx': WIDTH, 'endy': i, 'width': 1 }) # zoom controls ''' self.buttons['out'] = Button('out', (WIDTH*.801,HEIGHT*.6), WIDTH*.07, HEIGHT*.07, (200,200,200), '-', (100,100,100,), 50, (WIDTH*.823, HEIGHT*.6), 'game', action='zoom_out') self.buttons['in'] = Button('in', (WIDTH*.876,HEIGHT*.6), WIDTH*.07, HEIGHT*.07, (200,200,200), '+', (100,100,100,), 50, (WIDTH*.898, HEIGHT*.598), 'game', action='zoom_in') ''' # speed controls self.buttons['slow'] = Button('slow', (WIDTH * .801, HEIGHT * .675), WIDTH * .04, WIDTH * .04, (200, 200, 200), '<<', ( 100, 100, 100, ), 28, (WIDTH * .806, HEIGHT * .685), 'game', action='slow_down') self.buttons['normal'] = Button('normal', (WIDTH * .856, HEIGHT * .675), WIDTH * .04, WIDTH * .04, (200, 200, 200), '>', ( 100, 100, 100, ), 28, (WIDTH * .869, HEIGHT * .685), 'game', action='normal_speed') self.buttons['fast'] = Button('fast', (WIDTH * .906, HEIGHT * .675), WIDTH * .04, WIDTH * .04, (200, 200, 200), '>>', ( 100, 100, 100, ), 28, (WIDTH * .915, HEIGHT * .685), 'game', action='speed_up') # movement controls self.buttons['pause'] = Button('pause', (WIDTH * .801, HEIGHT * .75), WIDTH * .07, HEIGHT * .07, (200, 200, 200), 'PAUSE', ( 100, 100, 100, ), 28, (WIDTH * .803, HEIGHT * .765), 'pause') # clear screen self.buttons['clear'] = Button('clear', (WIDTH * .876, HEIGHT * .75), WIDTH * .07, HEIGHT * .07, (200, 200, 200), 'CLEAR', ( 100, 100, 100, ), 28, (WIDTH * .878, HEIGHT * .765), 'game', 'clear') # exit self.buttons['exit'] = Button('exit', (WIDTH * .801, HEIGHT * .825), WIDTH * .1445, HEIGHT * .07, (200, 200, 200), 'QUIT', ( 100, 100, 100, ), 28, (WIDTH * .8475, HEIGHT * .839), 'exit') # patterns i = 0 for name in patterns.keys(): i = i + HEIGHT * .04 self.buttons[name] = Button(name, (WIDTH * .801, HEIGHT * .0012 * i), WIDTH * .1445, HEIGHT * .035, (200, 200, 200), name, (100, 100, 100), 8, (WIDTH * .805, HEIGHT * .0012 * i + 7), 'game', action=name)
def addfiletype (self, filetype, added, removed): if self.filetypes.has_key (filetype): self.filetypes[filetype][self.ADDED] += added self.filetypes[filetype][self.REMOVED] += removed else: self.filetypes[filetype] = [added, removed] def addfile (self, filename, added, removed): self.files[filename] = [added, removed, max(added, removed)] def repr (self): return ('Patch', self.commit, self.author.repr(), 'Email', self.email) ns = {'n': 0 } for key in patterns.keys(): ns[key] = 0 def parse_numstat(line, file_filter): global ns, InvertFilter """ Receive a line of text, determine if fits a numstat line and parse the added and removed lines as well as the file type. """ m = patterns['numstat'].match (line) ns['n'] += 1 if m: if 'numstat' not in ns: ns['numstat'] = 1 else: ns['numstat'] += 1
def create_widgets(self): width = self.width * self.size height = self.height * self.size self.canvas = tk.Canvas(self, width=width, height=height, bg='white') self.canvas.grid(row=0, column=0) self.status = tk.Label(self, text="click to add or remove cells") self.status.grid(row=1, column=0) sidebar = self.sidebar = tk.Frame() sidebar.grid(row=0, column=1, rowspan=2, sticky=tk.N, padx=10, pady=10) tk.Label(sidebar, text='Steps').grid() self.steps = tk.StringVar() self.steps.set(STEPS[0]) opt_steps = self.opt_steps = tk.OptionMenu( sidebar, self.steps, *STEPS) opt_steps.grid() tk.Label(sidebar, text='Sleep (sec)').grid() self.sleep = tk.StringVar() self.sleep.set(SLEEPS[3]) opt_sleep = self.opt_sleep = tk.OptionMenu( sidebar, self.sleep, *SLEEPS) opt_sleep.grid() separator = tk.Frame(sidebar, height=2, bd=1, relief=tk.SUNKEN) separator.grid(sticky=tk.E+tk.W, padx=5, pady=10) self.btn_run = tk.Button(sidebar, text="Run", command=self.run) self.btn_run.grid() self.btn_stop = tk.Button(sidebar, text="Stop", command=self.stop) self.btn_stop.grid() self.btn_clear = tk.Button(sidebar, text="Clear", command=self.init_life) self.btn_clear.grid() separator = tk.Frame(sidebar, height=2, bd=1, relief=tk.SUNKEN) separator.grid(sticky=tk.E+tk.W, padx=5, pady=10) btn_patterns = self.btn_patterns = tk.Button( sidebar, text="Patterns", command=self.show_patterns) btn_patterns.grid() # --------------- # Patterns Window # --------------- win_patterns = self.win_patterns = tk.Toplevel(self) win_patterns.title('Patterns') win_patterns.rowconfigure(0, weight=1) win_patterns.columnconfigure(0, weight=1) scrollbar = tk.Scrollbar(win_patterns, orient=tk.VERTICAL) scrollbar.grid(row=0, column=1, sticky=tk.N+tk.S) lst_patterns = self.lst_patterns = tk.Listbox( win_patterns, yscrollcommand=scrollbar.set, height=20, width=30) for item in patterns.keys(): lst_patterns.insert(tk.END, item) lst_patterns.selection_set(0) scrollbar.config(command=lst_patterns.yview) lst_patterns.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W) win_patterns.protocol("WM_DELETE_WINDOW", self.save_top)