[Avida-cvs] [avida-svn] r802 - branches/developers/avida-edward/source/python/AvidaGui2
gerrishj@myxo.css.msu.edu
gerrishj at myxo.css.msu.edu
Wed Jul 5 08:23:50 PDT 2006
Author: gerrishj
Date: 2006-07-05 11:23:50 -0400 (Wed, 05 Jul 2006)
New Revision: 802
Added:
branches/developers/avida-edward/source/python/AvidaGui2/pyTaskDataCtrl.py
Modified:
branches/developers/avida-edward/source/python/AvidaGui2/pyOneOrg_ScopeCtrl.py
branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismDataCtrl.py
branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismScopeCtrl.py
branches/developers/avida-edward/source/python/AvidaGui2/pyTimeline.py
Log:
Added task control in organism viewer and changed task icons to numbers in timeline.
Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOneOrg_ScopeCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOneOrg_ScopeCtrl.py 2006-07-05 15:23:38 UTC (rev 801)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOneOrg_ScopeCtrl.py 2006-07-05 15:23:50 UTC (rev 802)
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pyOneOrg_ScopeView import pyOneOrg_ScopeView
-from pyTimeline import pyTimeline, Flag
+from pyTimeline import pyTimeline
import qt
import os
@@ -21,10 +21,6 @@
self.m_next = qt.QTimer()
self.m_timer_interval = 100
- # TODO: example to show flags, need to hook into TestCPU to get proper
- # organism events
-# self.m_timeline.addFlag(Flag("timeline_arrow.png", 86, "First write into child"))
-# self.m_timeline.addFlag(Flag("timeline_arrow.png", 385, "Organism divide"))
self.m_organism_scope_ctrl.m_timeline = self.m_timeline
self.connect(
Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismDataCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismDataCtrl.py 2006-07-05 15:23:38 UTC (rev 801)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismDataCtrl.py 2006-07-05 15:23:50 UTC (rev 802)
@@ -1,5 +1,6 @@
from pyBufferCtrl import pyBufferCtrl
from pyInstructionDescriptionCtrl import pyInstructionDescriptionCtrl
+from pyTaskDataCtrl import pyTaskDataCtrl
from pyTaskDescriptionCtrl import pyTaskDescriptionCtrl
from pyHideShowCtrl import pyHideShowCtrl
from descr import descr
@@ -51,8 +52,13 @@
layout.addWidget(label)
parent.updateMinWidth(label.maximumWidth())
return label
+def tasksSetup(parent, layout, name):
+ "Setup tasks widget"
+ tasks_widget = pyTaskDataCtrl(parent.getSubwidget())
+ layout.addWidget(tasks_widget)
+ parent.updateMinWidth(tasks_widget.maximumWidth())
+ return tasks_widget
-
#class pyOrganismDataCtrl(QScrollView):
class pyOrganismDataCtrl(QWidget):
def __init__(self,parent = None,name = None,fl = 0):
@@ -186,8 +192,22 @@
self.curinst_descr.setText("(no instruction)")
self.hideshow_all_hardware.updateMinWidth(self.hideshow_cur_inst.minimumWidth())
+ # Create tasks widget
+# self.widget_factory.setWidgetFn(tasksSetup)
+# self.hideshow_tasks = self.hideshow_tasks_create()
+
layout.addStretch(1)
+ def hideshow_tasks_create(self):
+ "Create tasks widget"
+ widget = self.hideshow_factory.newWidget()
+ widget.getLabel().setText("Tasks Performed")
+ self.widget_factory.setParent(widget)
+ self.tasks_descr = self.widget_factory.newWidget().setReadFn(self, None)
+ self.hideshow_all_hardware.updateMinWidth(widget.minimumWidth())
+ return widget
+
+
def frameShownSlot(self, frames, frame_no):
if frames is None:
if self.old_frame_no != -1:
Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismScopeCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismScopeCtrl.py 2006-07-05 15:23:38 UTC (rev 801)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismScopeCtrl.py 2006-07-05 15:23:50 UTC (rev 802)
@@ -3,7 +3,7 @@
from pyOrganismScopeView2 import pyOrganismScopeView2
from AvidaCore import cAnalyzeGenotype, cGenome, cInstruction, cInstUtil, cString
from pyHardwareTracer import pyHardwareTracer
-from pyTimeline import pyTimeline, Flag
+from pyTimeline import pyTimeline, TimelineFlag
from qt import *
import os
@@ -222,8 +222,8 @@
task_completed = []
task_lib = self.m_avida.m_environment.GetTaskLib()
num_tasks = task_lib.GetSize()
- print "num_tasks: %d" % (num_tasks)
for task in xrange(num_tasks):
+# print "task: %d, %s" % (task, task_lib.GetTask(task).GetName())
task_completed.append(False)
for task in xrange(num_tasks):
for frame in xrange(self.m_frames.getSnapshotCount()):
@@ -231,8 +231,9 @@
if task_completed[task] == False:
task_completed[task] = True
self.m_timeline.addFlag(
- Flag("timeline_arrow.png", frame,
- "Completed first %s task" % (task_lib.GetTask(task).GetDesc())))
+# TimelineFlag("timeline_arrow.png", frame,
+ TimelineFlag(str(task), frame,
+ "Completed first %s task" % (task_lib.GetTask(task).GetDesc())))
# Task completed, don't need to search any more frames for this
# task
break
Added: branches/developers/avida-edward/source/python/AvidaGui2/pyTaskDataCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyTaskDataCtrl.py 2006-07-05 15:23:38 UTC (rev 801)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyTaskDataCtrl.py 2006-07-05 15:23:50 UTC (rev 802)
@@ -0,0 +1,78 @@
+from qt import QListView, QListViewItem, QFont, qApp, QColorGroup, Qt, PYSIGNAL
+
+class ColoredListViewItem(QListViewItem):
+ "QListViewItem with colored text"
+ def __init__(self, parent, label1, label2):
+ QListViewItem.__init__(self, parent, label1, label2)
+ self.color = Qt.black
+ def __init__(self, parent, label1, label2, color):
+ QListViewItem.__init__(self, parent, label1, label2)
+ self.color = color
+ def setColor(self, color):
+ self.color = color
+ def paintCell(self, painter, cg, column, width, align):
+ painter.save()
+ grp = QColorGroup(cg)
+ grp.setColor(QColorGroup.Text, self.color)
+ QListViewItem.paintCell(self, painter, grp, column, width, align)
+ painter.restore()
+ def dim(self, flag):
+ "Dim the text if true, brighten if false"
+ if flag:
+ self.setColor(Qt.gray)
+ else:
+ self.setColor(Qt.black)
+
+class pyTaskDataCtrl(QListView):
+ "Control to list tasks accomplished by an organism"
+ def __init__(self, parent):
+ QListView.__init__(self, parent)
+
+ self.uncompleted_tasks = []
+
+ font = QFont(qApp.font())
+ font.setPointSize(9)
+ self.setFont(font)
+
+ self.addColumn("")
+ self.addColumn("Task")
+ self.add_tasks()
+ self.show()
+
+ def add_tasks(self):
+ self.list_items = []
+ # TODO: set from TaskLib
+ self.list_items.append(ColoredListViewItem(self, "0", "not", Qt.gray))
+ self.list_items.append(ColoredListViewItem(self, "1", "nand", Qt.gray))
+ self.list_items.append(ColoredListViewItem(self, "2", "and", Qt.gray))
+ self.list_items.append(ColoredListViewItem(self, "3", "orn", Qt.gray))
+ self.list_items.append(ColoredListViewItem(self, "4", "or", Qt.gray))
+ self.list_items.append(ColoredListViewItem(self, "5", "andn", Qt.gray))
+ self.list_items.append(ColoredListViewItem(self, "6", "nor", Qt.gray))
+ self.list_items.append(ColoredListViewItem(self, "7", "xor", Qt.gray))
+ self.list_items.append(ColoredListViewItem(self, "8", "equ", Qt.gray))
+ self.uncompleted_tasks = [0, 1, 2, 3, 4, 5, 6, 7, 8]
+
+ def setReadFn(self, sender, read_fn):
+ "Register to receive frame shown signals"
+ self.connect(sender, PYSIGNAL("propagated-FrameShownSig"),
+ self.frameShownSlot)
+
+ def frameShownSlot(self, frames, frame_no):
+ "Called when a frame is shown"
+ if frames is not None and frame_no < frames.m_gestation_time:
+ for task in self.uncompleted_tasks:
+ if frames.m_tasks_info[frame_no][task] > 0:
+ self.list_items[task].dim(False)
+ else:
+ self.list_items[task].dim(True)
+ self.list_items[task].repaint()
+# self.repaint()
+
+ def reset():
+ "Reset the uncompleted tasks"
+ # TODO: also use cTaskLib
+ self.uncompleted_tasks = [0, 1, 2, 3, 4, 5, 6, 7, 8]
+ for task in self.uncompleted_tasks:
+ self.list_items[task].dim(True)
+
Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyTimeline.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyTimeline.py 2006-07-05 15:23:38 UTC (rev 801)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyTimeline.py 2006-07-05 15:23:50 UTC (rev 802)
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
-from qt import Qt, QPainter, QPixmap, QWidget, QToolTip, QSize
+from qt import Qt, QPainter, QPixmap, QWidget, QToolTip, QSize, QLabel
from qwt import QwtThermo
-class FlagWidget(QWidget):
+class TimelineFlagWidget(QWidget):
+ "TimelineFlag widget"
def __init__(self, parent, pixmap, info):
QWidget.__init__(self, parent)
self.pixmap = pixmap
@@ -22,13 +23,21 @@
def sizeHint(self):
return self.pixmap_size
-class Flag:
+class TimelineFlagLabel(QLabel):
+ "Timeline flag based on QLabel"
+ def __init__(self, parent, label, info):
+ QLabel.__init__(self, parent)
+ self.setText(label)
+ QToolTip.add(self, info)
+ self.setFixedSize(self.sizeHint())
+
+class TimelineFlag:
"Flag contains information about event flags."
def __init__(self, filename, pos, info):
self.filename = filename
self.pos = pos
self.info = info
- self.pixmap = QPixmap(filename)
+# self.pixmap = QPixmap(filename)
class pyTimeline(QwtThermo):
"""pyTimeline is a generic timeline control.
@@ -43,7 +52,8 @@
def addFlag(self, flag):
"Add new flag to timeline"
self.flags.append(flag)
- flag.widget = FlagWidget(self, flag.pixmap, flag.info)
+# flag.widget = TimelineFlagWidget(self, flag.pixmap, flag.info)
+ flag.widget = TimelineFlagLabel(self, flag.filename, flag.info)
self.move_flag(flag)
if self.maxValue() == 0.0:
flag.widget.hide()
@@ -56,20 +66,15 @@
# Uninitialized range
return
# adj adjusts for the pixmap size
- adj = flag.pos - (flag.widget.pixmap_size.width() / 2)
+# adj = flag.pos - (flag.widget.pixmap_size.width() / 2)
+
+ adj = flag.pos - flag.widget.width() / 2
# adjust for borders
borders = self.borderWidth() * 2 + 13
# FIXME: horrible hack 418 depends on current geometry of window
# TODO: figure out proper geometry code
a = self.width() - 418
mult = a / (self.maxValue() - self.minValue())
-# print "frameGeometry: %d" % (self.frameSize().width())
-# print "size: %d" % (self.width())
-# print flag.pos * mult
-# print adj
-# print borders
-# print "maxValue(): %d" % (self.maxValue())
-# print "final value: %f" % ((flag.pos * mult) + adj + borders)
flag.widget.move((flag.pos * mult) + adj + borders, 2)
def removeFlag(self, pos):
More information about the Avida-cvs
mailing list