Skip to content

Commit a53b101

Browse files
JuanCJuanC
authored andcommitted
Changing snake case and Doc
Changing the readme to include more explanation, correcting typos and new sections added to table content
1 parent a0d3e07 commit a53b101

7 files changed

Lines changed: 507 additions & 382 deletions

File tree

README.md

Lines changed: 395 additions & 271 deletions
Large diffs are not rendered by default.
14 KB
Binary file not shown.
-120 KB
Binary file not shown.
117 KB
Loading

python_sharp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __init__(self)->None:
102102

103103

104104
@property
105-
def Cancel(self)->bool:
105+
def cancel(self)->bool:
106106
"""
107107
Gets property value.
108108
@@ -111,8 +111,8 @@ def Cancel(self)->bool:
111111
"""
112112
return self._cancel
113113

114-
@Cancel.setter
115-
def Cancel(self,value:bool)->None:
114+
@cancel.setter
115+
def cancel(self,value:bool)->None:
116116
"""
117117
Sets a new value.
118118

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
],
1818
python_requires=">=3.6", # Minimum required Python version
1919
install_requires=[ # Dependencies needed by package
20-
]
20+
],
21+
include_package_data=True #include the data mentioned on the manifest
2122
)

test.py

Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self,delta:int)->None:
1111
self._delta = delta
1212

1313
@property
14-
def Delta(self)->int:
14+
def delta(self)->int:
1515
return self._delta
1616

1717

@@ -24,7 +24,7 @@ def __init__(self,location:int)->None:
2424
self._location = location
2525

2626
@property
27-
def Location(self)->int:
27+
def location(self)->int:
2828
return self._location
2929

3030

@@ -33,142 +33,142 @@ def Location(self)->int:
3333
class Person:
3434

3535
_instance_created:int = 0
36-
_personCreatedcallbacks:Delegate = Delegate()
36+
_person_created:Delegate = Delegate()
3737

3838
_name:str
3939
_alive:bool
4040
_location:int
41-
_nameChangedcalbacks:Delegate
42-
_movedcallbacks:Delegate
43-
_locationChangingcallbacks:Delegate
44-
_diedcallbacks:Delegate
41+
_name_changed:Delegate
42+
_moved:Delegate
43+
_location_changing:Delegate
44+
_died:Delegate
4545

4646
def __init__(self,name:str)->None:
4747
self._name = name
4848
self._alive = True
4949
self._location = 0
50-
self._nameChangedcalbacks = Delegate()
51-
self._movedcallbacks = Delegate()
52-
self._locationChangingcallbacks = Delegate()
53-
self._diedcallbacks = Delegate()
54-
Person._OnPersonCreated(EventArgs())
50+
self._name_changed = Delegate()
51+
self._moved = Delegate()
52+
self._location_changing = Delegate()
53+
self._died = Delegate()
54+
Person._on_person_created(EventArgs())
5555

5656
# region Properties
5757

5858
@property
59-
def Name(self)->str:
59+
def name(self)->str:
6060
return self._name
6161

62-
@Name.setter
63-
def Name(self,value:str)->None:
62+
@name.setter
63+
def name(self,value:str)->None:
6464
self._name = value
65-
self._OnNameChanged(EventArgs())
65+
self._on_name_changed(EventArgs())
6666

6767

6868
@property
69-
def Alive(self)->bool:
69+
def alive(self)->bool:
7070
return self._alive
7171

7272

7373
@property
74-
def Location(self)->int:
74+
def location(self)->int:
7575
return self._location
7676

77-
@Location.setter
78-
def Location(self,value:int)->None:
77+
@location.setter
78+
def location(self,value:int)->None:
7979

8080
locationEventArgs = LocationChangingEventArgs(value)
81-
self._OnLocationChanging(locationEventArgs)
81+
self._on_location_changing(locationEventArgs)
8282

83-
if(not locationEventArgs.Cancel):
84-
previous = self.Location
83+
if(not locationEventArgs.cancel):
84+
previous = self.location
8585
self._location = value
86-
self._OnMoved(MovedEventArgs(self.Location - previous))
86+
self._on_moved(MovedEventArgs(self.location - previous))
8787

8888

8989
@staticmethod
90-
def get_InstanceCreated()->int:
90+
def get_instance_created()->int:
9191
return Person._instance_created
9292

9393
@staticmethod
94-
def _set_InstanceCreated(value:int)->None:
94+
def _set_instance_created(value:int)->None:
9595
Person._instance_created = value
9696

9797
# endregion
9898

9999
# region Methods
100100

101-
def _OnNameChanged(self,e:EventArgs)->None:
102-
self._nameChangedcalbacks(self,e)
101+
def _on_name_changed(self,e:EventArgs)->None:
102+
self._name_changed(self,e)
103103

104-
def _OnLocationChanging(self,e:LocationChangingEventArgs)->None:
105-
self._locationChangingcallbacks(self,e)
104+
def _on_location_changing(self,e:LocationChangingEventArgs)->None:
105+
self._location_changing(self,e)
106106

107-
def _OnMoved(self,e:MovedEventArgs)->None:
108-
self._movedcallbacks(self,e)
107+
def _on_moved(self,e:MovedEventArgs)->None:
108+
self._moved(self,e)
109109

110-
def _OnDied(self,e:EventArgs)->None:
111-
self._diedcallbacks(self,e)
110+
def _on_died(self,e:EventArgs)->None:
111+
self._died(self,e)
112112

113-
def Move(self,distance:int)->None:
114-
self.Location += distance
113+
def move(self,distance:int)->None:
114+
self.location += distance
115115

116116
@staticmethod
117-
def _OnPersonCreated(e:EventArgs)->None:
118-
Person._set_InstanceCreated(Person.get_InstanceCreated() + 1)
119-
Person._personCreatedcallbacks(None,e)
117+
def _on_person_created(e:EventArgs)->None:
118+
Person._set_instance_created(Person.get_instance_created() + 1)
119+
Person._person_created(None,e)
120120

121-
def Kill(self)->None:
121+
def kill(self)->None:
122122
self._alive = False
123-
self._OnDied(EventArgs())
123+
self._on_died(EventArgs())
124124

125125
# endregion
126126

127127
# region Events
128128

129129
@event #Simplest event, just notify something happens, no provide extra information about the event (like why,how,when), no recolection of information from suscribers
130-
def NameChanged(self,value: Callable[[object, EventArgs], None])->None:
131-
self._nameChangedcalbacks += value
130+
def name_changed(self,value: Callable[[object, EventArgs], None])->None:
131+
self._name_changed += value
132132

133-
@NameChanged.remove
134-
def NameChanged(self,value: Callable[[object, EventArgs], None])->None:
135-
self._nameChangedcalbacks -= value
133+
@name_changed.remove
134+
def name_changed(self,value: Callable[[object, EventArgs], None])->None:
135+
self._name_changed -= value
136136

137137

138138
@event #event with custom EventArgs, notify something happens and provides extra information (like why,how,when), no recolection of information from suscribers
139-
def Moved(self,value:Callable[[object, MovedEventArgs], None])->None:
140-
self._movedcallbacks += value
139+
def moved(self,value:Callable[[object, MovedEventArgs], None])->None:
140+
self._moved += value
141141

142-
@Moved.remove
143-
def Moved(self,value:Callable[[object, MovedEventArgs], None])->None:
144-
self._movedcallbacks -= value
142+
@moved.remove
143+
def moved(self,value:Callable[[object, MovedEventArgs], None])->None:
144+
self._moved -= value
145145

146146

147147
@event #event with custom EventArgs, notify something happens provides extra information (like why,how,when), and it is capable of recolect info from its suscribers (this case implemeted as prevent)
148-
def LocationChanging(self,value:Callable[[object, LocationChangingEventArgs], None])->None:
149-
self._locationChangingcallbacks += value
148+
def location_changing(self,value:Callable[[object, LocationChangingEventArgs], None])->None:
149+
self._location_changing += value
150150

151-
@LocationChanging.remove
152-
def LocationChanging(self,value:Callable[[object, LocationChangingEventArgs], None])->None:
153-
self._locationChangingcallbacks -= value
151+
@location_changing.remove
152+
def location_changing(self,value:Callable[[object, LocationChangingEventArgs], None])->None:
153+
self._location_changing -= value
154154

155155

156156
@event
157-
def Died(self,value:Callable[[object, EventArgs], None])->None:
158-
self._diedcallbacks += value
157+
def died(self,value:Callable[[object, EventArgs], None])->None:
158+
self._died += value
159159

160-
@Died.remove
161-
def Died(self,value:Callable[[object, EventArgs], None])->None:
162-
self._diedcallbacks -= value
160+
@died.remove
161+
def died(self,value:Callable[[object, EventArgs], None])->None:
162+
self._died -= value
163163

164164

165165
@staticevent
166-
def PersonCreated(value:Callable[[object, EventArgs], None])->None:
167-
Person._personCreatedcallbacks += value
166+
def person_created(value:Callable[[object, EventArgs], None])->None:
167+
Person._person_created += value
168168

169-
@PersonCreated.remove
170-
def PersonCreated(value:Callable[[object, EventArgs], None])->None:
171-
Person._personCreatedcallbacks -= value
169+
@person_created.remove
170+
def person_created(value:Callable[[object, EventArgs], None])->None:
171+
Person._person_created -= value
172172

173173
# endregion
174174

@@ -182,42 +182,42 @@ def __init__(self,name:str)->None:
182182
self._principal = None
183183

184184
@property
185-
def Name(self)->str:
185+
def name(self)->str:
186186
return self._name
187187

188-
@Name.setter
189-
def Name(self,value:str)->None:
188+
@name.setter
189+
def name(self,value:str)->None:
190190
self._name = value
191191

192192

193193
@property
194-
def Principal(self)->Person:
194+
def principal(self)->Person:
195195
return self._principal
196196

197-
@Principal.setter
198-
def Principal(self,value:Person)->None:
199-
if self.Principal is not None:
200-
self.Principal.Died -= self._person_died
197+
@principal.setter
198+
def principal(self,value:Person)->None:
199+
if self.principal is not None:
200+
self.principal.died -= self._person_died
201201

202202
self._principal = value
203203

204-
if self.Principal is not None:
205-
self.Principal.Died += self._person_died
204+
if self.principal is not None:
205+
self.principal.died += self._person_died
206206

207207

208-
def person_nameChanged(self,sender:object,e:EventArgs)->None:
209-
print("School %s just signed up %s"% (self.Name,sender.Name))
208+
def person_name_changed(self,sender:object,e:EventArgs)->None:
209+
print("School %s just signed up %s"% (self.name,sender.name))
210210

211211
def person_moved(self,sender:object,e:MovedEventArgs)->None:
212-
print("Person %s change its localitation by %s units" % (sender.Name,e.Delta))
212+
print("Person %s change its localitation by %s units" % (sender.name,e.delta))
213213

214-
def person_locationchanging(self,sender:object,e:LocationChangingEventArgs)->None:
215-
if e.Location > 100:
216-
print("Person %s can't be changed that far, Location cannot be greater than 100. value: %d'" % (sender.Name,e.Location))
217-
e.Cancel = True
214+
def person_location_changing(self,sender:object,e:LocationChangingEventArgs)->None:
215+
if e.location > 100:
216+
print("Person %s can't be changed that far, location cannot be greater than 100. value: %d'" % (sender.name,e.location))
217+
e.cancel = True
218218

219-
def _person_died(self,sender:object,e:EventArgs):
220-
print("School %s is sad because principal %s die" % (self.Name,sender.Name))
219+
def _person_died(self,sender:object,e:EventArgs): #This can be protected and shoud be due it is only interest of the school when the principal dies
220+
print("School %s is sad because principal %s die" % (self.name,sender.name))
221221

222222

223223
def method(self,sender:object,e:EventArgs)->None:
@@ -226,7 +226,7 @@ def method(self,sender:object,e:EventArgs)->None:
226226

227227
def callback_function(sender:object,e:EventArgs)->None:
228228
print("callback sender %s, Eventargs: %s" % (sender,e))
229-
print("Person name %s" % sender.Name)
229+
print("Person name %s" % sender.name)
230230

231231

232232

@@ -236,50 +236,50 @@ def callback_function(sender:object,e:EventArgs)->None:
236236

237237

238238
#Use of a simple event (In this case implemented as a property change event)------------------------------------------------------------
239-
person.NameChanged += school.person_nameChanged #suscribe the school instance method to Namechanged event, (this method will be executed when the person's name change)
240-
person.NameChanged += callback_function #suscribe an extra simple function (this function will be executed when the person's name change)
241-
person.Name = "Susa" #Change the person name to trigger the event
239+
person.name_changed += school.person_name_changed #suscribe the school instance method to Namechanged event, (this method will be executed when the person's name change)
240+
person.name_changed += callback_function #suscribe an extra simple function (this function will be executed when the person's name change)
241+
person.name = "Susa" #Change the person name to trigger the event
242242
#----------------------------------------------------------------------------------------------------------------------------------------
243243

244244
#How to unsuscribe an event--------------------------------------------------------------------------------------------------------------
245-
person.NameChanged -= callback_function#unsuscribe only the function
246-
person.Name = "Nos"#Change the person name to trigger the event
245+
person.name_changed -= callback_function#unsuscribe only the function
246+
person.name = "Nos"#Change the person name to trigger the event
247247
#----------------------------------------------------------------------------------------------------------------------------------------
248248

249249
#Use of an event with custom EventArgs---------------------------------------------------------------------------------------------------
250-
person.Location =5#changing location to show nothing happens
251-
person.Moved += school.person_moved#add a suscriber to the event
252-
person.Location = 15#changing the location again to trigger the event
253-
person.Moved -= school.person_moved#unsuscribe to the event
254-
person.Location = 30#changing again the location to verify nothing happens
250+
person.location =5#changing location to show nothing happens
251+
person.moved += school.person_moved#add a suscriber to the event
252+
person.location = 15#changing the location again to trigger the event
253+
person.moved -= school.person_moved#unsuscribe to the event
254+
person.location = 30#changing again the location to verify nothing happens
255255
#----------------------------------------------------------------------------------------------------------------------------------------
256256

257257
#Use of a custom Eventargs with setter (allows to suscriber send information) in this case is implemented as a pre-event (triggers before something happens) this allows in this case cancel the Change of the person's location
258-
person.LocationChanging += school.person_locationchanging #add the suscriber
259-
person.Location = 13 #change the location to trigger the event
260-
person.Location = 115 #changing location again to trigger the event, suscriber has the capability to cancel the asignation of the new value
261-
print("%s location at %s" %(person.Name, person.Location))#checking person's location it is (13,13) due suscriber cancel the asignation of the action thorugh the pre-event
258+
person.location_changing += school.person_location_changing #add the suscriber
259+
person.location = 13 #change the location to trigger the event
260+
person.location = 115 #changing location again to trigger the event, suscriber has the capability to cancel the asignation of the new value
261+
print("%s location at %s" %(person.name, person.location))#checking person's location it is (13,13) due suscriber cancel the asignation of the action thorugh the pre-event
262262
#----------------------------------------------------------------------------------------------------------------------------------------
263263

264264

265265
#suscribing a Delegate instead of passing a function/method directly (Due Delegates are callables) to an event, as well show case of using polimorfism, pasing an EventArgs parameter function to a LocationEventArgs parameter event
266266
delegate = Delegate(callback_function) #create a delagate with one function with signature Callable[[object, EventArgs], None]
267-
person.Moved += delegate #suscribing a Callable[[object, EventArgs], None] to Callable[[object, MovedEventArgs], None] event
268-
person.Location = 1#changing location to trigger event
267+
person.moved += delegate #suscribing a Callable[[object, EventArgs], None] to Callable[[object, MovedEventArgs], None] event
268+
person.location = 1#changing location to trigger event
269269
#in this case the event will provide an MovedEventArgs instance to the suscriber (the 'e' parameter), and suscriber handle the object as an EventArgs instance, by polimorfism is ok
270270
#-----------------------------------------------------------------------------------------------------------------------------------------
271271

272272
#suscribing the methods internally on the class-------------------------------------------------------------------------------------------
273-
school.Principal = person #Asign a principal to the school, the school will unsuscribe the old principal (if any) and suscribe to the new principal.Died event due it is of its interest know when its principal dies
274-
person.Kill() #We kill the person :( (school will do its logic due its principal dies)
273+
school.principal = person #Asign a principal to the school, the school will unsuscribe the old principal (if any) and suscribe to the new principal.died event due it is of its interest know when its principal dies
274+
person.kill() #We kill the person :( (school will do its logic due its principal dies)
275275
#------------------------------------------------------------------------------------------------------------------------------------------
276276

277277
#Static event example executing functions or methods
278278
def person_created_callback(sender:object,e:EventArgs):
279-
print("Static callback works! person count:%d"% Person.get_InstanceCreated())
279+
print("Static callback works! person count:%d"% Person.get_instance_created())
280280

281281

282-
Person.PersonCreated += person_created_callback
283-
Person.PersonCreated += school.method
282+
Person.person_created += person_created_callback
283+
Person.person_created += school.method
284284

285285
person2 = Person("")

0 commit comments

Comments
 (0)