自定义基类属性的序列化(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
最满意答案
对于这种类型的情况,有
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()
相关问答
更多-
在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: ... -
包装Kivy标签的文字(Wrapping the text of a Kivy Label)[2023-09-19]
首先,让我告诉你,你要让自己的生活方式比应该更难,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的标签(Label not updating Kivy)[2021-09-12]
使用Kivy ObjectProperty和ScreenManager ,您可以在kv文件中使用root.manager ... ,在Python脚本中使用self.manager 。 有关详细信息,请参阅以下建议和示例。 为ScreenManager定义一个类并为ScreenOne和ScreenTwo声明ObjectProperty。 使用ScreenManager,用kv文件中的root.manager ...替换app.root ...。 在类ScreenOne中实现类PhoneGridLayout中 ... -
Kivy Treeview职位问题(Kivy Treeview Position Issues)[2023-09-02]
标签下的TreeView 解决方案是使用GridLayout作为BoxLayout(root小部件,MainScreen)的子项,标签和TreeViews作为GridLayout的子项。 添加了一个ObjectProperty container将它连接到在kv文件中创建的GridLayout小部件(TreeView小部件的占位符)。 有关详细信息,请参阅示例。 示例 - 标签下的TreeView main.py from kivy.app import App from kivy.uix.boxlayou ... -
在Android上运行Kivy(Run Kivy on Android)[2023-09-22]
请查看您包含的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 ...