Skip to content

Commit

Permalink
Merge pull request #23 from mizo0203/feature-show-display
Browse files Browse the repository at this point in the history
画面にしりとりを表示できるソフトを作成
  • Loading branch information
みぞ@CrazyBeatCoder committed Sep 30, 2018
2 parents 265d42a + 5411c0c commit 6be7f0c
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tool/ShiritoriDisplay/ShiritoriDisplay.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- coding: UTF-8 -*-

# Copyright 2018 Hayato Kubo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ShiritoriDisplayWidget:

<ShiritoriDisplayWidget>:
BoxLayout:
orientation: 'vertical'
size: root.size
BoxLayout:
orientation: 'horizontal'
size_hint_y: 0.1
Button:
text: '通信停止' if root.is_connect else '通信開始'
font_size: 20
on_press: root.on_command('start/stop')
Button:
text: '画面更新'
font_size: 20
on_press: root.on_command('refresh')
Label:
text: root.count
text_size: self.size
halign: 'right'
valign: 'center'
font_size: 20
BoxLayout:
orientation: 'horizontal'
size_hint_y: 0.5
Label:
text: root.word
size_hint_x: 0.8
font_size: 100
Label:
text: root.word_end
size_hint_x: 0.2
font_size: 100
Label:
text: root.word_list
size_hint_y: 1
text_size: self.size
halign: 'left'
valign: 'top'
font_size: 50
<Widget>:
canvas.after:
Line:
rectangle: self.x+1,self.y+1,self.width-1,self.height-1
109 changes: 109 additions & 0 deletions tool/ShiritoriDisplay/ShiritoriDisplay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# -*- coding: UTF-8 -*-

# Copyright 2018 Hayato Kubo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from kivy.app import App
from kivy.clock import Clock
from kivy.core.text import LabelBase, DEFAULT_FONT
from kivy.properties import BooleanProperty, StringProperty
from kivy.resources import resource_add_path
from kivy.uix.widget import Widget

import requests

resource_add_path('./fonts')
LabelBase.register(DEFAULT_FONT, 'ipag.ttf')

# FIXME
URL = 'https://'
PARAMETER = '?id='
ID = ''
REQUEST_URL = URL + PARAMETER + ID

REQUEST_INTERVAL = 10.0


def convertWords2Text(words):
out_text = ''
word_list = words.split(',')
for i, v in enumerate(word_list):
if i % 2 == 0:
out_text = u'AI :' + v + u'\n' + out_text
else:
out_text = u'User:' + v + u'\n' + out_text
return out_text


class ShiritoriDisplayWidget(Widget):
is_connect = BooleanProperty()
word = StringProperty()
word_end = StringProperty()
count = StringProperty()
word_list = StringProperty()

def __init__(self, **kwargs):
super(ShiritoriDisplayWidget, self).__init__(**kwargs)
self.is_connect = False
self.word = u'開始待ち'
self.word_end = u'ち'
self.count = u'0回目'
self.word_list = u''

def get_JSON(self):
r = requests.get(REQUEST_URL)
if r.status_code == 200:
obj = r.json()
if obj and self.word != obj['last_word']:
self.word = obj['last_word']
self.word_end = obj['last_word_end']
self.count = str(obj['count']) + u'回目'
self.word_list = convertWords2Text(obj['words'])

def on_command(self, command):
if command == 'start/stop':
if self.is_connect:
self.stop_connect()
else:
self.start_connect()
elif command == 'refresh':
self.get_JSON()

def on_timer(self, dt):
self.get_JSON()

def start_connect(self):
self.is_connect = True
Clock.schedule_interval(self.on_timer, REQUEST_INTERVAL)

def stop_connect(self):
self.is_connect = False
Clock.unschedule(self.on_timer, REQUEST_INTERVAL)


class ShiritoriDisplayApp(App):
def __init__(self, **kwargs):
super(ShiritoriDisplayApp, self).__init__(**kwargs)
self.title = 'ShiritoriDisplay'

def build(self):
return ShiritoriDisplayWidget()


if __name__ == '__main__':
ShiritoriDisplayApp().run()
Loading

0 comments on commit 6be7f0c

Please sign in to comment.