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
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
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))
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])