Skip to content

Commit

Permalink
add a "starter GUI" + work-a-round for tkinter usage with virtualenv …
Browse files Browse the repository at this point in the history
…under windows

Squashed commit of the following:

commit e7beb32
Author: JensDiemer <git@jensdiemer.de>
Date:   Wed Aug 19 11:42:41 2015 +0200

    remove obsolete starter files

commit 5ed7406
Author: JensDiemer <git@jensdiemer.de>
Date:   Wed Aug 19 11:38:15 2015 +0200

    "starter GUI"

commit 0c1add8
Author: JensDiemer <git@jensdiemer.de>
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 <git@jensdiemer.de>
Date:   Wed Aug 19 09:42:45 2015 +0200

    move settings in a frame, add status bar + code cleanup

commit e6fa73e
Author: JensDiemer <git@jensdiemer.de>
Date:   Tue Aug 18 23:06:12 2015 +0200

    WIP: seperate in frame/class

commit b7008d6
Author: JensDiemer <git@jensdiemer.de>
Date:   Tue Aug 18 22:06:48 2015 +0200

    replace .sh scripts

commit 3cecd83
Author: JensDiemer <git@jensdiemer.de>
Date:   Tue Aug 18 17:27:39 2015 +0200

    WIP: starter GUI
  • Loading branch information
jedie committed Aug 19, 2015
1 parent e5de8b6 commit c6b0ae0
Show file tree
Hide file tree
Showing 16 changed files with 331 additions and 268 deletions.
31 changes: 0 additions & 31 deletions DragonPy_CLI.py

This file was deleted.

63 changes: 34 additions & 29 deletions README.creole
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ So you can easy update them e.g.:
/home/FooBar/DragonPy_env/src/dragonpy$ git pull
}}}

==== start DragonPy

The is a simple "starter GUI", just call the cli without arguments:

{{{~/DragonPy_env/bin/DragonPy}}}

Or call it in a activated environment, e.g.:
{{{
/home/FooBar$ cd DragonPy_env
/home/FooBar/DragonPy_env$ source bin/activate
(DragonPy_env)~/DragonPy_env$ DragonPy
}}}

It is possible to start machines directly:
{{{
(DragonPy_env)~/DragonPy_env$ DragonPy --machine=Dragon32 run
}}}

more info:
{{{
(DragonPy_env)~/DragonPy_env$ DragonPy --help
}}}


=== Windows

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

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

==== start DragonPy

The is a simple "starter GUI", just call the cli without arguments:

{{{%APPDATA%\DragonPy_env\Scripts\DragonPy.exe}}}



== ROMs

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


== cli example

start Dragon 32:
{{{
/home/FooBar$ cd DragonPy_env
/home/FooBar/DragonPy_env$ source bin/activate
(DragonPy_env)~/DragonPy_env$ DragonPy --machine=Dragon32 run
}}}

start Dragon 64:
{{{
(DragonPy_env)~/DragonPy_env$ DragonPy --machine=Dragon64 run
}}}

start CoCo with Extended Color Basic v1.1:
{{{
(DragonPy_env)~/DragonPy_env$ DragonPy --machine=CoCo2b run
}}}

start Multicomp 6809:
{{{
(DragonPy_env)~/DragonPy_env$ DragonPy --machine=Multicomp6809 run
}}}

start Lennart's 6809 single board computer:
{{{
(DragonPy_env)~/DragonPy_env$ DragonPy --machine=sbc09 run
}}}

== unittests ==

=== run unittests ===
Expand Down Expand Up @@ -412,6 +414,9 @@ Six is a Python 2 and 3 compatibility library.
== History

* [[https://github.com/jedie/DragonPy/compare/v0.5.0...v0.5.1|??.08.2015 - v0.5.1]]: (not released, yet)
** Add a "starter GUI"
** Add work-a-round for tkinter usage with virtualenv under windows, see: [[https://github.com/pypa/virtualenv/issues/93|virtualenv issues #93]]
* [[https://github.com/jedie/DragonPy/compare/v0.4.0...v0.5.0|18.08.2015 - v0.5.0]]:
** ROM files will be downloaded on-the-fly ({{{.sh}}} scripts are removed. So it's easier to use under Windows)
* [[https://github.com/jedie/DragonPy/compare/v0.3.2...v0.4.0|26.05.2015 - v0.4.0]]:
Expand Down
74 changes: 73 additions & 1 deletion dragonpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,74 @@
import os
import sys

__version__ = "0.5.0"

__version__ = "0.5.1.dev0"


def fix_virtualenv_tkinter():
"""
work-a-round for tkinter under windows in a virtualenv:
"TclError: Can't find a usable init.tcl..."
Known bug, see: https://github.com/pypa/virtualenv/issues/93
There are "fix tk" file here:
C:\Python27\Lib\lib-tk\FixTk.py
C:\Python34\Lib\tkinter\_fix.py
These modules will be automatic imported by tkinter import.
The fix set theses environment variables:
TCL_LIBRARY C:\Python27\tcl\tcl8.5
TIX_LIBRARY C:\Python27\tcl\tix8.4.3
TK_LIBRARY C:\Python27\tcl\tk8.5
TCL_LIBRARY C:\Python34\tcl\tcl8.6
TIX_LIBRARY C:\Python34\tcl\tix8.4.3
TK_LIBRARY C:\Python34\tcl\tk8.6
but only if:
os.path.exists(os.path.join(sys.prefix,"tcl"))
And the virtualenv activate script will change the sys.prefix
to the current env. So we temporary change it back to sys.real_prefix
and import the fix module.
If the fix module was imported before, then we reload it.
"""
if "TCL_LIBRARY" in os.environ:
# Fix not needed (e.g. virtualenv issues #93 fixed?)
return

if not hasattr(sys, "real_prefix"):
# we are not in a activated virtualenv
return

if sys.version_info[0] == 2:
# Python v2
virtualprefix = sys.prefix
sys.prefix = sys.real_prefix

import FixTk

if "TCL_LIBRARY" not in os.environ:
reload(FixTk)

sys.prefix = virtualprefix
else:
# Python v3
virtualprefix = sys.base_prefix
sys.base_prefix = sys.real_prefix

from tkinter import _fix

if "TCL_LIBRARY" not in os.environ:
from imp import reload
reload(_fix)

sys.base_prefix = virtualprefix


if sys.platform.startswith("win"):
fix_virtualenv_tkinter()
20 changes: 17 additions & 3 deletions dragonpy/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import atexit
import locale
import logging
import unittest
from dragonpy.tests import run_tests
import sys

try:
# https://pypi.python.org/pypi/click/
Expand All @@ -35,6 +34,8 @@
from basic_editor.editor import run_basic_editor

import dragonpy
from dragonpy.core.gui_starter import start_gui
from dragonpy.tests import run_tests
from dragonpy.CoCo.config import CoCo2bCfg
from dragonpy.CoCo.machine import run_CoCo2b
from dragonpy.Dragon32.config import Dragon32Cfg
Expand Down Expand Up @@ -204,5 +205,18 @@ def tests(verbosity, failfast):
run_tests(verbosity, failfast)


def main(confirm_exit=True):
if len(sys.argv)==1:
if confirm_exit:
def confirm():
# don't close the terminal window directly
# important for windows users ;)
click.prompt("Please press [ENTER] to exit", default="", show_default=False)
atexit.register(confirm)

start_gui(__file__, machine_dict)
else:
cli()

if __name__ == "__main__":
cli()
main()

0 comments on commit c6b0ae0

Please sign in to comment.