python类Variant()的实例源码

display-config.py 文件源码 项目:display-config 作者: xytovl 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def configure(self, output_requests, persistent=False):
        outputs, crtcs = self._configure(output_requests, [], [])
        params = GLib.Variant('(uba(uiiiuaua{sv})a(ua{sv}))',
                              (self.serial, persistent, crtcs, outputs))
        res = self.proxy.call('ApplyConfiguration', params,
                              Gio.DBusConnectionFlags.NONE, -1, None, None)
        if res is not None:
            print(res)
test_ble.py 文件源码 项目:coiotd 作者: coiot-ble 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def aio_offset(i):
    if i is None:
        return {}
    return {'offset': GLib.Variant('q', i)}
device.py 文件源码 项目:coiotd 作者: coiot-ble 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def readwrite_param(Cls, offset):
        if offset is None:
            return {}
        else:
            return {"offset": GLib.Variant('q', offset)}
main.py 文件源码 项目:pytimetrack 作者: fhackerz 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def fallback_set_accels(self, detailed_action_name, accels):
        if '::' in detailed_action_name:
            action_name, parameter = detailed_action_name.split('::', 1)
            parameter = GLib.Variant('s', parameter)
        else:
            action_name, parameter = detailed_action_name, None
        for accel in accels:
            self.add_accelerator(accel, action_name, parameter)
main.py 文件源码 项目:pytimetrack 作者: fhackerz 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def activate(self, action, value):
        new_state = not action.get_state().unpack()
        action.set_state(GLib.Variant(self.type_name, new_state))
        self.obj.set_property(self.property_name, new_state)
main.py 文件源码 项目:pytimetrack 作者: fhackerz 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def changed(self, widget, param_spec):
        new_value = self.obj.get_property(self.property_name)
        new_state = GLib.Variant(self.type_name, new_value)
        if self.action.get_state() != new_state:
            self.action.set_state(new_state)
main.py 文件源码 项目:pytimetrack 作者: fhackerz 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def virtual_midnight_set(self, *args):
        try:
            vm = parse_time(self.virtual_midnight_entry.get_text())
        except ValueError:
            self.virtual_midnight_changed()
        else:
            h, m = self.gsettings.get_value('virtual-midnight')
            if (h, m) != (vm.hour, vm.minute):
                self.gsettings.set_value('virtual-midnight', GLib.Variant('(ii)', (vm.hour, vm.minute)))
settings.py 文件源码 项目:Icon-Requests 作者: bil-elmoussaoui 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def set_window_postion(self, position):
        position = GLib.Variant('ai', list(position))
        self.set_value('window-position', position)
mpris.py 文件源码 项目:cozy 作者: geigi 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def on_method_call(self,
                       connection,
                       sender,
                       object_path,
                       interface_name,
                       method_name,
                       parameters,
                       invocation):

        args = list(parameters.unpack())
        for i, sig in enumerate(self.method_inargs[method_name]):
            if sig is "h":
                msg = invocation.get_message()
                fd_list = msg.get_unix_fd_list()
                args[i] = fd_list.get(args[i])

        try:
            result = getattr(self, method_name)(*args)

            # out_args is atleast (signature1).
            # We therefore always wrap the result as a tuple.
            # Refer to https://bugzilla.gnome.org/show_bug.cgi?id=765603
            result = (result,)

            out_args = self.method_outargs[method_name]
            if out_args != "()":
                variant = GLib.Variant(out_args, result)
                invocation.return_value(variant)
            else:
                invocation.return_value(None)
        except:
            pass
mpris.py 文件源码 项目:cozy 作者: geigi 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def Seeked(self, position):
        self.__bus.emit_signal(
            None,
            self.__MPRIS_PATH,
            self.__MPRIS_PLAYER_IFACE,
            "Seeked",
            GLib.Variant.new_tuple(GLib.Variant("x", position)))
mpris.py 文件源码 项目:cozy 作者: geigi 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def Get(self, interface, property_name):
        if property_name in ["CanQuit", "CanRaise", "CanSeek",
                             "CanControl", "HasRatingsExtension"]:
            return GLib.Variant("b", True)
        elif property_name == "HasTrackList":
            return GLib.Variant("b", False)
        elif property_name == "Identity":
            return GLib.Variant("s", "Cozy")
        elif property_name == "DesktopEntry":
            return GLib.Variant("s", "com.github.geigi.cozy")
        elif property_name == "SupportedUriSchemes":
            return GLib.Variant("as", ["file"])
        elif property_name == "SupportedMimeTypes":
            return GLib.Variant("as", ["application/ogg",
                                       "audio/x-vorbis+ogg",
                                       "audio/x-flac",
                                       "audio/mpeg"])
        elif property_name == "PlaybackStatus":
            return GLib.Variant("s", self.__get_status())
        elif property_name == "Metadata":
            return GLib.Variant("a{sv}", self.__metadata)
        elif property_name == "Position":
            return GLib.Variant(
                "x",
                get_current_duration())
        elif property_name in ["CanGoNext", "CanGoPrevious",
                               "CanPlay", "CanPause"]:
            return GLib.Variant("b", get_current_track() is not None)
