Skip to content

Commit

Permalink
added 'close observation' button
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierfriard committed Sep 4, 2018
1 parent 2a28ce8 commit 5943ef3
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 50 deletions.
66 changes: 35 additions & 31 deletions boris.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
fast = 10

currentStates = {}
subject_name_index = {}
flag_slow = False
play_rate = 1

Expand Down Expand Up @@ -472,6 +473,7 @@ def __init__(self, availablePlayers, ffmpeg_bin, parent=None):
self.actionFrame_by_frame.setIcon(QIcon(":/frame_mode"))
self.actionFrame_backward.setIcon(QIcon(":/frame_backward"))
self.actionFrame_forward.setIcon(QIcon(":/frame_forward"))
self.actionCloseObs.setIcon(QIcon(":/close_observation"))

self.setWindowTitle("{} ({})".format(programName, __version__))

Expand Down Expand Up @@ -680,9 +682,9 @@ def menu_options(self):
self.actionNext.setEnabled(self.playerType == VLC)
self.actionSnapshot.setEnabled(self.playerType == VLC)
self.actionFrame_by_frame.setEnabled(self.playerType == VLC)

self.actionFrame_backward.setEnabled(flagObs and (self.playMode == FFMPEG))
self.actionFrame_forward.setEnabled(flagObs and (self.playMode == FFMPEG))
self.actionCloseObs.setEnabled(flagObs)

# Tools
self.actionShow_spectrogram.setEnabled(self.playerType == VLC)
Expand Down Expand Up @@ -861,6 +863,7 @@ def connections(self):

self.actionFrame_backward.triggered.connect(self.frame_backward)
self.actionFrame_forward.triggered.connect(self.frame_forward)
self.actionCloseObs.triggered.connect(self.close_observation)

# table Widget double click
self.twEvents.itemDoubleClicked.connect(self.twEvents_doubleClicked)
Expand Down Expand Up @@ -1632,7 +1635,7 @@ def filter_behaviors(self):

def filter_subjects(self):
"""
allow user to select subjects to show in the subjects list
allow user to select subjects to show in the subjects widget
"""

