Mercurial > traipse_dev
comparison orpg/mapper/background_handler.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | 73d9286c22cf |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: mapper/background_handler.py | |
21 # Author: OpenRPG Team | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: background_handler.py,v 1.23 2007/03/09 14:17:15 digitalxero Exp $ | |
25 # | |
26 # Description: Background layer handler | |
27 # | |
28 __version__ = "$Id: background_handler.py,v 1.23 2007/03/09 14:17:15 digitalxero Exp $" | |
29 | |
30 import thread | |
31 from threading import Lock | |
32 from background import * | |
33 from base_handler import * | |
34 import mimetypes | |
35 | |
36 from base import * | |
37 | |
38 class background_handler(base_layer_handler): | |
39 def __init__(self, parent, id, canvas): | |
40 base_layer_handler.__init__(self, parent, id, canvas) | |
41 self.settings = self.canvas.settings | |
42 | |
43 def build_ctrls(self): | |
44 base_layer_handler.build_ctrls(self) | |
45 self.lock = Lock() | |
46 self.bg_type = wx.Choice(self, wx.ID_ANY, choices = ["Texture", "Image", "Color" ]) | |
47 self.bg_type.SetSelection(2) | |
48 self.localBrowse = wx.Button(self, wx.ID_ANY, 'Browse') | |
49 self.localBrowse.Hide() | |
50 self.url_path = wx.TextCtrl(self, wx.ID_ANY,"http://") | |
51 self.color_button = wx.Button(self, wx.ID_ANY, "Color", style=wx.BU_EXACTFIT) | |
52 self.color_button.SetBackgroundColour(wx.BLACK) | |
53 self.color_button.SetForegroundColour(wx.WHITE) | |
54 self.apply_button = wx.Button(self, wx.ID_ANY, "Apply", style=wx.BU_EXACTFIT) | |
55 self.sizer.Add(self.bg_type, 0, wx.EXPAND) | |
56 self.sizer.Add(self.url_path, 1, wx.EXPAND) | |
57 self.sizer.Add(self.color_button, 0, wx.EXPAND) | |
58 self.sizer.Add(self.localBrowse, 0, wx.EXPAND) | |
59 self.sizer.Add(self.apply_button, 0, wx.EXPAND) | |
60 self.Bind(wx.EVT_BUTTON, self.on_bg_color, self.color_button) | |
61 self.Bind(wx.EVT_BUTTON, self.on_apply, self.apply_button) | |
62 self.Bind(wx.EVT_BUTTON, self.on_browse, self.localBrowse) | |
63 self.Bind(wx.EVT_CHOICE, self.on_bg_type, self.bg_type) | |
64 self.update_info() | |
65 | |
66 def on_browse(self, evt): | |
67 if self.bg_type.GetStringSelection() == 'Texture' or self.bg_type.GetStringSelection() == 'Image': | |
68 dlg = wx.FileDialog(None, "Select a Miniature to load", orpg.dirpath.dir_struct["user"]+'webfiles/', wildcard="Image files (*.bmp, *.gif, *.jpg, *.png)|*.bmp;*.gif;*.jpg;*.png", style=wx.OPEN) | |
69 if not dlg.ShowModal() == wx.ID_OK: | |
70 dlg.Destroy() | |
71 return | |
72 file = open(dlg.GetPath(), "rb") | |
73 imgdata = file.read() | |
74 file.close() | |
75 filename = dlg.GetFilename() | |
76 (imgtype,j) = mimetypes.guess_type(filename) | |
77 postdata = urllib.urlencode({'filename':filename, 'imgdata':imgdata, 'imgtype':imgtype}) | |
78 | |
79 if self.settings.get_setting('LocalorRemote') == 'Remote': | |
80 thread.start_new_thread(self.canvas.layers['bg'].upload, (postdata, dlg.GetPath(), self.bg_type.GetStringSelection())) | |
81 else: | |
82 url = self.settings.get_setting('LocalImageBaseURL') | |
83 print dlg.GetDirectory() | |
84 print orpg.dirpath.dir_struct["user"] | |
85 if dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles/Textures' or dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles\Textures': url = self.settings.get_setting('LocalImageBaseURL') + 'Textures/' | |
86 if dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles/Maps' or dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles\Maps': url = self.settings.get_setting('LocalImageBaseURL') + 'Maps/' | |
87 if dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles/Miniatures' or dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles\Miniatures': url = self.settings.get_setting('LocalImageBaseURL') + 'Miniatures/' | |
88 path = url + filename | |
89 if self.bg_type.GetStringSelection() == 'Texture': | |
90 self.canvas.layers['bg'].set_texture(path) | |
91 elif self.bg_type.GetStringSelection() == 'Image': | |
92 self.size = self.canvas.layers['bg'].set_image(path,1) | |
93 self.update_info() | |
94 self.canvas.send_map_data() | |
95 self.canvas.Refresh(False) | |
96 | |
97 def update_info(self): | |
98 bg_type = self.canvas.layers['bg'].get_type() | |
99 session=self.canvas.frame.session | |
100 if (session.my_role() != session.ROLE_GM): | |
101 self.url_path.Hide() | |
102 else: | |
103 self.url_path.Show() | |
104 self.url_path.Enable(BG_COLOR!=bg_type) | |
105 self.color_button.SetBackgroundColour(self.canvas.layers['bg'].get_color()) | |
106 self.url_path.SetValue(self.canvas.layers['bg'].get_img_path()) | |
107 | |
108 def build_menu(self,label = "Background"): | |
109 base_layer_handler.build_menu(self,label) | |
110 | |
111 def on_bg_color(self,evt): | |
112 data = wx.ColourData() | |
113 data.SetChooseFull(True) | |
114 dlg = wx.ColourDialog(self.canvas, data) | |
115 if dlg.ShowModal() == wx.ID_OK: | |
116 data = dlg.GetColourData() | |
117 data = data.GetColour() | |
118 r = data.Red() | |
119 g = data.Green() | |
120 b = data.Blue() | |
121 fgcolor = wx.Colour(r^255, g^255, b^255) | |
122 bgcolor = wx.Colour(r, g, b) | |
123 self.color_button.SetBackgroundColour(bgcolor) | |
124 self.color_button.SetForegroundColour(fgcolor) | |
125 dlg.Destroy() | |
126 | |
127 def on_bg_type(self, evt): | |
128 if self.bg_type.GetStringSelection() == 'Texture' or self.bg_type.GetStringSelection() == 'Image': | |
129 self.localBrowse.Show() | |
130 self.url_path.Enable() | |
131 else: | |
132 self.localBrowse.Hide() | |
133 self.url_path.Disable() | |
134 self.Layout() | |
135 | |
136 def on_apply(self, evt): | |
137 session=self.canvas.frame.session | |
138 if (session.my_role() != session.ROLE_GM) and (session.use_roles()): | |
139 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature") | |
140 return | |
141 self.canvas.layers['bg'].set_color(self.color_button.GetBackgroundColour()) | |
142 | |
143 if self.bg_type.GetStringSelection() == 'Texture': | |
144 self.canvas.layers['bg'].set_texture(self.url_path.GetValue()) | |
145 elif self.bg_type.GetStringSelection() == 'Image': | |
146 self.size = self.canvas.layers['bg'].set_image(self.url_path.GetValue(),1) | |
147 | |
148 self.update_info() | |
149 self.canvas.send_map_data() | |
150 self.canvas.Refresh(False) |