mpris.py 文件源码 项目:cozy 作者: geigi 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __get_media_id(self, track_id):
        """
            TrackId's must be unique even up to
            the point that if you repeat a song
            it must have a different TrackId.
        """
        track_id = track_id + randint(10000000, 90000000)
        return GLib.Variant("o", "/de/geigi/Cozy/TrackId/%s" % track_id)
mpris.py 文件源码 项目:cozy 作者: geigi 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __update_metadata(self):
        track = get_current_track()
        if self.__get_status() == "Stopped":
            self.__metadata = {"mpris:trackid": GLib.Variant(
                "o",
                "/org/mpris/MediaPlayer2/TrackList/NoTrack")}
        else:
            self.__metadata["mpris:trackid"] = self.__track_id
            track_number = track.number
            if track_number is None:
                track_number = 1
            self.__metadata["xesam:trackNumber"] = GLib.Variant("i",
                                                                track_number)
            self.__metadata["xesam:title"] = GLib.Variant(
                "s",
                track.name)
            self.__metadata["xesam:album"] = GLib.Variant(
                "s",
                track.book.name)
            self.__metadata["xesam:artist"] = GLib.Variant(
                "s",
                track.book.author)
            self.__metadata["mpris:length"] = GLib.Variant(
                "x",
                track.length * 1000 * 1000)
            self.__metadata["xesam:url"] = GLib.Variant(
                "s",
                "file:///" + track.file)

            cover_path = "/tmp/cozy_mpris.jpg"
            pixbuf = get_cover_pixbuf(track.book)
            if pixbuf is not None:
                pixbuf.savev(cover_path, "jpeg",
                             ["quality"], ["90"])
            if cover_path is not None:
                self.__metadata["mpris:artUrl"] = GLib.Variant(
                    "s",
                    "file://" + cover_path)
mpris.py 文件源码 项目:cozy 作者: geigi 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __on_status_changed(self, data=None):
        properties = {"PlaybackStatus": GLib.Variant("s", self.__get_status())}
        self.PropertiesChanged(self.__MPRIS_PLAYER_IFACE, properties, [])
hunspell_table.py 文件源码 项目:ibus-typing-booster 作者: mike-fabian 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def set_current_imes(self, imes, update_dconf=True):
        '''Set current list of input methods

        :param imes: List of input methods
        :type imes: List of strings
        :param update_dconf: Whether to write the change to dconf.
                             Set this to False if this method is
                             called because the dconf key changed
                             to avoid endless loops when the dconf
                             key is changed twice in a short time.
        :type update_dconf: boolean
        '''
        if imes == self._current_imes: # nothing to do
            return
        if len(imes) > self._current_imes_max:
            sys.stderr.write(
                'Trying to set more than the allowed maximum of %s '
                %self._current_imes_max
                + 'input methods.\n'
                + 'Trying to set: %s\n' %imes
                + 'Really setting: %s\n' %imes[:self._current_imes_max])
            imes = imes[:self._current_imes_max]
        if set(imes) != set(self._current_imes):
            # Input methods have been added or removed from the list
            # of current input methods. Initialize the
            # transliterators. If only the order of the input methods
            # has changed, initialising the transliterators is not
            # necessary (and neither is updating the transliterated
            # strings necessary).
            self._current_imes = imes
            self._init_transliterators()
        else:
            self._current_imes = imes
        self._update_preedit_ime_menu_dicts()
        self._init_or_update_property_menu_preedit_ime(
            self.preedit_ime_menu, current_mode=0)
        if not self.is_empty():
            self._update_ui()
        if self._remember_last_used_preedit_ime and update_dconf:
            self._config.set_value(
                self._config_section,
                'inputmethod',
                GLib.Variant.new_string(','.join(imes)))
proxyzap.py 文件源码 项目:proxyzap 作者: uggla 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def set_proxy_settings(self, mode):
        '''
        Set proxy values

        :param mode: "manual" or "none"
        :type mode: str

        '''
        gsettings = Gio.Settings.new("org.gnome.system.proxy")
        gsettings.set_value(
                "mode",
                GLib.Variant('s', mode))
        msg = "Proxy has been set to %s" % mode
        notify(msg)
        logger.info(msg)

        if mode == 'manual':
            if self.proxy_ignore != self.PROXYIGNORE:
                # GLib.Variant('as', ['localhost', '127.0.0.0/8', '::1'])
                gsettings = Gio.Settings.new("org.gnome.system.proxy")
                gsettings.set_value(
                        "ignore-hosts",
                        GLib.Variant('as', self.PROXYIGNORE))

            if self.proxy_http_url != self.PROXY:
                gsettings = Gio.Settings.new("org.gnome.system.proxy.http")
                gsettings.set_value(
                        "host",
                        GLib.Variant('s', self.PROXY))
                gsettings.set_value(
                        "port",
                        GLib.Variant('i', self.PROXYPORT))
                gsettings = Gio.Settings.new("org.gnome.system.proxy.https")
                gsettings.set_value(
                        "host",
                        GLib.Variant('s', self.PROXY))
                gsettings.set_value(
                        "port",
                        GLib.Variant('i', self.PROXYPORT))
                gsettings = Gio.Settings.new("org.gnome.system.proxy.ftp")
                gsettings.set_value(
                        "host",
                        GLib.Variant('s', self.PROXY))
                gsettings.set_value(
                        "port",
                        GLib.Variant('i', self.PROXYPORT))
                logger.debug("Values : PROXY: %s, PORT: %s" % (
                        self.PROXY,
                        self.PROXYPORT))
                logger.debug("Ignoring proxy for : %s" % (str.join(
                    ',', self.PROXYIGNORE)))

        self.get_proxy_settings()
