Skip to content

Commit 4e7bfd1

Browse files
committed
other
1 parent b167d06 commit 4e7bfd1

File tree

15 files changed

+345
-1
lines changed

15 files changed

+345
-1
lines changed

astral/example-1.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
3+
from astral import Astral, Location
4+
5+
def info(city):
6+
7+
sun = city.sun()
8+
9+
print('Blue Hour :', city.blue_hour()[0], '---', city.blue_hour()[1])
10+
print('Dawn :', city.dawn())
11+
print('Daylight :', city.daylight()[0], '---', city.daylight()[1])
12+
print('Dusk :', city.dusk())
13+
print('Elevation :', city.elevation)
14+
print('Golden Hour :', city.golden_hour()[0], '---', city.golden_hour()[1])
15+
print('Latitude :', city.latitude)
16+
print('Longitude :', city.longitude)
17+
print('Moon Phase :', city.moon_phase())
18+
print('Name :', city.name)
19+
print('Night :', city.night()[0], '---', city.night()[1])
20+
print('Rahukaalam :', city.rahukaalam()[0], '---', city.rahukaalam()[1])
21+
print('Region :', city.region)
22+
print('Solar Azimuth :', city.solar_azimuth())
23+
print('Solar Depression :', city.solar_depression)
24+
print('Solar Elevation :', city.solar_elevation())
25+
print('Solar Midnight :', city.solar_midnight())
26+
print('Solar Noon :', city.solar_noon())
27+
print('Solar Zenith :', city.solar_zenith())
28+
print('Sun')
29+
print(' +-----> Dawn :', sun['dawn'])
30+
print(' +-----> Sunrise:', sun['sunrise'])
31+
print(' +-----> Noon :', sun['noon'])
32+
print(' +-----> Sunset :', sun['sunset'])
33+
print(' +-----> Dusk :', sun['dusk'])
34+
print('Sunrise :', city.sunrise())
35+
print('Sunset :', city.sunset())
36+
print('Time At Elevation:', city.time_at_elevation)
37+
print('Timezone :', city.timezone)
38+
print('Twilight :', city.twilight)
39+
print('TZ :', city.tz)
40+
print('TZinfo :', city.tzinfo)
41+
print('Url :', city.url)
42+
print('-'*80)
43+
44+
if __name__ == '__main__':
45+
46+
astral = Astral()
47+
48+
city = astral['Warsaw']
49+
info(city)
50+
51+
loc = Location(('Toruń', 'Poland', 53.022222, 18.611111, 'Europe/Warsaw', 0))
52+
info(loc)

astral/example-2.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python3
2+
3+
from astral import AstralGeocoder, Location
4+
5+
#Astral', 'AstralError', 'AstralGeocoder', 'GoogleGeocoder', 'Location', 'LocationGroup', 'SUN_RISING', 'SUN_SETTING', 'SunBelowHorizonError', 'URLError', '_LOCATION_INFO'
6+
7+
if __name__ == '__main__':
8+
9+
coder = AstralGeocoder()
10+
11+
for group in coder._groups:
12+
print('---', group, '---')
13+
14+
for city in coder._groups[group]:
15+
print(city.name)
16+

