首页 \ 问答 \ 自定义基类属性的序列化(Custom Serialization of base class properties)

自定义基类属性的序列化(Custom Serialization of base class properties)

我有一个类正在实现自定义序列化的ISerializable接口。 这适用于此类中的属性,但该类是派生类。 我遇到的问题是基类属性没有为我序列化。 基类具有可序列化的属性但不实现ISerializable。 有没有办法序列化基类属性,而不必在派生类的ISerializable .GetObjectData方法中手动添加所有这些属性?


I have a class that is implementing the ISerializable interface for custom serialization. This works great for the properties in this class but the class is a derived class. The problem i'm running into is that the base class properties aren't serialized for me. The base class has the serializable attribue but doesnt implement ISerializable. Is there a way to serialize the base class properties without having to add all of them manually in the derived class's ISerializable .GetObjectData method?


原文:https://stackoverflow.com/questions/1257198
更新时间:2021-09-15 19:09

最满意答案

对于这种类型的情况,有AnchorLayout ,用于将小部件与相对位置对齐。

import kivy

from kivy.app import App
from kivy.uix.label import Label

from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder

root = Builder.load_string('''
Screen:
    BoxLayout:
        orientation:'vertical'
        Label:
            text: '1'
            font_size: self.height
            size_hint: (1.0, 0.17)
        Label:
            text: '2'
            font_size: self.height
            size_hint: (1.0, 0.83)

    AnchorLayout:
        anchor_x: 'right'
        anchor_y: 'bottom'
        Label:
            text: '3'
            font_size: self.height
            size_hint: None, None
''')

class MyApp(App):
    def build(self):
        root.size_hint = (1.0, 1.0)
        return root

if __name__ == '__main__':
    MyApp().run()

在此处输入图像描述


For this type of cases there is AnchorLayout, which serves to align the widgets to a relative position.

import kivy

from kivy.app import App
from kivy.uix.label import Label

from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder

root = Builder.load_string('''
Screen:
    BoxLayout:
        orientation:'vertical'
        Label:
            text: '1'
            font_size: self.height
            size_hint: (1.0, 0.17)
        Label:
            text: '2'
            font_size: self.height
            size_hint: (1.0, 0.83)

    AnchorLayout:
        anchor_x: 'right'
        anchor_y: 'bottom'
        Label:
            text: '3'
            font_size: self.height
            size_hint: None, None
''')

class MyApp(App):
    def build(self):
        root.size_hint = (1.0, 1.0)
        return root

if __name__ == '__main__':
    MyApp().run()

enter image description here

相关问答

更多
  • 在kivy画布点(0,0)实际上是左下角。 您可以轻松自己计算最高排名: from kivy.app import App from kivy.uix.widget import Widget from kivy.lang import Builder from kivy.properties import ListProperty kv_string = ''' : r_size: [root.size[0]/2, root.size[1]/2] canvas: ...
  • 首先,让我告诉你,你要让自己的生活方式比应该更难,kv不难学,并且允许kivy为你做更多的重担。 在kv,做类似的事情 Label: text: 'blah blah ' * 1000 text_size: self.width, None size_hint: 1, None height: self.texture_size[1] 通常会这样做,因为小部件使用其容器的整个宽度,并且text_size被绑定到它的宽度,每当此宽度发生变化时,纹理将被重新计算,并且小部件的高 ...
  • 您可以使用相对布局而不是浮动布局来修复坐标系,但是您应该省略使用这些坐标系中的任何一个,并将标签添加到网格布局中。 检查kivy回购示例: https://github.com/kivy/kivy/blob/master/examples/widgets/scrollview.py https://github.com/kivy/kivy/blob/master/examples/widgets/scrollview.kv You could use a relative layout instead of ...
  • 对于这种类型的情况,有AnchorLayout ,用于将小部件与相对位置对齐。 import kivy from kivy.app import App from kivy.uix.label import Label from kivy.uix.boxlayout import BoxLayout from kivy.lang import Builder root = Builder.load_string(''' Screen: BoxLayout: orientatio ...
  • 无边界: from kivy.config import Config Config.set('graphics','borderless',1) Config.set('graphics','resizable',0) 在你的文件顶部之前的任何事情。 只剩下核心(Window)。 位置: Config.set('graphics','position','custom') Config.set('graphics','left',500) Config.set('graphics','top',10) ...
  • from kivy.app import App from kivy.lang import Builder from kivy.properties import StringProperty from kivy.uix.widget import Widget Builder.load_string(""" BoxLayout: orientation: 'vertical' Label: text: root.lab ...
  • 发生这种情况是因为您的Label与屏幕尺寸相同。 为了防止这种情况,你应该做size_hint: None, None 我会推荐你使用kv语言,因为它有助于使你的代码看起来更干净 这是改进代码的一个例子: from kivy.app import App from kivy.lang import Builder from kivy.uix.anchorlayout import AnchorLayout Builder.load_string(''' : anchor_x: 'rig ...
  • 使用Kivy ObjectProperty和ScreenManager ,您可以在kv文件中使用root.manager ... ,在Python脚本中使用self.manager 。 有关详细信息,请参阅以下建议和示例。 为ScreenManager定义一个类并为ScreenOne和ScreenTwo声明ObjectProperty。 使用ScreenManager,用kv文件中的root.manager ...替换app.root ...。 在类ScreenOne中实现类PhoneGridLayout中 ...
  • 标签下的TreeView 解决方案是使用GridLayout作为BoxLayout(root小部件,MainScreen)的子项,标签和TreeViews作为GridLayout的子项。 添加了一个ObjectProperty container将它连接到在kv文件中创建的GridLayout小部件(TreeView小部件的占位符)。 有关详细信息,请参阅示例。 示例 - 标签下的TreeView main.py from kivy.app import App from kivy.uix.boxlayou ...
  • 请查看您包含的python代码。 在class Mot你有 def bouger(self): 但功能体中没有任何内容。 你身体里真的没有任何东西吗? 您的代码甚至不应该在您的计算机上运行,所以我猜您只是没有发布所有内容。 如果您确定此函数中的代码没有导致崩溃,只需在函数体中写入“pass”,这样就不会混淆其他读者。 Please look at the python code you included. In class Mot you have def bouger(self): but nothi ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)