def __init__(self, width, height, type='spherical', parent=None): QtGui.QWidget.__init__(self,parent) self.agents=[] self.width=width self.height=height self.resize(width,height) self.setWindowTitle('Agent Modeling World') if type != 'bounded' and type != 'spherical' and type != 'toroidal': self.type='spherical' else: self.type=type self.food = [] self.food_granularity=8 for i in range(self.width/self.food_granularity): self.food.append([]) for j in range(self.height/self.food_granularity): self.food[i].append(False) self.food_spawn_prob = 0.03 self.food_rot_prob = 0.1 self.timer = QtCore.QTimer() self.timer.setSingleShot(False) self.connect(self.timer,QtCore.SIGNAL('timeout()'),self,QtCore.SLOT('update()')) self.timer.start(1) self.generation=0 for i in range(10): self.spawn_food() self.pop_plot = linegraph(1000) self.pop_plot.setcolor(0,QtGui.QColor(0,255,0)) self.pop_plot.setWindowTitle('Population') self.pop_plot.show()
def __init__(self, sugar_map, parent=None): QtGui.QWidget.__init__(self,parent) self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent) self.agents=[] self.agent_list=[] self.width=sugar_map.mwidth self.height=sugar_map.mheight self.cell_size = 8 self.setFixedSize(self.width*self.cell_size,self.height*self.cell_size) self.setWindowTitle('Sugarscape') self.sugar = [] self.sugar_map = sugar_map self.sugar_cap = self.sugar_map.current() self.previouslyDrawn = [] for i in range(self.width): self.agents.append([]) self.sugar.append([]) self.previouslyDrawn.append([]) for j in range(self.height): self.sugar[i].append(self.sugar_cap[i][j]) self.agents[i].append(None) self.previouslyDrawn[i].append(-1) self.timer = QtCore.QTimer() self.timer.setSingleShot(False) self.connect(self.timer,QtCore.SIGNAL('timeout()'),self,QtCore.SLOT('update()')) self.timer.start(00) self.generation=0 self.pop_plot = linegraph(400) self.pop_plot.setWindowTitle('Population') self.pop_plot.show()
def populate(self, revision=None): """Fill the treeview with contents. :param start: Revision id of revision to start with. :param maxnum: Maximum number of revisions to display, or None for no limit. :param broken_line_length: After how much lines branches \ should be broken. """ if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None: # We'are using our own ui, let's tell it to use our widget. ui.ui_factory.set_progress_bar_widget(self.progress_widget) self.progress_bar = ui.ui_factory.nested_progress_bar() self.progress_bar.update("Loading ancestry graph", 0, 5) try: if self.compact: broken_line_length = 32 else: broken_line_length = None show_graph = self.graph_column.get_visible() self.branch.lock_read() (linegraphdata, index, columns_len) = linegraph( self.branch.repository.get_graph(), self.start, self.maxnum, broken_line_length, show_graph, self.mainline_only, self.progress_bar, ) self.model = TreeModel(self.branch, linegraphdata) self.graph_cell.columns_len = columns_len width = self.graph_cell.get_size(self.treeview)[2] if width > 500: width = 500 self.graph_column.set_fixed_width(width) self.graph_column.set_max_width(width) self.index = index self.treeview.set_model(self.model) if not revision or revision == NULL_REVISION: self.treeview.set_cursor(0) else: self.set_revision(revision) self.emit("refreshed") return False finally: self.progress_bar.finished()