def init(self): self._shell_window = ShellWindow(self, self.ID) self._dialog_window = DialogWindow(self, self.ID) if self.ID == 0: self._menu = kikka.menu.createSoulMainMenu(self._ghost) else: self._menu = kikka.menu.createSoulDefaultMenu(self._ghost) self.loadClothBind() shellmenu = self._menu.getSubMenu("Shells") if shellmenu is not None: act = shellmenu.getAction(self._ghost.getShell().unicode_name) act.setChecked(True) balloon = self._ghost.getBalloon() if balloon is not None: self._dialog_window.setBalloon(balloon) balloonmenu = self._menu.getSubMenu("Balloons") if balloonmenu is not None: act = balloonmenu.getAction(balloon.name) act.setChecked(True) self._size = self._shell_window.size() self.resetWindowsPosition(False, self._ghost.getIsLockOnTaskbar()) self.setSurface(self._default_surfaceID) self.updateClothesMenu() kikka.menu.updateTestSurface(self._menu, self._ghost, self._default_surfaceID)
def on_init(self): #инициализация игры pygame.init() self.init_gamepad() self.set_full_screen() pygame.display.set_caption('Dead riot') #строчка на панели управления pygame.display.set_icon( pygame.image.load("enemy/zombie/idle_r.png")) #иконка self.running = True self.map = "level1.txt" self.battle_music = pygame.mixer.Sound("music/battle_music.ogg") self.battle_music.set_volume(VOLUME) self.end_music = pygame.mixer.Sound("music/end_music.ogg") self.menu_music = pygame.mixer.Sound("music/menu_music.ogg") self.menu_music.set_volume(VOLUME) self.music1 = pygame.mixer.Sound("music/music1.ogg") self.music2 = pygame.mixer.Sound("music/music2.ogg") self.music3 = pygame.mixer.Sound("music/music3.ogg") self.music4 = pygame.mixer.Sound("music/music4.ogg") self.music1.set_volume(VOLUME) self.music2.set_volume(VOLUME / 3) self.music3.set_volume(VOLUME * 3) self.music4.set_volume(VOLUME) self.songs = [] self.songs.append(self.music1) self.songs.append(self.music2) self.songs.append(self.music3) self.songs.append(self.music4) self.currently_playing_song = None self.SONGEND = pygame.USEREVENT + 1 self.game_channel = pygame.mixer.Channel(0) self.game_channel.set_endevent(self.SONGEND) self.screen = pygame.Surface(self.s_size) self.subscreen = pygame.Surface(self.w_size) self.gravity = Gravity(0.1) #главное меню self.mainMenu = MainMenu(0, 0, "gui/back.png", self) self.mainMenu.activate() #self.create_map(self.map) initAnims(self) #меню self.menu = SideMenu(0, 0, "gui/window.png", self) #вывод диалогового окна print(self.texts[self.language]["Msg1.1"]) self.msg11 = DialogWindow(self.texts[self.language]["Msg1.1"], self, 1) self.msg12 = DialogWindow(self.texts[self.language]["Msg1.2"], self, 1) self.msg13 = DialogWindow(self.texts[self.language]["Msg1.3"], self, 1) self.msg14 = DialogWindow(self.texts[self.language]["Msg1.4"], self, 1) self.msg21 = DialogWindow(self.texts[self.language]["Msg2.1"], self, 1) self.msg22 = DialogWindow(self.texts[self.language]["Msg2.2"], self, 1) self.msg23 = DialogWindow(self.texts[self.language]["Msg2.3"], self, 1) self.msg31 = DialogWindow(self.texts[self.language]["Msg3.1"], self, 1) self.msg32 = DialogWindow(self.texts[self.language]["Msg3.2"], self, 1) self.msg33 = DialogWindow(self.texts[self.language]["Msg3.3"], self, 1) self.msg41 = DialogWindow(self.texts[self.language]["Msg4.1"], self, 1) self.msg42 = DialogWindow(self.texts[self.language]["Msg4.2"], self, 1) self.msg43 = DialogWindow(self.texts[self.language]["Msg4.3"], self, 1) self.msg44 = DialogWindow(self.texts[self.language]["Msg4.4"], self, 1) self.msg45 = DialogWindow(self.texts[self.language]["Msg4.5"], self, 1) ''' self.newmobvampire = DialogWindow("Beware of bloodsuckers... ", self, 1) self.newmobskeleton = DialogWindow("Bones are ringing... ", self, 1) self.newmobgolem = DialogWindow("Something big is coming... ", self, 1) ''' self.greeting = DialogWindow(self.texts[self.language]["MsgA1"], self, 1) self.newboss = DialogWindow(self.texts[self.language]["MsgA2"], self, 1) #меню улучшений self.upgradesMenu = Upgrades(0, 0, "gui/windowWide.png", self) create_player(self) #self.new_game() self.pause = True self.game_channel.pause() self.menu_music.play(-1) #вывод надписи с номером волны text = pygame.font.Font(self.mainFont, 100).render( self.texts[self.language]["WaveCaption"] + str(0), True, (150, 150, 0)) #изначальный self.waveCaption = Delay(text, 500)
def initUI(self, params=None): if params == None: self.params = { "subjects": [ "P03", "P04", "P05", "P06", "P07", "P08", "P09", "eeg_plot0", "eeg_plot1", "eeg_plot2", "eeg_plot3", "eeg_plot4", "eeg_plot5", "eeg_plot6", "eeg_plot7", ], "channels": ["Cz", "Pz", "Fz"], "base_offset": 0, "chan_offset": 150, "gain": 1, "features": ["theta", "alpha", "beta", "means", "kurtosis", "skewness", "svd_entropy"], #'features' : ['alpha', 'means', 'entropy', 'kurtosis'], "envir": ["luxmetre", "sonometre"], "data_repo": "./data/", "fe": 256.0, # Hz "featCalc_win_size": 30.0, # s "featCalc_win_overlap": 1.0 / 2, "eegView_win_size": 30, # s "feat_offset": 1, # because feat data are normalized } self.selected = collections.OrderedDict( { "subject": "P03", "channels": [2, 2, 2], "features": [2, 2, 2, 2, 2, 2, 2], "feat_chan": "Cz", "envir": [2, 2], } ) self.last_selected = self.selected.copy() # Usefull params self.nb_win_EEG_values = self.params["eegView_win_size"] * self.params["fe"] print "nb EEG values : ", self.nb_win_EEG_values self.EEG_Xpos = np.round(self.nb_win_EEG_values / 2) print "EEG_Xpos: ", self.EEG_Xpos self.Feat_Xpos = 0 self.dialogPlotEdit = DialogWindow(self, self.params, self.selected) # Main Window and Layout self.main_win = QtGui.QWidget() self.main_win.setWindowTitle("EEG Super Viewer") self.main_win.resize(1200, 1000) self.main_layout = QtGui.QGridLayout() self.main_win.setLayout(self.main_layout) # Graph Properties Options self.prop_layout = QtGui.QHBoxLayout() # Subject selected vb_txt_subject = QtGui.QLabel("Subject selected :") self.prop_layout.addWidget(vb_txt_subject) subject_combo = QtGui.QComboBox() subject_combo.addItems(self.params["subjects"]) # TODO set combo initial to self.selected['subject'] self.prop_layout.addWidget(subject_combo) self.connect(subject_combo, QtCore.SIGNAL("activated(QString)"), self.change_subject) # EEG Time #TODO vb_time_EEG = QtGui.QLabel("EEG time :") self.prop_layout.addWidget(vb_time_EEG) # Edition windows self.EditButton = QtGui.QPushButton("Edit Plots properties") self.EditButton.clicked.connect(self.on_push_Edit_Button) self.prop_layout.addWidget(self.EditButton) self.main_layout.addLayout(self.prop_layout, 0, 0) # ~ self.dialogPlotEdit = DialogWindow(self, self.params, self.selected) # Grapfics window self.gWin = pg.GraphicsWindow() # ~ self.label = pg.LabelItem(justify='right') # ~ self.gWin.addItem(self.label) axisEEG = EEGAxis( sampling_rate=self.params["fe"], eegView_win_size=self.params["eegView_win_size"], orientation="bottom" ) # eeg_plot and feat_plot are viewbox self.eeg_plot = self.gWin.addPlot(row=1, col=0, axisItems={"bottom": axisEEG}) self.eeg_plot.invertY() self.eeg_plot.setMouseEnabled(x=True, y=True) ##axis in date s_rate = 1 / (self.params["featCalc_win_size"] * self.params["featCalc_win_overlap"]) print "sample_rate : ", 1 / self.params["featCalc_win_size"] axisFeat = DateAxisFeat(rec_datetime0=dt.datetime.now(), sampling_rate=s_rate, orientation="bottom") self.feat_plot = self.gWin.addPlot(row=2, col=0, axisItems={"bottom": axisFeat}) self.feat_plot.setMouseEnabled(x=True, y=True) self.main_layout.addWidget(self.gWin, 1, 0) # Line EEG : always in the center self.vLine_eeg = pg.InfiniteLine(pos=np.round(self.nb_win_EEG_values / 2), angle=90, movable=False) self.eeg_plot.addItem(self.vLine_eeg, ignoreBounds=True) # Line feat (movable and update EEG view) self.vLine_feat = pg.InfiniteLine(pos=self.Feat_Xpos, angle=90, movable=True) self.feat_plot.addItem(self.vLine_feat, ignoreBounds=True) self.vLine_feat.sigPositionChangeFinished.connect(self.update_cursor_pos) # Load and init plots self.nbEEGsamples = 0 # updated in loadSubjectdata self.nbFeatSamples = 0 self.env_sigs = 0 self.loadSubjectdata() self.update_eeg_plots() self.load_feat_plots() self.main_win.show()
class Soul: def __init__(self, ghost, soulid, surfaceID=0): self.ID = soulid self._ghost = ghost self._menu = None self._menustyle = None self._shell_window = None self._dialog_window = None self._size = None self._default_surfaceID = surfaceID self._surface = None self._animations = {} self._clothes = {} self._draw_offset = [] self._base_image = None self._surface_image = None self._soul_image = None self._center_point = QPoint() self._base_rect = QRect() self.init() def init(self): self._shell_window = ShellWindow(self, self.ID) self._dialog_window = DialogWindow(self, self.ID) if self.ID == 0: self._menu = kikka.menu.createSoulMainMenu(self._ghost) else: self._menu = kikka.menu.createSoulDefaultMenu(self._ghost) self.loadClothBind() shellmenu = self._menu.getSubMenu("Shells") if shellmenu is not None: act = shellmenu.getAction(self._ghost.getShell().unicode_name) act.setChecked(True) balloon = self._ghost.getBalloon() if balloon is not None: self._dialog_window.setBalloon(balloon) balloonmenu = self._menu.getSubMenu("Balloons") if balloonmenu is not None: act = balloonmenu.getAction(balloon.name) act.setChecked(True) self._size = self._shell_window.size() self.resetWindowsPosition(False, self._ghost.getIsLockOnTaskbar()) self.setSurface(self._default_surfaceID) self.updateClothesMenu() kikka.menu.updateTestSurface(self._menu, self._ghost, self._default_surfaceID) def show(self): self._shell_window.show() def hide(self): self._shell_window.hide() self._dialog_window.hide() def move(self, *__args): self._shell_window.move(*__args) def pos(self): return self._shell_window.pos() def showMenu(self, pos): if self._menu is not None: self._menu.setPosition(pos) self._menu.show() pass def getGhost(self): return self._ghost def getShellWindow(self): return self._shell_window def getDialog(self): return self._dialog_window def setBalloon(self, balloon): self._dialog_window.setBalloon(balloon) self._dialog_window.repaint() def setMenu(self, Menu): self._menu = Menu def getMenu(self): return self._menu def updateClothesMenu(self): shell = self._ghost.getShell() setting = shell.setting[self.ID] clothesmenu = OrderedDict(sorted(setting.clothesmenu.items())) clothesbind = shell.getBind(self.ID) bindgroups = setting.bindgroups bindoption = setting.bindoption menu = None for act in self._menu.actions(): if act.text() == 'Clothes': menu = act.menu() break if menu is None: return menu.clear() self._clothes.clear() if len(clothesmenu) == 0: menu.setEnabled(False) return menu.setEnabled(True) group = {} for bindgroup in bindgroups.values(): if bindgroup.type not in group: group[bindgroup.type] = QActionGroup(menu.parent()) if bindgroup.type in bindoption: option = bindoption[bindgroup.type] if option == 'multiple': group[bindgroup.type].setExclusive(False) # logging.info("%s %s" % (bindgroup.type, option)) pass for aid in clothesmenu.values(): if aid == -1: menu.addSeparator() elif aid in bindgroups.keys(): bindgroup = bindgroups[aid] text = "%s - %s" % (bindgroup.type, bindgroup.title) act = menu.addMenuItem(text, group=group[bindgroup.type]) callbackfunc = lambda checked, act=act, bindgroup=bindgroup: self.clickClothesMenuItem( checked, act, bindgroup) act.triggered.connect(callbackfunc) act.setCheckable(True) act.setData(aid) if bindgroup.type not in self._clothes.keys(): self._clothes[bindgroup.type] = -1 if (len(clothesbind) == 0 and bindgroup.default is True) \ or (len(clothesbind) > 0 and aid in clothesbind): self._clothes[bindgroup.type] = bindgroup.aID act.setChecked(True) self.setClothes(bindgroup.aID, True) pass pass def clickClothesMenuItem(self, checked, act, bindgroup): shell = self._ghost.getShell() setting = shell.setting[self.ID] # bindgroups = setting.bindgroups bindoption = setting.bindoption # group = act.actionGroup() lastcloth = self._clothes[bindgroup.type] if lastcloth == bindgroup.aID: if (bindgroup.type in bindoption and bindoption[bindgroup.type] != 'mustselect') \ or bindgroup.type not in bindoption: self._clothes[bindgroup.type] = -1 self.setClothes(bindgroup.aID, False) act.setChecked(not act.isChecked()) else: self.setClothes(lastcloth, False) self._clothes[bindgroup.type] = bindgroup.aID self.setClothes(bindgroup.aID, True) self.setSurface(-1) self.saveClothBind() logging.info("clickClothesMenuItem: %s %s", act.text(), act.isChecked()) def saveClothBind(self): data = {} count = kikka.shell.getShellCount() for i in range(count): shell = kikka.shell.getShellByIndex(i) if len(shell.bind) > 0: data[shell.name] = shell.bind[self.ID] self.memoryWrite('ClothBind', data) def loadClothBind(self): data = self.memoryRead('ClothBind', {}) if len(data) <= 0: return for name in data.keys(): shell = kikka.shell.getShell(name) if shell is None: continue shell.bind[self.ID] = data[name] pass def resetAnimation(self, animations): self._animations.clear() for aid, ani in animations.items(): self._animations[aid] = Animation(self, self.ID, ani) self._animations[aid].updateDrawRect() def getAnimation(self): return self._animations def getRunningAnimation(self): runningAni = [] for aid, ani in self._animations.items(): if ani.isRunning is True: runningAni.append(aid) return runningAni def animationStart(self, aid): if aid in self._animations.keys(): self._animations[aid].start() else: logging.warning("animation %d NOT exist!" % aid) def animationStop(self, aid): if aid in self._animations.keys(): self._animations[aid].stop() else: logging.warning("animation %d NOT exist!" % aid) def setSurface(self, surfaceID=-1): if self._surface is None: surfaceID = surfaceID if surfaceID != -1 else self._default_surfaceID elif surfaceID == -1: surfaceID = self._surface.ID elif surfaceID == self._surface.ID: return shell = self._ghost.getShell() if surfaceID in shell.alias.keys(): surfaceID = random.choice(shell.alias[surfaceID]) surface = shell.getSurface(surfaceID) if surface is None and surfaceID != self._default_surfaceID: logging.info("get default surface %d", self._default_surfaceID) surface = shell.getSurface(self._default_surfaceID) surfaceID = self._default_surfaceID if surface is None: logging.error("setSurface FAIL") self._surface = None surfaceID = -1 self.resetAnimation({}) else: logging.info("setSurface: %3d - %s(%s)", surface.ID, surface.name, surface.unicode_name) self._surface = surface self.resetAnimation(surface.animations) self.updateDrawRect() self.repaint() self._shell_window.setBoxes(shell.getCollisionBoxes(surfaceID), self._draw_offset) kikka.menu.updateTestSurface(self._menu, self._ghost, surfaceID) def setDefaultSurface(self): self.setSurface(self._default_surfaceID) def getCurrentSurface(self): return self._surface def getCurrentSurfaceID(self): return self._surface.ID if self._surface is not None else -1 def setClothes(self, aid, isEnable=True): self._ghost.getShell().setClothes(self.ID, aid, isEnable) self.repaint() def getSize(self): return QSize(self._size) def getDrawOffset(self): return QPoint(self._draw_offset) def getCenterPoint(self): return QPoint(self._center_point) def getBaseRect(self): return QRect(self._base_rect) def resetWindowsPosition(self, usingDefaultPos=True, isLockTaskBar=True, rightOffset=0): shell = self._ghost.getShell() w, h = kikka.helper.getScreenClientRect() if usingDefaultPos is True: pos = QPoint(shell.setting[self.ID].position) if pos.x() == WindowConst.UNSET.x(): pos.setX(w - self._size.width() - rightOffset) else: pos = self._shell_window.pos() if isLockTaskBar is True or pos.y() == WindowConst.UNSET.y(): pos.setY(h - self._size.height()) self._shell_window.move(pos) self._shell_window.saveShellRect() def memoryRead(self, key, default): return self._ghost.memoryRead(key, default, self.ID) def memoryWrite(self, key, value): self._ghost.memoryWrite(key, value, self.ID) # ################################################################ def onUpdate(self, updatetime): isNeedUpdate = False for aid, ani in self._animations.items(): if ani.onUpdate(updatetime) is True: isNeedUpdate = True if isNeedUpdate is True: self.repaint() return isNeedUpdate def repaint(self): self.repaintBaseImage() self.repaintSoulImage() self._shell_window.setImage(self._soul_image) self._dialog_window.repaint() def getShellImage(self, faceID): shell_image = self._ghost.getShellImage() filename1 = "surface%04d.png" % faceID filename2 = "surface%d.png" % faceID if filename1 in shell_image: return shell_image[filename1] if filename2 in shell_image: return shell_image[filename2] else: logging.warning("Image lost: %s or %s" % (filename1, filename2)) return kikka.helper.getDefaultImage() def updateDrawRect(self): if self._surface is None or self._surface.ID == -1: self._draw_offset = self._ghost.getShell().getOffset(self.ID) self._size = kikka.const.WindowConst.ShellWindowDefaultSize self._center_point = kikka.const.WindowConst.ShellWindowDefaultCenter self._base_rect = QRect(self._draw_offset, self._size) else: shell_image = self._ghost.getShellImage() baserect = QRect() if len(self._surface.elements) > 0: for i, ele in self._surface.elements.items(): if ele.filename in shell_image: baserect = baserect.united( QRect(ele.offset, shell_image[ele.filename].size())) else: img = self.getShellImage(self._surface.ID) baserect = QRect(0, 0, img.width(), img.height()) self._base_rect = QRect(baserect) baserect.translate(self._ghost.getShell().getOffset(self.ID)) rect = QRect(baserect) for aid, ani in self._animations.items(): rect = rect.united(ani.rect) self._draw_offset = QPoint(baserect.x() - rect.x(), baserect.y() - rect.y()) self._size = rect.size() if self._surface.basepos != WindowConst.UNSET: self._center_point = self._surface.basepos else: self._center_point = QPoint(self._size.width() / 2, self._size.height()) pass def repaintBaseImage(self): shell_image = self._ghost.getShellImage() self._base_image = QImage(self._size, QImage.Format_ARGB32_Premultiplied) painter = QPainter(self._base_image) painter.setCompositionMode(QPainter.CompositionMode_Source) painter.fillRect(self._base_image.rect(), Qt.transparent) painter.end() del painter if self._surface is None: return if len(self._surface.elements) > 0: for i, ele in self._surface.elements.items(): if ele.filename in shell_image: offset = self._draw_offset + ele.offset kikka.helper.drawImage(self._base_image, shell_image[ele.filename], offset.x(), offset.y(), ele.PaintType) else: img = self.getShellImage(self._surface.ID) painter = QPainter(self._base_image) painter.setCompositionMode(QPainter.CompositionMode_SourceOver) painter.drawImage(self._draw_offset, img) painter.end() # self._base_image.save("_base_image.png") pass def repaintSoulImage(self): self._soul_image = QImage(self._base_image) for aid, ani in self._animations.items(): ani.draw(self._soul_image) pass
class MainWindow(QtGui.QWidget): def __init__(self): super(MainWindow, self).__init__() self.initUI() def initUI(self, params=None): if params == None: self.params = { "subjects": [ "P03", "P04", "P05", "P06", "P07", "P08", "P09", "eeg_plot0", "eeg_plot1", "eeg_plot2", "eeg_plot3", "eeg_plot4", "eeg_plot5", "eeg_plot6", "eeg_plot7", ], "channels": ["Cz", "Pz", "Fz"], "base_offset": 0, "chan_offset": 150, "gain": 1, "features": ["theta", "alpha", "beta", "means", "kurtosis", "skewness", "svd_entropy"], #'features' : ['alpha', 'means', 'entropy', 'kurtosis'], "envir": ["luxmetre", "sonometre"], "data_repo": "./data/", "fe": 256.0, # Hz "featCalc_win_size": 30.0, # s "featCalc_win_overlap": 1.0 / 2, "eegView_win_size": 30, # s "feat_offset": 1, # because feat data are normalized } self.selected = collections.OrderedDict( { "subject": "P03", "channels": [2, 2, 2], "features": [2, 2, 2, 2, 2, 2, 2], "feat_chan": "Cz", "envir": [2, 2], } ) self.last_selected = self.selected.copy() # Usefull params self.nb_win_EEG_values = self.params["eegView_win_size"] * self.params["fe"] print "nb EEG values : ", self.nb_win_EEG_values self.EEG_Xpos = np.round(self.nb_win_EEG_values / 2) print "EEG_Xpos: ", self.EEG_Xpos self.Feat_Xpos = 0 self.dialogPlotEdit = DialogWindow(self, self.params, self.selected) # Main Window and Layout self.main_win = QtGui.QWidget() self.main_win.setWindowTitle("EEG Super Viewer") self.main_win.resize(1200, 1000) self.main_layout = QtGui.QGridLayout() self.main_win.setLayout(self.main_layout) # Graph Properties Options self.prop_layout = QtGui.QHBoxLayout() # Subject selected vb_txt_subject = QtGui.QLabel("Subject selected :") self.prop_layout.addWidget(vb_txt_subject) subject_combo = QtGui.QComboBox() subject_combo.addItems(self.params["subjects"]) # TODO set combo initial to self.selected['subject'] self.prop_layout.addWidget(subject_combo) self.connect(subject_combo, QtCore.SIGNAL("activated(QString)"), self.change_subject) # EEG Time #TODO vb_time_EEG = QtGui.QLabel("EEG time :") self.prop_layout.addWidget(vb_time_EEG) # Edition windows self.EditButton = QtGui.QPushButton("Edit Plots properties") self.EditButton.clicked.connect(self.on_push_Edit_Button) self.prop_layout.addWidget(self.EditButton) self.main_layout.addLayout(self.prop_layout, 0, 0) # ~ self.dialogPlotEdit = DialogWindow(self, self.params, self.selected) # Grapfics window self.gWin = pg.GraphicsWindow() # ~ self.label = pg.LabelItem(justify='right') # ~ self.gWin.addItem(self.label) axisEEG = EEGAxis( sampling_rate=self.params["fe"], eegView_win_size=self.params["eegView_win_size"], orientation="bottom" ) # eeg_plot and feat_plot are viewbox self.eeg_plot = self.gWin.addPlot(row=1, col=0, axisItems={"bottom": axisEEG}) self.eeg_plot.invertY() self.eeg_plot.setMouseEnabled(x=True, y=True) ##axis in date s_rate = 1 / (self.params["featCalc_win_size"] * self.params["featCalc_win_overlap"]) print "sample_rate : ", 1 / self.params["featCalc_win_size"] axisFeat = DateAxisFeat(rec_datetime0=dt.datetime.now(), sampling_rate=s_rate, orientation="bottom") self.feat_plot = self.gWin.addPlot(row=2, col=0, axisItems={"bottom": axisFeat}) self.feat_plot.setMouseEnabled(x=True, y=True) self.main_layout.addWidget(self.gWin, 1, 0) # Line EEG : always in the center self.vLine_eeg = pg.InfiniteLine(pos=np.round(self.nb_win_EEG_values / 2), angle=90, movable=False) self.eeg_plot.addItem(self.vLine_eeg, ignoreBounds=True) # Line feat (movable and update EEG view) self.vLine_feat = pg.InfiniteLine(pos=self.Feat_Xpos, angle=90, movable=True) self.feat_plot.addItem(self.vLine_feat, ignoreBounds=True) self.vLine_feat.sigPositionChangeFinished.connect(self.update_cursor_pos) # Load and init plots self.nbEEGsamples = 0 # updated in loadSubjectdata self.nbFeatSamples = 0 self.env_sigs = 0 self.loadSubjectdata() self.update_eeg_plots() self.load_feat_plots() self.main_win.show() def on_push_Edit_Button(self): print "Properties Pushed" self.dialogPlotEdit.exec_() def on_valid_dialogWindow(self): print "validation dialogWindow" self.dialogPlotEdit.close() def update_cursor_pos(self, evt): win = self.params["featCalc_win_size"] featCalc_win_overlap = self.params["featCalc_win_overlap"] fe = self.params["fe"] # Or int, depends how you want to proceed betwen feat dots ? self.Feat_Xpos = np.round(self.vLine_feat.value()) if self.Feat_Xpos < 0: self.Feat_Xpos = 0 if self.Feat_Xpos > self.nbEEGsamples: self.Feat_Xpos = self.nbEEGsamples print "new feat pos is : ", self.Feat_Xpos # TODO put it in time self.EEG_Xpos = self.Feat_Xpos * (win * featCalc_win_overlap * fe) print "new eeg pos is : ", self.EEG_Xpos # TODO put it in time self.update_eeg_plots() def load_feat_plots(self): nb_feat = len(self.params["features"]) self.feat_plot.clear() for j in range(nb_feat): data = self.feat_df[self.params["features"][j]][self.selected["subject"]][ self.selected["feat_chan"] ].values.reshape((self.nbFeatSamples)) min_feat = min(data) max_feat = np.percentile(data, 90) data = (data - max_feat) / (max_feat - min_feat) + (nb_feat - j) * self.params["feat_offset"] print np.shape(data)[0] self.feat_plot.plot(x=range(np.shape(data)[0]), y=data, pen=(j, nb_feat * 1.3)) self.vLine_feat.setValue(self.Feat_Xpos) self.feat_plot.addItem(self.vLine_feat, ignoreBounds=True) self.feat_plot.setLimits(yMin=0, yMax=nb_feat + 1) def update_eeg_plots(self): print "update EEG plots, self.EEG_Xpos is :", self.EEG_Xpos # EEG params nb_chan = len(self.params["channels"]) base_offset = self.params["base_offset"] chan_offset = self.params["chan_offset"] gain = self.params["gain"] x0 = np.int(self.EEG_Xpos - self.nb_win_EEG_values / 2) x1 = np.int(self.EEG_Xpos + self.nb_win_EEG_values / 2) print "x0 : ", x0 print "x1 : ", x1 eeg_win = np.empty((x1 - x0)) # EEG Lines plots self.eeg_plot.clear() for i, name_chan in enumerate(self.params["channels"]): eeg_win = self.eeg_df[name_chan][x0:x1].values * gain + (nb_chan - i) * chan_offset self.eeg_plot.plot(eeg_win, pen="g") # Update EEG central Line self.eeg_plot.addItem(self.vLine_eeg, ignoreBounds=True) def change_subject(self, text): self.selected["subject"] = str(text) print "Patient selected : ", self.selected["subject"] self.loadSubjectdata() self.update_eeg_plots() self.load_feat_plots() def loadSubjectdata(self): # load eeg data print "subject file : ", join( self.params["data_repo"], self.selected["subject"], self.selected["subject"] + ".h5" ) eeg_Store = pd.HDFStore( join(self.params["data_repo"], self.selected["subject"], self.selected["subject"] + ".h5") ) self.eeg_df = eeg_Store.df # load features data self.feat_df = {} for feat in self.params["features"]: print "file : ", join(self.params["data_repo"], feat + ".h5") feat_Store = pd.HDFStore(join(self.params["data_repo"], feat + ".h5")) # read_hdf ?? self.feat_df[feat] = feat_Store.df.dropna() # load environment data env_raw = join(self.params["data_repo"], self.selected["subject"], self.selected["subject"] + ".raw") env_raw_header = join(self.params["data_repo"], self.selected["subject"], self.selected["subject"] + ".header") d = self.read_header(env_raw_header) # (re)set params self.nbEEGsamples = np.shape(self.eeg_df["Cz"])[0] print "size EEG : ", self.nbEEGsamples self.nbFeatSamples = np.shape(self.feat_df[self.params["features"][0]])[0] print "nb feat samples : ", self.nbFeatSamples self.env_sigs = np.fromfile(env_raw, dtype=d["dtype"]).reshape(-1, d["nbvoies"]) print "size env sigs : ", np.shape(self.env_sigs)[0] self.EEG_Xpos = np.round(self.nb_win_EEG_values / 2) self.Feat_Xpos = 0 def read_header(self, header_filename): d = {} for line in open(header_filename): k, v = line.replace("\n", "").replace("\r", "").split(":") d[k] = v if "frequence" in d: d["frequence"] = float(d["frequence"]) if "dtype" in d: d["dtype"] = np.dtype(d["dtype"]) if "nbvoies" in d: d["nbvoies"] = int(d["nbvoies"]) channelnames = [] for i in range(d["nbvoies"]): channelnames.append(d["nom" + str(i + 1)]) d["channelnames"] = channelnames return d