当前位置: 首页>>代码示例>>Python>>正文


Python Signal.emit方法代码示例

本文整理汇总了Python中pyanaconda.core.signal.Signal.emit方法的典型用法代码示例。如果您正苦于以下问题:Python Signal.emit方法的具体用法?Python Signal.emit怎么用?Python Signal.emit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyanaconda.core.signal.Signal的用法示例。


在下文中一共展示了Signal.emit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: InputField

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]
class InputField(object):
    """An input field containing data to be checked.

    The input field can have an initial value that can be
    monitored for change via signals.
    """

    def __init__(self, initial_content):
        self._initial_content = initial_content
        self._content = initial_content
        self.changed = Signal()
        self._initial_change_signal_fired = False
        self.changed_from_initial_state = Signal()

    @property
    def content(self):
        return self._content

    @content.setter
    def content(self, new_content):
        old_content = self._content
        self._content = new_content
        # check if the input changed from the initial state
        if old_content != new_content:
            self.changed.emit()
            # also fire the changed-from-initial-state signal if required
            if not self._initial_change_signal_fired and new_content != self._initial_content:
                self.changed_from_initial_state.emit()
                self._initial_change_signal_fired = True
开发者ID:rvykydal,项目名称:anaconda,代码行数:31,代码来源:input_checking.py

示例2: clear_test

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]
    def clear_test(self):
        """Test if the clear() method correctly clears any connected callbacks."""
        def set_var(value):
            self.var = value

        signal = Signal()
        foo = FooClass()
        lambda_foo = FooClass()
        self.assertIsNone(foo.var)
        self.assertIsNone(lambda_foo.var)
        self.assertIsNone(self.var)
        # connect the callbacks
        signal.connect(set_var)
        signal.connect(foo.set_var)
        # pylint: disable=unnecessary-lambda
        signal.connect(lambda x: lambda_foo.set_var(x))
        # trigger the signal
        signal.emit("bar")
        # check that the callbacks were triggered
        self.assertEqual(self.var, "bar")
        self.assertEqual(foo.var, "bar")
        self.assertEqual(lambda_foo.var, "bar")
        # clear the callbacks
        signal.clear()
        # trigger the signal again
        signal.emit("anaconda")
        # check that the callbacks were not triggered
        self.assertEqual(self.var, "bar")
        self.assertEqual(foo.var, "bar")
        self.assertEqual(lambda_foo.var, "bar")
开发者ID:rvykydal,项目名称:anaconda,代码行数:32,代码来源:signal_test.py

示例3: Test3Implementation

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]
    class Test3Implementation(object):

        def __init__(self):
            self.module_properties_changed = Signal()
            self.a_changed = Signal()
            self.b_changed = Signal()

            self._a = 1
            self._b = 2

        @property
        def a(self):
            return self._a

        def set_a(self, a):
            self._a = a
            self.a_changed.emit()

        @property
        def b(self):
            return self._b

        @b.setter
        def b(self, b):
            self._b = b
            self.b_changed.emit()

        def do_external_changes(self, a, b):
            self.set_a(a)
            self.b = b

        def do_secret_changes(self, a, b):
            self._a = a
            self._b = b
开发者ID:rvykydal,项目名称:anaconda,代码行数:36,代码来源:dbus_property_test.py

示例4: CheckResult

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]
class CheckResult(object):
    """Result of an input check."""

    def __init__(self):
        self._success = False
        self._error_message = ""
        self.error_message_changed = Signal()

    @property
    def success(self):
        return self._success

    @success.setter
    def success(self, value):
        self._success = value

    @property
    def error_message(self):
        """Optional error message describing why the input is not valid.

        :returns: why the input is bad (provided it is bad) or None
        :rtype: str or None
        """
        return self._error_message

    @error_message.setter
    def error_message(self, new_error_message):
        self._error_message = new_error_message
        self.error_message_changed.emit(new_error_message)
开发者ID:rvykydal,项目名称:anaconda,代码行数:31,代码来源:input_checking.py

示例5: signal_chain_test

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]
 def signal_chain_test(self):
     """Check if signals can be chained together."""
     foo = FooClass()
     self.assertIsNone(foo.var)
     signal1 = Signal()
     signal1.connect(foo.set_var)
     signal2 = Signal()
     signal2.connect(signal1.emit)
     signal3 = Signal()
     signal3.connect(signal2.emit)
     # trigger the chain
     signal3.emit("bar")
     # check if the initial callback was triggered
     self.assertEqual(foo.var, "bar")
