Пример #1
0
    def OnFileWander(self, event):
        """A file was checked/unchecked somewhere else.
        
        set/unset the data.

        """
        f = event.filename
        s = event.status

        if s is True:
            r = self.SetData(f)
            if r is False:
                evt = FileWanderEvent(filename=f, status=False)
                evt.SetEventObject(self)
                wx.PostEvent(self.GetParent().GetParent().GetParent(), evt)

        else:
            if f is None:
                self.UnsetAllData()

            else:
                try:
                    self.UnsetData(f)
                    evt = FileWanderEvent(filename=f, status=False)
                    evt.SetEventObject(self)
                    wx.PostEvent(self.GetParent().GetParent().GetParent(), evt)
                except Exception:
                    pass
Пример #2
0
    def FileDeSelected(self):
        """Remove the file."""

        if self._trsPanel.dirty is True:
            # dlg to ask to save or not
            user_choice = ShowYesNoQuestion(None,
                                            self._prefsIO,
                                            "Do you want to save changes on the "
                                            "transcription of audio file {:s}?"
                                            "".format(self._sndname))
            if user_choice == wx.ID_YES:
                self._trsPanel.Save()

        try:
            self._trsPanel.UnsetData()
            self._current_page = 0
            self._txtinfo.SetLabel("")
            self._mediaPanel.FileDeSelected()
            self._mediaPanel.onClose(None)
        except Exception as e:
            logging.debug('ERROR for file %s: %s' % (self._sndname, str(e)))

        evt = FileWanderEvent(filename=self._sndname, status=False)
        evt.SetEventObject(self)
        wx.PostEvent(self.GetParent().GetParent().GetParent(), evt)
        self._sndname = None
Пример #3
0
    def OnCheckBox(self, event):
        """ Action when a check box is clicked. """

        # Grab the CustomCheckBox that generated the event
        control = event.GetEventObject()

        # Get the filename
        filename = None
        for i in range(self._xfiles.GetSize()):
            if self._xfiles.GetObject(i) == control:
                filename = self._xfiles.GetFilename(i)

        # Get the checked/unchecked value
        value = event.IsChecked()

        # Here, we use CustomCheckBox as a RadioBox...
        if value is True and self._ccbmultiple is False:
            # Uncheck the other ccb
            for i in range(self._xfiles.GetSize()):
                ccb = self._xfiles.GetObject(i)
                if ccb != control:
                    ccb.SetValue(False)

        # Send the information to the frame
        evt = FileWanderEvent(filename=filename, status=value)
        evt.SetEventObject(self)
        wx.PostEvent(self.GetTopLevelParent(), evt)
Пример #4
0
    def SaveAs(self):
        """Save as... the selected file."""

        if self._selection is None:
            ShowInformation(self,
                            self._prefsIO, "No file selected!\n"
                            "Click on a tier to select a file...",
                            style=wx.ICON_INFORMATION)
            return

        found = -1
        for i in range(self._filetrs.GetSize()):
            p = self._filetrs.GetObject(i)
            if p == self._selection:
                found = i
                break

        if found > -1:
            f = self._filetrs.GetFilename(i)
            p = self._filetrs.GetObject(i)

            # Ask for the new file name
            filename = filedialogs.SaveAsAnnotationFile()

            if filename is None:
                return

            # do not erase the file if it is already existing!
            if os.path.exists(filename) and f != filename:
                ShowInformation(
                    self,
                    self._prefsIO,
                    "File not saved: this file name is already existing!",
                    style=wx.ICON_INFORMATION)
            elif f == filename:
                p.Save()
            else:
                p.SaveAs(filename)
                # Add the newly created file in the file manager
                evt = FileWanderEvent(filename=filename, status=True)
                evt.SetEventObject(self)
                wx.PostEvent(self.GetTopLevelParent(), evt)

                evt = FileWanderEvent(filename=filename, status=True)
                evt.SetEventObject(self)
                wx.PostEvent(self.GetParent().GetParent().GetParent(), evt)
Пример #5
0
    def OnFileClosed(self, event):
        """Remove of the file manager."""

        # Get the list of closed files and remove them of the file manager
        files = event.filenames

        for f in files:
            # Remove of the file manager
            evt = FileWanderEvent(filename=f, status=False)
            evt.SetEventObject(self)
            wx.PostEvent(self._filepanel, evt)
Пример #6
0
    def onEject(self, event):
        """
        Eject the music.

        """
        if self._mediaplayer is None: return

        evt = FileWanderEvent(filename=self._filename,status=False)
        evt.SetEventObject(self)
        wx.PostEvent(self.GetParent(), evt)

        self.FileDeSelected()
Пример #7
0
    def New(self):
        """Add a new file into the current page."""

        # Ask for the new file name
        filename = filedialogs.SaveAsAnnotationFile()
        if filename is None:
            return

        # Add the newly created file in the file manager and that's it!
        evt = FileWanderEvent(filename=filename, status=False)
        evt.SetEventObject(self)
        wx.PostEvent(self.GetTopLevelParent(), evt)
