Skip to content

Commit

Permalink
Merge branch 'dev_v0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
p1-dta committed Oct 26, 2018
2 parents f9a1de0 + f104e97 commit c93228a
Show file tree
Hide file tree
Showing 16 changed files with 281 additions and 218 deletions.
2 changes: 1 addition & 1 deletion chi_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from tkinter import Tk

from Window import MainWindow
from windows.MainWindow import MainWindow


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion EditGameSettingMenu.py → menus/EditGameSettingMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
from tkinter import Menu

from EditLengthMenu import EditLengthMenu
from menus.EditLengthMenu import EditLengthMenu


class EditGameSettingMenu(Menu):
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions EditMenu.py → menus/EditMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
from functools import partial
from tkinter import Menu, Tk

import Window
import WordsSets
from EditGameSettingMenu import EditGameSettingMenu
from windows import Window, SetWindow
from words_sets import WordsSets
from menus.EditGameSettingMenu import EditGameSettingMenu


class EditMenu(Menu):
Expand Down Expand Up @@ -54,5 +54,5 @@ def update_menu(self) -> None:

def create_set_window(self, word_set: WordsSets):
window = Tk()
Window.SetWindow(self, word_set, window)
SetWindow.SetWindow(self, word_set, window)
return
7 changes: 7 additions & 0 deletions FileMenu.py → menus/FileMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ def __init__(self, window) -> None:
self.add_command(label='Settings', command=callback)
self.add_separator()
self.add_command(label='Exit', command=window.ask_quit)
# disable : Under construction
self.entryconfig('Restart Game', state='disabled')
self.entryconfig('Stop Game', state='disabled')
self.entryconfig('New Set', state='disabled')
self.entryconfig('Import Set Pack', state='disabled')
self.entryconfig('Export Set Pack', state='disabled')
self.entryconfig('Settings', state='disabled')
return
8 changes: 8 additions & 0 deletions HelpMenu.py → menus/HelpMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def issue_redirect():
webbrowser.open('https://github.com/Vikka/ChiTrain/issues')


def trello_redirect():
webbrowser.open('https://trello.com/b/BzJe34V1/chitrain')


class HelpMenu(Menu):
def __init__(self) -> None:
Menu.__init__(self)
Expand All @@ -40,4 +44,8 @@ def __init__(self) -> None:
self.add_command(label='Github Repository',
command=repository_redirect)
self.add_command(label='Report Problem', command=issue_redirect)
self.add_command(label='Trello', command=trello_redirect)
self.add_command(label='About', command=callback)
# disable : Under construction
self.entryconfig('Getting Started', state='disabled')
self.entryconfig('About', state='disabled')
6 changes: 2 additions & 4 deletions MainMenuBar.py → menus/MainMenuBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
#
from tkinter import Menu

import EditMenu
import FileMenu
import HelpMenu
import Window
from menus import EditMenu, FileMenu, HelpMenu
from windows import Window


class MainMenuBar(Menu):
Expand Down
30 changes: 0 additions & 30 deletions sets.json

This file was deleted.

