def __call__( self, instance, call_done_cb, call_error_cb, user_data, *args, **kwargs ): argdiff = len(args) - len(self._inargs) if argdiff != 0: dbg_args = { "instance": instance, "call_done_cb": call_done_cb, "call_error_cb": call_error_cb, "user_data": user_data, "args": args, "kwargs": kwargs, } if argdiff < 0: raise TypeError( self.__qualname__ + " missing {} required positional argument(s), expected: {}, given: {}".format( -argdiff, len(self._inargs), dbg_args ) ) elif argdiff > 0: raise TypeError( self.__qualname__ + " takes {} positional argument(s) but {} was/were given: {}".format( len(self._inargs), len(args), dbg_args ) ) timeout = kwargs.get("timeout", None) def done_cb(obj, res, data): try: ret = obj.call_finish(res) if call_done_cb: call_done_cb(instance, ret, data) except Exception as e: if call_error_cb: call_error_cb(instance, e, data) ret = instance._bus.con.call( instance._bus_name, instance._path, self._iface_name, self.__name__[0 : -len("Async")], Variant(self._sinargs, args), VariantType.new(self._soutargs), 0, timeout_to_glib(timeout), None, done_cb, user_data, ) return ret
def get_variant_type(type_hint): """Return a type of a variant data type. :param type_hint: a type hint or a type string :return: an instance of VariantType """ if type(type_hint) == str: type_string = type_hint else: type_string = get_dbus_type(type_hint) return VariantType.new(type_string)
def __init__(self, editor, renderer, preferences): super(EditorActionGroup, self).__init__() self.editor = editor self.renderer = renderer self.preferences = preferences self.editor_pref = preferences.editor self.create_stateful_action("period-save-toggle", 'b', self.editor_pref.period_save, self.on_period_save) self.create_stateful_action("check-spelling-toggle", 'b', self.editor_pref.check_spelling, self.on_check_spelling) action = SimpleAction.new("spell-lang", VariantType('s')) action.connect("activate", self.on_spell_lang) self.add_action(action) self.create_stateful_action("use-spaces-toggle", 'b', self.editor_pref.spaces_instead_of_tabs, self.on_use_spaces) self.create_stateful_action("tab-width", 'i', self.editor_pref.tab_width, self.on_tab_width) self.create_stateful_action("auto-indent-toggle", 'b', self.editor_pref.auto_indent, self.on_auto_indent) self.create_stateful_action("line-numbers-toggle", 'b', self.editor_pref.line_numbers, self.on_line_numbers) self.create_stateful_action("right-margin-toggle", 'b', self.editor_pref.right_margin, self.on_right_margin) self.create_stateful_action("current-line-toggle", 'b', self.editor_pref.current_line, self.on_current_line) self.create_stateful_action("text-wrapping-toggle", 'b', self.editor_pref.text_wrapping, self.on_text_wrapping) self.create_stateful_action("white-chars-toggle", 'b', self.editor_pref.white_chars, self.on_white_chars)
def do_startup(self): GtkApplication.do_startup(self) action = SimpleAction.new("new-window", None) action.connect("activate", self.on_new_window) self.add_action(action) action = SimpleAction.new("shortcuts", None) action.connect("activate", self.on_shortcuts) self.add_action(action) action = SimpleAction.new("about", None) action.connect("activate", self.on_about) self.add_action(action) action = SimpleAction.new("traceback", VariantType.new('s')) action.connect("activate", self.on_traceback) self.add_action(action) action = SimpleAction.new("quit", None) action.connect("activate", self.on_quit) self.add_action(action) self.set_app_menu(AppMenu())
def create_stateful_action(self, name, _type, default_value, method): action = SimpleAction.new_stateful(name, VariantType.new(_type), Variant(_type, default_value)) action.connect("change-state", method) self.add_action(action)