astral/main.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python3
2+
3+
from astral import Astral, Location
4+
5+
#Astral', 'AstralError', 'AstralGeocoder', 'GoogleGeocoder', 'Location', 'LocationGroup', 'SUN_RISING', 'SUN_SETTING', 'SunBelowHorizonError', 'URLError', '_LOCATION_INFO'
6+
7+
def info(city):
8+
sun = city.sun()
9+
10+
#print('Astral :', city.astral)
11+
print('Blue Hour :', city.blue_hour()[0], '---', city.blue_hour()[1])
12+
print('Dawn :', city.dawn())
13+
print('Daylight :', city.daylight()[0], '---', city.daylight()[1])
14+
print('Dusk :', city.dusk())
15+
print('Elevation :', city.elevation)
16+
print('Golden Hour :', city.golden_hour()[0], '---', city.golden_hour()[1])
17+
print('Latitude :', city.latitude)
18+
print('Longitude :', city.longitude)
19+
print('Moon Phase :', city.moon_phase())
20+
print('Name :', city.name)
21+
print('Night :', city.night()[0], '---', city.night()[1])
22+
print('Rahukaalam :', city.rahukaalam()[0], '---', city.rahukaalam()[1])
23+
print('Region :', city.region)
24+
print('Solar Azimuth :', city.solar_azimuth())
25+
print('Solar Depression :', city.solar_depression)
26+
print('Solar Elevation :', city.solar_elevation())
27+
print('Solar Midnight :', city.solar_midnight())
28+
print('Solar Noon :', city.solar_noon())
29+
print('Solar Zenith :', city.solar_zenith())
30+
print('Sun :')#, city.sun())
31+
print(' Dawn :', sun['dawn'])
32+
print(' Sunrise:', sun['sunrise'])
33+
print(' Noon :', sun['noon'])
34+
print(' Sunset :', sun['sunset'])
35+
print(' Dusk :', sun['dusk'])
36+
print('Sunrise :', city.sunrise())
37+
print('Sunset :', city.sunset())
38+
print('Time At Elevation:', city.time_at_elevation)
39+
print('Timezone :', city.timezone)
40+
print('Twilight :', city.twilight)
41+
print('TZ :', city.tz)
42+
print('TZinfo :', city.tzinfo)
43+
print('Url :', city.url)
44+
print('-'*80)
45+
46+
if __name__ == '__main__':
47+
48+
astral = Astral()
49+
50+
city = astral['Warsaw']
51+
info(city)
52+
53+
loc = Location(('Toruń', 'Poland', 53.022222, 18.611111, 'Europe/Warsaw', 0))
54+
info(loc)
55+
56+
for x in astral.geocoder._groups['europe'].keys():
57+
print(x)
58+