1 change: 1 addition & 0 deletions sets/sets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"sets": [{"name": "Beginner set 1", "first_language": "English", "second_language": "Chinese", "words": [{"first": "the body / one's health", "second": "shēntǐ - 身体", "weight": 50}, {"first": "how? / how about? / how was it? / how are things?", "second": "zěnmeyàng - 怎么样", "weight": 50}, {"first": "China", "second": "Zhōngguó - 中国", "weight": 50}, {"first": "early morning", "second": "zǎoshang - 早上", "weight": 50}, {"first": "to learn / to study", "second": "xuéxí - 学习", "weight": 50}, {"first": "foreign (country)", "second": "wàiguó - 外国", "weight": 50}, {"first": "map", "second": "dìtú - 地图", "weight": 50}, {"first": "(cooked) rice", "second": "mǐfàn - 米饭", "weight": 50}, {"first": "cake", "second": "dàngāo - 蛋糕", "weight": 50}, {"first": "writing brush", "second": "máobǐ - 毛笔", "weight": 50}, {"first": "stair / staircase", "second": "lóutī - 楼梯", "weight": 50}, {"first": "raincoat", "second": "yǔyī - 雨衣", "weight": 50}, {"first": "cat", "second": "māo - 猫", "weight": 50}, {"first": "dog", "second": "gǒu - 狗", "weight": 50}, {"first": "blackboard", "second": "hēibǎn - 黑板", "weight": 50}, {"first": "textbook", "second": "kèběn - 课本", "weight": 50}, {"first": "skin", "second": "pífū - 皮肤", "weight": 50}, {"first": "(wool) sweater", "second": "máoyī - 毛衣", "weight": 50}, {"first": "male / Baron, lowest of five orders of nobility", "second": "nán - 男", "weight": 50}, {"first": "south", "second": "nán - 南", "weight": 50}, {"first": "to reply / to answer / the answer", "second": "huídá - 回答", "weight": 50}, {"first": "question / problem / issue / topic", "second": "wèntí - 问题", "weight": 50}, {"first": "Chinese language", "second": "Hànyǔ - 汉语", "weight": 50}, {"first": "happy / merry", "second": "kuàilè - 快乐", "weight": 50}, {"first": "grammar", "second": "yǔfǎ - 语法", "weight": 50}, {"first": "United States / USA / US", "second": "Měiguó - 美国", "weight": 50}, {"first": "Thailand / Thai", "second": "Tàiguó - 泰国", "weight": 50}, {"first": "excessively / too", "second": "tàiguò - 太过", "weight": 50}, {"first": "Germany / German", "second": "Déguó - 德国", "weight": 50}, {"first": "Japan / Japanese", "second": "Rìběn - 日本", "weight": 50}, {"first": "man / person / people", "second": "rén - 人", "weight": 50}, {"first": "France / French", "second": "Fǎguó - 法国", "weight": 50}, {"first": "to welcome / welcome", "second": "huānyíng - 欢迎", "weight": 50}, {"first": "you (informal, as opposed to courteous 您)", "second": "nǐ - 你", "weight": 50}]}, {"name": "Beginner set 2", "first_language": "English", "second_language": "Chinese", "words": [{"first": "dictionary (of Chinese compound words)", "second": "cídiǎn - 词典", "weight": 50}, {"first": "(chicken) egg / hen's egg", "second": "jīdàn - 鸡蛋", "weight": 50}, {"first": "soccer ball / a football", "second": "zúqiú - 足球", "weight": 50}, {"first": "newspaper / newsprint", "second": "bàozhǐ - 报纸", "weight": 50}, {"first": "tissue / kleenex", "second": "báozhǐ - 薄纸", "weight": 50}, {"first": "banana", "second": "xiāngjiāo - 香蕉", "weight": 50}, {"first": "rubber / caoutchouc", "second": "xiàngjiāo - 橡胶", "weight": 50}, {"first": "piano", "second": "gāngqín - 钢琴", "weight": 50}, {"first": "bread", "second": "miànbāo - 面包", "weight": 50}, {"first": "coffee (loanword)", "second": "kāfēi - 咖啡", "weight": 50}, {"first": "beer (loanword)", "second": "píjiǔ - 啤酒", "weight": 50}, {"first": "tea / tea plant", "second": "chá - 茶", "weight": 50}, {"first": "book / letter / document", "second": "shū - 书", "weight": 50}, {"first": "pen / pencil / writing brush / to write or compose / the strokes of Chinese characters / classifier for sums of money, deals", "second": "bǐ - 笔", "weight": 50}, {"first": "exercise book / workbook", "second": "liànxíběn - 练习本", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}, {"first": "airplane", "second": "fēijī - 飞机", "weight": 50}]}, {"name": "People of China", "first_language": "English", "second_language": "Chinese", "words": [{"first": "Baozhi, or Pao-chih, Chinese monk (418–514)", "second": "Bǎozhì - 宝志", "weight": 50}]}, {"name": "Dictation 25/10/18", "first_language": "English", "second_language": "Chinese", "words": [{"first": "goodbye / see you again later", "second": "zàijiàn - 再见", "weight": 50}, {"first": "some / a few / a little / (following an adjective) slightly", "second": "yīxiē - 一些", "weight": 50}, {"first": "vegetables", "second": "shūcài - 蔬菜", "weight": 50}, {"first": "dining hall", "second": "shítáng - 食堂", "weight": 50}, {"first": "classroom", "second": "jiàoshì - 教室", "weight": 50}, {"first": "dormitory / dorm room / living quarters / hostel", "second": "sùshè - 宿舍", "weight": 50}, {"first": "American dollar / US dollar", "second": "Měiyuán - 美元", "weight": 50}, {"first": "we / us / ourselves / our", "second": "wǒmen - 我们", "weight": 50}, {"first": "Renminbi (RMB) / Chinese Yuan (CNY)", "second": "rénmínbì - 人民币", "weight": 50}, {"first": "student studying abroad / (foreign) exchange student ", "second": "liúxuéshēng - 留学生", "weight": 50}, {"first": "where? / wherever / anywhere", "second": "nǎr - 哪儿", "weight": 50}, {"first": "supermarket", "second": "chāoshì - 超市", "weight": 50}]}]}
151 changes: 6 additions & 145 deletions Window.py → windows/GameWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
import codecs
from json import load
from random import choices
from tkinter import IntVar, Label, Checkbutton, NE, Frame, Menu, StringVar, \
Entry, Tk, Button, EW
from tkinter.messagebox import askokcancel
from tkinter import Button, Label