main.py 文件源码 项目:pytimetrack 作者: fhackerz 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def load_settings(self):
        self.gsettings = Gio.Settings.new("org.gtimelog")
        self.gsettings.bind('detail-level', self, 'detail-level', Gio.SettingsBindFlags.DEFAULT)
        self.gsettings.bind('show-task-pane', self.task_pane, 'visible', Gio.SettingsBindFlags.DEFAULT)
        self.gsettings.bind('hours', self.log_view, 'hours', Gio.SettingsBindFlags.DEFAULT)
        self.gsettings.bind('office-hours', self.log_view, 'office-hours', Gio.SettingsBindFlags.DEFAULT)
        self.gsettings.bind('name', self.report_view, 'name', Gio.SettingsBindFlags.DEFAULT)
        self.gsettings.bind('sender', self.sender_entry, 'text', Gio.SettingsBindFlags.DEFAULT)
        self.gsettings.bind('list-email', self.recipient_entry, 'text', Gio.SettingsBindFlags.DEFAULT)
        self.gsettings.bind('report-style', self.report_view, 'report-style', Gio.SettingsBindFlags.DEFAULT)
        self.gsettings.bind('remote-task-list', self.app.actions.refresh_tasks, 'enabled', Gio.SettingsBindFlags.DEFAULT)
        self.gsettings.bind('gtk-completion', self.task_entry, 'gtk-completion-enabled', Gio.SettingsBindFlags.DEFAULT)
        self.gsettings.connect('changed::remote-task-list', self.load_tasks)
        self.gsettings.connect('changed::task-list-url', self.load_tasks)
        self.gsettings.connect('changed::task-list-edit-url', self.update_edit_tasks_availability)
        self.gsettings.connect('changed::virtual-midnight', self.virtual_midnight_changed)
        self.update_edit_tasks_availability()

        x, y = self.gsettings.get_value('window-position')
        w, h = self.gsettings.get_value('window-size')
        tpp = self.gsettings.get_int('task-pane-position')
        self.resize(w, h)
        if (x, y) != (-1, -1):
            self.move(x, y)
        self.paned.set_position(tpp)
        self.paned.connect('notify::position', self.delay_store_window_size)
        self.connect("configure-event", self.delay_store_window_size)

        if not self.gsettings.get_boolean('settings-migrated'):
            old_settings = Settings()
            old_settings.load()
            if old_settings.summary_view:
                self.gsettings.set_string('detail-level', 'summary')
            elif old_settings.chronological:
                self.gsettings.set_string('detail-level', 'chronological')
            else:
                self.gsettings.set_string('detail-level', 'grouped')
            self.gsettings.set_boolean('show-task-pane', old_settings.show_tasks)
            self.gsettings.set_double('hours', old_settings.hours)
            self.gsettings.set_double('office-hours', old_settings.office_hours)
            self.gsettings.set_string('name', old_settings.name)
            self.gsettings.set_string('sender', old_settings.sender)
            self.gsettings.set_string('list-email', old_settings.email)
            self.gsettings.set_string('report-style', old_settings.report_style)
            self.gsettings.set_string('task-list-url', old_settings.task_list_url)
            self.gsettings.set_boolean('remote-task-list', bool(old_settings.task_list_url))
            for arg in old_settings.edit_task_list_cmd.split():
                if arg.startswith(('http://', 'https://')):
                    self.gsettings.set_string('task-list-edit-url', arg)
            vm = old_settings.virtual_midnight
            self.gsettings.set_value('virtual-midnight', GLib.Variant('(ii)', (vm.hour, vm.minute)))
            self.gsettings.set_boolean('gtk-completion', bool(old_settings.enable_gtk_completion))
            self.gsettings.set_boolean('settings-migrated', True)
            log.info(_('Settings from {filename} migrated to GSettings (org.gtimelog)').format(filename=old_settings.get_config_file()))

        mark_time('settings loaded')


问题


面经


文章

微信
公众号

扫码关注公众号