Skip to content

Commit

Permalink
GUIKit配置
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroki Fujii committed Mar 21, 2020
0 parents commit d8f248f
Show file tree
Hide file tree
Showing 75 changed files with 2,433 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.pyc
*.log
__pycache__
settings.ini
keymap.ini
*.bat
*log.txt
build/
dist/
*.obj
*.exp
*.lib
*.spec
23 changes: 23 additions & 0 deletions Application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
#Application startup file

import win32timezone#ダミー
def _(string): pass#dummy

#dllを相対パスで指定した時のため、カレントディレクトリを変更
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))

import app as application
import constants
import globalVars

def main():
app=application.Main()
globalVars.app=app
app.initialize()
app.MainLoop()
app.config.write()

#global schope
if __name__ == "__main__": main()
73 changes: 73 additions & 0 deletions ConfigManager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
#ConfigManager
#Copyright (C) 2019-2020 yamahubuki <[email protected]>

import os
import configparser
import logging
from logging import getLogger

class ConfigManager(configparser.ConfigParser):


def __init__(self):
super().__init__()
self.identifier="ConfigManager"
self.log=getLogger(self.identifier)
self.log.debug("Create config instance")

def read(self,fileName):
self.fileName=fileName
if os.path.exists(fileName):
self.log.info("read configFile:"+fileName)
try:
return super().read(fileName)
except configparser.ParsingError:
self.log.warning("configFile parse failed.")
return []
else:
self.log.warning("configFile not found.")
return []

def write(self):
self.log.info("write configFile:"+self.fileName)
with open(self.fileName,"w") as f: return super().write(f)

def __getitem__(self,key):
try:
return ConfigSection(super().__getitem__(key))
except KeyError as e:
self.log.debug("created new section:"+key)
self.add_section(key)
return self.__getitem__(key)

def getint(self,section,key,default=0):
try:
return super().getint(section,key)
except configparser.NoOptionError as e:
self.log.debug("add new intval "+str(default)+" at section "+section+", key "+key)
self[section][key]=str(default)
return int(default)
except configparser.NoSectionError as e:
self.log.debug("add new section and intval "+str(default)+" at section "+section+", key "+key)
self.add_section(section)
self.__getitem__(section).__setitem__(key,str(default))
return int(default)

def add_section(self,name):
if not self.has_section(name):
return super().add_section(name)

class ConfigSection(configparser.SectionProxy):
def __init__(self,proxy):
super().__init__(proxy._parser, proxy._name)

def __getitem__(self,key):
try:
return super().__getitem__(key)
except KeyError:
self._parser[self._name][key]=""
return ""

def __setitem__(self,key,value):
return super().__setitem__(key,str(value))
27 changes: 27 additions & 0 deletions DefaultSettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
#default config

from ConfigManager import *


class DefaultSettings:
def get():
config = ConfigManager()
config["general"]={
"language": "ja-JP",
"fileVersion": "100",
"locale": "ja-JP"
}
config["view"]={
"font": "bold 'MS ゴシック' 22 windows-932",
"colorMode":"normal"
}
config["speech"]={
"reader" : "AUTO"
}
config["mainView"]={
"sizeX": "800",
"sizeY": "600",
}

return config
66 changes: 66 additions & 0 deletions accessible_output2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from __future__ import absolute_import
import ctypes
import os
import sys
import types

def load_library(libname, cdll=False):
if is_frozen():
libfile = os.path.join(embedded_data_path(), 'accessible_output2', 'lib', libname)
else:
libfile = os.path.join(module_path(), 'lib', libname)
if cdll:
return ctypes.cdll[libfile]
else:
return ctypes.windll[libfile]

def get_output_classes():
from . import outputs
module_type = types.ModuleType
classes = [m.output_class for m in outputs.__dict__.values() if type(m) == module_type and hasattr(m, 'output_class')]
return sorted(classes, key=lambda c: c.priority)

def find_datafiles():
import os
import platform
from glob import glob
import accessible_output2
if platform.system() != 'Windows':
return []
path = os.path.join(accessible_output2.__path__[0], 'lib', '*.dll')
results = glob(path)
dest_dir = os.path.join('accessible_output2', 'lib')
return [(dest_dir, results)]

def is_frozen():
"""Return a bool indicating if application is compressed"""
import imp
return hasattr(sys, 'frozen') or imp.is_frozen("__main__")

#------------------------------------------------------
#
#platform_utilsからのぬきだし
#
#------------------------------------------------------
import inspect

def embedded_data_path():
"""Returns the full executable path/name if frozen, or the full path/name of the main module if not."""
if is_frozen():
executable = sys.executable
else:
try:
import __main__
executable = os.path.abspath(__main__.__file__)
except AttributeError:
executable = sys.argv[0]

