tegaki-train-0.3.1/0000755000175000017500000000000011352066723013751 5ustar mathieumathieutegaki-train-0.3.1/AUTHORS0000644000175000017500000000005711342122454015014 0ustar mathieumathieuMathieu Blondel tegaki-train-0.3.1/COPYING0000644000175000017500000004326211342122454015004 0ustar mathieumathieu GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program 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 2 of the License, or (at your option) any later version. This program 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. tegaki-train-0.3.1/PKG-INFO0000644000175000017500000000040111352066723015041 0ustar mathieumathieuMetadata-Version: 1.0 Name: tegaki-train Version: 0.3.1 Summary: Train Tegaki with your own handwriting Home-page: http://www.tegaki.org Author: Mathieu Blondel Author-email: mathieu ÂT mblondel DÔT org License: GPL Description: UNKNOWN Platform: UNKNOWN tegaki-train-0.3.1/README0000644000175000017500000000053511342122454014625 0ustar mathieumathieutegaki-train ============ Train Tegaki with your own handwriting. Requirements ------------ tegaki-pygtk 0.2 Install ------- ($ su) # python setup.py install License ------- This package is distributed under the terms of the GNU General Public License. See the COPYING file for more information. Homepage -------- http://www.tegaki.org tegaki-train-0.3.1/ChangeLog0000644000175000017500000001234511352066723015530 0ustar mathieumathieucommit 5b0b86343c91cbf3d7ee683e82f41f9df75edf4d Author: Mathieu Blondel Date: Mon Mar 22 15:32:33 2010 +0900 [all] Set current version to 0.3.1. commit e82a9a10d6026bb00986771ba271a3e3bd4b2dba Author: Mathieu Blondel Date: Wed Dec 9 14:38:30 2009 +0900 [tegaki-train] Display number of samples loaded. commit b617936d1d4fd3ab90ea9e809269bd60640765d0 Author: Mathieu Blondel Date: Wed Dec 9 14:33:15 2009 +0900 [tegaki-train] Fixed issue when remove set. commit 3a8fda6ee285f4a345f78c11786aaa98ee4210c4 Author: Mathieu Blondel Date: Wed Dec 9 14:12:59 2009 +0900 [tegaki-train] Various optimizations. commit b01080cac237d887095914c235c475c8715d7b6f Author: Mathieu Blondel Date: Wed Dec 2 20:38:05 2009 +0900 [tegaki-train] Use new add_sets() method from CharacterCollection. commit 05f0d6cff9083f8ed7b609ec5b17f5566f24a9ee Author: Mathieu Blondel Date: Wed Dec 2 20:23:52 2009 +0900 [tegaki-train] Use CharacterCollection new save method. commit acdb0ccf066906c9659ca5842c36167c99248d38 Author: Mathieu Blondel Date: Tue Dec 1 17:29:02 2009 +0900 [tegaki-train] Support for new CharacterCollection features. commit 23428970b5125e6effc233ff3261e6cb368ff93d Author: Mathieu Blondel Date: Sun Nov 1 20:56:48 2009 +0900 [all] Include ChangeLog. commit 991c47ea9f7649668ce7d2f956324d089cbcbf3b Author: Mathieu Blondel Date: Sun Oct 25 17:51:33 2009 +0900 [tegaki-train] Updated program usage. commit a12003aa571315d61746e6d7d4f7d01486de6f6c Author: Christoph Burgmer Date: Thu Oct 22 23:58:45 2009 +0200 [tegaki-train] Fix path issue when opening file from command-line. commit f6cbdc87b45a49eafb3017fbd4f27611e3d81157 Author: Christoph Burgmer Date: Wed Oct 21 12:31:44 2009 +0200 [tegaki-train] Allow passing a file to tegaki-train on the command line. commit d9da822b70070363a4f7f62dde3b3c848793385f Author: Mathieu Blondel Date: Fri Sep 18 01:47:11 2009 +0900 [tegaki-train] Added "play" button. commit 4250cd855f4f734e00db2dbdf69416ca5846489c Author: Mathieu Blondel Date: Sat Sep 12 18:08:13 2009 +0900 [tegaki-train] Display information about opened file. commit 072589a2417565b3697ae3abc8e547b06ccde39d Author: Mathieu Blondel Date: Sun Jul 19 11:45:53 2009 +0200 [all] Update project URL. commit 10ea23607f9a0879e1c1c459cf83e763286871da Author: Mathieu Blondel Date: Sun Jul 19 05:23:37 2009 +0200 [tegaki,tegaki-gtk] Renamed the packages to respectively tegaki-python and tegaki-pygtk to make it clear that they are Python packages. commit c66e016c6a63617fa1f3e0a1b79a99188fea59df Author: Mathieu Blondel Date: Fri Jul 10 13:09:38 2009 +0200 [all] Added --version option for command line tools. commit ec4bd0c94683b85e1ef2beac4b7f5e5e5f1c5dfd Author: Mathieu Blondel Date: Wed Jul 8 05:17:10 2009 +0200 [all] Changed the way credits are displayed. commit 0d17a2fe71128383fb3e7d0def4e5062b1c930e7 Author: Mathieu Blondel Date: Mon Jul 6 16:57:32 2009 +0200 [all] Updated for future version 0.2. commit 1dde5564e7e00c8fb0fcd9e8995172fec492e517 Author: Mathieu Blondel Date: Wed Jul 1 07:53:59 2009 +0200 [tegaki-train] Training support! commit 61cf082f9308708a67bc7faa25daf34003b12aa3 Author: Mathieu Blondel Date: Mon Jun 29 17:53:06 2009 +0200 [tegaki-train] Display number of samples in set. commit 75de71812021c5e965ee12f7625870efb8d5c5a3 Author: Mathieu Blondel Date: Mon Jun 29 17:19:40 2009 +0200 [tegaki-train] Show file name in window's title. commit 7a08d70ef9ad75d35609e7ace5d505d3bc5c77e4 Author: Mathieu Blondel Date: Mon Jun 29 17:10:21 2009 +0200 [tegaki-train] Added recent file menu. commit dc478bf53651916168f64615c5f399ff8b35d00f Author: Mathieu Blondel Date: Mon Jun 29 14:13:04 2009 +0200 [tegaki-train] Can now double click on icons. commit 602de5aa9d5e0d02436fea64da03e1890433f745 Author: Mathieu Blondel Date: Mon Jun 29 14:08:23 2009 +0200 [tegaki-train] Replaces buttons with checkboxes for "center", "normalize" and "smooth". commit ba8666145fdeecec53e86755a76af202bc489a81 Author: Mathieu Blondel Date: Mon Jun 29 13:00:04 2009 +0200 [tegaki-train] Can now use New/Open/Save/SaveAs. commit 6aa548e08ab46926fb7cc4fb9e29db6de304b409 Author: Mathieu Blondel Date: Mon Jun 29 11:06:56 2009 +0200 [tegaki-train] Can now add character samples to character sets. commit 1ec31f641c7eb7e7d1e661c355fce157aa596955 Author: Mathieu Blondel Date: Mon Jun 29 06:51:03 2009 +0200 [tegaki-train] Populate the left pane. commit 3b62d6f803ae4863ac00a667a55035379bf3e723 Author: Mathieu Blondel Date: Sat Jun 27 10:27:02 2009 +0200 [tegaki-train] User interface skeleton. tegaki-train-0.3.1/setup.py0000644000175000017500000000126611342122454015461 0ustar mathieumathieu# -*- coding: utf-8 -*- from distutils.core import setup import os def getversion(): currdir = os.path.dirname(os.path.abspath(__file__)) path = os.path.join(currdir, "bin", "tegaki-train") import re regexp = re.compile(r"VERSION = '([^']*)'") f = open(path) buf = f.read() f.close() return regexp.search(buf).group(1) # Please run # python setup.py install setup( name = 'tegaki-train', description = 'Train Tegaki with your own handwriting', author = 'Mathieu Blondel', author_email = 'mathieu ÂT mblondel DÔT org', url = 'http://www.tegaki.org', version = getversion(), license='GPL', scripts = ['bin/tegaki-train'], )tegaki-train-0.3.1/MANIFEST.in0000644000175000017500000000024411342122454015500 0ustar mathieumathieuinclude AUTHORS COPYING COPYRIGHT README TODO MANIFEST.in ChangeLog exclude *~ *.orig *.bak *.tmp *.pyc MANIFEST recursive-include tests * recursive-include data * tegaki-train-0.3.1/COPYRIGHT0000644000175000017500000000027411342122454015240 0ustar mathieumathieuThe code included in this package is copyrighted by Mathieu Blondel : Copyright (C) 2009 Mathieu Blondel. All Rights Reserved. See the COPYING File for the terms of distribution licence.tegaki-train-0.3.1/bin/0000755000175000017500000000000011352066723014521 5ustar mathieumathieutegaki-train-0.3.1/bin/tegaki-train0000755000175000017500000012305611352064314017027 0ustar mathieumathieu#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2009 The Tegaki project contributors # # This program 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 2 of the License, or # (at your option) any later version. # # This program 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. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Contributors to this file: # - Mathieu Blondel # - Christoph Burgmer import os from optparse import OptionParser import glib import gtk from gtk import gdk from tegaki.character import Character from tegaki.charcol import CharacterCollection from tegaki.trainer import Trainer from tegakigtk.iconview import WritingIconView, _WritingPixbufRenderer from tegakigtk.canvas import Canvas VERSION = '0.3.1' PREDEFINED_SETS = { "Digits" : [[48,57]], "Letters" : [[97,122]], "Hiragana" : [[0x3041, 0x3096]], "Katakana" : [[0x30A1, 0x30F7]] } class AddCharacterSetDialog(gtk.Dialog): def __init__(self, parent): gtk.Dialog.__init__(self) self._init_dialog(parent) self._create_ui() def _init_dialog(self, parent): self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) self.set_default_response(gtk.RESPONSE_OK) self.set_has_separator(True) self.set_transient_for(parent) self.set_border_width(6) self.set_modal(True) self.set_title("Add characters") def _create_ui(self): # Add from char self._char_vbox = gtk.VBox(spacing=5) self._char_radio = gtk.RadioButton(group=None, label="Characters") self._char_entry = gtk.Entry() label = gtk.Label() label.set_alignment(0.0, 0.0) ex = "Examples:\na\na, b, c\n0x65..0x70, 0x72" label.set_markup(ex) self._char_vbox.pack_start(self._char_entry) self._char_vbox.pack_start(label) # Add from predefined set self._set_vbox = gtk.VBox(spacing=5) self._set_radio = gtk.RadioButton(group=self._char_radio, label="Predefined set") self._create_set_combo() self._set_vbox.pack_start(self._set_combo) self._set_vbox.set_sensitive(False) # Add from file self._file_vbox = gtk.VBox(spacing=5) self._file_radio = gtk.RadioButton(group=self._char_radio, label="From UTF8 file") self._file_button = gtk.FileChooserButton("Choose file") exp = "All the characters found in this file will be added." label = gtk.Label() label.set_alignment(0.0, 0.0) label.set_markup(exp) self._file_vbox.pack_start(self._file_button) self._file_vbox.pack_start(label) self._file_vbox.set_sensitive(False) # Main vbox main_vbox = self.get_child() main_vbox.set_spacing(10) main_vbox.pack_start(self._char_radio) main_vbox.pack_start(self._char_vbox) main_vbox.pack_start(self._set_radio) main_vbox.pack_start(self._set_vbox) main_vbox.pack_start(self._file_radio) main_vbox.pack_start(self._file_vbox) self._char_radio.connect("toggled", self._on_toggle_option) self._set_radio.connect("toggled", self._on_toggle_option) self._file_radio.connect("toggled", self._on_toggle_option) self.show_all() def _on_toggle_option(self, widget): for radio, vbox in [[self._char_radio, self._char_vbox], [self._set_radio, self._set_vbox], [self._file_radio, self._file_vbox]]: vbox.set_sensitive(radio.get_active()) def _create_set_combo(self): self._set_combo = gtk.ComboBox(gtk.ListStore(str)) cell = gtk.CellRendererText() self._set_combo.pack_start(cell, True) self._set_combo.add_attribute(cell, 'text', 0) keys = PREDEFINED_SETS.keys() keys.sort() for k in keys: self._set_combo.append_text(k) self._set_combo.set_active(0) def get_charsets(self): if self._char_radio.get_active(): return self._get_charsets_from_list() elif self._set_radio.get_active(): return self._get_charsets_from_predefined_set() elif self._file_radio.get_active(): return self._get_charsets_from_file() def _get_char_from_str(self, s): try: return self._get_utf8_from_int(self._get_int_from_str(s)) except ValueError: return s def _get_int_from_str(self, s): if s.startswith("0x"): return int(s, 16) else: return int(s) def _get_utf8_from_int(self, i): return unichr(i).encode("utf-8") def _get_charsets_from_list(self): elements = self._char_entry.get_text().strip().split(",") chars = [] for element in elements: element = element.strip() if ".." in element: # this is a range val = [s.strip() for s in element.split("..")] inf = self._get_int_from_str(val[0]) sup = self._get_int_from_str(val[1]) if sup < inf: continue chars += [self._get_utf8_from_int(i) for i in range(inf, sup+1)] else: # this is an individual character chars.append(self._get_char_from_str(element)) return chars def _get_charsets_from_predefined_set(self): keys = PREDEFINED_SETS.keys() keys.sort() k = keys[self._set_combo.get_active()] characters = [] for val in PREDEFINED_SETS[k]: if isinstance(val, int): characters.append(self._get_utf8_from_int(val)) elif isinstance(val, list): for code in range(val[0], val[1]+1): characters.append(self._get_utf8_from_int(code)) return characters def _get_charsets_from_file(self): filename = self._file_button.get_filename() if not filename: return [] f = open(filename) buf = f.read() f.close() try: unicodestr = unicode(buf, "utf-8") except UnicodeDecodeError: return [] unicodestr = unicodestr.replace("\t", "") unicodestr = unicodestr.replace("\n", "") unicodestr = unicodestr.replace("\r", "") unicodestr = unicodestr.replace(" ", "") d = {} for char in unicodestr: d[char] = 1 return d.keys() class TrainDialog(gtk.Dialog): def __init__(self, parent): gtk.Dialog.__init__(self) self._init_dialog(parent) self._create_ui() def _init_dialog(self, parent): self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) self.set_response_sensitive(gtk.RESPONSE_OK, False) self.set_default_response(gtk.RESPONSE_OK) self.set_has_separator(True) self.set_transient_for(parent) self.set_border_width(6) self.set_modal(True) self.set_title("Train") def _create_ui(self): self._table = gtk.Table(rows=4, columns=2) self._table.set_row_spacings(8) self._table.set_col_spacings(5) self._table.attach(gtk.Label("Engine"), 0, 1, 0, 1) self._create_engine_combo() self._table.attach(self._engine_combo, 1, 2, 0, 1) self._table.attach(gtk.Label("Name"), 0, 1, 1, 2) self._name_entry = gtk.Entry() self._name_entry.connect("changed", self._on_entry_changed) self._table.attach(self._name_entry, 1, 2, 1, 2) self._table.attach(gtk.Label("Short name"), 0, 1, 2, 3) self._shortname_entry = gtk.Entry() self._shortname_entry.connect("changed", self._on_entry_changed) self._table.attach(self._shortname_entry, 1, 2, 2, 3) self._table.attach(gtk.Label("Language"), 0, 1, 3, 4) self._create_lang_comboentry() self._table.attach(self._lang_comboentry, 1, 2, 3, 4) # Main vbox main_vbox = self.get_child() main_vbox.set_spacing(10) main_vbox.pack_start(self._table) #msg = "The model is going to be saved in\n%s." % \ #os.path.join(os.environ["HOME"], ".tegaki", "models") #label = gtk.Label() #label.set_markup(msg) #main_vbox.pack_start(label) self.show_all() def _on_entry_changed(self, widget): if len(Trainer.get_available_trainers()) == 0: self.set_response_sensitive(gtk.RESPONSE_OK, False) return for entry in [self._name_entry, self._shortname_entry]: if entry.get_text().strip() == "": self.set_response_sensitive(gtk.RESPONSE_OK, False) return self.set_response_sensitive(gtk.RESPONSE_OK, True) def _create_engine_combo(self): self._engine_combo = gtk.ComboBox(gtk.ListStore(str)) cell = gtk.CellRendererText() self._engine_combo.pack_start(cell, True) self._engine_combo.add_attribute(cell, 'text', 0) for engine in Trainer.get_available_trainers(): self._engine_combo.append_text(engine) self._engine_combo.set_active(0) def _create_lang_comboentry(self): self._lang_comboentry = gtk.ComboBoxEntry(gtk.ListStore(str)) for lang in ["ja", "zh_CN", "zh_TW", "None"]: self._lang_comboentry.append_text(lang) self._lang_comboentry.set_active(0) def get_name(self): return self._name_entry.get_text().strip() def get_shortname(self): return self._shortname_entry.get_text().strip() def get_lang(self): lang = self._lang_comboentry.child.get_text().strip() if lang == "None": lang = None return lang def get_meta(self): return { "name" : self.get_name(), "shortname" : self.get_shortname(), "language" : self.get_lang() } def get_engine(self): i = self._engine_combo.get_active() keys = Trainer.get_available_trainers().keys() return keys[i] class EditCharacterSampleWindow(gtk.Window): def __init__(self, parent): gtk.Window.__init__(self) self._init_window(parent) def _init_window(self, parent): vbox = gtk.VBox(spacing=2) hbox = gtk.HBox(spacing=3) label = gtk.Label() label.set_markup("Character value:") hbox.pack_start(label, expand=False) self._entry = gtk.Entry() hbox.pack_start(self._entry) vbox.pack_start(hbox) frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_ETCHED_IN) self._canvas = Canvas() frame.add(self._canvas) vbox.pack_start(frame) hbox = gtk.HBox() self._revert_button = gtk.Button(stock=gtk.STOCK_UNDO) self._revert_button.connect("clicked", self._on_revert) hbox.pack_start(self._revert_button) self._clear_button = gtk.Button(stock=gtk.STOCK_CLEAR) self._clear_button.connect("clicked", self._on_clear) hbox.pack_start(self._clear_button) self._replay_button = gtk.Button(stock=gtk.STOCK_MEDIA_PLAY) self._replay_button.connect("clicked", self._on_replay) hbox.pack_start(self._replay_button) vbox.pack_start(hbox) align = gtk.Alignment(xalign=0.5, yalign=0.0, xscale=0.0, yscale=0.0) vbox2 = gtk.VBox() self._center_button = gtk.CheckButton("Center") self._center_button.set_active(True) vbox2.pack_start(self._center_button) self._norm_button = gtk.CheckButton("Normalize") self._norm_button.set_active(False) vbox2.pack_start(self._norm_button) self._smooth_button = gtk.CheckButton("Smooth") self._smooth_button.set_active(False) vbox2.pack_start(self._smooth_button) align.add(vbox2) vbox.pack_start(align) self.add(vbox) self.set_default_size(400, 500) self.set_title("Edit character sample") self.set_transient_for(parent) self.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.set_modal(True) def _on_revert(self, widget): self._canvas.revert_stroke() def _on_clear(self, widget): self._canvas.clear() def _on_replay(self, widget): self._canvas.replay() def get_character_value(self): return self._entry.get_text().strip() def set_character_value(self, value): self._entry.set_text(value.strip()) def get_writing(self): writing = self._canvas.get_writing() if self._center_button.get_active(): writing .normalize_position() if self._norm_button.get_active(): writing .normalize() if self._smooth_button.get_active(): writing .smooth() return writing def set_writing(self, writing): self._canvas.set_writing(writing) def get_character(self): utf8 = self.get_character_value() writing = self.get_writing() character = Character() character.set_utf8(utf8) character.set_writing(writing) return character def set_character(self, character): self.set_character_value(character.get_utf8()) self.set_writing(character.get_writing()) class CharacterSetListView(gtk.TreeView): def __init__(self, parent): self._model = gtk.ListStore(str) gtk.TreeView.__init__(self, self._model) self._init() self._parentw = parent self._charsets = {} def _init(self): column = gtk.TreeViewColumn("Character sets") cell = gtk.CellRendererText() column.pack_start(cell, expand=True) column.set_min_width(100) column.add_attribute(cell, 'text', 0) column.set_sort_column_id(0) self.set_search_column(0) self.set_headers_visible(False) self.set_reorderable(True) self.append_column(column) cell = gtk.CellRendererText() column = gtk.TreeViewColumn(None, cell) column.set_cell_data_func(cell, self._set_to_cell) self.append_column(column) def _set_to_cell(self, column, cell, model, iter): charset = model[iter][0] n_chars = self._parentw._charcol.get_n_characters(charset) cell.props.text = str(n_chars) def append_charset(self, charset): if not self.includes_charset(charset): self._model.append((charset,)) self._charsets[charset] = 1 def remove_selected_charset(self): seliter = self.get_selection().get_selected()[1] charset = self.get_model().get_value(seliter, 0) self.get_model().remove(seliter) del self._charsets[charset] return charset def includes_charset(self, charset): return charset in self._charsets def get_selected_charset(self): if self.get_selection().count_selected_rows() == 0: return None else: seliter = self.get_selection().get_selected()[1] return self._model.get_value(seliter, 0) class CharacterFileChooserDialog(gtk.FileChooserDialog): def __init__(self, title, parent, action=gtk.FILE_CHOOSER_ACTION_OPEN): if action == gtk.FILE_CHOOSER_ACTION_OPEN: buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK) else: buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK) gtk.FileChooserDialog.__init__(self, title, parent, action, buttons) self._init_dialog() def _init_dialog(self): self.set_default_size(400, 400) for name, pat in [["XML", "*.xml"], ["Gzip-compressed XML", "*.xml.gz"], ["Bz2-compressed XML", "*.xml.bz2"], ["All files", "*.*"]]: filt = gtk.FileFilter() filt.set_name(name) filt.add_pattern(pat) self.add_filter(filt) self.set_default_response(gtk.RESPONSE_OK) self.set_preview_widget(gtk.Image()) self.connect("selection-changed", self._selection_changed) def _selection_changed(self, widget): filename = self.get_preview_filename() if filename: char = self._get_character(filename) if char: image = self.get_preview_widget() writing = char.get_writing() writing.smooth() renderer = _WritingPixbufRenderer(writing, 200, 200) renderer.set_draw_annotations(False) renderer.draw_background() #renderer.draw_axis() renderer.draw_writing() pixbuf = renderer.get_pixbuf() image.set_from_pixbuf(pixbuf) self.set_preview_widget_active(True) else: self.set_preview_widget_active(False) def get_character(self): return self._get_character(self.get_filename()) def _get_character(self, filename): char = Character() try: if filename.endswith(".gz"): char.read(filename, gzip=True) elif filename.endswith(".bz2"): char.read(filename, bz2=True) else: char.read(filename) except ValueError: # incorrect XML return None return char def set_character(self, char): filename = self.get_filename() if filename.endswith(".gz"): char.write(filename, gzip=True) elif filename.endswith(".bz2"): char.write(filename, bz2=True) else: char.write(filename) class CharacterCollectionFileChooserDialog(gtk.FileChooserDialog): def __init__(self, title, parent, action=gtk.FILE_CHOOSER_ACTION_OPEN): if action == gtk.FILE_CHOOSER_ACTION_OPEN: buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK) else: buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK) gtk.FileChooserDialog.__init__(self, title, parent, action, buttons) self._init_dialog() def _init_dialog(self): self.set_default_size(400, 400) alltypes = ["*.charcol", "*.charcol.gz", "*.charcol.bz2", "*.chardb"] for name, pats in [["All supported files", alltypes], ["Character collection (DB)", alltypes[3]], ["Character collection (XML)", alltypes[0]], ["Gzip-compressed Character collection (XML)", alltypes[1]], ["Bz2-compressed Character collection (XML)", alltypes[2]], ["All files", "*.*"]]: filt = gtk.FileFilter() filt.set_name(name) if not isinstance(pats, list): pats = [pats] for pat in pats: filt.add_pattern(pat) self.add_filter(filt) self.set_default_response(gtk.RESPONSE_OK) def get_character_collection(self): return CharacterCollectionFileChooserDialog. \ open_character_collection(self.get_filename ()) @staticmethod def open_character_collection(filename): try: return CharacterCollection(filename) except ValueError: return None def set_character_collection(self, charcol): filename = self.get_filename() CharacterCollectionFileChooserDialog. \ save_character_collection(charcol, filename) @staticmethod def save_character_collection(charcol, filename): charcol.save(filename) class QuestionDialog(gtk.MessageDialog): def __init__(self, parent, msg): gtk.MessageDialog.__init__(self, parent, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, msg) class TegakiTrainError(Exception): pass class TegakiTrain(object): def __init__(self, options, args): self._charcol = CharacterCollection() self._create_window() self._update_title() if args: if len(args) != 1: raise TegakiTrainError("More than one input specified") charcol = CharacterCollectionFileChooserDialog\ .open_character_collection(args[0]) current_folder, filename = os.path.split(args[0]) self._load_file(charcol, current_folder, args[0]) def _load_file(self, charcol, current_folder, filename): self._curr_folder = current_folder self._curr_file = filename self._update_title() if charcol: self._add_recent(self._curr_file) self._charcol = charcol self._iconview.get_model().clear() self._refresh_treeview() self._disable_save() self._display_charcol_stats() def _on_new(self, widget): if not self._save_is_enabled() or self._confirm_continue(): if "_curr_file" in self.__dict__: del self.__dict__["_curr_file"] self._update_title() self._charcol = CharacterCollection() self._treeview.get_model().clear() self._iconview.get_model().clear() def _display_charcol_stats(self): msg = "%d sets (%d characters) loaded!" % \ (self._charcol.get_n_sets(), self._charcol.get_total_n_characters()) self._statusbar_push(msg, sec=5) def _on_open(self, widget): if not self._save_is_enabled() or self._confirm_continue(): dialog = CharacterCollectionFileChooserDialog( "Open Character Collection", self._window, action=gtk.FILE_CHOOSER_ACTION_OPEN) if "_curr_folder" in self.__dict__ and self._curr_folder: dialog.set_current_folder(self._curr_folder) response = dialog.run() if response == gtk.RESPONSE_OK: charcol = dialog.get_character_collection() self._load_file(charcol, dialog.get_current_folder(), dialog.get_filename()) dialog.destroy() def _on_recent_activated(self, widget): filename = self._recent_menu.get_current_item().get_uri_display() self._curr_file = filename self._update_title() self._charcol = CharacterCollectionFileChooserDialog.\ open_character_collection(filename) self._iconview.get_model().clear() self._refresh_treeview() self._disable_save() self._display_charcol_stats() def _add_recent(self, filename): meta = {'mime_type':'text/xml', 'app_name':'tegaki-train', 'app_exec':'tegaki-train'} if not filename.startswith("file://"): filename = "file://" + filename self._recent_manager.add_full(filename, meta) def _update_title(self): if "_curr_file" in self.__dict__: basename = os.path.basename(self._curr_file) self._window.set_title("Tegaki Train - %s" % basename) else: self._window.set_title("Tegaki Train - Unsaved file") def _refresh_treeview(self): self._treeview.get_model().clear() for charset in self._charcol.get_set_list(): self._treeview.append_charset(charset) def _confirm_continue(self): dialog = QuestionDialog(self._window, "Some changes have not been saved yet, continue anyway?") response = dialog.run() dialog.destroy() return response == gtk.RESPONSE_YES def _on_save(self, widget): if "_curr_file" in self.__dict__: CharacterCollectionFileChooserDialog. \ save_character_collection(self._charcol, self._curr_file) self._disable_save() self._statusbar_push("File saved!", sec=5) else: self._on_save_as(widget) def _on_save_as(self, widget): dialog = CharacterCollectionFileChooserDialog( "Save Character Collection", self._window, action=gtk.FILE_CHOOSER_ACTION_SAVE) if "_curr_folder" in self.__dict__: dialog.set_current_folder(self._curr_folder) response = dialog.run() if response == gtk.RESPONSE_OK: self._curr_folder = dialog.get_current_folder() self._curr_file = dialog.get_filename() self._update_title() self._add_recent(self._curr_file) dialog.set_character_collection(self._charcol) self._disable_save() self._statusbar_push("File saved!", sec=5) dialog.destroy() def _enable_save(self): self._global_actions.get_action("Save").set_sensitive(True) def _disable_save(self): self._global_actions.get_action("Save").set_sensitive(False) def _save_is_enabled(self): return self._global_actions.get_action("Save").get_sensitive() def _on_train(self, widget): dialog = TrainDialog(self._window) dialog.connect("response", self._on_train_done) dialog.run() def _on_train_done(self, dialog, response): if response == gtk.RESPONSE_OK: if self._charcol.get_total_n_characters() > 0: meta = dialog.get_meta() engine = dialog.get_engine() trainer_class = Trainer.get_available_trainers()[engine] trainer = trainer_class() trainer.train(self._charcol, meta) self._statusbar_push("Model trained!", sec=5) dialog.destroy() def _on_quit(self, widget): if not self._save_is_enabled() or self._confirm_continue(): gtk.main_quit() else: return True #def _on_copy(self, widget): #pass #def _on_select_all(self, widget): #pass def _on_toggle_statusbar(self, widget): active = self._global_actions.get_action("Statusbar").get_active() self._statusbar.set_property("visible", active) def _on_toggle_toolbar(self, widget): active = self._global_actions.get_action("Toolbar").get_active() self._toolbar.set_property("visible", active) def _on_toggle_icon_text(self, widget): active = self._global_actions.get_action("IconText").get_active() if active: self._iconview.show_icon_text() else: self._iconview.hide_icon_text() def _on_icon_large(self, widget): self._set_icon_size(150) def _on_icon_medium(self, widget): self._set_icon_size(100) def _on_icon_small(self, widget): self._set_icon_size(50) def _set_icon_size(self, size): self._iconview.set_item_width(size) charset = self._treeview.get_selected_charset() if charset: characters = self._charcol.get_characters(charset) self._iconview.set_characters(characters) def _on_add_charset(self, widget): dialog = AddCharacterSetDialog(self._window) dialog.connect("response", self._on_add_charset_done) dialog.run() def _on_add_charset_done(self, dialog, response): if response == gtk.RESPONSE_OK: charsets = dialog.get_charsets() for charset in charsets: self._treeview.append_charset(charset) self._charcol.add_sets(charsets) self._enable_save() dialog.destroy() def _on_remove_charset(self, widget): charset = self._treeview.remove_selected_charset() self._charcol.remove_set(charset) self._enable_save() def _on_charset_selection_changed(self, widget): if self._treeview.get_selection().count_selected_rows() >= 1: sensitive = True charset = self._treeview.get_selected_charset() characters = self._charcol.get_characters(charset) else: sensitive = False characters = [] # Sensitize button accordingly self._remove_charset_button.set_sensitive(sensitive) for s in ["AddSample", "AddSampleFromFile"]: self._global_actions.get_action(s).set_sensitive(sensitive) # Iconview self._iconview.set_characters(characters) # Status bar msg self._statusbar_push("%d samples loaded!" % len(characters), sec=5) def _on_add_sample(self, widget): window = EditCharacterSampleWindow(self._window) charset = self._treeview.get_selected_charset() if self._charcol.get_n_characters(charset) == 0: charvalue = charset else: char = self._charcol.get_characters(charset, limit=1) charvalue = char[0].get_utf8() window.set_character_value(charvalue) window.connect("delete-event", self._on_add_sample_done) window.show_all() def _on_add_sample_done(self, window, event): charset = self._treeview.get_selected_charset() character = window.get_character() self._charcol.append_character(charset, character) # FIXME; update the corresponding character only self._iconview.set_characters(self._charcol.get_characters(charset)) self._enable_save() def _on_icon_selection_changed(self, widget): selitems = widget.get_selected_items() if len(selitems) == 0: sensitive = False else: sensitive = True for s in ["EditSample", "SaveSampleToFile", "RemoveSample"]: self._global_actions.get_action(s).set_sensitive(sensitive) def _on_add_sample_from_file(self, widget): dialog = CharacterFileChooserDialog("Open Character", self._window) if "_curr_folder" in self.__dict__: dialog.set_current_folder(self._curr_folder) response = dialog.run() if response == gtk.RESPONSE_OK: self._curr_folder = dialog.get_current_folder() char = dialog.get_character() if char: charset = self._treeview.get_selected_charset() self._charcol.append_character(charset, char) chars = self._charcol.get_characters(charset) self._iconview.set_characters(chars) self._enable_save() dialog.destroy() def _on_edit_sample(self, widget, path=None): window = EditCharacterSampleWindow(self._window) charset = self._treeview.get_selected_charset() selitems = self._iconview.get_selected_items() charindex = selitems[0][0] char = self._charcol.get_characters(charset, limit=1, offset=charindex) window.set_character(char[0]) window.connect("delete-event", self._on_edit_sample_done) window.show_all() def _on_edit_sample_done(self, window, event): charset = self._treeview.get_selected_charset() character = window.get_character() selitems = self._iconview.get_selected_items() charindex = selitems[0][0] self._charcol.replace_character(charset, charindex, character) self._iconview.set_characters(self._charcol.get_characters(charset)) self._enable_save() def _on_remove_sample(self, widget): selitems = self._iconview.get_selected_items() charset = self._treeview.get_selected_charset() charindex = selitems[0][0] self._charcol.remove_character(charset, charindex) chars = self._charcol.get_characters(charset) self._iconview.set_characters(chars) self._enable_save() def _on_save_sample_to_file(self, widget): dialog = CharacterFileChooserDialog("Save Character", self._window, action=gtk.FILE_CHOOSER_ACTION_SAVE) if "_curr_folder" in self.__dict__: dialog.set_current_folder(self._curr_folder) response = dialog.run() if response == gtk.RESPONSE_OK: self._curr_folder = dialog.get_current_folder() charset = self._treeview.get_selected_charset() selitems = self._iconview.get_selected_items() charindex = selitems[0][0] char = self._charcol.get_characters(charset, limit=1, offset=charindex) dialog.set_character(char[0]) dialog.destroy() def _statusbar_push(self, msg, sec=-1): msgid = self._statusbar.push(0, msg) if sec != -1: def myfunc(): self._statusbar.remove(0, msgid) return False glib.timeout_add_seconds(sec, myfunc) def _create_menu(self): self._uimanager = gtk.UIManager() menu_xml = \ """ """ toolbar_xml = \ """ """ # [(name, stock_id, label, accelerator, tooltip, proc), ... ] standard_actions = [ ("FileMenu", None, "_File"), ("New", gtk.STOCK_NEW, None, None, None, self._on_new), ("Open", gtk.STOCK_OPEN, None, None, None, self._on_open), ("OpenRecent", None, "Open Recent"), ("Save", gtk.STOCK_SAVE, None, None, None, self._on_save), ("SaveAs", gtk.STOCK_SAVE_AS, None, None, None, self._on_save_as), ("Train", gtk.STOCK_EXECUTE, "_Train", None, None, self._on_train), ("Quit", gtk.STOCK_QUIT, None, None, None, self._on_quit), ("EditMenu", None, "_Edit"), ("AddSample", gtk.STOCK_ADD, "Add sample", None, None, self._on_add_sample), ("AddSampleFromFile", None, "Add sample from file", None, None, self._on_add_sample_from_file), ("EditSample", gtk.STOCK_EDIT, "Edit sample", None, None, self._on_edit_sample), ("SaveSampleToFile", None, "Save sample to file", None, None, self._on_save_sample_to_file), ("RemoveSample", gtk.STOCK_REMOVE, "Remove sample", None, None, self._on_remove_sample), #("Copy", gtk.STOCK_COPY, None, None, None, self._on_copy), #("SelectAll", None, "Select _All", "A", None, self._on_select_all), ("ViewMenu", None, "_View"), ("IconSizeMenu", None, "Icon size"), ("IconLarge", None, "Large", None, None, self._on_icon_large), ("IconMedium", None, "Medium", None, None, self._on_icon_medium), ("IconSmall", None, "Small", None, None, self._on_icon_small), ] toggle_actions = [ ("IconText", None, "Icon text", None, None, self._on_toggle_icon_text, 1), ("Statusbar", None, "_Statusbar", None, None, self._on_toggle_statusbar, 1), ("Toolbar", None, "_Toolbar", None, None, self._on_toggle_toolbar, 1), ] self._global_actions = gtk.ActionGroup("Standard actions") self._global_actions.add_actions(standard_actions) self._global_actions.add_toggle_actions(toggle_actions) # Default to False for s in ["AddSample", "AddSampleFromFile", "EditSample", "SaveSampleToFile", "RemoveSample", "Save"]: self._global_actions.get_action(s).set_sensitive(False) self._uimanager.insert_action_group(self._global_actions, 0) self._uimanager.add_ui_from_string(menu_xml) self._uimanager.add_ui_from_string(toolbar_xml) self._menubar = self._uimanager.get_widget("/MainMenubar") self._toolbar = self._uimanager.get_widget("/Toolbar") self._toolbar.set_border_width(0) # Recent files self._recent_manager = gtk.recent_manager_get_default() self._recent_menu = gtk.RecentChooserMenu(self._recent_manager) self._recent_menu.connect("item-activated", self._on_recent_activated) self._recent_menu.set_show_not_found(False) self._recent_menu.set_local_only(True) self._recent_menu.set_show_tips(False) self._recent_menu.set_sort_type(gtk.RECENT_SORT_MRU) filt = gtk.RecentFilter() filt.add_application("tegaki-train") #filt.add_pattern("*.charcol") #filt.add_pattern("*.charcol.gz") #filt.add_pattern("*.charcol.bz2") self._recent_menu.add_filter(filt) self._recent_menu.set_limit(15) open_r = self._uimanager.get_widget("/MainMenubar/FileMenu/OpenRecent") open_r.set_submenu(self._recent_menu) open_r.show() def _create_left_pane(self): self._leftvbox = gtk.VBox() frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_ETCHED_IN) label = gtk.Label("Character sets") frame.add(label) self._leftvbox.pack_start(frame, expand=False) frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_ETCHED_IN) scrolledwindow = gtk.ScrolledWindow() scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self._treeview = CharacterSetListView(self) selection = self._treeview.get_selection() selection.connect("changed", self._on_charset_selection_changed) scrolledwindow.add(self._treeview) frame.add(scrolledwindow) self._leftvbox.pack_start(frame) hbox = gtk.HBox() self._add_charset_button = gtk.Button(stock=gtk.STOCK_ADD) self._add_charset_button.connect("clicked", self._on_add_charset) self._remove_charset_button = gtk.Button(stock=gtk.STOCK_REMOVE) self._remove_charset_button.connect("clicked", self._on_remove_charset) self._remove_charset_button.set_sensitive(False) hbox.pack_start(self._add_charset_button) hbox.pack_start(self._remove_charset_button) self._leftvbox.pack_start(hbox, expand=False) def _create_window(self): self._window = gtk.Window() self._window.connect("delete-event", lambda w,e: self._on_quit(w)) self._create_menu() self._window.add_accel_group(self._uimanager.get_accel_group()) main_vbox = gtk.VBox() main_vbox.pack_start(self._menubar, expand=False) main_vbox.pack_start(self._toolbar, expand=False) self._sidepane = gtk.HPaned() self._create_left_pane() self._sidepane.add1(self._leftvbox) frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_ETCHED_IN) scrolledwindow = gtk.ScrolledWindow() scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self._iconview = WritingIconView() self._iconview.connect("selection-changed", self._on_icon_selection_changed) self._iconview.connect("item-activated", self._on_edit_sample) self._global_actions.get_action("IconText").set_active(False) scrolledwindow.add(self._iconview) frame.add(scrolledwindow) self._sidepane.add2(frame) main_vbox.pack_start(self._sidepane, padding=2) self._statusbar = gtk.Statusbar() main_vbox.pack_start(self._statusbar, expand=False, padding=2) self._window.add(main_vbox) self._window.set_default_size(650, 500) self._window.show_all() def run(self): gtk.main() usage = "Usage: %prog [options] [charcol-file]" parser = OptionParser(usage=usage, version="%prog " + VERSION) (options, args) = parser.parse_args() try: TegakiTrain(options, args).run() except TegakiTrainError, e: sys.stderr.write(str(e) + "\n\n") parser.print_help() sys.exit(1)