+ def getStateForPosition(self, pos):
+ state = -1
+ for (where, what) in self.cut_list:
+ if what in [0, 1]:
+ if where < pos:
+ state = what
+ elif where == pos:
+ state = 1
+ elif state == -1:
+ state = 1 - what
+ if state == -1:
+ state = 0
+ return state
+
+ def showMenu(self):
+ curpos = self.cueGetCurrentPosition()
+ if curpos is None:
+ return
+
+ self.setSeekState(self.SEEK_STATE_PAUSE)
+
+ self.context_position = curpos
+
+ self.context_nearest_mark = self.toggleMark(onlyreturn=True)
+
+ cur_state = self.getStateForPosition(curpos)
+ if cur_state == 0:
+ print "currently in 'IN'"
+ if self.cut_start is None or self.context_position < self.cut_start:
+ state = CutListContextMenu.SHOW_STARTCUT
+ else:
+ state = CutListContextMenu.SHOW_ENDCUT
+ else:
+ print "currently in 'OUT'"
+ state = CutListContextMenu.SHOW_DELETECUT
+
+ if self.context_nearest_mark is None:
+ nearmark = False
+ else:
+ nearmark = True
+
+ self.session.openWithCallback(self.menuCallback, CutListContextMenu, state, nearmark)
+
+ def menuCallback(self, *result):
+ if not len(result):
+ return
+ result = result[0]
+
+ if result == CutListContextMenu.RET_STARTCUT:
+ self.cut_start = self.context_position
+ elif result == CutListContextMenu.RET_ENDCUT:
+ # remove in/out marks between the new cut
+ for (where, what) in self.cut_list[:]:
+ if self.cut_start <= where <= self.context_position and what in (0,1):
+ self.cut_list.remove((where, what))
+
+ bisect.insort(self.cut_list, (self.cut_start, 1))
+ bisect.insort(self.cut_list, (self.context_position, 0))
+ self.uploadCuesheet()
+ self.cut_start = None
+ elif result == CutListContextMenu.RET_DELETECUT:
+ out_before = None
+ in_after = None
+
+ for (where, what) in self.cut_list:
+ if what == 1 and where <= self.context_position: # out
+ out_before = (where, what)
+ elif what == 0 and where < self.context_position: # in, before out
+ out_before = None
+ elif what == 0 and where >= self.context_position and in_after is None:
+ in_after = (where, what)
+
+ if out_before is not None:
+ self.cut_list.remove(out_before)
+
+ if in_after is not None:
+ self.cut_list.remove(in_after)
+ self.inhibit_seek = True
+ self.uploadCuesheet()
+ self.inhibit_seek = False
+ elif result == CutListContextMenu.RET_MARK:
+ self.__addMark()
+ elif result == CutListContextMenu.RET_DELETEMARK:
+ self.cut_list.remove(self.context_nearest_mark)
+ self.inhibit_seek = True
+ self.uploadCuesheet()
+ self.inhibit_seek = False
+ elif result == CutListContextMenu.RET_REMOVEBEFORE:
+ # remove in/out marks before current position
+ for (where, what) in self.cut_list[:]:
+ if where <= self.context_position and what in (0,1):
+ self.cut_list.remove((where, what))
+ # add 'in' point
+ bisect.insort(self.cut_list, (self.context_position, 0))
+ self.inhibit_seek = True
+ self.uploadCuesheet()
+ self.inhibit_seek = False
+ elif result == CutListContextMenu.RET_REMOVEAFTER:
+ # remove in/out marks after current position
+ for (where, what) in self.cut_list[:]:
+ if where >= self.context_position and what in (0,1):
+ self.cut_list.remove((where, what))
+ # add 'out' point
+ bisect.insort(self.cut_list, (self.context_position, 1))
+ self.inhibit_seek = True
+ self.uploadCuesheet()
+ self.inhibit_seek = False
+ elif result == CutListContextMenu.RET_GRABFRAME:
+ self.grabFrame()
+
+ # we modify the "play" behavior a bit:
+ # if we press pause while being in slowmotion, we will pause (and not play)
+ def playpauseService(self):
+ if self.seekstate != self.SEEK_STATE_PLAY and not self.isStateSlowMotion(self.seekstate):
+ self.unPauseService()
+ else:
+ self.pauseService()
+
+ def grabFrame(self):
+ path = self.session.nav.getCurrentlyPlayingServiceReference().getPath()
+ from Components.Console import Console
+ grabConsole = Console()
+ cmd = 'grab -vblpr%d "%s"' % (180, path.rsplit('.',1)[0] + ".png")
+ grabConsole.ePopen(cmd)
+ self.playpauseService()
+
+def main(session, service, **kwargs):