开发者ID:rvykydal,项目名称:anaconda,代码行数:16,代码来源:signal_test.py

示例6: UserModule

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]
class UserModule(KickstartBaseModule):
    """The user module."""

    def __init__(self):
        super().__init__()

        self.name_changed = Signal()
        self._name = ""

    # pylint: disable=arguments-differ
    def process_kickstart(self, data, user_data=None):
        """Process the kickstart data."""
        if not user_data:
            return

        self.set_name(user_data.name)

    def setup_kickstart(self, data):
        """Setup the kickstart data."""
        user_data = data.UserData()
        user_data.name = self.name

        data.user.userList.append(user_data)
        return data

    @property
    def name(self):
        """Name of the user."""
        return self._name

    def set_name(self, name):
        """Set a name of the user.

        :param name: a name
        """
        self._name = name
        self.name_changed.emit()
        log.debug("User name is set to '%s'.", name)
开发者ID:rvykydal,项目名称:anaconda,代码行数:40,代码来源:user.py

示例7: method_test

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]
 def method_test(self):
     """Test if a method can be correctly connected to a signal."""
     signal = Signal()
     foo = FooClass()
     self.assertIsNone(foo.var)
     # connect the signal
     signal.connect(foo.set_var)
     # trigger the signal
     signal.emit("bar")
     # check if the callback triggered correctly
     self.assertEqual(foo.var, "bar")
     # try to trigger the signal again
     signal.emit("baz")
     self.assertEqual(foo.var, "baz")
     # now try to disconnect the signal
     signal.disconnect(foo.set_var)
     # check that calling the signal again
     # no longer triggers the callback
     signal.emit("anaconda")
     self.assertEqual(foo.var, "baz")
开发者ID:rvykydal,项目名称:anaconda,代码行数:22,代码来源:signal_test.py

示例8: lambda_test

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]
 def lambda_test(self):
     """Test if a lambda can be correctly connected to a signal."""
     foo = FooClass()
     signal = Signal()
     self.assertIsNone(foo.var)
     # connect the signal
     # pylint: disable=unnecessary-lambda
     lambda_instance = lambda x: foo.set_var(x)
     signal.connect(lambda_instance)
     # trigger the signal
     signal.emit("bar")
     # check if the callback triggered correctly
     self.assertEqual(foo.var, "bar")
     # try to trigger the signal again
     signal.emit("baz")
     self.assertEqual(foo.var, "baz")
     # now try to disconnect the signal
     signal.disconnect(lambda_instance)
     # check that calling the signal again
     # no longer triggers the callback
     signal.emit("anaconda")
     self.assertEqual(foo.var, "baz")
开发者ID:rvykydal,项目名称:anaconda,代码行数:24,代码来源:signal_test.py

示例9: function_test

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]
    def function_test(self):
        """Test if a local function can be correctly connected to a signal."""

        # create a local function
        def set_var(value):
            self.var = value

        signal = Signal()
        self.assertIsNone(self.var)
        # connect the signal
        signal.connect(set_var)
        # trigger the signal
        signal.emit("bar")
        # check if the callback triggered correctly
        self.assertEqual(self.var, "bar")
        # try to trigger the signal again
        signal.emit("baz")
        self.assertEqual(self.var, "baz")
        # now try to disconnect the signal
        signal.disconnect(set_var)
        # check that calling the signal again
        # no longer triggers the callback
        signal.emit("anaconda")
        self.assertEqual(self.var, "baz")
开发者ID:rvykydal,项目名称:anaconda,代码行数:26,代码来源:signal_test.py