mpi/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
[mpi4py documentation](https://pythonhosted.org/mpi4py/usrman/tutorial.html)
55

6+
http://pythonhosted.org/mpi4py/
7+
68
# Running (on Linux)
79

810
$ mpiexec -n 5 python script.py
@@ -21,3 +23,13 @@ There is also older version 1.3.1 in Linux repository which doesn't need compila
2123

2224
apt install python-mpi4py
2325
apt install python3-mpi4py
26+
27+
28+
---
29+
30+
Other packages with `mpi.h`: [Ubuntu packages]([http://packages.ubuntu.com/search?searchon=contents&keywords=mpi.h&mode=exactfilename&suite=lucid&arch=any)
31+
32+
---
33+
34+
- [MPICH](http://www.mpich.org/)
35+
- [MPI tutorial](http://mpitutorial.com/)

pyqt4/button-on_click/main.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python2
2+
3+
from PyQt4 import QtGui
4+
import sys
5+
6+
class MyWindow(QtGui.QWidget):
7+
8+
def __init__(self, parent=None):
9+
super(MyWindow, self).__init__()
10+
11+
self.clicks = 0
12+
13+
self.vbox = QtGui.QVBoxLayout()
14+
self.setLayout(self.vbox)
15+
16+
self.label = QtGui.QLabel(str(self.clicks), self)
17+
self.vbox.addWidget(self.label)
18+
19+
self.button = QtGui.QPushButton("Click Me!", self)
20+
self.vbox.addWidget(self.button)
21+
self.button.clicked.connect(self.on_click)
22+
23+
self.show()
24+
25+
def on_click(self):
26+
self.clicks += 1
27+
self.label.setText(str(self.clicks))
28+
29+
app = QtGui.QApplication(sys.argv)
30+
win = MyWindow()
31+
app.exec_()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
3+
'''Get starndard parameters'''
4+
5+
import tkinter as tk
6+
7+
# --- functions ---
8+
9+
def callback(event):
10+
print('Text:', event.widget['text'])
11+
12+
# --- main ---
13+
14+
root = tk.Tk()
15+
16+
w = tk.Label(root, text="Click here")
17+
w.pack()
18+
w.bind("<Button-1>", callback)
19+
20+
root.mainloop()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
3+
'''Assign extra parameter to instance'''
4+
5+
import tkinter as tk
6+
7+
# --- functions ---
8+
9+
def callback(event):
10+
print(' Text:', event.widget['text'])
11+
print('Extra:', event.widget.extra) # extra parameter
12+
13+
# --- main ---
14+
15+
root = tk.Tk()
16+
17+
w = tk.Label(root, text="Click here")
18+
w.pack()
19+
w.bind("<Button-1>", callback)
20+
w.extra = "Hello World" # extra parameter
21+
22+
root.mainloop()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
3+
'''Use extra parameter in bind'''
4+
5+
import tkinter as tk
6+
7+
# --- functions ---
8+
9+
def callback(event, extra):
10+
print(' Text:', event.widget['text'])
11+
print('Extra:', extra)
12+
13+
# --- main ---
14+
15+
root = tk.Tk()
16+
17+
w = tk.Label(root, text="Click here")
18+
w.pack()
19+
w.bind("<Button-1>", lambda event:callback(event, "Hello World"))
20+
21+
root.mainloop()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
You can find oryginal MessageBox
3+
4+
import tkinter.messagebox
5+
6+
print(tkinter.messagebox.__file__)
7+
8+
and see how it was made.
9+
10+
11+
But you can use `tkinter.Toplevel()` to create own MsgBox
12+
13+
# example-1.py
14+
15+
It uses function
16+
17+
![#1](screenshots/example-1.png?raw=true)
18+
19+
# example-1.py
20+
21+
It uses class `MsgBox` and shows how to change elements inside class.
22+
23+
For example it changes: label font, button text and position
24+
25+
![#2](screenshots/example-2.png?raw=true)
26+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import tkinter as tk
2+
3+
4+
# --- functions ---
5+
6+
def about():
7+
8+
win = tk.Toplevel()
9+
win.title("ABOUT")
10+
11+
l = tk.Label(win, text="One\nTwo Two\nThree Three Three", bg='white')
12+
l.pack(ipadx=50, ipady=10, fill='both', expand=True)
13+
14+
b = tk.Button(win, text="OK", command=win.destroy)
15+
b.pack(pady=10, padx=10, ipadx=20, side='right')
16+
17+
# --- main ---
18+
19+
root = tk.Tk()
20+
21+
b = tk.Button(root, text="About", command=about)
22+
b.pack(fill='x', expand=True)
23+
24+
b = tk.Button(root, text="Close", command=root.destroy)
25+
b.pack(fill='x', expand=True)
26+
27+
root.mainloop()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import tkinter as tk
2+
3+
# --- classes ---
4+
# you can put this in separated file (it will need `import tkinter`)
5+
6+
import tkinter
7+
8+
class MsgBox(tkinter.Toplevel):
9+
10+
def __init__(self, title="MsgBox", message="Hello World"):
11+
tkinter.Toplevel.__init__(self)
12+
13+
self.title(title)
14+
15+
self.label = tkinter.Label(self, text=message)
16+
self.label['bg'] = 'white'
17+
self.label.pack(ipadx=50, ipady=10, fill='both', expand=True)
18+
19+
self.button = tkinter.Button(self, text="OK")
20+
self.button['command'] = self.destroy
21+
self.button.pack(pady=10, padx=10, ipadx=20, side='right')
22+
23+
# --- functions ---
24+
25+
def about():
26+
27+
msg = MsgBox("ABOUT", "One\nTwo Two\nThree Three Three")
28+
msg.label['font'] = 'Verdana 20 bold'
29+
msg.button['text'] = 'Close'
30+
msg.button.pack(side='left')
31+
32+
# --- main ---
33+
34+
root = tk.Tk()
35+
36+
b = tk.Button(root, text="About", command=about)
37+
b.pack(fill='x', expand=True)
38+
39+
b = tk.Button(root, text="Close", command=root.destroy)
40+
b.pack(fill='x', expand=True)
41+
42+
root.mainloop()
Loading
Loading

tkinter/spinbox/example-2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import tkinter as tk
2+
3+
# --- functions ---
4+
5+
def callback():
6+
print("value:", w.get())
7+
8+
# --- main ---
9+
10+
root = tk.Tk()
11+
12+
w = tk.Spinbox(root, state='readonly', from_=1, to=5, command=callback)
13+
w.pack()
14+
15+
root.mainloop()

tkinter/spinbox/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import tkinter as tk
44

5+
# --- functions ---
6+
57
def on_change(event=None):
68
if event:
79
print('--- bind ---')
@@ -15,6 +17,7 @@ def on_change(event=None):
1517
print('widget:', sb)
1618
print(' value:', sb.get())
1719

20+
# --- main ---
1821

1922
root =tk.Tk()
2023

@@ -24,5 +27,4 @@ def on_change(event=None):
2427
sb.bind('<Key>', on_change)
2528
#sb.bind('<<Change>>', on_change) # doesn't work
2629

27-
2830
root.mainloop()

0 commit comments

Comments
 (0)