paramPanelWindow = param_panel.Param_panel()
Expand Down Expand Up @@ -2638,7 +2641,7 @@ def update_subject(self, subject):
Args:
subject (str): subject
"""
if not subject or (self.currentSubject == subject):
if (not subject) or (subject == NO_FOCAL_SUBJECT) or (self.currentSubject == subject):
self.currentSubject = ""
self.lbSubject.setText("<b>{}</b>".format(NO_FOCAL_SUBJECT))
self.lbFocalSubject.setText(NO_FOCAL_SUBJECT)
Expand Down Expand Up @@ -3371,7 +3374,6 @@ def initialize_new_observation_vlc(self):
mediaFPS = self.pj[OBSERVATIONS][self.observationId]["media_info"]["fps"][mediaFile]
except:
logging.debug("media_info key not found")
#nframe, videoTime, videoDuration, fps, hasVideo, hasAudio = accurate_media_analysis(self.ffmpeg_bin, media_full_path)
r = utilities.accurate_media_analysis2(self.ffmpeg_bin, media_full_path)
if "error" not in r:
if "media_info" not in self.pj[OBSERVATIONS][self.observationId]:
Expand All @@ -3389,12 +3391,8 @@ def initialize_new_observation_vlc(self):

self.projectChanged = True

#self.duration.append(int(mediaLength))
self.dw_player[i].media_durations.append(int(mediaLength))
#self.fps[mediaFile] = mediaFPS
self.dw_player[i].fps[mediaFile] = mediaFPS

#self.media_list[-1].add_media(media)
self.dw_player[i].media_list.add_media(media)

# add media list to media player list
Expand Down Expand Up @@ -4187,6 +4185,9 @@ def close_observation(self):
for i in range(N_PLAYER):
if str(i + 1) in self.pj[OBSERVATIONS][self.observationId][FILE] and self.pj[OBSERVATIONS][self.observationId][FILE][str(i + 1)]:
self.dw_player[i].mediaplayer.stop()
self.verticalLayout_3.removeWidget(self.video_slider)
self.video_slider.deleteLater()
self.video_slider = None

if self.playerType == LIVE:
self.liveTimer.stop()
Expand Down Expand Up @@ -7655,14 +7656,15 @@ def add_event(self):
editWindow.setWindowTitle("Add a new event")

# send pj to edit_event window
editWindow.pj, editWindow.currentModifier = self.pj, ""
'''editWindow.pj, editWindow.currentModifier = self.pj, ""'''

editWindow.teTime.setTime(QtCore.QTime.fromString(seconds2time(laps), HHMMSSZZZ))
editWindow.dsbTime.setValue(float(laps))

sortedSubjects = [""] + sorted([self.pj[SUBJECTS][x]["name"] for x in self.pj[SUBJECTS]])

editWindow.cobSubject.addItems(sortedSubjects)
editWindow.cobSubject.setCurrentIndex(editWindow.cobSubject.findText(self.currentSubject, Qt.MatchFixedString))

sortedCodes = sorted([self.pj[ETHOGRAM][x][BEHAVIOR_CODE] for x in self.pj[ETHOGRAM]])

Expand Down Expand Up @@ -7720,7 +7722,6 @@ def add_event(self):
self.show_current_states_in_subjects_table()



if self.pause_before_addevent:
# restart media
if self.pj[OBSERVATIONS][self.observationId][TYPE] in [MEDIA]:
Expand Down Expand Up @@ -7852,8 +7853,6 @@ def edit_event(self):
editWindow.setWindowTitle("Edit event parameters")

# pass project to window
editWindow.pj, editWindow.currentModifier = self.pj, ""

row = self.twEvents.selectedItems()[0].row()

editWindow.teTime.setTime(QtCore.QTime.fromString(seconds2time(self.pj[OBSERVATIONS][self.observationId][EVENTS][row][0]), HHMMSSZZZ))
Expand All @@ -7871,7 +7870,6 @@ def edit_event(self):
editWindow.cobSubject.setCurrentIndex(0)

sortedCodes = sorted([self.pj[ETHOGRAM][x][BEHAVIOR_CODE] for x in self.pj[ETHOGRAM]])

editWindow.cobCode.addItems(sortedCodes)

# check if selected code is in code's list (no modification of codes)
Expand Down Expand Up @@ -8180,12 +8178,25 @@ def get_current_states_by_subject(self, stateBehaviorsCodes, events, subjects, t

def show_current_states_in_subjects_table(self):
"""
show current state(s) for all subjects in subjects widget
show current state(s) for all subjects (including "No focal subject") in subjects widget
"""
'''
for idx in sorted_keys(self.pj[SUBJECTS]):
for j in range(self.twSubjects.rowCount()):
if self.twSubjects.item(j, 1).text() == self.pj[SUBJECTS][idx]["name"]:
self.twSubjects.item(j, len(subjectsFields)).setText(",".join(self.currentStates[idx]))
'''

'''self.subject_name_index = dict([(self.pj[SUBJECTS][x]["name"], x) for x in self.pj[SUBJECTS]])'''

for i in range(self.twSubjects.rowCount()):
try:
if self.twSubjects.item(i, 1).text() == NO_FOCAL_SUBJECT:
self.twSubjects.item(i, len(subjectsFields)).setText(",".join(self.currentStates[""]))
else:
self.twSubjects.item(i, len(subjectsFields)).setText(",".join(self.currentStates[self.subject_name_index[self.twSubjects.item(i, 1).text()]]))
except KeyError:
self.twSubjects.item(i, len(subjectsFields)).setText("")


def sync_time(self, n_player: int, new_time: float) -> None:
Expand Down Expand Up @@ -8513,17 +8524,20 @@ def load_subjects_in_twSubjects(self, subjects_to_show):
subjects_to_show (list): list of subject to be shown
"""

print("subjects_to_show", subjects_to_show)
self.subject_name_index = {} # dict([(self.pj[SUBJECTS][x]["name"], x) for x in self.pj[SUBJECTS]])