示例10: Runnable

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]
class Runnable(ABC):
    """Abstract class that allows to run a task."""

    def __init__(self):
        super().__init__()
        self._started_signal = Signal()
        self._stopped_signal = Signal()
        self._failed_signal = Signal()

    @property
    def started_signal(self):
        """Signal emitted when the task starts."""
        return self._started_signal

    @property
    def stopped_signal(self):
        """Signal emitted when the task stops."""
        return self._stopped_signal

    @property
    def failed_signal(self):
        """Signal emitted when the task fails."""
        return self._failed_signal

    @property
    @abstractmethod
    def is_running(self):
        """Is the task running."""
        return False

    @abstractmethod
    def start(self):
        """Start the task run.

        Your task should run the following callbacks:

            self._task_started_callback
            self._task_run_callback
            self._task_failed_callback
            self._task_stopped_callback

        Make sure that you call self._task_started_callback at the
        beginning of the task lifetime to inform that the task is
        running now. Run self._task_run_callback to do the actual
        job of the task.

        In a case of failure, call self._task_failed_callback to
        inform that the task has failed. You will still need to
        call also self._task_stopped_callback.

        Make sure that you always call self._task_stopped_callback
        at the end of the task lifetime to inform that the task is
        not running anymore.
        """
        pass

    @async_action_nowait
    def _task_started_callback(self):
        """Callback for a started task."""
        self._started_signal.emit()

    @abstractmethod
    def _task_run_callback(self):
        """Run the task."""
        pass

    @async_action_nowait
    def _task_failed_callback(self):
        """Callback for a failed task."""
        self._failed_signal.emit()

    @async_action_nowait
    def _task_stopped_callback(self):
        """Callback for a terminated task."""
        self._stopped_signal.emit()

    @abstractmethod
    def finish(self):
        """Finish the task run.

        This method should be called after the task was started and stopped.
        Re-raise any exception that was raised during the task run and wasn't
        propagated by the self.start method.
        """
        pass
开发者ID:zhangsju,项目名称:anaconda,代码行数:87,代码来源:runnable.py

示例11: AutoPartitioningModule

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]

#.........这里部分代码省略.........

        data.autopart.autopart = self.enabled
        data.autopart.fstype = self.fstype

        if self.type != AutoPartitioningType.DEFAULT:
            data.autopart.type = self.type.value

        data.autopart.nohome = self.nohome
        data.autopart.noboot = self.noboot
        data.autopart.noswap = self.noswap

        data.autopart.encrypted = self.encrypted
        data.autopart.passphrase = self.passphrase
        data.autopart.luks_version = self.luks_version
        data.autopart.pbkdf = self.pbkdf
        data.autopart.pbkdf_memory = self.pbkdf_memory
        data.autopart.pbkdf_time = self.pbkdf_time
        data.autopart.pbkdf_iterations = self.pbkdf_iterations
        data.autopart.escrowcert = self.escrowcert
        data.autopart.backuppassphrase = self.backup_passphrase_enabled
        data.autopart.cipher = self.cipher

    @property
    def enabled(self):
        """Is the auto partitioning enabled?"""
        return self._enabled

    def set_enabled(self, enabled):
        """Is the auto partitioning enabled?

        :param enabled: a boolean value
        """
        self._enabled = enabled
        self.enabled_changed.emit()
        log.debug("Enabled is set to '%s'.", enabled)

    @property
    def type(self):
        """Type of a filesystem used on the partitions."""
        return self._type

    def set_type(self, scheme):
        """Set the partitioning scheme.

        :param scheme: an instance of AutoPartitioningType
        """
        self._type = scheme
        self.type_changed.emit()
        log.debug("Type is set to '%s'.", scheme)

    @property
    def fstype(self):
        """Type of a filesystem used on the partitions."""
        return self._fstype

    def set_fstype(self, fstype):
        """Set the type of a filesystem used on the partitions.

        :param fstype: a string with the filesystem type
        """
        self._fstype = fstype
        self.fstype_changed.emit()
        log.debug("Filesystem type is set to '%s'.", fstype)

    @property
    def nohome(self):
开发者ID:zhangsju,项目名称:anaconda,代码行数:70,代码来源:automatic.py

示例12: DiskInitializationModule

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]

