Mercurial > fife-parpg
annotate engine/extensions/pychan/internal.py @ 354:dfd48d49c044
* Removed shebang and svn:executable for python files which are not meant to be executed directly
* Made sure all executable files with shebang has svn:executable
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 21 Sep 2009 19:48:00 +0000 |
parents | 48c99636453e |
children |
rev | line source |
---|---|
207
40257a6dc57d
PyChan: Meaningful error if a font wasn't loaded.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
205
diff
changeset
|
1 # -*- coding: utf-8 -*- |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
331
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
3 # #################################################################### |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
4 # Copyright (C) 2005-2009 by the FIFE team |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
5 # http://www.fifengine.de |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
6 # This file is part of FIFE. |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
7 # |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
8 # FIFE is free software; you can redistribute it and/or |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
9 # modify it under the terms of the GNU Lesser General Public |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
10 # License as published by the Free Software Foundation; either |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
11 # version 2.1 of the License, or (at your option) any later version. |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
12 # |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
13 # This library is distributed in the hope that it will be useful, |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
16 # Lesser General Public License for more details. |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
17 # |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
18 # You should have received a copy of the GNU Lesser General Public |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
19 # License along with this library; if not, write to the |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
20 # Free Software Foundation, Inc., |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
22 # #################################################################### |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
255
diff
changeset
|
23 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 from compat import guichan, in_fife |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 import widgets |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
26 import fife_timer as timer |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 import fonts |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 from exceptions import * |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 from traceback import print_exc |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 def get_manager(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 Get the manager from inside pychan. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 To avoid cyclic imports write:: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 from internal import get_manager |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 return Manager.manager |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 def screen_width(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 return get_manager().hook.screen_width |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 def screen_height(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 return get_manager().hook.screen_height |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 class Manager(object): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 manager = None |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
49 def __init__(self, hook, debug = False, compat_layout = False): |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 super(Manager,self).__init__() |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 self.hook = hook |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 self.debug = debug |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
53 self.compat_layout = compat_layout |
228
756b895e1dab
Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
218
diff
changeset
|
54 self.unicodePolicy = ('ignore',) |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 if in_fife: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 if not hook.engine.getEventManager(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 raise InitializationError("No event manager installed.") |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 if not hook.engine.getGuiManager(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 raise InitializationError("No GUI manager installed.") |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
61 timer.init(hook.engine.getTimeManager()) |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 self.fonts = {} |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 #glyphs = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/:();%`\'*#=[]"' |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 self.fonts['default'] = hook.default_font |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 self.styles = {} |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 self.addStyle('default',DEFAULT_STYLE) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
70 Manager.manager = self |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 # Setup synchronous dialogs |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 self.mainLoop = None |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 self.breakFromMainLoop = None |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 self.can_execute = False |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
77 import weakref |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
78 self.allWidgets = weakref.WeakKeyDictionary() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
79 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 # Autopos |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 from autoposition import placeWidget |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 self.placeWidget = placeWidget |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 def setupModalExecution(self,mainLoop,breakFromMainLoop): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 Setup synchronous execution of dialogs. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 self.mainLoop = mainLoop |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 self.breakFromMainLoop = breakFromMainLoop |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 self.can_execute = True |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
91 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 def show(self,widget): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
94 Shows a widget on screen. Used by L{Widget.show} - do not use directly. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
95 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 self.placeWidget(widget, widget.position_technique) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
97 assert widget not in self.allWidgets |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
98 self.allWidgets[ widget ] = 1 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 self.hook.add_widget( widget.real_widget ) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 def hide(self,widget): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
103 Hides a widget again. Used by L{Widget.hide} - do not use directly. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
104 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 self.hook.remove_widget( widget.real_widget ) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
106 del self.allWidgets[ widget ] |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
107 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
108 def setDefaultFont(self,name): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
109 self.fonts['default'] = self.getFont(name) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 def getFont(self,name): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
113 B{pending deprecation} |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
114 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
115 Returns a GuiFont identified by its name. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
116 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
117 @param name: A string identifier from the font definitions in pychans config files. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
118 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
119 if in_fife: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
120 font = self.fonts.get(name) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
121 if isinstance(font,guichan.GuiFont): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 return font |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
123 if hasattr(font,"font") and isinstance(getattr(font,"font"),guichan.GuiFont): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
124 return font.font |
207
40257a6dc57d
PyChan: Meaningful error if a font wasn't loaded.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
205
diff
changeset
|
125 raise InitializationError("Couldn't find the font '%s' - did you forget loading a .fontdef?" % str(name)) |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
126 else: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
127 return self.hook.get_font(name) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
128 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
129 def addFont(self,font): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
130 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
131 B{deprecated} |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
132 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
133 Add a font to the font registry. It's not necessary to call this directly. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
134 But it expects a L{Font} instance and throws an L{InitializationError} |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
135 otherwise. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
136 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
137 @param font: A L{Font} instance. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
138 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
139 if not isinstance(font,fonts.Font): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
140 raise InitializationError("PyChan Manager expected a fonts.Font instance, not %s." % repr(font)) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
141 self.fonts[font.name] = font |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
142 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
143 def addStyle(self,name,style): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
144 style = self._remapStyleKeys(style) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
145 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
146 for k,v in self.styles.get('default',{}).items(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
147 style[k] = style.get(k,v) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
148 self.styles[name] = style |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
149 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
150 def stylize(self,widget, style, **kwargs): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
151 style = self.styles[style] |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
152 for k,v in style.get('default',{}).items(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
153 v = kwargs.get(k,v) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
154 setattr(widget,k,v) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
155 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
156 cls = widget.__class__ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
157 for applicable,specstyle in style.items(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
158 if not isinstance(applicable,tuple): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
159 applicable = (applicable,) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
160 if cls in applicable: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
161 for k,v in specstyle.items(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
162 v = kwargs.get(k,v) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
163 setattr(widget,k,v) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
164 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
165 def _remapStyleKeys(self,style): |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
166 """ |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
167 Translate style selectors to tuples of widget classes. (internal) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
168 """ |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 # Remap class names, create copy: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
170 def _toClass(class_): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
171 if class_ == "default": |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
172 return class_ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
173 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
174 if type(class_) == type(widgets.Widget) and issubclass(class_,widgets.Widget): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
175 return class_ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
176 if not widgets.WIDGETS.has_key(str(class_)): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
177 raise InitializationError("Can't resolve %s to a widget class." % repr(class_)) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
178 return widgets.WIDGETS[str(class_)] |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
179 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
180 style_copy = {} |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
181 for k,v in style.items(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
182 if isinstance(k,tuple): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
183 new_k = tuple(map(_toClass,k)) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
184 else: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
185 new_k = _toClass(k) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
186 style_copy[new_k] = v |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
187 return style_copy |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
188 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
189 def loadImage(self,filename): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
190 if not filename: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
191 raise InitializationError("Empty Image file.") |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
192 return self.hook.load_image(filename) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
193 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
194 # Default Widget style. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
195 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
196 DEFAULT_STYLE = { |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
197 'default' : { |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
198 'border_size': 0, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
199 'margins': (0,0), |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
200 'base_color' : guichan.Color(28,28,28), |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
201 'foreground_color' : guichan.Color(255,255,255), |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
202 'background_color' : guichan.Color(50,50,50), |
218
724f3a5f3e96
Added selection_color, and darkened the default for it a bit.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
207
diff
changeset
|
203 'selection_color' : guichan.Color(80,80,80), |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
204 'font' : 'default' |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
205 }, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
206 'Button' : { |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
207 'border_size': 2, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
208 'margins' : (5,2), |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
209 'min_size' : (15,10), |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
210 }, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
211 'CheckBox' : { |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
212 'border_size': 0, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
213 }, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
214 'RadioButton' : { |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
215 'border_size': 0, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
216 'background_color' : guichan.Color(0,0,0), |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
217 }, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
218 'Label' : { |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
219 'border_size': 0, |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
220 'background_color' : guichan.Color(50,50,50,0) |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
221 }, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
222 'ClickLabel' : { |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
223 'border_size': 0, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
224 }, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
225 'ListBox' : { |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
226 'border_size': 0, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
227 }, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
228 'Window' : { |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
229 'border_size': 0, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
230 'margins': (5,5), |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
231 'opaque' : 1, |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
232 'padding':2, |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
233 'titlebar_height' : 12, |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
234 'background_image' : None, |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
235 }, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
236 'TextBox' : { |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
237 }, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
238 ('Container','HBox','VBox') : { |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
239 'border_size': 0, |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
240 'margins': (0,0), |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
241 'padding':2, |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
242 'opaque' : 1, |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
228
diff
changeset
|
243 'background_image' : None, |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
244 } |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
245 } |