self.twSubjects.setRowCount(1)
# no focal subject
self.twSubjects.setRowCount(1)
self.twSubjects.setItem(0, 0, QTableWidgetItem(""))
self.twSubjects.setItem(0, 1, QTableWidgetItem(NO_FOCAL_SUBJECT))
self.twSubjects.setItem(0, 2, QTableWidgetItem(""))
self.twSubjects.setItem(0, 3, QTableWidgetItem(""))

if self.pj[SUBJECTS]:
for idx in sorted_keys(self.pj[SUBJECTS]):

self.subject_name_index[self.pj[SUBJECTS][idx]["name"]] = idx

if self.pj[SUBJECTS][idx]["name"] in subjects_to_show:

self.twSubjects.setRowCount(self.twSubjects.rowCount() + 1)
Expand Down Expand Up @@ -9210,17 +9224,7 @@ def twSubjects_doubleClicked(self):

if self.observationId:
if self.twSubjects.selectedIndexes():

row = self.twSubjects.selectedIndexes()[0].row()

# select or deselect current subject
'''
if self.currentSubject == self.twSubjects.item(row, 1).text():
self.update_subject("")
else:
self.update_subject(self.twSubjects.item(row, 1).text())
'''
self.update_subject(self.twSubjects.item(row, 1).text())
self.update_subject(self.twSubjects.item(self.twSubjects.selectedIndexes()[0].row(), 1).text())
else:
self.no_observation()

Expand Down Expand Up @@ -10030,6 +10034,7 @@ def play_video(self):
if self.playerType == VLC:
if self.playMode == FFMPEG:
self.FFmpegTimer.start()
self.actionPlay.setIcon(QIcon(":/pause"))
return True
else:
# check if player 1 is ended
Expand All @@ -10043,6 +10048,7 @@ def play_video(self):

self.timer.start(VLC_TIMER_OUT)
self.timer_spectro.start()
self.actionPlay.setIcon(QIcon(":/pause"))
return True


Expand All @@ -10067,6 +10073,7 @@ def pause_video(self):
while True:
if self.dw_player[i].mediaListPlayer.get_state() in [vlc.State.Paused, vlc.State.Ended]:
break
self.actionPlay.setIcon(QIcon(":/play"))

