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


Python Signal.connect方法代码示例

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


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

示例1: method_test

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import connect [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

示例2: clear_test

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import connect [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: lambda_test

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import connect [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

示例4: function_test

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import connect [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

示例5: signal_chain_test

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import connect [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: Hub

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import connect [as 别名]
class Hub(object, metaclass=ABCMeta):
    """A Hub is an overview UI screen.  A Hub consists of one or more grids of
       configuration options that the user may choose from.  Each grid is
       provided by a SpokeCategory, and each option is provided by a Spoke.
       When the user dives down into a Spoke and is finished interacting with
       it, they are returned to the Hub.

       Some Spokes are required.  The user must interact with all required
       Spokes before they are allowed to proceed to the next stage of
       installation.

       From a layout perspective, a Hub is the entirety of the screen, though
       the screen itself can be roughly divided into thirds.  The top third is
       some basic navigation information (where you are, what you're
       installing).  The middle third is the grid of Spokes.  The bottom third
       is an action area providing additional buttons (quit, continue) or
       progress information (during package installation).

       Installation may consist of multiple chained Hubs, or Hubs with
       additional standalone screens either before or after them.
    """

    def __init__(self, storage, payload):
        """Create a new Hub instance.

           The arguments this base class accepts defines the API that Hubs
           have to work with.  A Hub does not get free reign over everything
           in the anaconda class, as that would be a big mess.  Instead, a
           Hub may count on the following:

           data         -- An instance of a pykickstart Handler object.  The
                           Hub uses this to populate its UI with defaults
                           and to pass results back after it has run. The data
                           property must be implemented by classes inheriting
                           from Hub.
           storage      -- An instance of storage.Storage.  This is useful for
                           determining what storage devices are present and how
                           they are configured.
           payload      -- An instance of a payload.Payload subclass.  This
                           is useful for displaying and selecting packages to
                           install, and in carrying out the actual installation.
        """
        self._storage = storage
        self.payload = payload

        self.paths = {}
        self._spokes = {}

        # entry and exit signals
        # - get the hub instance as a single argument
        self.entered = Signal()
        self.exited = Signal()

        # connect the default callbacks
        self.entered.connect(self.entry_logger)
        self.exited.connect(self.exit_logger)

    @abstractproperty
    def data(self):
        pass

    @property
    def storage(self):
        return self._storage

    def set_path(self, path_id, paths):
        """Update the paths attribute with list of tuples in the form (module
           name format string, directory name)"""
        self.paths[path_id] = paths

    def entry_logger(self, hub_instance):
        """Log immediately before this hub is about to be displayed on the
           screen.  Subclasses may override this method if they want to log
           more specific information, but an overridden method should finish
           by calling this method so the entry will be logged.

           Note that due to how the GUI flows, hubs are only entered once -
           when they are initially displayed.  Going to a spoke from a hub
           and then coming back to the hub does not count as exiting and
           entering.
        """
        log.debug("Entered hub: %s", hub_instance)

    def _collectCategoriesAndSpokes(self):
        """This method is provided so that is can be overridden in a subclass
           by a custom collect method.
           One example of such usage is the Initial Setup application.
        """
        return collectCategoriesAndSpokes(self.paths, self.__class__, self.data.displaymode.displayMode)

    def exit_logger(self, hub_instance):
        """Log when a user leaves the hub.  Subclasses may override this
           method if they want to log more specific information, but an
           overridden method should finish by calling this method so the
           exit will be logged.

           Note that due to how the GUI flows, hubs are not exited when the
           user selects a spoke from the hub.  They are only exited when the
           continue or quit button is clicked on the hub.
        """
#.........这里部分代码省略.........
开发者ID:rvykydal,项目名称:anaconda,代码行数:103,代码来源:common.py

示例7: Spoke

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import connect [as 别名]
class Spoke(object, metaclass=ABCMeta):
    """A Spoke is a single configuration screen.  There are several different
       places where a Spoke can be displayed, each of which will have its own
       unique class.  A Spoke is typically used when an element in the Hub is
       selected but can also be displayed before a Hub or between multiple
       Hubs.

       What amount of the UI layout a Spoke provides depends upon where it is
       to be shown.  Regardless, the UI of a Spoke should be given by an
       interface description file like glade as often as possible, though this
       is not a strict requirement.

       Class attributes:

       category   -- Under which SpokeCategory shall this Spoke be displayed
                     in the Hub?  This is a reference to a Hub subclass (not an
                     object, but the class itself).  If no category is given,
                     this Spoke will not be displayed.  Note that category is
                     not required for any Spokes appearing before or after a
                     Hub.
       icon       -- The name of the icon to be displayed in the SpokeSelector
                     widget corresponding to this Spoke instance.  If no icon
                     is given, the default from SpokeSelector will be used.
       title      -- The title to be displayed in the SpokeSelector widget
                     corresponding to this Spoke instance.  If no title is
                     given, the default from SpokeSelector will be used.
    """

    category = None
    icon = None
    title = None

    def __init__(self, storage, payload):
        """Create a new Spoke instance.

           The arguments this base class accepts defines the API that spokes
           have to work with.  A Spoke does not get free reign over everything
           in the anaconda class, as that would be a big mess.  Instead, a
           Spoke may count on the following:

           data         -- An instance of a pykickstart Handler object.  The
                           Spoke uses this to populate its UI with defaults
                           and to pass results back after it has run. The data
                           property must be implemented by classes inherting
                           from Spoke.
           storage      -- An instance of storage.Storage.  This is useful for
                           determining what storage devices are present and how
                           they are configured.
           payload      -- An instance of a payload.Payload subclass.  This
                           is useful for displaying and selecting packages to
                           install, and in carrying out the actual installation.
        """
        self._storage = storage
        self.payload = payload
        self.applyOnSkip = False

        self.visitedSinceApplied = True

        # entry and exit signals
        # - get the hub instance as a single argument
        self.entered = Signal()
        self.exited = Signal()

        # connect default callbacks for the signals
        self.entered.connect(self.entry_logger)
        self.entered.connect(self._mark_screen_visited)
        self.exited.connect(self.exit_logger)

    @abstractproperty
    def data(self):
        pass

    @property
    def storage(self):
        return self._storage

    @classmethod
    def should_run(cls, environment, data):
        """This method is responsible for beginning Spoke initialization.

           It should return True if the spoke is to be shown while in
           <environment> and False if it should be skipped.

           It might be called multiple times, with or without (None)
           the data argument.
        """
        return environment == ANACONDA_ENVIRON

    def apply(self):
        """Apply the selections made on this Spoke to the object's preset
           data object.  This method must be provided by every subclass.
        """
        raise NotImplementedError

    @property
    def changed(self):
        """Have the values on the spoke changed since the last time it was
           run?  If not, the apply and execute methods will be skipped.  This
           is to avoid the spoke doing potentially long-lived and destructive
           actions that are completely unnecessary.
#.........这里部分代码省略.........
开发者ID:rvykydal,项目名称:anaconda,代码行数:103,代码来源:common.py

示例8: StorageModule

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import connect [as 别名]
class StorageModule(KickstartModule):
    """The Storage module."""

    def __init__(self):
        super().__init__()
        # Initialize Blivet.
        enable_installer_mode()

        # The storage model.
        self._storage = None
        self.storage_changed = Signal()

        # Initialize modules.
        self._modules = []

        self._device_tree_module = DeviceTreeModule()
        self._add_module(self._device_tree_module)

        self._disk_init_module = DiskInitializationModule()
        self._add_module(self._disk_init_module)

        self._disk_selection_module = DiskSelectionModule()
        self._add_module(self._disk_selection_module)

        self._snapshot_module = SnapshotModule()
        self._add_module(self._snapshot_module)

        self._bootloader_module = BootloaderModule()
        self._add_module(self._bootloader_module)

        self._fcoe_module = FCOEModule()
        self._add_module(self._fcoe_module)

        self._nvdimm_module = NVDIMMModule()
        self._add_module(self._nvdimm_module)

        self._dasd_module = None
        self._zfcp_module = None

        if arch.is_s390():
            self._dasd_module = DASDModule()
            self._add_module(self._dasd_module)

            self._zfcp_module = ZFCPModule()
            self._add_module(self._zfcp_module)

        # Initialize the partitioning modules.
        self._partitioning_modules = {}

        self._auto_part_module = AutoPartitioningModule()
        self._add_partitioning_module(AUTO_PARTITIONING.object_path, self._auto_part_module)

        self._manual_part_module = ManualPartitioningModule()
        self._add_partitioning_module(MANUAL_PARTITIONING.object_path, self._manual_part_module)

        self._custom_part_module = CustomPartitioningModule()
        self._add_partitioning_module(CUSTOM_PARTITIONING.object_path, self._custom_part_module)

        self._blivet_part_module = BlivetPartitioningModule()
        self._add_partitioning_module(BLIVET_PARTITIONING.object_path, self._blivet_part_module)

        # Connect modules to signals.
        self.storage_changed.connect(
            self._device_tree_module.on_storage_reset
        )
        self.storage_changed.connect(
            self._disk_init_module.on_storage_reset
        )
        self.storage_changed.connect(
            self._disk_selection_module.on_storage_reset
        )
        self.storage_changed.connect(
            self._snapshot_module.on_storage_reset
        )
        self.storage_changed.connect(
            self._bootloader_module.on_storage_reset
        )
        self._disk_selection_module.protected_devices_changed.connect(
            self.on_protected_devices_changed
        )

    def _add_module(self, storage_module):
        """Add a base kickstart module."""
        self._modules.append(storage_module)

    def _add_partitioning_module(self, object_path, partitioning_module):
        """Add a partitioning module."""
        # Add the module.
        self._modules.append(partitioning_module)
        self._partitioning_modules[object_path] = partitioning_module

        # Update the module.
        partitioning_module.on_storage_reset(
            self._storage
        )
        partitioning_module.on_selected_disks_changed(
            self._disk_selection_module.selected_disks
        )

        # Connect the callbacks to signals.
#.........这里部分代码省略.........
开发者ID:rvykydal,项目名称:anaconda,代码行数:103,代码来源:storage.py

示例9: DasdFormatting

# 需要导入模块: from pyanaconda.core.signal import Signal [as 别名]
# 或者: from pyanaconda.core.signal.Signal import connect [as 别名]
class DasdFormatting(object):
    """Class for formatting DASDs."""

    def __init__(self):
        self._dasds = []

        self._can_format_unformatted = True
        self._can_format_ldl = True

        self._report = Signal()
        self._report.connect(log.debug)
        self._last_message = ""

        self._dasd_module = STORAGE.get_proxy(DASD)

    @staticmethod
    def is_supported():
        """Is DASD formatting supported on this machine?"""
        return arch.is_s390()

    @property
    def report(self):
        """Signal for the progress reporting.

        Emits messages during the formatting.
        """
        return self._report

    @property
    def dasds(self):
        """List of found DASDs to format."""
        return self._dasds

    @property
    def dasds_summary(self):
        """Returns a string summary of DASDs to format."""
        return "\n".join(map(self.get_dasd_info, self.dasds))

    def get_dasd_info(self, disk):
        """Returns a string with description of a DASD."""
        return "/dev/" + disk.name + " (" + disk.busid + ")"

    def _is_dasd(self, disk):
        """Is it a DASD disk?"""
        return disk.type == "dasd"

    def _is_unformatted_dasd(self, disk):
        """Is it an unformatted DASD?"""
        return self._is_dasd(disk) and blockdev.s390.dasd_needs_format(disk.busid)

    def _is_ldl_dasd(self, disk):
        """Is it an LDL DASD?"""
        return self._is_dasd(disk) and blockdev.s390.dasd_is_ldl(disk.name)

    def _get_unformatted_dasds(self, disks):
        """Returns a list of unformatted DASDs."""
        result = []

        if not self._can_format_unformatted:
            log.debug("We are not allowed to format unformatted DASDs.")
            return result

        for disk in disks:
            if self._is_unformatted_dasd(disk):
                log.debug("Found unformatted DASD: %s", self.get_dasd_info(disk))
                result.append(disk)

        return result

    def _get_ldl_dasds(self, disks):
        """Returns a list of LDL DASDs."""
        result = []

        if not self._can_format_ldl:
            log.debug("We are not allowed to format LDL DASDs.")
            return result

        for disk in disks:
            if self._is_ldl_dasd(disk):
                log.debug("Found LDL DASD: %s", self.get_dasd_info(disk))
                result.append(disk)

        return result

    def update_restrictions(self):
        """Update the restrictions."""
        disk_init_proxy = STORAGE.get_proxy(DISK_INITIALIZATION)

        self._can_format_unformatted = disk_init_proxy.FormatUnrecognizedEnabled
        self._can_format_ldl = disk_init_proxy.FormatLDLEnabled

    def search_disks(self, disks):
        """Search for a list of disks for DASDs to format."""
        self._dasds = list(set(self._get_unformatted_dasds(disks) + self._get_ldl_dasds(disks)))

    def should_run(self):
        """Should we run the formatting?"""
        return bool(self._dasds)

    def do_format(self):
#.........这里部分代码省略.........
开发者ID:zhangsju,项目名称:anaconda,代码行数:103,代码来源:format_dasd.py


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