@@ -8,14 +8,33 @@ class PlatformNotDetectedError(Exception):
88 pass
99
1010
11+ class View :
12+ def __init__ (self ) -> None :
13+ self .native_instance = None
14+ self .native_class = None
15+
16+ def add_view (self , view ):
17+ raise NotImplementedError (
18+ "This method should be implemented in a subclass." )
19+
20+ def set_layout (self , layout ):
21+ raise NotImplementedError (
22+ "This method should be implemented in a subclass." )
23+
24+ def show (self ):
25+ raise NotImplementedError (
26+ "This method should be implemented in a subclass." )
27+
28+
1129# Depending on the system, import appropriate classes
1230if system == "iOS" :
1331 from rubicon .objc import ObjCClass
1432
15- class Screen :
33+ class Screen ( View ) :
1634 native_class = ObjCClass ("UIViewController" )
1735
1836 def __init__ (self ):
37+ super ().__init__ ()
1938 self .native_instance = self .native_class .alloc ().init ()
2039 self .layout = None
2140
@@ -32,10 +51,11 @@ def show(self):
3251 # This method should contain code to present the ViewController
3352 pass
3453
35- class Button :
54+ class Button ( View ) :
3655 native_class = ObjCClass ("UIButton" )
3756
3857 def __init__ (self , title : str = "" ) -> None :
58+ super ().__init__ ()
3959 self .native_instance = self .native_class .alloc ().init ()
4060 self .set_title (title )
4161
@@ -45,10 +65,11 @@ def set_title(self, title: str) -> None:
4565 def get_title (self ) -> str :
4666 return self .native_instance .titleForState_ (0 )
4767
48- class Label :
68+ class Label ( View ) :
4969 native_class = ObjCClass ("UILabel" )
5070
5171 def __init__ (self , text : str = "" ) -> None :
72+ super ().__init__ ()
5273 self .native_instance = self .native_class .alloc ().init ()
5374 self .set_text (text )
5475
@@ -58,10 +79,11 @@ def set_text(self, text: str) -> None:
5879 def get_text (self ) -> str :
5980 return self .native_instance .text ()
6081
61- class LinearLayout :
82+ class LinearLayout ( View ) :
6283 native_class = ObjCClass ("UIStackView" )
6384
6485 def __init__ (self ) -> None :
86+ super ().__init__ ()
6587 self .native_instance = self .native_class .alloc ().initWithFrame_ (
6688 ((0 , 0 ), (0 , 0 ))
6789 )
@@ -75,10 +97,11 @@ def add_view(self, view):
7597elif system == "Android" :
7698 from java import jclass
7799
78- class Screen :
100+ class Screen ( View ) :
79101 native_class = jclass ("android.app.Activity" )
80102
81103 def __init__ (self ):
104+ super ().__init__ ()
82105 self .native_instance = self .native_class ()
83106 self .layout = None
84107
@@ -95,10 +118,11 @@ def show(self):
95118 # This method should contain code to start the Activity
96119 pass
97120
98- class Button :
121+ class Button ( View ) :
99122 native_class = jclass ("android.widget.Button" )
100123
101124 def __init__ (self , title : str = "" ) -> None :
125+ super ().__init__ ()
102126 self .native_instance = self .native_class ()
103127 self .set_title (title )
104128
@@ -108,10 +132,11 @@ def set_title(self, title: str) -> None:
108132 def get_title (self ) -> str :
109133 return self .native_instance .getText ().toString ()
110134
111- class Label :
135+ class Label ( View ) :
112136 native_class = jclass ("android.widget.TextView" )
113137
114138 def __init__ (self , text : str = "" ) -> None :
139+ super ().__init__ ()
115140 self .native_instance = self .native_class ()
116141 self .set_text (text )
117142
@@ -121,10 +146,11 @@ def set_text(self, text: str) -> None:
121146 def get_text (self ) -> str :
122147 return self .native_instance .getText ().toString ()
123148
124- class LinearLayout :
149+ class LinearLayout ( View ) :
125150 native_class = jclass ("android.widget.LinearLayout" )
126151
127152 def __init__ (self ) -> None :
153+ super ().__init__ ()
128154 self .native_instance = self .native_class ()
129155 self .native_instance .setOrientation (1 ) # Set orientation to vertical
130156 self .views = []
0 commit comments