小编And*_*ing的帖子

Python 抽象基类:为什么 abc 不阻止实例化?

据我所知,Python 模块 abc 应该防止类的实例化,这些类没有@abstractmethod实现基类的所有标记方法(前提是基类已经__metaclass__ = ABCMeta设置)

但是,这似乎不适用于以下代码:

抽象基类:

""" Contains payment processors for executing payments """

from abc import ABCMeta, abstractmethod

class AbstractPaymentProcessor:
    """ Abstract class for executing faucet Payments
    Implement this at your own. Possible implementations include
    online wallets and RPC calls to running dogecoin wallets """

    __metaclass__ = ABCMeta

    @abstractmethod
    def execute_payment(self, destination_address, amount):
        """ Execute a payment to one receiving single address

        return the transaction id or None """
        pass

    @abstractmethod
    def execute_multi_payment(self, …
Run Code Online (Sandbox Code Playgroud)

python abc abstract-base-class

4
推荐指数
1
解决办法
1534
查看次数

WPF ComboBox:将SelectedItem设置为不在ItemsSource中的项目 - >绑定奇怪

我想实现以下目标:我想要一个显示可用COM端口的ComboBox.在启动时(并单击"刷新"按钮)我想获得可用的COM端口并将选择设置为最后选择的值(来自应用程序设置).

如果设置(最后一个COM端口)中的值不在值列表(可用COM端口)中,则会发生以下情况:

虽然ComboBox没有显示任何内容(知道新的SelectedItem不在ItemsSource中"足够聪明"),但ViewModel更新为"无效值".我实际上期望Binding具有与ComboBox显示的值相同的值.

用于演示目的的代码:

MainWindow.xaml:

    <Window x:Class="DemoComboBinding.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525"
            xmlns:local="clr-namespace:DemoComboBinding">
        <Window.Resources>
            <local:DemoViewModel x:Key="vm" />
        </Window.Resources>
        <StackPanel Orientation="Vertical">
            <ComboBox SelectedItem="{Binding Source={StaticResource vm}, Path=Selected}" x:Name="combo"
            ItemsSource="{Binding Source={StaticResource vm}, Path=Source}"/>
            <Button Click="Button_Click">Set different</Button> <!-- would be refresh button -->
            <Label Content="{Binding Source={StaticResource vm}, Path=Selected}"/> <!-- shows the value from the view model -->
        </StackPanel>
    </Window>
Run Code Online (Sandbox Code Playgroud)

MainWindow.xaml.cs:

    // usings removed
    namespace DemoComboBinding
    {
        public partial class MainWindow : Window
        {
            //...
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                combo.SelectedItem = "COM4"; …
Run Code Online (Sandbox Code Playgroud)

c# wpf binding combobox

1
推荐指数
2
解决办法
8609
查看次数

标签 统计

abc ×1

abstract-base-class ×1

binding ×1

c# ×1

combobox ×1

python ×1

wpf ×1