Exemple #1
0
def get_source_index(source_name):
    status, output = g15os.get_command_output("pacmd list-sources")
    if status == 0 and len(output) > 0:
        i = 0
        for line in output.split("\n"):
            line = line.strip()
            if line.startswith("index: "):
                i = int(line[7:])
            elif line.startswith("name: <%s" % source_name):
                return i
    logger.warn("Audio source %s not found, default to first source", source_name)
    return 0
Exemple #2
0
def show_preferences(parent, driver, gconf_client, gconf_key):
    widget_tree = gtk.Builder()
    widget_tree.add_from_file(os.path.join(os.path.dirname(__file__), "impulse15.ui"))
    
    dialog = widget_tree.get_object("ImpulseDialog")
    dialog.set_transient_for(parent)
    
    # Set up the audio source model  
    audio_source_model = widget_tree.get_object("AudioSourceModel")
    status, output = g15os.get_command_output("pacmd list-sources")
    source_name = "0"
    if status == 0 and len(output) > 0:
        i = 0
        for line in output.split("\n"):
            line = line.strip()
            if line.startswith("index: "):
                i = int(line[7:])
                source_name = str(i)
            elif line.startswith("name: "):
                source_name = line[7:-1]
            elif line.startswith("device.description = "):
                audio_source_model.append((source_name, line[22:-1]))
    else:
        for i in range(0, 9):
            audio_source_model.append((str(i), "Source %d" % i))

    g15uigconf.configure_checkbox_from_gconf(gconf_client, gconf_key + "/disco", "Disco", False, widget_tree)
    g15uigconf.configure_checkbox_from_gconf(gconf_client, gconf_key + "/animate_mkeys", "AnimateMKeys", False, widget_tree)
    g15uigconf.configure_combo_from_gconf(gconf_client, gconf_key + "/mode", "ModeCombo", "spectrum", widget_tree)
    g15uigconf.configure_combo_from_gconf(gconf_client, gconf_key + "/paint", "PaintCombo", "screen", widget_tree)
    g15uigconf.configure_spinner_from_gconf(gconf_client, gconf_key + "/bars", "BarsSpinner", 16, widget_tree)
    g15uigconf.configure_combo_from_gconf(gconf_client, gconf_key + "/audio_source_name", "AudioSource", source_name, widget_tree)
    g15uigconf.configure_spinner_from_gconf(gconf_client, gconf_key + "/bar_width", "BarWidthSpinner", 16, widget_tree)
    g15uigconf.configure_spinner_from_gconf(gconf_client, gconf_key + "/spacing", "SpacingSpinner", 0, widget_tree)
    g15uigconf.configure_spinner_from_gconf(gconf_client, gconf_key + "/rows", "RowsSpinner", 16, widget_tree)
    g15uigconf.configure_spinner_from_gconf(gconf_client, gconf_key + "/bar_height", "BarHeightSpinner", 2, widget_tree)
    g15uigconf.configure_colorchooser_from_gconf(gconf_client, gconf_key + "/col1", "Color1", ( 255, 0, 0 ), widget_tree, default_alpha = 255)
    g15uigconf.configure_colorchooser_from_gconf(gconf_client, gconf_key + "/col2", "Color2", ( 0, 0, 255 ), widget_tree, default_alpha = 255)
    g15uigconf.configure_adjustment_from_gconf(gconf_client, gconf_key + "/frame_rate", "FrameRateAdjustment", 10.0, widget_tree)
    g15uigconf.configure_adjustment_from_gconf(gconf_client, gconf_key + "/gain", "GainAdjustment", 1.0, widget_tree)
    
    if driver.get_bpp() == 0:
        widget_tree.get_object("LCDTable").set_visible(False)

    
    dialog.run()
    dialog.hide() 
