summaryrefslogtreecommitdiff
path: root/misc/pylib/robofab/world.py
blob: 203753d6c55aa1f54eadacd69e5ff21eab32f10e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os, sys
from robofab import RoboFabError, version, numberVersion


class RFWorld:

	"""All parameters about platforms, versions and environments included in one object."""

	def __init__(self):
		self.mac = None
		self.pc = None
		self.platform = sys.platform
		self.applicationName = None # name of the application we're running in
		self.name = os.name
		self.version = version	# the robofab version
		self.numberVersion = numberVersion
		self.run = True

		# get some platform information
		if self.name == 'mac' or self.name == 'posix':
			if self.platform == "darwin":
				self.mac = "X"
			else:
				self.mac = "pre-X"
		elif self.name == 'nt':
			# if you know more about PC & win stuff, add it here!
			self.pc = True
		else:
			raise RoboFabError, "We're running on an unknown platform."

		# collect versions
		self.pyVersion = sys.version[:3]
		self.inPython = False 
		self.inFontLab = False
		self.flVersion = None
		self.inGlyphs = False
		self.glyphsVersion = None
		self.inRoboFont = False
		self.roboFontVersion = None

		# are we in Glyphs?
		try:
			import objectsGS
			from AppKit import NSBundle
			bundle = NSBundle.mainBundle()
			self.applicationName = bundle.infoDictionary()["CFBundleName"]
			self.inGlyphs = True
			self.glyphsVersion = bundle.infoDictionary()["CFBundleVersion"]
		except ImportError:
			# are we in RoboFont
			try:
				import mojo
				from AppKit import NSBundle
				bundle = NSBundle.mainBundle()
				self.applicationName = bundle.infoDictionary()["CFBundleName"]
				self.inRoboFont = True
				self.roboFontVersion = bundle.infoDictionary()["CFBundleVersion"]
			except ImportError:
				# are we in FontLab?
				try:
					from FL import fl
					self.applicationName = fl.filename
					self.inFontLab = True
					self.flVersion = fl.version
				except ImportError: pass
		# we are in NoneLab
		if not self.inFontLab:
			self.inPython = True

		# see if we have DialogKit
		self.supportsDialogKit = False

	def __repr__(self):
		s = [
			"Robofab is running on %s" % self.platform,
			"Python version: %s" % self.pyVersion,
			"Mac stuff: %s" % self.mac,
			"PC stuff: %s" % self.pc,
			"FontLab stuff: %s" % self.inFontLab,
			"FLversion: %s" % self.flVersion,
			"Glyphs stuff: %s" % self.inGlyphs,
			"Glyphs version: %s" % self.glyphsVersion,
			"RoboFont stuff: %s" %self.inRoboFont,
			"RoboFont version: %s" %self.roboFontVersion,
		]
		return ", ".join(s)


world = RFWorld()

lineBreak = os.linesep

if world.inFontLab:
	from robofab.interface.all.dialogs import SelectFont, SelectGlyph
	from robofab.objects.objectsFL import CurrentFont, CurrentGlyph, RFont, RGlyph, OpenFont, NewFont, AllFonts
	lineBreak = "\n"
elif world.inRoboFont:
	from mojo.roboFont import CurrentFont, CurrentGlyph, RFont, RGlyph, OpenFont, NewFont, AllFonts
elif world.inGlyphs:
	from objectsGS import CurrentFont, CurrentGlyph, RFont, RGlyph, OpenFont, NewFont, AllFonts
elif world.inPython:
	from robofab.objects.objectsRF import CurrentFont, CurrentGlyph, RFont, RGlyph, OpenFont, NewFont, AllFonts

    

if __name__ == "__main__":
	f = RFWorld()
	print f