Exemplo n.º 1
0
    def window_state_change_event(self, window, event):
        """
            Saves the current maximized and fullscreen
            states and minimizes to tray if requested
        """
        if event.changed_mask & Gdk.WindowState.MAXIMIZED:
            settings.set_option(
                'gui/mainw_maximized',
                bool(event.new_window_state & Gdk.WindowState.MAXIMIZED),
            )
        if event.changed_mask & Gdk.WindowState.FULLSCREEN:
            self._fullscreen = bool(event.new_window_state
                                    & Gdk.WindowState.FULLSCREEN)
            self.notify('is-fullscreen')

        # detect minimization state changes
        prev_minimized = self.minimized

        if not self.minimized:

            if (event.changed_mask & Gdk.WindowState.ICONIFIED
                    and not event.changed_mask & Gdk.WindowState.WITHDRAWN
                    and event.new_window_state & Gdk.WindowState.ICONIFIED
                    and not event.new_window_state & Gdk.WindowState.WITHDRAWN
                    and not self.window_state & Gdk.WindowState.ICONIFIED):
                self.minimized = True
        else:
            if (event.changed_mask & Gdk.WindowState.WITHDRAWN
                    and not event.new_window_state &
                (Gdk.WindowState.WITHDRAWN)):  # and \
                self.minimized = False

        # track this
        self.window_state = event.new_window_state

        if settings.get_option('gui/minimize_to_tray', False):

            # old code to detect minimization
            # -> it must have worked at some point, perhaps this is a GTK version
            # specific set of behaviors? Current code works now on 2.24.17

            # if wm_state is not None:
            #    if '_NET_WM_STATE_HIDDEN' in wm_state[2]:
            #        show tray
            #        window.hide
            # else
            #    destroy tray

            if self.minimized != prev_minimized and self.minimized is True:
                if (not settings.get_option('gui/use_tray', False)
                        and self.controller.tray_icon is None):
                    self.controller.tray_icon = tray.TrayIcon(self)

                window.hide()
            elif (not settings.get_option('gui/use_tray', False)
                  and self.controller.tray_icon is not None):
                self.controller.tray_icon.destroy()
                self.controller.tray_icon = None

        return False
Exemplo n.º 2
0
    def _on_option_set(self, name, object, option):
        """
           Handles changes of settings
        """
        if option == 'gui/main_window_title_format':
            self.title_formatter.props.format = settings.get_option(
                option, self.title_formatter.props.format)

        elif option == 'gui/use_tray':
            usetray = settings.get_option(option, False)
            if self.controller.tray_icon and not usetray:
                self.controller.tray_icon.destroy()
                self.controller.tray_icon = None
            elif not self.controller.tray_icon and usetray:
                self.controller.tray_icon = tray.TrayIcon(self)

        elif option == 'gui/show_info_area':
            self.info_area.set_no_show_all(False)
            if settings.get_option(option, True):
                self.info_area.show_all()
            else:
                self.info_area.hide()
            self.info_area.set_no_show_all(True)

        elif option == 'gui/show_info_area_covers':
            cover = self.info_area.cover
            cover.set_no_show_all(False)
            if settings.get_option(option, True):
                cover.show_all()
            else:
                cover.hide()
            cover.set_no_show_all(True)

        elif option == 'gui/transparency':
            self._update_alpha()
Exemplo n.º 3
0
    def _on_option_set(self, name, object, option):
        """
           Handles changes of settings
        """
        if option == 'gui/main_window_title_format':
            self.title_formatter.props.format = settings.get_option(
                option, self.title_formatter.props.format)

        if option == 'gui/use_tray':
            usetray = settings.get_option(option, False)
            if self.controller.tray_icon and not usetray:
                glib.idle_add(self.controller.tray_icon.destroy)
                self.controller.tray_icon = None
            elif not self.controller.tray_icon and usetray:
                self.controller.tray_icon = tray.TrayIcon(self)

        if option == 'gui/show_info_area':
            glib.idle_add(self.info_area.set_no_show_all, False)
            if settings.get_option(option, True):
                glib.idle_add(self.info_area.show_all)
            else:
                glib.idle_add(self.info_area.hide_all)
            glib.idle_add(self.info_area.set_no_show_all, True)

        if option == 'gui/show_info_area_covers':

            def _setup_info_covers():
                cover = self.info_area.cover
                cover.set_no_show_all(False)
                if settings.get_option(option, True):
                    cover.show_all()
                else:
                    cover.hide_all()
                cover.set_no_show_all(True)

            glib.idle_add(_setup_info_covers)
