Пример #1
0
    def extractMovieTreeAsList(self, treeIter):
        """
        Extract the movie data from the movieTreeStore in the form of a list.

        Recursively construct a list of the movies and series in the rows and
        child rows of the store.
        The base treeIter should point to the tree root, i.e.,
        movieTreeStore.get_iter_first().
        The list is sorted by title before returning.
        """

        list = []
        while treeIter:
            if self.movieList.movieTreeStore[treeIter][-1]:
                seriesList = []
                if self.movieList.movieTreeStore.iter_has_child(treeIter):
                    childIter = \
                        self.movieList.movieTreeStore.iter_children(treeIter)
                    seriesList.extend(self.extractMovieTreeAsList(childIter))
                    list.append(
                        MovieSeries.fromList(
                            self.movieList.movieTreeStore[treeIter],
                            seriesList))
            else:
                list.append(
                    Movie.fromList(self.movieList.movieTreeStore[treeIter]))

            treeIter = self.movieList.movieTreeStore.iter_next(treeIter)

        return sorted(list, key=lambda item: item.title)
Пример #2
0
    def on_copyAction_activate(self, widget):
        """
        Handler for the movie copy action. Add a duplicate movie entity to the
        list.
        """

        # the status bar context
        contextId = self.statusbar.get_context_id(COPY)

        # select the movie/series to change
        treeIndex, movieEntity = self.getMovieOrSeriesFromSelection(contextId,
                                                                    COPY)
        if not movieEntity:
            return
        seriesIndex = None
        copiedMovieEntity = copiedSeriesIndex = None

        if isinstance(movieEntity, MovieSeries):
            copiedMovieEntity = MovieSeries.fromList(movieEntity.toList(), [])
        else:
            copiedSeriesIndex = self.findParentMovieSeries(treeIndex)
            copiedMovieEntity = Movie.fromList(movieEntity.toList())

        # update the model and display
        self.addMovieEntity(contextId, COPY, Gtk.ResponseType.OK,
                            None,
                            None, None,
                            copiedMovieEntity, copiedSeriesIndex)
Пример #3
0
    def __init__(self,
                 context='Add',
                 parent=None,
                 series=MovieSeries(),
                 parentSeriesIndex=None,
                 movieTreeStore=None):
        """
        Construct and run the dialog
        """

        self.builder = Gtk.Builder()
        self.builder.add_from_file(DIALOG_BUILD_FILE)
        self.builder.connect_signals(self)

        # get references to widgets we need to use
        self.dialog = self.builder.get_object('movieSeriesEditDialog')
        self.dialog.set_title('{} Series'.format(context.capitalize()))
        self.titleEntry = self.builder.get_object('titleEntry')

        # create the series selector
        movieSeriesSelectorSocket = \
            self.builder.get_object('movieSeriesSelectorSocket')
        self.movieSeriesSelector = \
            MovieSeriesSelector(parent=movieSeriesSelectorSocket,
                                movieTreeStore=movieTreeStore)
        movieSeriesSelectorSocket.add(self.movieSeriesSelector)

        # set the comboBox's current selection to the current parent series
        self.movieSeriesSelector.setSelected(parentSeriesIndex)

        self.dialog.set_transient_for(parent)
        self.titleEntry.set_text(series.title)

        # retain the list of child movies
        self.seriesChildren = series.series
Пример #4
0
    def extractMovieTreeAsList(self, treeIter):
        """
        Extract the movie data from the movieTreeStore in the form of a list.

        Recursively construct a list of the movies and series in the rows and
        child rows of the store.
        The base treeIter should point to the tree root, i.e.,
        movieTreeStore.get_iter_first().
        The list is sorted by title before returning.
        """

        list = []
        while treeIter:
            if self.movieList.movieTreeStore[treeIter][-1]:
                seriesList = []
                if self.movieList.movieTreeStore.iter_has_child(treeIter):
                    childIter = \
                        self.movieList.movieTreeStore.iter_children(treeIter)
                    seriesList.extend(self.extractMovieTreeAsList(childIter))
                    list.append(
    MovieSeries.fromList(self.movieList.movieTreeStore[treeIter], seriesList))
            else:
                list.append(
    Movie.fromList(self.movieList.movieTreeStore[treeIter]))

            treeIter = self.movieList.movieTreeStore.iter_next(treeIter)

        return sorted(list, key=lambda item:item.title)
