小编Spe*_*ZAR的帖子

在Cython中共享扩展类型以进行静态类型

我将Python类转换为.pyx文件中的扩展类型.我可以在另一个Cython模块中创建这个对象,但我不能用它做静态类型.

这是我班级的一部分:

cdef class PatternTree:

    cdef public PatternTree previous
    cdef public PatternTree next
    cdef public PatternTree parent
    cdef public list children

    cdef public int type
    cdef public unicode name
    cdef public dict attributes
    cdef public list categories
    cdef public unicode output

    def __init__(self, name, parent=None, nodeType=XML):
        # Some code

    cpdef int isExpressions(self):
        # Some code

    cpdef MatchResult isMatch(self, PatternTree other):
        # Some code

    # More functions...
Run Code Online (Sandbox Code Playgroud)

我已经尝试使用.pxd文件来声明它,但它在所有函数上都说"C方法[某些函数]已声明但未定义".我也尝试在我的实现的功能中剥离C的东西,使它像一个增强类,但这也不起作用.

这是我的.pxd:

cdef class PatternTree:
    cdef public PatternTree previous
    cdef …
Run Code Online (Sandbox Code Playgroud)

python cython

10
推荐指数
1
解决办法
1696
查看次数

WPF中CheckBox的自定义鼠标点击区域

我为我的复选框设置了一个自定义样式,它看起来像这样(未选中状态):

扩展器的图象有在它附近的边界和象征复选框的狗耳朵

选中"选中"复选框时,它应如下所示:

扩展器的图像与它周围的边框和狗耳朵突出显示绿色.

我想要发生的是用户应该只能通过单击右上角的复选标记来切换它.现在,复选框将切换用户单击框内部而不是扩展器内部的任何位置.

有没有办法我可以设置鼠标单击区域切换复选框只在右上角的复选标记周围?

这是我的代码:

<SolidColorBrush x:Key="SelectedCheckboxColor" Color="Green"/>
<SolidColorBrush x:Key="UnselectedCheckboxColor" Color="Gray"/>
<Style x:Key="SelectBoxCheckBoxStyle" TargetType="{x:Type CheckBox}">
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type CheckBox}">
                <Border x:Name="border" BorderThickness="2" BorderBrush="#FF666666">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <ContentPresenter Grid.Column="0" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        <Image x:Name="image" Width="24" Height="24" Grid.Column="1" VerticalAlignment="Top" Source="Resources/checkbox-dogear-unchecked.png"/>
                    </Grid>

                    <!--<BulletDecorator Background="Transparent" SnapsToDevicePixels="true">
                        <BulletDecorator.Bullet>
                            <Themes:BulletChrome BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" IsChecked="{TemplateBinding IsChecked}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}"/>
                        </BulletDecorator.Bullet>
                    </BulletDecorator>-->
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="HasContent" Value="true">
                        <Setter Property="Padding" Value="4,0,0,0"/>
                    </Trigger> …
Run Code Online (Sandbox Code Playgroud)

c# wpf checkbox wpf-style

5
推荐指数
1
解决办法
1249
查看次数

为 py2app 资源使用目录

我有一些目录敏感的数据文件。如何将它们添加到我的 .app 包中?

py2app 提供的文档都没有说明如何具体执行此操作。但是在网上查了一下,发现可以使用元组在特定的目录结构中添加资源。我假设订单是(directoryInResourceFolder, pathToFile).

当我尝试这样做时,出现以下错误:

error: No such file or directory: m
Run Code Online (Sandbox Code Playgroud)

我不知道为什么会这样说,因为我的元组都不是m. 这是我生成的元组列表:

[('src/math_patterns', 'math_patterns/_BordersSlashes.txt'), ('src/math_patterns', 'math_patterns/_codes.txt'), ('src/math_patterns', 'math_patterns/_Dollars.txt'), ('src/math_patterns', 'math_patterns/_Fences.txt'), ('src/math_patterns', 'math_patterns/_Final.txt'), ('src/math_patterns', 'math_patterns/_Fractions.txt'), ('src/math_patterns', 'math_patterns/_FunctionsLimits.txt'), ('src/math_patterns', 'math_patterns/_Integrals.txt'), ('src/math_patterns', 'math_patterns/_Numbers.txt'), ('src/math_patterns', 'math_patterns/_PowersPrimes.txt'), ('src/math_patterns', 'math_patterns/_SoftFractions.txt'), ('src/math_patterns', 'math_patterns/_test.txt'), ('src/math_patterns', 'math_patterns/_Trig.txt'), ('src/math_patterns', 'math_patterns/_Unicodes.txt'), ('src/math_patterns', 'math_patterns/_Vocab.txt'), ('src/math_patterns', 'math_patterns/Calculus.txt'), ('src/math_patterns', 'math_patterns/General.txt'), ('src/math_patterns', 'math_patterns/Geometry and Trigonometry.txt'), ('src/math_patterns', 'math_patterns/Linear Algebra.txt'), ('src/math_patterns', 'math_patterns/Logic.txt'), ('src/math_patterns', 'math_patterns/Statistics.txt')]
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的 setup.py:

from setuptools import setup
import os

APP = ['main.py']

# Prepare all of …
Run Code Online (Sandbox Code Playgroud)

python py2app

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

标签 统计

python ×2

c# ×1

checkbox ×1

cython ×1

py2app ×1

wpf ×1

wpf-style ×1