from MainMenuBar import MainMenuBar, EditMenu
from WordsSets import WordsSet, WordsSets


class Window(Frame):
root: Tk

def __init__(self, parent=None):
Frame.__init__(self, parent)
Frame.pack(self)
self.root = parent

def ask_quit(self):
if askokcancel("Quit", "You want to quit now?"):
self.quit()
from windows.Window import Window


class GameWindow(Window):
Expand All @@ -58,7 +40,6 @@ def __init__(self, parent, root=None):
if value.get():
for it2, word in enumerate(
self.parent.words_sets.w_s_array[it].words):
print(word.second)
words_sample.append((word, it, it2))
if len(words_weight) > 0:
words_weight.append(words_weight[-1] + word.weight)
Expand All @@ -70,11 +51,6 @@ def __init__(self, parent, root=None):
game_length.get())
self.it = 0
self.first_turn()
print(words_sample)
print(words_weight)
# for words in self.parent.words_sets.ws_array
# weight = sum()
# self.root.var

def first_turn(self):
first_lang_lbl_txt = '{} : {}'.format(
Expand All @@ -85,16 +61,15 @@ def first_turn(self):
self.parent.words_sets.w_s_array[
self.words_choice[self.it][1]].second_language)
self.first_lang_lbl = Label(self, text=first_lang_lbl_txt,
font=("TkDefaultFont", 12))
font=("TkDefaultFont", 20))
self.scd_lang_lbl = Label(self, text=sec_lang_lbl_txt,
font=("TkDefaultFont", 12))
font=("TkDefaultFont", 20))
self.show_solution_btn = Button(self, text='Show solution',
font=("TkDefaultFont", 12),
command=self.show_solution)
self.first_lang_lbl.grid(column=0)
self.scd_lang_lbl.grid(column=0)
self.show_solution_btn.grid(column=0)
print(self.words_choice[self.it])

def show_solution(self):
self.show_solution_btn.destroy()
Expand All @@ -116,9 +91,6 @@ def correct(self):
self.words_choice[self.it][2]].weight -= \
self.parent.words_sets.w_s_array[self.words_choice[
self.it][1]].words[self.words_choice[self.it][2]].weight / 10
print(int(self.parent.words_sets.w_s_array[
self.words_choice[self.it][1]].words[
self.words_choice[self.it][2]].weight))
self.it += 1
if self.it < len(self.words_choice):
self.next_turn()
Expand All @@ -131,9 +103,6 @@ def incorrect(self):
weight += (100 - self.parent.words_sets.
w_s_array[self.words_choice[self.it][1]].
words[self.words_choice[self.it][2]].weight) / 10
print(int(self.parent.words_sets.w_s_array[
self.words_choice[self.it][1]].words[
self.words_choice[self.it][2]].weight))
self.it += 1
if self.it < len(self.words_choice):
self.next_turn()
Expand All @@ -153,126 +122,18 @@ def next_turn(self):
self.parent.words_sets.w_s_array[
self.words_choice[self.it][1]].second_language)
self.first_lang_lbl = Label(self, text=first_lang_lbl_txt,
font=("TkDefaultFont", 12))
font=("TkDefaultFont", 20))
self.scd_lang_lbl = Label(self, text=sec_lang_lbl_txt,
font=("TkDefaultFont", 12))
font=("TkDefaultFont", 20))
self.show_solution_btn = Button(self, text='Show solution',
font=("TkDefaultFont", 12),
command=self.show_solution)
self.first_lang_lbl.grid(column=0)
self.scd_lang_lbl.grid(column=0)
self.show_solution_btn.grid(column=0)
print(self.words_choice[self.it])