#.........这里部分代码省略.........
        data.clearpart.drives = drives

    def _map_clearpart_type(self, value, reverse=False):
        """Convert the clearpart type to the initialization mode.

        :param value: a value to convert
        :param reverse: reverse the direction
        :return: a converted value
        """
        mapping = {
            None: InitializationMode.DEFAULT,
            CLEARPART_TYPE_NONE: InitializationMode.CLEAR_NONE,
            CLEARPART_TYPE_ALL: InitializationMode.CLEAR_ALL,
            CLEARPART_TYPE_LIST: InitializationMode.CLEAR_LIST,
            CLEARPART_TYPE_LINUX: InitializationMode.CLEAR_LINUX
        }

        if reverse:
            mapping = {v: k for k, v in mapping.items()}

        return mapping[value]

    @property
    def initialization_mode(self):
        """The initialization mode."""
        return self._initialization_mode

    def set_initialization_mode(self, mode):
        """Set the initialization mode.

        :param mode: an instance of InitializationMode
        """
        self._initialization_mode = mode
        self.initialization_mode_changed.emit()
        log.debug("The initialization mode is set to '%s'.", mode)

    @property
    def devices_to_clear(self):
        """The list of devices to clear."""
        return self._devices_to_clear

    def set_devices_to_clear(self, devices):
        """Set the list of devices to clear.

        :param devices: a list of devices names
        """
        self._devices_to_clear = devices
        self.devices_to_clear_changed.emit()
        log.debug("Devices to clear are set to '%s'.", devices)

    @property
    def drives_to_clear(self):
        """The list of drives to clear."""
        return self._drives_to_clear

    def set_drives_to_clear(self, drives):
        """Set the list of drives to clear.

        :param drives: a list of drive names
        """
        self._drives_to_clear = drives
        self.drives_to_clear_changed.emit()
        log.debug("Drives to clear are set to '%s'.", drives)

    @property
    def default_disk_label(self):
开发者ID:rvykydal,项目名称:anaconda,代码行数:70,代码来源:initialization.py

示例13: BootloaderModule

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]

#.........这里部分代码省略.........
            data.bootloader.location = False
            data.bootloader.location = "partition"
        else:
            data.bootloader.location = False
            data.bootloader.location = None

        data.bootloader.bootDrive = self.drive
        data.bootloader.driveorder = self.drive_order
        data.bootloader.nombr = self.keep_mbr
        data.bootloader.leavebootorder = self.keep_boot_order
        data.bootloader.appendLine = " ".join(self.extra_arguments)

        if self.timeout == BOOTLOADER_TIMEOUT_UNSET:
            data.bootloader.timeout = None
        else:
            data.bootloader.timeout = self.timeout

        data.bootloader.password = self.password
        data.bootloader.isCrypted = self.password_is_encrypted

        return data

    @property
    def bootloader_mode(self):
        """The mode of the bootloader."""
        return self._bootloader_mode

    def set_bootloader_mode(self, mode):
        """Set the type of the bootloader.

        :param mode: an instance of BootloaderMode
        """
        self._bootloader_mode = mode
        self.bootloader_mode_changed.emit()
        log.debug("Bootloader mode is set to '%s'.", mode)

    @property
    def bootloader_type(self):
        """The type of the bootloader."""
        return self._bootloader_type

    def set_bootloader_type(self, bootloader_type):
        """Set the type of the bootloader.

        :param bootloader_type: an instance of BootloaderType
        """
        self._bootloader_type = bootloader_type
        self.bootloader_type_changed.emit()
        log.debug("Bootloader type is set to '%s'.", bootloader_type)

    @property
    def preferred_location(self):
        """Where the boot record is written."""
        return self._preferred_location

    def set_preferred_location(self, location):
        """Specify where the boot record is written.

        Supported values: DEFAULT, MBR, PARTITION

        :param location: a string with the location
        """
        self._preferred_location = location
        self.preferred_location_changed.emit()
        log.debug("Preferred location is set to '%s'.", location)
开发者ID:zhangsju,项目名称:anaconda,代码行数:69,代码来源:bootloader.py

