Skip to content

Commit c6b0ae0

Browse files
committed
add a "starter GUI" + work-a-round for tkinter usage with virtualenv under windows
Squashed commit of the following: commit e7beb32 Author: JensDiemer <[email protected]> Date: Wed Aug 19 11:42:41 2015 +0200 remove obsolete starter files commit 5ed7406 Author: JensDiemer <[email protected]> Date: Wed Aug 19 11:38:15 2015 +0200 "starter GUI" commit 0c1add8 Author: JensDiemer <[email protected]> Date: Wed Aug 19 11:27:20 2015 +0200 Add work-a-round for tkinter usage with virtualenv under windows, see: pypa/virtualenv#93 commit a35a94c Author: JensDiemer <[email protected]> Date: Wed Aug 19 09:42:45 2015 +0200 move settings in a frame, add status bar + code cleanup commit e6fa73e Author: JensDiemer <[email protected]> Date: Tue Aug 18 23:06:12 2015 +0200 WIP: seperate in frame/class commit b7008d6 Author: JensDiemer <[email protected]> Date: Tue Aug 18 22:06:48 2015 +0200 replace .sh scripts commit 3cecd83 Author: JensDiemer <[email protected]> Date: Tue Aug 18 17:27:39 2015 +0200 WIP: starter GUI
1 parent e5de8b6 commit c6b0ae0

16 files changed

+331
-268
lines changed

DragonPy_CLI.py

-31
This file was deleted.

README.creole

+34-29
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,30 @@ So you can easy update them e.g.:
110110
/home/FooBar/DragonPy_env/src/dragonpy$ git pull
111111
}}}
112112

113+
==== start DragonPy
114+
115+
The is a simple "starter GUI", just call the cli without arguments:
116+
117+
{{{~/DragonPy_env/bin/DragonPy}}}
118+
119+
Or call it in a activated environment, e.g.:
120+
{{{
121+
/home/FooBar$ cd DragonPy_env
122+
/home/FooBar/DragonPy_env$ source bin/activate
123+
(DragonPy_env)~/DragonPy_env$ DragonPy
124+
}}}
125+
126+
It is possible to start machines directly:
127+
{{{
128+
(DragonPy_env)~/DragonPy_env$ DragonPy --machine=Dragon32 run
129+
}}}
130+
131+
more info:
132+
{{{
133+
(DragonPy_env)~/DragonPy_env$ DragonPy --help
134+
}}}
135+
136+
113137
=== Windows
114138

115139
There are several ways to install the project under windows.
@@ -126,6 +150,13 @@ The default {{{boot_dragonpy.cmd}}} will install via {{{Python Package Index}}}
126150

127151
There exist some {{{.cmd}}} batch files for easy startup in {{{%APPDATA%\DragonPy_env\}}}
128152

153+
==== start DragonPy
154+
155+
The is a simple "starter GUI", just call the cli without arguments:
156+
157+
{{{%APPDATA%\DragonPy_env\Scripts\DragonPy.exe}}}
158+
159+
129160

130161
== ROMs
131162

@@ -143,35 +174,6 @@ sbc09 and vectrex ROMs are included.
143174
All ROM files and download will be checked by SHA1 value, before use.
144175

145176

146-
== cli example
147-
148-
start Dragon 32:
149-
{{{
150-
/home/FooBar$ cd DragonPy_env
151-
/home/FooBar/DragonPy_env$ source bin/activate
152-
(DragonPy_env)~/DragonPy_env$ DragonPy --machine=Dragon32 run
153-
}}}
154-
155-
start Dragon 64:
156-
{{{
157-
(DragonPy_env)~/DragonPy_env$ DragonPy --machine=Dragon64 run
158-
}}}
159-
160-
start CoCo with Extended Color Basic v1.1:
161-
{{{
162-
(DragonPy_env)~/DragonPy_env$ DragonPy --machine=CoCo2b run
163-
}}}
164-
165-
start Multicomp 6809:
166-
{{{
167-
(DragonPy_env)~/DragonPy_env$ DragonPy --machine=Multicomp6809 run
168-
}}}
169-
170-
start Lennart's 6809 single board computer:
171-
{{{
172-
(DragonPy_env)~/DragonPy_env$ DragonPy --machine=sbc09 run
173-
}}}
174-
175177
== unittests ==
176178

177179
=== run unittests ===
@@ -412,6 +414,9 @@ Six is a Python 2 and 3 compatibility library.
412414
413415
== History
414416

