Skip to content

Commit

Permalink
Fixes #148 make import of tkinter conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Smith committed Jan 27, 2015
1 parent 2dc85bc commit c99c135
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 24 deletions.
11 changes: 8 additions & 3 deletions commands/import_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
import math
import plugins
import re
import tkinter
import tkinter.filedialog as tkfd
import transfers

try:
import tkinter
import tkinter.filedialog as tkfd
hasTkInter = True
except ImportError:
hasTkInter = False

######################################################################
# Parser config

Expand Down Expand Up @@ -106,7 +111,7 @@ def run(results, cmdenv, tdb):

# If the filename specified was "-" or None, then go ahead
# and present the user with an open file dialog.
if not cmdenv.filename:
if not cmdenv.filename and hasTkInter:
tk = tkinter.Tk()
tk.withdraw()
filetypes = (
Expand Down
44 changes: 28 additions & 16 deletions misc/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@
Wrapper for trade-dangerous clipboard functionality.
"""

from tkinter import Tk
import os

class SystemNameClip(object):
"""
A cross-platform wrapper for copying system names into
the clipboard such that they can be pasted into the E:D
galaxy search - which means forcing them into lower case
because E:D's search doesn't work with upper case
characters.
"""
if 'NOTK' not in os.environ:
try:
from tkinter import Tk

def __init__(self):
self.tkroot = Tk()
self.tkroot.withdraw()
class SystemNameClip(object):
"""
A cross-platform wrapper for copying system names into
the clipboard such that they can be pasted into the E:D
galaxy search - which means forcing them into lower case
because E:D's search doesn't work with upper case
characters.
"""

def __init__(self):
self.tkroot = Tk()
self.tkroot.withdraw()

def copy_text(self, text):
""" Copies the specified text into the clipboard. """
self.tkroot.clipboard_clear()
self.tkroot.clipboard_append(text.lower())

except ImportError:
print(
"WARNING: This feature expects you to have 'tkinter' package "
"installed to work. It is either not installed or broken.\n"
"Set the environment variable 'NOTK' to disable this warning."
)

def copy_text(self, text):
""" Copies the specified text into the clipboard. """
self.tkroot.clipboard_clear()
self.tkroot.clipboard_append(text.lower())
30 changes: 25 additions & 5 deletions plugins/maddavo_plug.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import cache
import os
import pathlib
import platform
import plugins
import re
import time
import tkinter
import tkinter.messagebox as mbox
import tradedb
import tradeenv
import transfers

from plugins import PluginException


hasTkInter = False
print(platform.system())
if not 'NOTK' in os.environ and platform.system() != 'Darwin': # focus bug
try:
import tkinter
import tkinter.messagebox as mbox
hasTkInter = True
except ImportError:
pass


class ImportPlugin(plugins.ImportPluginBase):
"""
Plugin that downloads data from maddavo's site.
Expand Down Expand Up @@ -97,6 +108,17 @@ def checkShebang(self, line, checkAge):
self.prevImportDate
))

def splash(self, title, text):
if hasTkInter:
tk = tkinter.Tk()
tk.withdraw()
mbox.showinfo(title, text)
else:
print("=== {} ===\n".format(title))
print(text)
input("Press return to continue: ")


def checkForFirstTimeUse(self):
iniFilePath = self.tdb.dataPath / "maddavo.ini"
if not iniFilePath.is_file():
Expand All @@ -106,9 +128,7 @@ def checkForFirstTimeUse(self):
"firstUse={}".format(time.time()),
file=fh
)
tk = tkinter.Tk()
tk.withdraw()
mbox.showinfo(
self.splash(
"Maddavo Plugin",
"This plugin fetches price data from Maddavo's site, "
"a 3rd party crowd-source data project.\n"
Expand Down

0 comments on commit c99c135

Please sign in to comment.