Пример #8
0
    def RemoveFile(self, f):
        """ Remove the given file. """

        if self._xfiles.Exists(f) is True:
            i = self._xfiles.GetIndex(f)
            self._xfiles.GetObject(i).Destroy()
            self._ccbsizer.Remove(i)
            self._xfiles.Remove(i)
            self.Layout()

        # Send the information to the parent: a file was removed successfully
        evt = FileWanderEvent(filename=f, status=False)
        evt.SetEventObject(self)
        wx.PostEvent(self.GetTopLevelParent(), evt)
Пример #9
0
    def UnsetData(self, f):
        """Remove the given file."""

        if not self._xfiles.Exists(f):
            logging.debug('WARNING. Try to unset an un-existing data:%s ' % f)
            return

        # Get information about this file (index, Display object, page)
        idx = self._xfiles.GetIndex(f)
        client = self._xfiles.GetObject(idx)
        #page   = self._xfiles.GetOther(idx)

        evt = FileWanderEvent(filename=f, status=False)
        evt.SetEventObject(self)
        wx.PostEvent(client, evt)
        wx.PostEvent(self.GetTopLevelParent(), evt)
Пример #10
0
    def AddFiles(self, files):
        """
        Add files into the file manager.

        :param files: (list of String)

        """
        if len(files) > 0:
            # Get the list of files to open/view
            for f in files:
                # Add in the file manager
                evt = FileWanderEvent(filename=f, status=True)
                evt.SetEventObject(self)
                wx.PostEvent(self._filepanel, evt)

            self.Refresh()
Пример #11
0
    def OnFileWander(self, event):
        """
        Add/Remove data.
        """
        f = event.filename
        s = event.status

        if s is True:
            try:
                self._displayctrl.SetData(event.filename)
            except Exception as e:
                #import traceback
                #print(traceback.format_exc())
                logging.info(' ** WARNING **: Got exception %s '%(str(e)))
                pass
        else:
            self._displayctrl.UnsetData(f)
            self._media.SetMedia()   # if the file was a sound...
            self._trans.SetTrs()     # if the file was a trs...
            self.Refresh()
            evt = FileWanderEvent(filename=f, status=False)
            evt.SetEventObject(self)
            wx.PostEvent(self.GetParent().GetParent().GetParent(), evt)
Пример #12
0
    def SetData(self, filename):
        """
        Add new data to draw.

        @param filename (String / List of String) is file name(s) to draw.

        """
        loaded = []
        if not type(filename) is list:
            filenames = [filename]
        else:
            filenames = filename

        #self.GetTopLevelParent().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
        wx.BeginBusyCursor()

        for f in filenames:

            # Do not add an existing file
            if self._xfiles.Exists(f):
                loaded.append(False)
                continue

            # get all required data
            page = self._notebook.GetCurrentPage()
            if page is None:
                self.AddEmptyPage()
                self._LayoutFrame()
            i = self.__getIndexPageXFiles(page)

            if i > -1 and self._multiplefiles is False:
                # the current page has already a component and it can't support multiple files
                # -- > add a page.
                self.AddEmptyPage()
                self._notebook.SetSelection(self._notebook.GetPageCount() - 1)
                page = self._notebook.GetCurrentPage()
                i = self.__getIndexPageXFiles(page)

            if i == -1:
                # none of the loaded files is using this page: create a component
                client = self.CreateComponent(parent=page,
                                              prefsIO=self._prefsIO)
                sizer = page.GetSizer()
                sizer.Add(client, proportion=1, flag=wx.EXPAND, border=0)
                n = self.__getIndexPageNotebook(page)
                if n > -1:
                    self._notebook.SetPageText(
                        n,
                        os.path.splitext(os.path.basename(f))[0])
                    self.SetImage(n, NON_EMPTY_ICON)
                page.Layout()
            else:
                client = self._xfiles.GetObject(i)

            try:
                self._xfiles.Append(f, client, page)
                evt = FileWanderEvent(filename=f, status=True)
                evt.SetEventObject(self)
                wx.PostEvent(client, evt)
            except Exception as e:
                logging.info('Error uploading: ' + f + ' ' + str(e))
                loaded.append(False)
                evt = FileWanderEvent(filename=f, status=False)
                evt.SetEventObject(self)
                wx.PostEvent(self.GetTopLevelParent(), evt)
            loaded.append(True)

        # redraw objects of this page
        wx.EndBusyCursor()
        #self.GetTopLevelParent().SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
        self.Refresh()

        if len(loaded) == 1:
            return loaded[0]

        return loaded
Пример #13
0
    def OnRemove(self, event):
        """Received an event to close files."""

        evt = FileWanderEvent(filename=None, status=False)
        evt.SetEventObject(self)
        wx.PostEvent(self._filepanel, evt)