Exemple #3
0
    def load_menu_items(self):
        items = []
        self.volume_monitor_signals = []

        # Webcams etc
        video_devices = []
        for i in os.listdir("/dev"):
            if i.startswith("video"):
                video_devices.append(i)

        if len(video_devices) > 0:
            items.append(
                g15theme.MenuItem("video-devices",
                                  True,
                                  _("Video Devices"),
                                  icon=g15icontools.get_icon_path(
                                      ["camera-web", "camera-video"]),
                                  activatable=False))
            for i in video_devices:
                items.append(G15VideoDeviceMenuItem(self, i))

        # Video File
        def activate_video_file():
            GObject.idle_add(self._open_video_file)

        items.append(
            g15theme.MenuItem("video-file",
                              True,
                              _("Open Audio/Video File"),
                              activate=activate_video_file,
                              icon=g15icontools.get_icon_path("folder")))

        # DVD / Mounts
        self.volume_monitor = Gio.VolumeMonitor.get()
        self.volume_monitor_signals.append(
            self.volume_monitor.connect("mount_added", self._on_mount_added))
        self.volume_monitor_signals.append(
            self.volume_monitor.connect("mount_removed",
                                        self._on_mount_removed))
        removable_media_items = []
        for i, mount in enumerate(self.volume_monitor.get_mounts()):
            drive = mount.get_drive()
            if not mount.is_shadowed(
            ) and drive is not None and drive.is_media_removable():
                removable_media_items.append(
                    MountMenuItem('mount-%d' % i, mount, self))
        if len(removable_media_items):
            items.append(
                g15theme.MenuItem("removable-devices",
                                  True,
                                  _("Removable Devices"),
                                  icon=g15icontools.get_icon_path([
                                      "driver-removable-media",
                                      "gnome-dev-removable"
                                  ]),
                                  activatable=False))
            items += removable_media_items

        # Pulse
        status, output = g15os.get_command_output("pacmd list-sources")
        if status == 0 and len(output) > 0:
            i = 0
            pulse_items = []
            for line in output.split("\n"):
                line = line.strip()
                if line.startswith("name: "):
                    name = line[7:-1]
                elif line.startswith("device.description = "):
                    pulse_items.append(
                        PulseSourceMenuItem(name, line[22:-1], self))
            if len(pulse_items) > 0:
                items.append(
                    g15theme.MenuItem("pulse-sources",
                                      True,
                                      _("PulseAudio Source"),
                                      icon=g15icontools.get_icon_path([
                                          "audio-card", "audio-speakers",
                                          "audio-volume-high",
                                          "audio-x-generic"
                                      ]),
                                      activatable=False))
                items += pulse_items

        # Visualisations - TODO - there must be a better way to list them
        items.append(
            g15theme.MenuItem("visualisation-mode",
                              True,
                              _("Visualisation Mode"),
                              icon=g15icontools.get_icon_path([
                                  "preferences-color", "gtk-select-color",
                                  "preferences-desktop-screensaver",
                                  "kscreensaver", "xscreensaver"
                              ]),
                              activatable=False))
        for c in [ "goom", \
                  "libvisual_bumpscope", \
                  "libvisual_corona", \
                  "libvisual_infinite", \
                  "libvisual_jakdaw", \
                  "libvisual_jess", \
                  "libvisual_lv_analyzer", \
                  "libvisual_lv_scope", \
                  "libvisual_lv_oinksie", \
                  "synaesthesia", \
                  "spacescope", \
                  "spectrascope", \
                  "synaescope", \
                  "wavescope", \
                  "monoscope"]:
            try:
                Gst.ElementFactory.make(c, None)
                items.append(G15VisualisationMenuItem(c, self))
            except Exception as e:
                logger.debug("Error creating visualizations", exc_info=e)
                pass

        self.menu.set_children(items)
        if len(items) > 0:
            self.menu.selected = items[0]
        else:
            self.menu.selected = None
