Пример #1
0
    def on_content_open(self, event):
        """Provides an opportunity for user to choose content files for
        loading.

        :param event: Event that entailed an execution of the callback
        :type event: :class:`wx.CommandEvent` with type :const:`wx.EVT_MENU`

        """
        widget_id = event.GetId()
        workdir = self.app.get_setting(u'working_directory', None)
        if not workdir:
            workdir = wx.StandardPaths.Get().GetDocumentsDir()
        dialog = wx.FileDialog(
            self,
            message=Defaults.VIDEO_OPEN_DIALOG_TITLE if widget_id == wx.ID_OPEN
            else Defaults.SUBTITLES_OPEN_DIALOG_TITLE,
            defaultDir=workdir,
            wildcard=Defaults.VIDEO_WILDCARD
            if widget_id == wx.ID_OPEN else Defaults.SUBTITLES_WILDCARD,
            style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        if dialog.ShowModal() == wx.ID_OK:
            path = dialog.GetPath()
            wx.PostEvent(
                self,
                ev.LoadVideo(filepath=path) if widget_id == wx.ID_OPEN else
                ev.LoadSubtitles(filepath=path))
            newwd = op.split(path)[0] if op.isfile(path) else path
            if newwd != workdir:
                wx.PostEvent(
                    self,
                    ev.ConfigUpdate(params={u'working_directory': newwd}))
        dialog.Destroy()
Пример #2
0
    def __init__(self, app, pargs=None):
        """:class:`Player` implements graphical user interface of the
        application.

        :param app: Application instance
        :type app: :class:`wx.App`
        :param pargs: Command line arguments
        :type pargs: :class:`argparse.Namespace`

        """

        self.app = app
        super(Player, self).__init__(None, -1, "")
        self.SetMinSize(wx.Size(*Defaults.PLAYER_MIN_SIZE))
        self.word_translate.SetMinSize(
            wx.Size(*Defaults.WORD_TRANSLATE_MIN_SIZE))
        self.subtitle_translate.SetMinSize(
            wx.Size(*Defaults.SUBTITLE_TRANSLATE_MIN_SIZE))

        self._video_state = self._subtitles_state = False
        self._aspect_ratio = None
        self._filters = self.app.load_filters()
        self.enable_menu_actions(play=False,
                                 pause=False,
                                 hint=False,
                                 repeat=False,
                                 stop=False)

        self.playback_timer = wx.Timer(self, id=ids.PLAYBACK_TICK)

        filedroptarget = FileDropTarget(self)
        self.SetDropTarget(filedroptarget)

        self.Bind(ev.LOAD_VIDEO, self.load_video)
        self.Bind(ev.LOAD_SUBTITLES, self.load_subtitles)
        self.Bind(ev.CONTENT_LOADING_STATE,
                  self.on_content_loading_state_change)
        self.Bind(wx.EVT_TIMER, self.on_playback_timer, id=ids.PLAYBACK_TICK)
        self.Bind(ev.FRAGMENT_COMPLETE, self.on_fragment_completion)
        self.Bind(ev.FRAGMENT_STARTED, self.on_fragment_starting)
        self.Bind(wx.EVT_SIZE, self.on_resize)
        self.Bind(wx.EVT_MOVE, self.on_move)
        self.Bind(ev.SUBTITLES_SHIFT, self.on_subtitles_shift)
        self.Bind(ev.TRANSLATE_REQUEST, self.on_translate_request)
        self.Bind(ev.TRANSLATION_RESULT, self.on_translation_result)
        self.Bind(ev.CONFIG_UPDATE, self.on_config_update)
        self.Bind(ev.TRANSLATE_ANSWER, self.on_translate_answer)
        if globals().get(u'EVT_MEDIA_LOADED', False):
            self.Bind(EVT_MEDIA_LOADED, self.on_video_backend_response)

        video_widget_size = self._get_video_slot_size()
        self.answer_edit.SetMinSize(wx.Size(*Defaults.ANSWER_FIELD_MIN_SIZE))
        self.video.SetMinSize(video_widget_size)
        self.video.SetSize(video_widget_size)

        if pargs:
            self._accept_args(pargs)

        wx.PostEvent(self, ev.ConfigUpdate(apply_all=True))
        self.Layout()
Пример #3
0
    def on_volume(self, event):
        """Applies new volume level.

        :param event: Event that entailed an execution of the callback
        :type event: :class:`wx.ScrollEvent`

        """
        volume = event.GetPosition()
        self.video.SetVolume(volume / 100.0)
        ev.ConfigUpdate(params={u'volume': volume})
Пример #4
0
    def _save_frame_size_and_position(self):
        """Saves player window size and position coordinates.

        """
        pos = self.GetPosition()
        size = self.GetSize()
        wx.PostEvent(self, ev.ConfigUpdate(params={
            u'player_width': size.GetWidth(),
            u'player_height': size.GetHeight(),
            u'player_position_x': pos.x, u'player_position_y': pos.y,
        }))
Пример #5
0
    def on_delay(self, event):
        """Handles editing of subtitles shift value.

        :param event: Event that entailed an execution of the callback
        :type event: :class:`wx.SpinEvent`

        """
        if isinstance(getattr(self, 'subtitles', None),
                      pysrt.srtfile.SubRipFile):
            shift = self.delay_spin.GetValue()
            wx.PostEvent(self, ev.SubtitlesShift(shift=shift))
            wx.PostEvent(self,
                         ev.ConfigUpdate(params={u'subtitles_shift': shift}))
Пример #6
0
    def on_preferences(self, event):
        """Creates and shows :class:`dialogs.PreferencesDialog` to edit the
        configuration parameters.

        :param event: Event entailed execution of the callback
        :type event: :class:`wx.CommandEvent` with type :const:`wx.EVT_MENU`

        """
        dialog = PreferencesDialog(player=self)
        if dialog.ShowModal() == wx.ID_OK:
            wx.PostEvent(
                self,
                ev.ConfigUpdate(params=dialog.get_preferences(),
                                apply_updated=True))
            self._filters = dialog.get_filters()
            self.app.dump_filters(self._filters)
        dialog.Destroy()