time.sleep(1)
self.timer_out()
Expand All @@ -10079,12 +10086,9 @@ def play_activated(self):
"""
if self.observationId and self.pj[OBSERVATIONS][self.observationId][TYPE] in [MEDIA]:
if self.dw_player[0].mediaListPlayer.get_state() == vlc.State.Paused:
if self.play_video():
self.actionPlay.setIcon(QIcon(":/pause"))

self.play_video()
else:
self.pause_video()
self.actionPlay.setIcon(QIcon(":/play"))


def jumpBackward_activated(self):
Expand Down
1 change: 1 addition & 0 deletions boris.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<qresource>
<file alias="logo">icons/logo_eye.128px.png</file>
<file alias="observations_list">icons/glyphicons_157_show_thumbnails_with_lines.png</file>
<file alias="close_observation">icons/glyphicons_207_remove_2.png</file>
<file alias="play">icons/glyphicons_173_play.png</file>
<file alias="pause">icons/glyphicons_174_pause.png</file>
<file alias="reset">icons/glyphicons_170_step_backward.png</file>
Expand Down
13 changes: 11 additions & 2 deletions boris.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1108</width>
<width>1198</width>
<height>604</height>
</rect>
</property>
Expand Down Expand Up @@ -129,7 +129,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1108</width>
<width>1198</width>
<height>22</height>
</rect>
</property>
Expand Down Expand Up @@ -351,6 +351,7 @@
<addaction name="actionFrame_by_frame"/>
<addaction name="actionFrame_backward"/>
<addaction name="actionFrame_forward"/>
<addaction name="actionCloseObs"/>
</widget>
<widget class="QDockWidget" name="dwEthogram">
<property name="floating">
Expand Down Expand Up @@ -1246,6 +1247,14 @@
<string>JWatcher</string>
</property>
</action>
<action name="actionCloseObs">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Close observation</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down
9 changes: 7 additions & 2 deletions boris_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _translate(context, text, disambig):
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(1108, 604)
MainWindow.resize(1198, 604)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.horizontalLayout_2 = QtGui.QHBoxLayout(self.centralwidget)
Expand Down Expand Up @@ -90,7 +90,7 @@ def setupUi(self, MainWindow):
self.horizontalLayout_2.addLayout(self.horizontalLayout)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1108, 22))
self.menubar.setGeometry(QtCore.QRect(0, 0, 1198, 22))
self.menubar.setObjectName(_fromUtf8("menubar"))
self.menuHelp = QtGui.QMenu(self.menubar)
self.menuHelp.setObjectName(_fromUtf8("menuHelp"))
Expand Down Expand Up @@ -480,6 +480,9 @@ def setupUi(self, MainWindow):
self.actionExportEvents_2.setObjectName(_fromUtf8("actionExportEvents_2"))
self.actionJWatcher = QtGui.QAction(MainWindow)
self.actionJWatcher.setObjectName(_fromUtf8("actionJWatcher"))
self.actionCloseObs = QtGui.QAction(MainWindow)
self.actionCloseObs.setEnabled(True)
self.actionCloseObs.setObjectName(_fromUtf8("actionCloseObs"))
self.menuHelp.addAction(self.actionUser_guide)
self.menuHelp.addAction(self.actionCheckUpdate)
self.menuHelp.addSeparator()
Expand Down Expand Up @@ -606,6 +609,7 @@ def setupUi(self, MainWindow):
self.toolBar.addAction(self.actionFrame_by_frame)
self.toolBar.addAction(self.actionFrame_backward)
self.toolBar.addAction(self.actionFrame_forward)
self.toolBar.addAction(self.actionCloseObs)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
Expand Down Expand Up @@ -793,4 +797,5 @@ def retranslateUi(self, MainWindow):
self.actionExport_observations_list.setText(_translate("MainWindow", "Export observations list", None))
self.actionExportEvents_2.setText(_translate("MainWindow", "Tabular events", None))
self.actionJWatcher.setText(_translate("MainWindow", "JWatcher", None))
self.actionCloseObs.setText(_translate("MainWindow", "Close observation", None))

9 changes: 7 additions & 2 deletions boris_ui5.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1108, 604)
MainWindow.resize(1198, 604)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.centralwidget)
Expand Down Expand Up @@ -73,7 +73,7 @@ def setupUi(self, MainWindow):
self.horizontalLayout_2.addLayout(self.horizontalLayout)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1108, 22))
self.menubar.setGeometry(QtCore.QRect(0, 0, 1198, 22))
self.menubar.setObjectName("menubar")
self.menuHelp = QtWidgets.QMenu(self.menubar)
self.menuHelp.setObjectName("menuHelp")
Expand Down Expand Up @@ -460,6 +460,9 @@ def setupUi(self, MainWindow):
self.actionExportEvents_2.setObjectName("actionExportEvents_2")
self.actionJWatcher = QtWidgets.QAction(MainWindow)
self.actionJWatcher.setObjectName("actionJWatcher")
self.actionCloseObs = QtWidgets.QAction(MainWindow)
self.actionCloseObs.setEnabled(True)
self.actionCloseObs.setObjectName("actionCloseObs")
self.menuHelp.addAction(self.actionUser_guide)
self.menuHelp.addAction(self.actionCheckUpdate)
self.menuHelp.addSeparator()
Expand Down Expand Up @@ -586,6 +589,7 @@ def setupUi(self, MainWindow):
self.toolBar.addAction(self.actionFrame_by_frame)
self.toolBar.addAction(self.actionFrame_backward)
self.toolBar.addAction(self.actionFrame_forward)
self.toolBar.addAction(self.actionCloseObs)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
Expand Down Expand Up @@ -774,4 +778,5 @@ def retranslateUi(self, MainWindow):
self.actionExport_observations_list.setText(_translate("MainWindow", "Export observations list"))
self.actionExportEvents_2.setText(_translate("MainWindow", "Tabular events"))
self.actionJWatcher.setText(_translate("MainWindow", "JWatcher"))
self.actionCloseObs.setText(_translate("MainWindow", "Close observation"))

Binary file removed icons/glyphicons_197_remove.png
Binary file not shown.
Loading

0 comments on commit 5943ef3

Please sign in to comment.