Exemple #4
0
    def load_menu_items(self):
        items = []
        self.volume_monitor_signals = []
        
        # Webcams etc
        video_devices = []
        for i in os.listdir("/dev"):
            if i.startswith("video"):
                video_devices.append(i)
                
        if len(video_devices) > 0:
            items.append(g15theme.MenuItem("video-devices", True, _("Video Devices"), icon = g15icontools.get_icon_path(["camera-web", "camera-video"]), activatable = False))
            for i in video_devices:
                items.append(G15VideoDeviceMenuItem(self, i))
                
        # Video File
        def activate_video_file():
            gobject.idle_add(self._open_video_file)
        items.append(g15theme.MenuItem("video-file", True, _("Open Audio/Video File"), activate = activate_video_file, icon = g15icontools.get_icon_path("folder")))
        
        # DVD / Mounts
        self.volume_monitor = gio.VolumeMonitor()
        self.volume_monitor_signals.append(self.volume_monitor.connect("mount_added", self._on_mount_added))
        self.volume_monitor_signals.append(self.volume_monitor.connect("mount_removed", self._on_mount_removed))
        removable_media_items = []
        for i, mount in enumerate(self.volume_monitor.get_mounts()):
            drive = mount.get_drive()
            if not mount.is_shadowed() and drive is not None and drive.is_media_removable():
                removable_media_items.append(MountMenuItem('mount-%d' % i, mount, self))
        if len(removable_media_items):
            items.append(g15theme.MenuItem("removable-devices", True, _("Removable Devices"), icon = g15icontools.get_icon_path(["driver-removable-media", "gnome-dev-removable"]), activatable = False))
            items += removable_media_items
            
        # Pulse
        status, output = g15os.get_command_output("pacmd list-sources")
        if status == 0 and len(output) > 0:
            i = 0
            pulse_items = []
            for line in output.split("\n"):
                line = line.strip()
                if line.startswith("name: "):
                    name = line[7:-1]
                elif line.startswith("device.description = "):
                    pulse_items.append(PulseSourceMenuItem(name, line[22:-1], self))
            if len(pulse_items) > 0:
                items.append(g15theme.MenuItem("pulse-sources", True, _("PulseAudio Source"), icon = g15icontools.get_icon_path(["audio-card", "audio-speakers", "audio-volume-high", "audio-x-generic"]), activatable = False))
                items += pulse_items


        # Visualisations - TODO - there must be a better way to list them
        items.append(g15theme.MenuItem("visualisation-mode", True, _("Visualisation Mode"), icon = g15icontools.get_icon_path(["preferences-color", "gtk-select-color", "preferences-desktop-screensaver", "kscreensaver", "xscreensaver"]), activatable = False))
        for c in [ "goom", \
                  "libvisual_bumpscope", \
                  "libvisual_corona", \
                  "libvisual_infinite", \
                  "libvisual_jakdaw", \
                  "libvisual_jess", \
                  "libvisual_lv_analyzer", \
                  "libvisual_lv_scope", \
                  "libvisual_lv_oinksie", \
                  "synaesthesia", \
                  "spacescope", \
                  "spectrascope", \
                  "synaescope", \
                  "wavescope", \
                  "monoscope"]:
            try:
                gst.element_factory_make(c)
                items.append(G15VisualisationMenuItem(c, self))
            except Exception as e:
                logger.debug("Error creating visualizations", exc_info = e)
                pass            
        
        self.menu.set_children(items)
        if len(items) > 0:
            self.menu.selected = items[0]
        else:
            self.menu.selected = None
Exemple #5
0
    def get_theme_properties(self):
        properties = {}

        def convert_bytes(bytes):
            bytes = float(bytes)
            if bytes >= 1099511627776:
                terabytes = bytes / 1099511627776
                size = '%.2fT' % terabytes
            elif bytes >= 1073741824:
                gigabytes = bytes / 1073741824
                size = '%.2fG' % gigabytes
            elif bytes >= 1048576:
                megabytes = bytes / 1048576
                size = '%.2fM' % megabytes
            elif bytes >= 1024:
                kilobytes = bytes / 1024
                size = '%.2fK' % kilobytes
            else:
                size = '%.2fb' % bytes
            return size

        # Split vnstat data into array
        def get_traffic_data(dataType, dataValue, vn):
            line = ''
            for item in vn.split("\n"):
                if "%s;%d;" % (dataType, dataValue) in item:
                    line = item.strip().split(';')
                    break
            return line

        # convert MiB and KiB into KB
        def cb(mib, kib):
            return (int(mib) * 1000000) + (int(kib) * 1000)

        """
        Get the details to display and place them as properties which are passed to
        the theme
        """

        if self.use_vnstat is False:
            bootup = datetime.datetime.fromtimestamp(
                int(gtop.uptime().boot_time)).strftime('%d.%m.%y %H:%M')
            sd = gtop.netload(self.networkdevice)
            properties["sdn"] = "DL: " + convert_bytes(sd.bytes_in)
            properties["sup"] = "UL: " + convert_bytes(sd.bytes_out)
            properties["des1"] = "Traffic since: " + bootup
            properties["title"] = self.networkdevice + " Traffic"

        else:
            vnstat, vn = g15os.get_command_output('vnstat -i ' +
                                                  self.networkdevice +
                                                  ' --dumpdb')
            if vnstat != 0:
                properties["message"] = "vnstat is not installed!"
            else:
                chErr = str(vn.find("Error"))
                if chErr != "-1":
                    properties[
                        "message"] = "No stats for device " + self.networkdevice
                else:
                    properties["title"] = self.networkdevice + " Traffic (U/D)"

                    def get_data(kind, period):
                        # get vnstat data as array, array content: 2 = unixtime, 4 = up MiB, 6 = up KiB, 3 = dn MiB, 5 = dn KiB
                        line = get_traffic_data(kind, period, vn)
                        if line[7] == '1':
                            up = convert_bytes(cb(line[4], line[6]))
                            dn = convert_bytes(cb(line[3], line[5]))
                            des = int(line[2])
                            return [up, dn, des]
                        else:
                            return None

                    if self.loadpage == 'vnstat_daily':
                        k = "d"
                        fmt = '%A'
                    elif self.loadpage == 'vnstat_monthly':
                        k = "m"
                        fmt = '%B'

                    for p in range(0, 3):
                        data = get_data(k, p)
                        if data is not None:
                            properties["d"] = "/"
                            properties["dup" + str(p + 1)] = data[0]
                            properties["ddn" + str(p + 1)] = data[1]
                            properties[
                                "des" +
                                str(p + 1)] = datetime.datetime.fromtimestamp(
                                    data[2]).strftime(fmt)

        return properties