Exemplo n.º 4
0
    def __init__(self, exaile):
        """
            Initializes the GUI

            @param exaile: The Exaile instance
        """
        from xlgui import icons, main, panels, tray, progress

        Gdk.set_program_class("Exaile")

        self.exaile = exaile
        self.first_removed = False
        self.tray_icon = None

        self.builder = Gtk.Builder()
        self.builder.add_from_file(xdg.get_data_path('ui', 'main.ui'))
        self.progress_box = self.builder.get_object('progress_box')
        self.progress_manager = progress.ProgressManager(self.progress_box)

        for name in ('exaile', 'exaile-pause', 'exaile-play', 'folder-music',
                     'audio-x-generic', 'office-calendar', 'extension',
                     'music-library', 'artist', 'genre'):
            icons.MANAGER.add_icon_name_from_directory(
                name, xdg.get_data_path('images'))
        Gtk.Window.set_default_icon_name('exaile')

        for name in ('dynamic', 'repeat', 'shuffle'):
            icon_name = 'media-playlist-%s' % name
            icons.MANAGER.add_icon_name_from_directory(
                icon_name, xdg.get_data_path('images'))

        logger.info("Loading main window...")
        self.main = main.MainWindow(self, self.builder, exaile.collection)

        if self.exaile.options.StartMinimized:
            self.main.window.iconify()

        self.play_toolbar = self.builder.get_object('play_toolbar')

        panel_notebook = self.builder.get_object('panel_notebook')
        self.panel_notebook = panels.PanelNotebook(exaile, self)

        self.device_panels = {}

        # add the device panels
        for device in self.exaile.devices.list_devices():
            if device.connected:
                self.add_device_panel(None, None, device)

        logger.info("Connecting panel events...")
        self.main._connect_panel_events()

        guiutil.gtk_widget_replace(panel_notebook, self.panel_notebook)
        self.panel_notebook.get_parent()    \
            .child_set_property(self.panel_notebook, 'shrink', False)

        if settings.get_option('gui/use_tray', False):
            if tray.is_supported():
                self.tray_icon = tray.TrayIcon(self.main)
            else:
                settings.set_option('gui/use_tray', False)
                logger.warn(
                    "Tray icons are not supported on your platform. Disabling tray icon."
                )

        from xl import event
        event.add_ui_callback(self.add_device_panel, 'device_connected')
        event.add_ui_callback(self.remove_device_panel, 'device_disconnected')
        event.add_ui_callback(self.on_gui_loaded, 'gui_loaded')

        logger.info("Done loading main window...")
        Main._main = self
Exemplo n.º 5
0
    def __init__(self, exaile):
        """
            Initializes the GUI

            @param exaile: The Exaile instance
        """
        from xlgui import icons, main, panels, tray, progress

        Gdk.set_program_class("Exaile")  # For GNOME Shell

        # https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/Developer/Clients/ApplicationProperties/
        GLib.set_application_name("Exaile")
        os.environ['PULSE_PROP_media.role'] = 'music'

        self.exaile = exaile
        self.first_removed = False
        self.tray_icon = None

        self.builder = Gtk.Builder()
        self.builder.add_from_file(xdg.get_data_path('ui', 'main.ui'))
        self.progress_box = self.builder.get_object('progress_box')
        self.progress_manager = progress.ProgressManager(self.progress_box)

        add_icon = icons.MANAGER.add_icon_name_from_directory
        images_dir = xdg.get_data_path('images')

        exaile_icon_path = add_icon('exaile', images_dir)
        Gtk.Window.set_default_icon_name('exaile')
        if xdg.local_hack:
            # PulseAudio also attaches the above name to streams. However, if
            # Exaile is not installed, any app trying to display the icon won't
            # be able to find it just by name. The following is a hack to tell
            # PA the icon file path instead of the name; this only works on
            # some clients, e.g. pavucontrol.
            os.environ['PULSE_PROP_application.icon_name'] = exaile_icon_path

        for name in ('exaile-pause', 'exaile-play', 'folder-music',
                     'audio-x-generic', 'office-calendar', 'extension',
                     'music-library', 'artist', 'genre'):
            add_icon(name, images_dir)
        for name in ('dynamic', 'repeat', 'shuffle'):
            add_icon('media-playlist-' + name, images_dir)

        logger.info("Loading main window...")
        self.main = main.MainWindow(self, self.builder, exaile.collection)

        if self.exaile.options.StartMinimized:
            self.main.window.iconify()

        self.play_toolbar = self.builder.get_object('play_toolbar')

        panel_notebook = self.builder.get_object('panel_notebook')
        self.panel_notebook = panels.PanelNotebook(exaile, self)

        self.device_panels = {}

        # add the device panels
        for device in self.exaile.devices.list_devices():
            if device.connected:
                self.add_device_panel(None, None, device)

        logger.info("Connecting panel events...")
        self.main._connect_panel_events()

        guiutil.gtk_widget_replace(panel_notebook, self.panel_notebook)
        self.panel_notebook.get_parent()    \
            .child_set_property(self.panel_notebook, 'shrink', False)

        if settings.get_option('gui/use_tray', False):
            if tray.is_supported():
                self.tray_icon = tray.TrayIcon(self.main)
            else:
                settings.set_option('gui/use_tray', False)
                logger.warn(
                    "Tray icons are not supported on your platform. Disabling tray icon."
                )

        from xl import event
        event.add_ui_callback(self.add_device_panel, 'device_connected')
        event.add_ui_callback(self.remove_device_panel, 'device_disconnected')
        event.add_ui_callback(self.on_gui_loaded, 'gui_loaded')

        logger.info("Done loading main window...")
        Main._main = self

        if sys.platform == 'darwin':
            self._setup_osx()