def destroy(self):
print('TEST DESTRUCTION')
self.parent.menu.file_menu.entryconfig("Start Game",
state='normal')
Window.destroy(self)
return


class MainWindow(Window):
var: list
menu: MainMenuBar
words_sets: WordsSets
set_checkbutton: Checkbutton
game_window: GameWindow

def __init__(self, parent=None):
Window.__init__(self, parent)
self.root.protocol('WM_DELETE_WINDOW', self.ask_quit)
select_label = Label(self, text='Select a set of word', anchor=NE)
select_label.grid(column=0, columnspan=2)
self.var = list()
with codecs.open('sets.json', 'r', encoding='utf-8') as sets:
self.words_sets = WordsSets(load(sets))
for words_set in self.words_sets.w_s_array:
self.var.append(IntVar())
self.set_checkbutton = Checkbutton(self,
text=words_set.get_name(),
variable=self.var[-1],
command=self.cb)
self.set_checkbutton.grid(column=0)
self.menu = MainMenuBar(self)
self.cb()
self.root.config(menu=self.menu)

def cb(self):
if len([value for value in self.var if value.get() > 0]):
self.menu.file_menu.entryconfig("Start Game", state='normal')
print('true')
else:
self.menu.file_menu.entryconfig("Start Game",
state='disabled')
print('false')
print('variable is {}'.format(list(map(lambda i: i.get(), self.var))))

def start(self):
window = Tk()
self.game_window = GameWindow(self, root=window)

def save(self):
print('save')
self.words_sets.save()

def ask_quit(self):
self.save()
Window.ask_quit(self)


# def askokcancel(title=None, message=None, **options):
# "Ask if operation should proceed; return true if the answer is ok"
# print("test")
# s = _show(title, message, QUESTION, OKCANCEL, **options)
# return s == OK


class SetWindow(Window):
menu: Menu
words_set: WordsSet

def __init__(self, edit_menu: EditMenu, words_set: WordsSet,
parent=None, ):
Window.__init__(self, parent)
self.window = parent
self.edit_menu = edit_menu
self.words_set = words_set
edit_menu.edit_set_menu.entryconfig(words_set.get_name(),
state='disabled')
self.menu = edit_menu.edit_set_menu
self.master.title(words_set.get_name())
first_lang_lbl = Label(self, text=words_set.first_language)
sec_lang_lbl = Label(self, text=words_set.second_language)
weight_lang_lbl = Label(self, text='Weight')
first_lang_lbl.grid(row=0, column=0)
sec_lang_lbl.grid(row=0, column=1)
weight_lang_lbl.grid(row=0, column=2)
for word in words_set.words:
frame = Frame(self)
frame.grid(column=0, columnspan=3)
first_txt_var = StringVar()
sec_txt_var = StringVar()
weight_txt_var = StringVar()
word_entry_left = Entry(frame,
textvariable=first_txt_var)
word_entry_left.grid(row=0, column=0)
word_entry_right = Entry(frame,
textvariable=sec_txt_var)
word_entry_right.grid(row=0, column=1)
word_entry_weight = Entry(frame,
textvariable=weight_txt_var)
word_entry_weight.grid(row=0, column=2)
word_entry_left.insert(0, word.first)
word_entry_right.insert(0, word.second)
word_entry_weight.insert(0, word.weight)

save_btn = Button(self, text='Save',
command=self.edit_menu.window.save)
save_btn.grid(column=0, columnspan=3, sticky=EW)

def destroy(self):
self.menu.entryconfig(self.words_set.get_name(),
state='normal')
Window.destroy(self)
return
Loading

1 comment on commit c93228a

@p1-dta
Copy link
Owner Author

@p1-dta p1-dta commented on c93228a Oct 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.