Exemple #6
0
    def get_theme_properties(self):
        properties = { }

        def convert_bytes(bytes):
            bytes = float(bytes)
            if bytes >= 1099511627776:
                terabytes = bytes / 1099511627776
                size = '%.2fT' % terabytes
            elif bytes >= 1073741824:
                gigabytes = bytes / 1073741824
                size = '%.2fG' % gigabytes
            elif bytes >= 1048576:
                megabytes = bytes / 1048576
                size = '%.2fM' % megabytes
            elif bytes >= 1024:
                kilobytes = bytes / 1024
                size = '%.2fK' % kilobytes
            else:
                size = '%.2fb' % bytes
            return size

        # Split vnstat data into array
        def get_traffic_data(dataType, dataValue, vn):
            line=''
            for item in vn.split("\n"):
                if "%s;%d;" % (dataType, dataValue) in item:
                    line = item.strip().split(';')
                    break
            return line

        # convert MiB and KiB into KB
        def cb(mib, kib):
            return (int(mib) * 1000000) + (int(kib) * 1000)

        '''
        Get the details to display and place them as properties which are passed to
        the theme
        '''

        if self.use_vnstat is False:
            bootup = datetime.datetime.fromtimestamp(int(gtop.uptime().boot_time)).strftime('%d.%m.%y %H:%M')
            sd = gtop.netload(self.networkdevice)
            properties["sdn"] = "DL: " +convert_bytes(sd.bytes_in)
            properties["sup"] = "UL: " +convert_bytes(sd.bytes_out)
            properties["des1"] = "Traffic since: " +bootup
            properties["title"] = self.networkdevice + " Traffic"

        else:
            vnstat, vn = g15os.get_command_output('vnstat -i ' + self.networkdevice + ' --dumpdb')
            if vnstat != 0:
                properties["message"] = "vnstat is not installed!"
            else:
                chErr = str(vn.find("Error"));
                if chErr != "-1":
                    properties["message"] = "No stats for device " + self.networkdevice
                else:
                    properties["title"] = self.networkdevice +" Traffic (U/D)"

                    def get_data(kind, period):
                        # get vnstat data as array, array content: 2 = unixtime, 4 = up MiB, 6 = up KiB, 3 = dn MiB, 5 = dn KiB
                        line = get_traffic_data(kind, period, vn)
                        if line[7] == '1':
                            up = convert_bytes(cb(line[4], line[6]))
                            dn = convert_bytes(cb(line[3], line[5]))
                            des = int(line[2])
                            return [up, dn, des]
                        else:
                            return None

                    if self.loadpage == 'vnstat_daily':
                        k = "d"
                        fmt = '%A'
                    elif self.loadpage == 'vnstat_monthly':
                        k = "m"
                        fmt = '%B'

                    for p in range(0,3):
                        data = get_data(k,p)
                        if data is not None:
                            properties["d"] = "/"
                            properties["dup" + str(p + 1)] = data[0]
                            properties["ddn" + str(p + 1)] = data[1]
                            properties["des" + str(p + 1)] = datetime.datetime.fromtimestamp(data[2]).strftime(fmt)

        return properties
Exemple #7
0
def execute_for_output(cmd):
    return g15os.get_command_output(cmd)
Exemple #8
0
def get_command_output(cmd):
    return g15os.get_command_output(cmd)