Exemplo n.º 6
0
    def __init__(self, exaile):
        """
            Initializes the GUI

            @param exaile: The Exaile instance
        """
        from xlgui import main, panel, tray, progress
        from xlgui.panel import collection, radio, playlists, files

        gtk.gdk.set_program_class("Exaile")

        self.exaile = exaile
        self.first_removed = False
        self.tray_icon = None
        self.panels = {}
        self.builder = gtk.Builder()
        self.builder.add_from_file(xdg.get_data_path("ui/main.ui"))
        self.progress_box = self.builder.get_object('progress_box')
        self.progress_manager = progress.ProgressManager(self.progress_box)

        icons.MANAGER.add_icon_name_from_directory('exaile',
                                                   xdg.get_data_path('images'))
        gtk.window_set_default_icon_name('exaile')
        icons.MANAGER.add_icon_name_from_directory('exaile-pause',
                                                   xdg.get_data_path('images'))
        icons.MANAGER.add_icon_name_from_directory('exaile-play',
                                                   xdg.get_data_path('images'))

        for name in ('dynamic', 'repeat', 'shuffle'):
            icon_name = 'media-playlist-%s' % name
            icons.MANAGER.add_icon_name_from_directory(
                icon_name, xdg.get_data_path('images'))

        logger.info("Loading main window...")
        self.main = main.MainWindow(self, self.builder, exaile.collection,
                                    exaile.player, exaile.queue,
                                    covers.MANAGER)
        self.panel_notebook = self.builder.get_object('panel_notebook')
        self.play_toolbar = self.builder.get_object('play_toolbar')

        logger.info("Loading panels...")
        self.panels['collection'] = collection.CollectionPanel(
            self.main.window,
            exaile.collection,
            _show_collection_empty_message=True)
        self.panels['radio'] = radio.RadioPanel(self.main.window,
                                                exaile.collection,
                                                exaile.radio, exaile.stations)
        self.panels['playlists'] = playlists.PlaylistsPanel(
            self.main.window, exaile.playlists, exaile.smart_playlists,
            exaile.collection)
        self.panels['files'] = files.FilesPanel(self.main.window,
                                                exaile.collection)

        for panel in ('collection', 'radio', 'playlists', 'files'):
            self.add_panel(*self.panels[panel].get_panel())

        # add the device panels
        for device in self.exaile.devices.list_devices():
            if device.connected:
                self.add_device_panel(None, None, device)

        logger.info("Connecting panel events...")
        self.main._connect_panel_events()

        if settings.get_option('gui/use_tray', False):
            self.tray_icon = tray.TrayIcon(self.main)

        self.device_panels = {}
        event.add_callback(self.add_device_panel, 'device_connected')
        event.add_callback(self.remove_device_panel, 'device_disconnected')
        event.add_callback(self.on_gui_loaded, 'gui_loaded')

        logger.info("Done loading main window...")
        Main._main = self