def showOpenDialogue(self, widget=None): ## Shows the open file dialogue. # Prepare the dialogue. dlg = dialogues.OpenFile(self.mainWindow, useful.lastFolder, allowSub=True) if (dlg.files): # If the response is OK, play the first file, then queue the others. # Clear the queue first though, since it is now obsolete. queue.clear() # Set the last folder, (if it exists). if (dlg.dir): useful.lastFolder = dlg.dir if dlg.chkSubs.get_active(): # If the user want's subtitles, let them choose the stream. dlg2 = dialogues.OpenFile(self.mainWindow, useful.lastFolder, multiple=False, useFilter=False, title=_("Choose a Subtitle Stream")) if dlg2.files: player.player.set_property('suburi', useful.filenameToUri(dlg2.files[0])) player.player.set_property('subtitle-encoding', cfg.getStr('video/subenc')) else: # Bail if they chose add subtitles but then clicked cancel. return # Play the first file and append the rest to the queue. self.playFile(dlg.files[0]) queue.appendMany(dlg.files[1:])
def __init__(self): # Set the last folder to the directory from which the program was called. useful.lastFolder = useful.origDir # Set the application's name (for about dialogue etc). gobject.set_application_name(str(useful.lName)) # Create & prepare the player for playing. self.preparePlayer() # Connect up the sigterm signal. signal.signal(signal.SIGTERM, self.sigterm) if msgBus.avail: self.dbus = msgBus.IntObject(self) # Set up the gtk-builder and interface. self.wTree = gtk.Builder() windowname = "main" self.wTree.add_from_file(useful.getBuilderFile('main')) dic = { "on_main_delete_event" : self.quit, "on_mnuiQuit_activate" : self.quit, "on_mnuiOpen_activate" : self.showOpenDialogue, "on_mnuiOpenURI_activate" : self.showOpenURIDialogue, "on_btnPlayToggle_clicked" : self.togglePlayPause, "on_btnStop_clicked" : self.stopPlayer, "on_btnNext_clicked" : self._cb_on_btnNext_clicked, "on_btnRestart_clicked" : self.restartTrack, "on_pbarProgress_button_press_event" : self.progressBarClick, "on_pbarProgress_button_release_event" : self.seekEnd, "on_pbarProgress_motion_notify_event" : self.progressBarMotion, "on_btnVolume_value_changed" : self.changeVolume, "on_mnuiFS_activate" : self.toggleFullscreen, "on_btnLeaveFullscreen_clicked" : self.toggleFullscreen, "on_videoWindow_expose_event" : self.videoWindowExpose, "on_videoWindow_configure_event" : self.videoWindowConfigure, "on_main_key_press_event" : self.windowKeyPressed, "on_videoWindow_button_press_event" : self.videoWindowClicked, "on_videoWindow_scroll_event" : self.videoWindowScroll, "on_mnuiAbout_activate" : self.showAboutDialogue, "on_main_drag_data_received" : self.openDroppedFiles, "on_videoWindow_motion_notify_event" : self.videoWindowMotion, "on_videoWindow_leave_notify_event" : self.videoWindowLeave, "on_videoWindow_enter_notify_event" : self.videoWindowEnter, "on_mnuiPreferences_activate" : self.showPreferencesDialogue, "on_mnuiPlayDVD_activate" : self.showPlayDVDDialogue, "on_mnuiDVDMenu_activate" : self.gotoDVDMenu, "on_mnuiAudioTrack_activate" : self.showAudioTracksDialogue, "on_mnuiSubtitleManager_activate" : self.openSubtitleManager, "on_mnuiReportBug_activate" : self.openBugReporter, "on_main_window_state_event" : self.onMainStateEvent, "on_mnuiQueue_toggled" : self.toggleQueueWindow, "on_eventNumQueued_button_release_event" : self.toggleQueueWindow, "on_mnuiAdvCtrls_toggled" : self.toggleAdvControls, "on_mnuiSupFeatures_activate" : self.openSupFeaturesDlg, "on_spnPlaySpeed_value_changed" : self.onPlaySpeedChange } self.wTree.connect_signals(dic) # Add the queue to the queue box. self.wTree.get_object("queueBox").pack_start(queue.qwin) # Get several items for access later. useful.mainWin = self.mainWindow = self.wTree.get_object(windowname) self.progressBar = self.wTree.get_object("pbarProgress") self.videoWindow = self.wTree.get_object("videoWindow") self.nowPlyLbl = self.wTree.get_object("lblNowPlaying") self.volAdj = self.wTree.get_object("btnVolume").get_adjustment() self.hboxVideo = self.wTree.get_object("hboxVideo") queue.mnuiWidget = self.wTree.get_object("mnuiQueue") # Set gapless flag self.isvideo = None # Set the icon. self.mainWindow.set_icon_from_file(os.path.join(useful.dataDir, 'images', 'whaawmp48.png')) # Set the window to allow drops self.mainWindow.drag_dest_set(gtk.DEST_DEFAULT_ALL, [("text/uri-list", 0, 0)], gtk.gdk.ACTION_COPY) # If we drop stuff on the queue label we want it queued (bottom right) self.wTree.get_object('lblNumQueued').drag_dest_set(gtk.DEST_DEFAULT_ALL, [("text/uri-list", 0, 0)], gtk.gdk.ACTION_COPY) self.wTree.get_object('lblNumQueued').connect('drag-data-received', queue.enqueueDropped) # Update the progress bar. self.progressUpdate() # Get the volume from the configuration. volVal = cfg.getFloat("audio/volume") if (cfg.cl.volume == None) else float(cfg.cl.volume) self.volAdj.value = useful.toRange(volVal, 0, 1) # Set the quit on stop checkbox. self.wTree.get_object("mnuiQuitOnStop").set_active(cfg.cl.quitOnEnd) # Set up the default flags. self.controlsShown = True self.seeking = False # Call the function to change the play/pause image. self.playPauseChange(False) # Show the next button & restart track button if enabled. if (cfg.getBool("gui/shownextbutton")): self.wTree.get_object("btnNext").show() if (cfg.getBool("gui/showrestartbutton")): self.wTree.get_object("btnRestart").show() # Setup the signals. signals.connect('toggle-play-pause', self.togglePlayPause) signals.connect('toggle-fullscreen', self.toggleFullscreen) signals.connect('play-next', self.playNext, False) signals.connect('restart-track', self.restartTrack) signals.connect('toggle-queue', queue.toggle) signals.connect('toggle-advanced-controls', self.toggleAdvancedControls) signals.connect('queue-changed', self.numQueuedChanged) # Show the window. self.mainWindow.show() # Save the windows ID so we can use it to inhibit screensaver. useful.winID = self.mainWindow.get_window().xid # Set the queue play command, so it can play tracks. queue.playCommand = self.playFile # Play a file (if it was specified on the command line). if (len(cfg.args) > 0): # Append all tracks to the queue. queue.appendMany(cfg.args) # Then play the next track. gobject.idle_add(self.playNext, False) if (cfg.cl.fullscreen): # If the fullscreen option was passed, start fullscreen. self.activateFullscreen() # Connect the hooks. self.connectLinkHooks() # Enter the GTK main loop. gtk.main()