示例14: KickstartModule

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]
class KickstartModule(MainModule, KickstartBaseModule):
    """Implementation of a main kickstart module.

    The main kickstart module is able to parse and generate the given
    kickstart string based on its kickstart specification.
    """

    def __init__(self):
        super().__init__()
        self.kickstarted_changed = Signal()
        self._kickstarted = False

    @property
    def kickstart_specification(self):
        """Return a kickstart specification.

        Every kickstart module that is interested in processing
        kickstart files, should provide its own specification.

        :return: a subclass of KickstartSpecification
        """
        return NoKickstartSpecification

    @property
    def kickstart_command_names(self):
        """Return a list of kickstart command names."""
        return list(self.kickstart_specification.commands.keys())

    @property
    def kickstart_section_names(self):
        """Return a list of kickstart section names."""
        return list(self.kickstart_specification.sections.keys())

    @property
    def kickstart_addon_names(self):
        """Return a list of kickstart addon names."""
        # TODO: We need to add support for addons.
        return list()

    @property
    def kickstarted(self):
        """Was this module set up by the kickstart?"""
        return self._kickstarted

    @kickstarted.setter
    def kickstarted(self, value):
        self._kickstarted = value
        self.kickstarted_changed.emit()
        log.debug("Kickstarted is set to %s.", value)

    def get_kickstart_handler(self):
        """Return a kickstart handler.

        :return: a kickstart handler
        """
        return KickstartSpecificationHandler(self.kickstart_specification)

    def get_kickstart_parser(self, handler):
        """Return a kickstart parser.

        :param handler: a kickstart handler
        :return: a kickstart parser
        """
        return KickstartSpecificationParser(handler, self.kickstart_specification)

    def read_kickstart(self, s):
        """Read the given kickstart string.

        The kickstart string should contain only commands and
        sections that are defined by the kickstart specification.

        :param s: a kickstart string
        :raises: instances of KickstartError
        """
        log.debug("Reading kickstart...")
        handler = self.get_kickstart_handler()
        parser = self.get_kickstart_parser(handler)

        parser.readKickstartFromString(s)
        self.process_kickstart(handler)
        self.kickstarted = True

    def generate_kickstart(self):
        """Return a kickstart representation of this module.

        The kickstart string should contain only commands and
        sections that are defined by the kickstart specification.

        :return: a kickstart string
        """
        handler = self.get_kickstart_handler()
        self.setup_kickstart(handler)
        return str(handler)

    def generate_temporary_kickstart(self):
        """Return a temporary kickstart representation of this module.

        Don't include kickstart commands temporarily unsupported in UI.

        :return: a kickstart string
#.........这里部分代码省略.........
开发者ID:rvykydal,项目名称:anaconda,代码行数:103,代码来源:base.py

示例15: Controller

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import emit [as 别名]
class Controller(object):
    """A singleton that track initialization of Anaconda modules."""
    def __init__(self):
        self._lock = RLock()
        self._modules = set()
        self._all_modules_added = False
        self.init_done = Signal()
        self._init_done_triggered = False
        self._added_module_count = 0

    @synchronized
    def module_init_start(self, module):
        """Tell the controller that a module has started initialization.

        :param module: a module which has started initialization
        """
        if self._all_modules_added:
            log.warning("Late module_init_start() from: %s", self)
        elif module in self._modules:
            log.warning("Module already marked as initializing: %s", module)
        else:
            self._added_module_count += 1
            self._modules.add(module)

    def all_modules_added(self):
        """Tell the controller that all expected modules have started initialization.

        Tell the controller that all expected modules have been registered
        for initialization tracking (or have already been initialized)
        and no more are expected to be added.

        This is needed so that we don't prematurely trigger the init_done signal
        when all known modules finish initialization while other modules have not
        yet been added.
        """
        init_done = False
        with self._lock:
            log.info("Initialization of all modules (%d) has been started.", self._added_module_count)
            self._all_modules_added = True

            # if all modules finished initialization before this was added then
            # trigger the init_done signal at once
            if not self._modules and not self._init_done_triggered:
                self._init_done_triggered = True
                init_done = True

        # we should emit the signal out of the main lock as it doesn't make sense
        # to hold the controller-state lock once we decide to the trigger init_done signal
        # (and any callbacks registered on it)
        if init_done:
            self._trigger_init_done()

    def module_init_done(self, module):
        """Tell the controller that a module has finished initialization.

        And if no more modules are being initialized trigger the init_done signal.

        :param module: a module that has finished initialization
        """
        init_done = False
        with self._lock:
            # prevent the init_done signal from
            # being triggered more than once
            if self._init_done_triggered:
                log.warning("Late module_init_done from module %s.", module)
            else:
                if module in self._modules:
                    log.info("Module initialized: %s", module)
                    self._modules.discard(module)
                else:
                    log.warning("Unknown module reported as initialized: %s", module)
                # don't trigger the signal if all modules have not yet been added
                if self._all_modules_added and not self._modules:
                    init_done = True
                    self._init_done_triggered = True

        # we should emit the signal out of the main lock as it doesn't make sense
        # to hold the controller-state lock once we decide to the trigger init_done signal
        # (and any callbacks registered on it)
        if init_done:
            self._trigger_init_done()

    def _trigger_init_done(self):
        log.info("All modules have been initialized.")
        self.init_done.emit()
开发者ID:rvykydal,项目名称:anaconda,代码行数:87,代码来源:lifecycle.py


注:本文中的pyanaconda.core.signal.Signal.emit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。