Пример #5
0
    def run(self):
        """
        Display the edit dialog and return any changes.
        """

        response = self.dialog.run()
        series = None
        parentSeriesIter = None

        # if the ok button was pressed update the movie object
        if response == Gtk.ResponseType.OK:
            series = MovieSeries(title=self.titleEntry.get_text(),
                                 series=self.seriesChildren)
            parentSeriesIter = self.movieSeriesSelector.getSelected()

        else:
            series = MovieSeries()

        self.dialog.destroy()
        return response, series, parentSeriesIter
Пример #6
0
    def getMovieOrSeriesFromSelection(self, contextId, context):
        """
        Obtain a movie or series from the currently-selected treeView row.
        """

        # get the current movie selection
        parentModel, parentIter = self.movieTreeSelection.get_selected()

        treeModel = self.movieTreeStore
        treeIndex = getChildModelSelection(parentModel, parentIter)
        if treeIndex is None:
            self.displaySelectMovieErrorMessage(contextId, context)
            return None, None
        if treeModel[treeIndex][-1]:
            childIter = treeModel.iter_children(treeIndex)
            seriesList = self.movieListIO.extractMovieTreeAsList(childIter)
            return treeIndex, MovieSeries.fromList(treeModel[treeIndex],
                                                   seriesList)
        else:
            return treeIndex, Movie.fromList(treeModel[treeIndex])
Пример #7
0
    def getSeriesFromXml(self, series):
        """
        Obtain a movie series from an xml tree object as a list of movies.
        """

        # get the series title
        seriesTitle = series.findtext('title')
        seriesList = []

        # get any child series
        seriesNodes = series.findall('series')
        for node in seriesNodes:
            seriesList.append(self.getSeriesFromXml(node))

        # get the movies in the series
        movieNodes = series.findall('movie')
        for node in movieNodes:
            seriesList.append(self.getMovieFromXml(node))

        return MovieSeries(title=seriesTitle, series=sorted(seriesList))
Пример #8
0
    def on_addAction_activate(self, widget):
        """
        Handler for the movie add action. Add a new movie to the list.

        Displays a new empty movie in the edit dialog. If the movie information
        is changed, add the movie information to the list.
        """

        # the status bar context
        contextId = self.statusbar.get_context_id(ADD)

        # a selector to choose movie or series add
        dialog = Gtk.MessageDialog(self.window,
                                   Gtk.DialogFlags.MODAL,
                                   Gtk.MessageType.QUESTION,
                                   Gtk.ButtonsType.NONE,
                                   'Add a Movie or a Movie Series?',
                                   )
        dialog.set_title('Choose Add Movie or Series')
        dialog.add_buttons('Movie', MOVIE_RESPONSE,
                           'Movie Series', MOVIE_SERIES_RESPONSE,
                           Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
        selectionResponse = dialog.run()
        dialog.destroy()
        if selectionResponse == Gtk.ResponseType.CANCEL:
            return

        movieEntity = None
        response = ()
        if selectionResponse == MOVIE_SERIES_RESPONSE:
            movieEntity = MovieSeries()
            response = self.editMovieSeriesDialog(ADD, movieEntity, None, None)
        elif selectionResponse == MOVIE_RESPONSE:
            movieEntity = Movie()
            response = self.editMovieDialog(ADD, movieEntity, None, None)

        # update the model and display
        self.addMovieEntity(contextId, ADD, response[0],
                            None,
                            movieEntity, None,
                            response[1], response[2])