417+
* [[https://github.com/jedie/DragonPy/compare/v0.5.0...v0.5.1|??.08.2015 - v0.5.1]]: (not released, yet)
418+
** Add a "starter GUI"
419+
** Add work-a-round for tkinter usage with virtualenv under windows, see: [[https://github.com/pypa/virtualenv/issues/93|virtualenv issues #93]]
415420
* [[https://github.com/jedie/DragonPy/compare/v0.4.0...v0.5.0|18.08.2015 - v0.5.0]]:
416421
** ROM files will be downloaded on-the-fly ({{{.sh}}} scripts are removed. So it's easier to use under Windows)
417422
* [[https://github.com/jedie/DragonPy/compare/v0.3.2...v0.4.0|26.05.2015 - v0.4.0]]:

dragonpy/__init__.py

+73-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,74 @@
1+
import os
2+
import sys
13

2-
__version__ = "0.5.0"
4+
5+
__version__ = "0.5.1.dev0"
6+
7+
8+
def fix_virtualenv_tkinter():
9+
"""
10+
work-a-round for tkinter under windows in a virtualenv:
11+
"TclError: Can't find a usable init.tcl..."
12+
Known bug, see: https://github.com/pypa/virtualenv/issues/93
13+
14+
There are "fix tk" file here:
15+
16+
C:\Python27\Lib\lib-tk\FixTk.py
17+
C:\Python34\Lib\tkinter\_fix.py
18+
19+
These modules will be automatic imported by tkinter import.
20+
21+
The fix set theses environment variables:
22+
23+
TCL_LIBRARY C:\Python27\tcl\tcl8.5
24+
TIX_LIBRARY C:\Python27\tcl\tix8.4.3
25+
TK_LIBRARY C:\Python27\tcl\tk8.5
26+
27+
TCL_LIBRARY C:\Python34\tcl\tcl8.6
28+
TIX_LIBRARY C:\Python34\tcl\tix8.4.3
29+
TK_LIBRARY C:\Python34\tcl\tk8.6
30+
31+
but only if:
32+
33+
os.path.exists(os.path.join(sys.prefix,"tcl"))
34+
35+
And the virtualenv activate script will change the sys.prefix
36+
to the current env. So we temporary change it back to sys.real_prefix
37+
and import the fix module.
38+
If the fix module was imported before, then we reload it.
39+
"""
40+
if "TCL_LIBRARY" in os.environ:
41+
# Fix not needed (e.g. virtualenv issues #93 fixed?)
42+
return
43+
44+
if not hasattr(sys, "real_prefix"):
45+
# we are not in a activated virtualenv
46+
return
47+
48+
if sys.version_info[0] == 2:
49+
# Python v2
50+
virtualprefix = sys.prefix
51+
sys.prefix = sys.real_prefix
52+
53+
import FixTk
54+
55+
if "TCL_LIBRARY" not in os.environ:
56+
reload(FixTk)
57+
58+
sys.prefix = virtualprefix
59+
else:
60+
# Python v3
61+
virtualprefix = sys.base_prefix
62+
sys.base_prefix = sys.real_prefix
63+
64+
from tkinter import _fix
65+
66+
if "TCL_LIBRARY" not in os.environ:
67+
from imp import reload
68+
reload(_fix)
69+
70+
sys.base_prefix = virtualprefix
71+
72+
73+
if sys.platform.startswith("win"):
74+
fix_virtualenv_tkinter()

dragonpy/core/cli.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
import atexit
1717
import locale
1818
import logging
19-
import unittest
20-
from dragonpy.tests import run_tests
19+
import sys
2120

2221
try:
2322
# https://pypi.python.org/pypi/click/
@@ -35,6 +34,8 @@
3534
from basic_editor.editor import run_basic_editor
3635

3736
import dragonpy
37+
from dragonpy.core.gui_starter import start_gui
38+
from dragonpy.tests import run_tests
3839
from dragonpy.CoCo.config import CoCo2bCfg
3940
from dragonpy.CoCo.machine import run_CoCo2b
4041
from dragonpy.Dragon32.config import Dragon32Cfg
@@ -204,5 +205,18 @@ def tests(verbosity, failfast):
204205
run_tests(verbosity, failfast)
205206

206207

208+
def main(confirm_exit=True):
209+
if len(sys.argv)==1:
210+
if confirm_exit:
211+
def confirm():
212+
# don't close the terminal window directly
213+
# important for windows users ;)
214+
click.prompt("Please press [ENTER] to exit", default="", show_default=False)
215+
atexit.register(confirm)
216+
217+
start_gui(__file__, machine_dict)
218+
else:
219+
cli()
220+
207221
if __name__ == "__main__":
208-
cli()
222+
main()

0 commit comments

Comments
 (0)