path = os.path.abspath(os.path.dirname(executable))
return path

def module_path(level=2):
return os.path.abspath(os.path.dirname(get_module(level)))

def get_module(level=2):
"""Hacky method for deriving the caller of this function's module."""
return inspect.getmodule(inspect.stack()[level][0]).__file__
Binary file added accessible_output2/lib/PCTKUSR.dll
Binary file not shown.
Binary file added accessible_output2/lib/PCTKUSR64.dll
Binary file not shown.
Binary file added accessible_output2/lib/SAAPI32.dll
Binary file not shown.
Binary file added accessible_output2/lib/dolapi.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
21 changes: 21 additions & 0 deletions accessible_output2/outputs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from __future__ import absolute_import
import platform
if platform.system() == 'Windows':
from . import nvda
from . import jaws
from . import sapi5
# from . import sapi4
from . import window_eyes
from . import system_access
from . import dolphin
from . import pc_talker
#import sapi4

if platform.system() == 'Darwin':
from . import nsSpeechSynth
from . import voiceover

if platform.system() == 'Linux':
from . import e_speak

from . import auto
40 changes: 40 additions & 0 deletions accessible_output2/outputs/auto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from __future__ import absolute_import
import accessible_output2
from .base import Output, OutputError

class Auto(Output):

def __init__(self):
output_classes = accessible_output2.get_output_classes()
self.outputs = []
for output in output_classes:
try:
self.outputs.append(output())
except OutputError:
pass

def get_first_available_output(self):
for output in self.outputs:
if output.is_active():
return output
return None

def speak(self, *args, **kwargs):
output = self.get_first_available_output()
if output:
output.speak(*args, **kwargs)

def braille(self, *args, **kwargs):
output = self.get_first_available_output()
if output:
output.braille(*args, **kwargs)

def output(self, *args, **kwargs):
output = self.get_first_available_output()
if output:
output.speak(*args, **kwargs)

def is_system_output(self):
output = self.get_first_available_output()
if output:
return output.is_system_output()
47 changes: 47 additions & 0 deletions accessible_output2/outputs/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from accessible_output2 import load_library
import platform

class OutputError(Exception):
pass

class Output(object):
name = "Unnamed Output"
lib32 = None
lib64 = None
argtypes = {}
cdll = False
priority = 100
system_output = False

def __init__(self):
self.is_32bit = platform.architecture()[0] == "32bit"
if self.lib32 and self.is_32bit:
self.lib = load_library(self.lib32, cdll=self.cdll)
elif self.lib64:
self.lib = load_library(self.lib64, cdll=self.cdll)
else:
self.lib = None
if self.lib is not None:
for func in self.argtypes:
try:
getattr(self.lib, func).argtypes = self.argtypes[func]
except AttributeError:
pass

def output(self, text, **options):
output = False
if self.speak(text, **options):
output = True
if self.braille(text, **options):
output = True
if not output:
raise RuntimeError("Output %r does not have any method defined to output" % self)

def is_system_output(self):
return self.system_output

def speak(self, text, **options):
return False

def braille(self, text, **options):
return False
33 changes: 33 additions & 0 deletions accessible_output2/outputs/dolphin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from __future__ import absolute_import
import os
import ctypes

from .base import Output

class Dolphin (Output):
"""Supports dolphin products."""

name = 'Dolphin'
lib32 = 'dolapi.dll'
argtypes = {
'DolAccess_Command': (ctypes.c_wchar_p, ctypes.c_int, ctypes.c_int),
'DolAccess_Action': (ctypes.c_int,),
}

def speak(self, text, interrupt=0):
if interrupt:
self.silence()
#If we don't call this, the API won't let us speak.
if self.is_active():
self.lib.DolAccess_Command(text, (len(text)*2)+2, 1)

def silence(self):
self.lib.DolAccess_Action(141)

def is_active(self):
try:
return self.lib.DolAccess_GetSystem() in (1, 4, 8)
except:
return False

output_class = Dolphin
31 changes: 31 additions & 0 deletions accessible_output2/outputs/e_speak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from __future__ import absolute_import
from .base import Output

try:
import espeak.core
except:
raise RuntimeError("Cannot find espeak.core. Please install python-espeak")

class ESpeak(Output):
"""Speech output supporting ESpeak on Linux
Note this requires python-espeak to be installed
This can be done on Debian distros by using apt-get install python-espeak
Or through this tarball: https://launchpad.net/python-espeak
"""
name = "Linux ESpeak"

def is_active(self):
try:
import espeak.core
except:
return False
return True

def speak(self, text, interrupt = 0):
if interrupt:
self.silence()
espeak.core.synth(text)
def silence(self):
espeak.core.cancel()

output_class = ESpeak
Loading

0 comments on commit d8f248f

Please sign in to comment.