-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
209 lines (151 loc) · 5.74 KB
/
main.py
File metadata and controls
209 lines (151 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
########################################################################
# This file is part of wikikircandroid3.
#
# wikikircandroid3 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wikikircandroid3 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
########################################################################
from os import _exit
from threading import Thread
import textwrap
import kivy
kivy.require('1.10.0')
from kivy.core.window import Window
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.widget import Widget
from kivy.properties import NumericProperty, ListProperty
from kivy.properties import StringProperty
from kivy.clock import Clock
from kivy.core.audio import SoundLoader
from wikikIRC3 import MyIRCBot
from note import Note
from sys import platform
print("Platform = {}".format(platform))
# Window size sur PC
if platform == 'linux':
k = 0.6
WS = (int(720*k), int(1280*k))
Window.size = WS
class WikikIRC:
def __init__(self):
print("Initialisation de WikikIRC ok")
server_list = [("irc.wikimedia.org", 6667)]
channel = "#fr.wikipedia"
nickname = "La Labomedia"
realname = "Syntaxis analysis with Python bot"
# Tourne tout le temps
self.bot = MyIRCBot(server_list,
channel,
nickname,
realname,
bavard=False)
# Boucle infinie pour envoi continu à tous les joueurs
self.get_modif_thread()
def get_modif(self):
self.bot.start()
def get_modif_thread(self):
thread_s = Thread(target=self.get_modif)
thread_s.start()
class MainScreen(Screen, WikikIRC):
"""Ecran principal"""
info = StringProperty()
volume = NumericProperty(1.0)
f_size = NumericProperty(18) #36)
def __init__(self, **kwargs):
Screen.__init__(self, **kwargs)
WikikIRC.__init__(self)
self.info = "Patience et longueur de temps font plus que force ni que rage !"
self.f_size = 18 #36
# Chargement des sons
self.notes = {}
for i in range(36):
self.notes[i] = SoundLoader.load( './samples/' +
str(i) +
'.ogg')
# Rafraichissement du jeu
tempo = 0.03
self.event = Clock.schedule_interval(self.wikirc_update, tempo)
print("Initialisation de MainScreen ok")
def wikirc_update(self, dt):
# Pour nouvel info
info_old = self.info
# Sortie IRC
try:
wo = self.bot.wiki_out
if 600 < len(wo) <= 1000:
self.f_size = 14 #28
ln = 50
elif 1000 < len(wo) <= 1400:
self.f_size = 12 #24
ln = 60
elif 1400 < len(wo) <= 1800:
self.f_size = 10 #20
ln = 70
elif 1800 < len(wo):
self.f_size = 9 #18
ln = 80
else:
self.f_size = 18 #36
ln = 40
except:
self.info = "Patience et longueur de temps font plus que force ni que rage !"
self.info = textwrap.fill(wo, ln)
# Si un nouvel info, donc une seule fois par info
if self.info != info_old:
self.phrase_note = Note(self.info)
n = self.phrase_note.get_note()
self.volume = self.phrase_note.get_volume()
if n:
self.sound(n)
def sound(self, n):
"""Joue la note n"""
self.notes[n].volume = self.volume
self.notes[n].play()
def get_sm(self):
return WikikircAndroidApp.get_running_app().sm
class WikikircAndroidApp(App):
"""Construction de l'application. Execute par __main__"""
def build(self):
"""Execute en premier apres run()"""
# Création des écrans
self.sm = ScreenManager()
self.sm.add_widget(MainScreen(name="Main"))
return self.sm
def build_config(self, config):
"""Si le fichier *.ini n'existe pas,
il est créé avec ces valeurs par défaut.
Si il manque seulement des lignes, il ne fait rien !
"""
config.setdefaults('kivy',
{ 'log_level': 'debug',
'log_name': 'multipong_%y-%m-%d_%_.txt',
'log_dir': '/sdcard',
'log_enable': '1'})
config.setdefaults('postproc',
{ 'double_tap_time': 250,
'double_tap_distance': 20})
def go_mainscreen(self):
"""Retour au menu principal depuis les autres ecrans."""
#if touch.is_double_tap:
self.sm.current = ("Main")
def do_quit(self):
print("Je quitte proprement")
# Stop propre de Clock
menu = self.sm.get_screen("Main")
menu.event.cancel()
# Kivy
WikikircAndroidApp.get_running_app().stop()
# Extinction de tout
_exit(0)
if __name__ == '__main__':
WikikircAndroidApp().run()