Mercurial > openrpg
changeset 540:69f2abad0d92
Refactored the Alias Lib window
Start work on bug #79
author | digitalxero |
---|---|
date | Thu, 25 Mar 2010 14:36:32 -0600 |
parents | 4652c82bf351 |
children | 078483c8fbbf |
files | images/open.gif images/save.gif orpg/chat/chatwnd.py orpg/main.py orpg/tools/aliaslib.py orpg/tools/rgbhex.py orpg/ui/__init__.py orpg/ui/_alias_lib.py orpg/ui/toolbars/__init__.py orpg/ui/toolbars/_alias.py orpg/ui/toolbars/_dice.py orpg/ui/toolbars/_status.py orpg/ui/toolbars/_text.py orpg/ui/util/__init__.py orpg/ui/util/dlg/__init__.py orpg/ui/util/dlg/_checkbox.py orpg/ui/util/html/__init__.py orpg/ui/util/misc/__init__.py orpg/ui/util/misc/_buttons.py orpg/ui/util/tab/__init__.py orpg/ui/util/text/__init__.py |
diffstat | 17 files changed, 1280 insertions(+), 379 deletions(-) [+] |
line wrap: on
line diff
--- a/orpg/chat/chatwnd.py Mon Mar 22 23:56:51 2010 -0600 +++ b/orpg/chat/chatwnd.py Thu Mar 25 14:36:32 2010 -0600 @@ -58,6 +58,8 @@ from orpg.tools.orpg_log import logger from orpg.tools.decorators import debugging +from orpg.ui.toolbars import DiceToolBar, TextFormatToolBar, AliasToolBar + from orpg.orpg_version import VERSION # needed to only send typing/not_typing messages while connected @@ -402,8 +404,8 @@ private_tab.chatwnd.SetDefaultFontAndSize(self.font, self.fontsize) self.whisper_tabs.append(private_tab) self.newMsg(self.GetPageCount()-1) - self.AliasLib = open_rpg.get_component('alias') - wx.CallAfter(self.AliasLib.RefreshAliases) + AliasLib = open_rpg.get_component('alias') + wx.CallAfter(AliasLib.refresh_aliases) return private_tab @@ -419,8 +421,8 @@ private_tab.chatwnd.SetDefaultFontAndSize(self.font, self.fontsize) self.group_tabs.append(private_tab) self.newMsg(self.GetPageCount()-1) - self.AliasLib = open_rpg.get_component('alias') - wx.CallAfter(self.AliasLib.RefreshAliases) + AliasLib = open_rpg.get_component('alias') + wx.CallAfter(AliasLib.refresh_aliases) return private_tab @@ -434,8 +436,8 @@ private_tab.chatwnd.SetDefaultFontAndSize(self.font, self.fontsize) self.null_tabs.append(private_tab) self.newMsg(self.GetPageCount()-1) - self.AliasLib = open_rpg.get_component('alias') - wx.CallAfter(self.AliasLib.RefreshAliases) + AliasLib = open_rpg.get_component('alias') + wx.CallAfter(AliasLib.refresh_aliases) return private_tab @@ -548,6 +550,7 @@ self.session = open_rpg.get_component('session') self.activeplugins = open_rpg.get_component('plugins') self.parent = parent + self.__aliasLib = open_rpg.get('alias') # who receives outbound messages, either "all" or "playerid" string self.sendtarget = sendtarget @@ -563,7 +566,7 @@ self.temptext = "" self.history = [] self.storedata = [] - self.parsed=0 + self.parsed = 0 #chat commands self.lockscroll = False @@ -571,13 +574,12 @@ self.html_strip = chat_util.strip_html #Alias Lib stuff - self.defaultAliasName = 'Use Real Name' - self.defaultFilterName = 'No Filter' self.advancedFilter = False self.lastSend = 0 self.lastPress = 0 self.Bind(wx.EVT_SIZE, self.OnSize) - self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnSize) #require to keep text at bottom of chat when text entry expands --SD + #require to keep text at bottom of chat when text entry expands --SD + self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnSize) self.build_ctrls() # F key macros @@ -1010,31 +1012,9 @@ self.SetSizer(self.basesizer) self.SetAutoLayout(True) self.Fit() - self.update_color_button(self.mytextcolor) #events - self.Bind(wx.EVT_BUTTON, self.on_text_format, self.boldButton) - self.Bind(wx.EVT_BUTTON, self.on_text_format, self.italicButton) - self.Bind(wx.EVT_BUTTON, self.on_text_format, self.underlineButton) - self.Bind(wx.EVT_BUTTON, self.on_text_color, self.color_button) self.Bind(wx.EVT_BUTTON, self.on_chat_save, self.saveButton) - self.Bind(wx.EVT_BUTTON, self.onDieRoll, self.d4Button) - self.Bind(wx.EVT_BUTTON, self.onDieRoll, self.d6Button) - self.Bind(wx.EVT_BUTTON, self.onDieRoll, self.d8Button) - self.Bind(wx.EVT_BUTTON, self.onDieRoll, self.d10Button) - self.Bind(wx.EVT_BUTTON, self.onDieRoll, self.d12Button) - self.Bind(wx.EVT_BUTTON, self.onDieRoll, self.d20Button) - self.Bind(wx.EVT_BUTTON, self.onDieRoll, self.d100Button) - - self.dieIDs = {} - self.dieIDs[self.d4Button.GetId()] = 'd4' - self.dieIDs[self.d6Button.GetId()] = 'd6' - self.dieIDs[self.d8Button.GetId()] = 'd8' - self.dieIDs[self.d10Button.GetId()] = 'd10' - self.dieIDs[self.d12Button.GetId()] = 'd12' - self.dieIDs[self.d20Button.GetId()] = 'd20' - self.dieIDs[self.d100Button.GetId()] = 'd100' - self.Bind(wx.EVT_BUTTON, self.pop_textpop, self.textpop_lock) self.Bind(wx.EVT_BUTTON, self.lock_scroll, self.scroll_lock) self.chattxt.Bind(wx.EVT_MOUSEWHEEL, self.chatwnd.mouse_wheel) @@ -1053,8 +1033,6 @@ def build_bar(self): self.toolbar_sizer = wx.BoxSizer(wx.HORIZONTAL) self.scroll_lock = None - self.numDieText = None - self.dieModText = None if settings.get('Toolbar_On') == "1": self.build_alias() @@ -1064,7 +1042,6 @@ self.toolbar_sizer.Add(self.textpop_lock, 0, wx.EXPAND) self.toolbar_sizer.Add(self.scroll_lock,0,wx.EXPAND) self.build_formating() - self.build_colorbutton() self.build_misc_controls() @debugging @@ -1074,46 +1051,18 @@ @debugging def build_alias(self): - self.aliasList = wx.Choice(self, wx.ID_ANY, size=(100, 25), - choices=[self.defaultAliasName]) - tip = 'Refresh list of aliases from Game Tree' - self.aliasButton = createMaskedButton(self, - dir_struct["icon"]+'player.gif', - tip, wx.ID_ANY, '#bdbdbd') - self.aliasList.SetSelection(0) - - self.filterList = wx.Choice(self, wx.ID_ANY, size=(100, 25), - choices=[self.defaultFilterName]) - tip = 'Refresh list of filters from Game Tree' - self.filterButton = createMaskedButton(self, - dir_struct["icon"]+'add_filter.gif', - tip, wx.ID_ANY, '#bdbdbd') - self.filterList.SetSelection(0) - - self.toolbar_sizer.Add(self.aliasButton, 0, wx.EXPAND) - self.toolbar_sizer.Add(self.aliasList,0,wx.EXPAND) - self.toolbar_sizer.Add(self.filterButton, 0, wx.EXPAND) - self.toolbar_sizer.Add(self.filterList,0,wx.EXPAND) - - if settings.get('AliasTool_On') == '0': - self.toggle_alias('0') - else: - self.toggle_alias('1') + self.alias_bar = AliasToolBar(self) + self.toolbar_sizer.Add(self.alias_bar, 0, wx.EXPAND) + self.toggle_alias() @debugging - def toggle_alias(self, act): - if act == '0': - self.toolbar_sizer.Show(self.aliasList, False) - self.toolbar_sizer.Show(self.filterList, False) - self.toolbar_sizer.Show(self.aliasButton, False) - self.toolbar_sizer.Show(self.filterButton, False) - self.toolbar_sizer.Layout() + def toggle_alias(self, act=None): + if settings.get('AliasTool_On').lower() in ['1', 'true', 'yes']: + self.alias_bar.Show() else: - self.toolbar_sizer.Show(self.aliasList, True) - self.toolbar_sizer.Show(self.filterList, True) - self.toolbar_sizer.Show(self.aliasButton, True) - self.toolbar_sizer.Show(self.filterButton, True) - self.toolbar_sizer.Layout() + self.alias_bar.Hide() + + self.toolbar_sizer.Layout() @debugging def build_text(self): @@ -1124,123 +1073,33 @@ @debugging def build_dice(self): - self.numDieText = wx.TextCtrl(self, wx.ID_ANY, "1", - size=wx.Size(25, 25), - validator=orpg.tools.inputValidator.MathOnlyValidator()) - self.dieModText = wx.TextCtrl(self, wx.ID_ANY, "", - size= wx.Size(50, 25), - validator=orpg.tools.inputValidator.MathOnlyValidator()) - - #Fixed masking for buttons -- Snowdog 8-09 - self.d4Button = createMaskedButton(self, dir_struct["icon"]+'b_d4.gif', - 'Roll d4', wx.ID_ANY, wx.WHITE) - self.d6Button = createMaskedButton(self, dir_struct["icon"]+'b_d6.gif', - 'Roll d6', wx.ID_ANY, wx.WHITE) - self.d8Button = createMaskedButton(self, dir_struct["icon"]+'b_d8.gif', - 'Roll d8', wx.ID_ANY, wx.WHITE) - self.d10Button = createMaskedButton(self, - dir_struct["icon"]+'b_d10.gif', - 'Roll d10', wx.ID_ANY, wx.WHITE) - self.d12Button = createMaskedButton(self, - dir_struct["icon"]+'b_d12.gif', - 'Roll d12', wx.ID_ANY, wx.WHITE) - self.d20Button = createMaskedButton(self, - dir_struct["icon"]+'b_d20.gif', - 'Roll d20', wx.ID_ANY, wx.WHITE) - self.d100Button = createMaskedButton(self, - dir_struct["icon"]+'b_d100.gif', - 'Roll d100', wx.ID_ANY, wx.WHITE) - - self.toolbar_sizer.Add(self.numDieText, 0, wx.ALIGN_CENTER|wx.EXPAND) - self.toolbar_sizer.Add(self.d4Button, 0 ,wx.EXPAND) - self.toolbar_sizer.Add(self.d6Button, 0 ,wx.EXPAND) - self.toolbar_sizer.Add(self.d8Button, 0 ,wx.EXPAND) - self.toolbar_sizer.Add(self.d10Button, 0 ,wx.EXPAND) - self.toolbar_sizer.Add(self.d12Button, 0 ,wx.EXPAND) - self.toolbar_sizer.Add(self.d20Button, 0 ,wx.EXPAND) - self.toolbar_sizer.Add(self.d100Button, 0 ,wx.EXPAND) - self.toolbar_sizer.Add(self.dieModText, 0, wx.ALIGN_CENTER, 5) - - if settings.get('DiceButtons_On') == '0': - self.toggle_dice('0') - else: - self.toggle_dice('1') + self.dice_bar = DiceToolBar(self, callback=self.ParsePost) + self.toolbar_sizer.Add(self.dice_bar, 0, wx.ALIGN_CENTER|wx.EXPAND) + self.toggle_dice() @debugging - def toggle_dice(self, act): - if act == '0': - self.toolbar_sizer.Show(self.numDieText, False) - self.toolbar_sizer.Show(self.d4Button, False) - self.toolbar_sizer.Show(self.d6Button, False) - self.toolbar_sizer.Show(self.d8Button, False) - self.toolbar_sizer.Show(self.d10Button, False) - self.toolbar_sizer.Show(self.d12Button, False) - self.toolbar_sizer.Show(self.d20Button, False) - self.toolbar_sizer.Show(self.d100Button, False) - self.toolbar_sizer.Show(self.dieModText, False) - self.toolbar_sizer.Layout() + def toggle_dice(self, act=None): + if settings.get('DiceButtons_On').lower() in ['1', 'true', 'yes']: + self.dice_bar.Show() else: - self.toolbar_sizer.Show(self.numDieText, True) - self.toolbar_sizer.Show(self.d4Button, True) - self.toolbar_sizer.Show(self.d6Button, True) - self.toolbar_sizer.Show(self.d8Button, True) - self.toolbar_sizer.Show(self.d10Button, True) - self.toolbar_sizer.Show(self.d12Button, True) - self.toolbar_sizer.Show(self.d20Button, True) - self.toolbar_sizer.Show(self.d100Button, True) - self.toolbar_sizer.Show(self.dieModText, True) - self.toolbar_sizer.Layout() + self.dice_bar.Hide() + + self.toolbar_sizer.Layout() @debugging def build_formating(self): - self.boldButton = createMaskedButton(self, - dir_struct["icon"]+'bold.gif', - 'Make the selected text Bold', - wx.ID_ANY, '#bdbdbd') - self.italicButton = createMaskedButton(self, - dir_struct["icon"]+'italic.gif', - 'Italicize the selected text', - wx.ID_ANY, '#bdbdbd') - self.underlineButton = createMaskedButton(self, - dir_struct["icon"]+'underlined.gif', - 'Underline the selected text', - wx.ID_ANY, '#bdbdbd') - - self.toolbar_sizer.Add(self.boldButton, 0, wx.EXPAND) - self.toolbar_sizer.Add(self.italicButton, 0, wx.EXPAND) - self.toolbar_sizer.Add(self.underlineButton, 0, wx.EXPAND) - - if settings.get('FormattingButtons_On') == '0': - self.toggle_formating('0') - else: - self.toggle_formating('1') + self.format_bar = TextFormatToolBar(self, self.chattxt) + self.toolbar_sizer.Add(self.format_bar, 0, wx.EXPAND) + self.toggle_formating() @debugging - def toggle_formating(self, act): - if act == '0': - self.toolbar_sizer.Show(self.boldButton, False) - self.toolbar_sizer.Show(self.italicButton, False) - self.toolbar_sizer.Show(self.underlineButton, False) - self.toolbar_sizer.Layout() + def toggle_formating(self, act=None): + if settings.get('FormattingButtons_On').lower() in ['1', 'true', 'yes']: + self.format_bar.Show() else: - self.toolbar_sizer.Show(self.boldButton, True) - self.toolbar_sizer.Show(self.italicButton, True) - self.toolbar_sizer.Show(self.underlineButton, True) - self.toolbar_sizer.Layout() - + self.format_bar.Hide() - @debugging - def build_colorbutton(self): - self.color_button_image = wx.Image(dir_struct["icon"]+'textcolor.gif', - wx.BITMAP_TYPE_GIF).ConvertToBitmap() - mask = wx.Mask(self.color_button_image, '#bdbdbd') - #stored so we don't have to keep reloading image - self.color_button_image.SetMask(mask) - self.color_button = wx.BitmapButton(self, wx.ID_ANY, - self.color_button_image) - self.color_button.SetToolTip(wx.ToolTip('Text Color')) - - self.toolbar_sizer.Add(self.color_button, 0, wx.EXPAND) + self.toolbar_sizer.Layout() def build_misc_controls(self): self.saveButton = createMaskedButton(self, @@ -1389,8 +1248,8 @@ self.sound_player.play(sound_file) # get the alias as the context - alias = self.aliasList.GetStringSelection() - if alias == self.defaultAliasName: + alias = self.alias_bar.alias + if alias == self.alias_bar.default_alias: alias = self.session.get_my_info()[0] # check for the entire string being a reference without the !@...@! format # this is a special case not checked for except for cases of one line direct user input @@ -1517,31 +1376,6 @@ event.Skip() @debugging - def onDieRoll(self, evt): - """ - Roll the dice based on the button pressed and the die modifiers - entered, if any. - """ - # Get any die modifiers if they have been entered - numDie = self.numDieText.GetValue() - dieMod = self.dieModText.GetValue() - dieText = numDie - - # Now, apply and roll die mods based on the button that was pressed - id = evt.GetId() - if self.dieIDs.has_key(id): - dieText += self.dieIDs[id] - - if len(dieMod) and dieMod[0] not in "*/-+": - dieMod = "+" + dieMod - - dieText += dieMod - dieText = "[" + dieText + "]" - self.ParsePost(dieText, 1, 1) - self.chattxt.SetFocus() - - - @debugging def on_chat_save(self, evt): f = wx.FileDialog(self, "Save Chat Buffer", ".", "", "HTM* (*.htm*)|*.htm*|HTML (*.html)|*.html|HTM " @@ -1565,41 +1399,6 @@ return buffertext - - @debugging - def on_text_color(self, event): - hexcolor = self.r_h.do_hex_color_dlg(self) - if hexcolor != None: - (beg,end) = self.chattxt.GetSelection() - if beg != end: - txt = self.chattxt.GetValue() - txt = txt[:beg]+self.colorize(hexcolor,txt[beg:end]) +txt[end:] - self.chattxt.SetValue(txt) - self.chattxt.SetInsertionPointEnd() - self.chattxt.SetFocus() - else: - self.update_color_button(hexcolor) - self.mytextcolor = hexcolor - settings.set('mytextcolor',hexcolor) - self.set_colors() - self.Post() - - - def update_color_button(self, color): - """ - Dynamically Generates a properly colored background for the text color - button to maintain uniform look on buttons - """ - w,h = self.color_button_image.GetSize() - btn_img = wx.EmptyBitmap(w,h) - dc = wx.MemoryDC() - dc.SelectObject(btn_img) - dc.SetBackground(wx.Brush(color)) - dc.Clear() - dc.DrawBitmap(self.color_button_image,0,0,True) - self.color_button.SetBitmapLabel(btn_img) - - @debugging def colorize(self, color, text): """ @@ -1608,32 +1407,6 @@ return '<font color="' + color + '">' + text + '</font>' @debugging - def on_text_format(self, event): - id = event.GetId() - txt = self.chattxt.GetValue() - (beg,end) = self.chattxt.GetSelection() - if beg != end: - sel_txt = txt[beg:end] - else: - sel_txt = txt - - if id == self.boldButton.GetId(): - sel_txt = "<b>" + sel_txt + "</b>" - elif id == self.italicButton.GetId(): - sel_txt = "<i>" + sel_txt + "</i>" - elif id == self.underlineButton.GetId(): - sel_txt = "<u>" + sel_txt + "</u>" - - if beg != end: - txt = txt[:beg] + sel_txt + txt[end:] - else: - txt = sel_txt - - self.chattxt.SetValue(txt) - self.chattxt.SetInsertionPointEnd() - self.chattxt.SetFocus() - - @debugging def lock_scroll(self, event): if self.lockscroll: self.lockscroll = False @@ -1705,48 +1478,39 @@ @debugging def GetName(self, context=None): - self.AliasLib = open_rpg.get_component('alias') player = self.session.get_my_info() - if self.AliasLib != None: - self.AliasLib.alias = self.aliasList.GetStringSelection() - if context: - if isinstance(context.namespace_hint, node_handler): - namespace_name = open_rpg.get_component('tree').get_namespace_name(context.namespace_hint.mytree_node) - elif isinstance(context.namespace_hint, (str, unicode)): - namespace_name = context.namespace_hint - else: - namespace_name = None - if namespace_name: - for n in xrange(self.AliasLib.selectAliasWnd.GetItemCount()): - alias = self.AliasLib.selectAliasWnd.GetItem(n, 0).GetText() - if alias.strip().lower() == namespace_name: - self.AliasLib.alias = alias - break + if context: + if isinstance(context.namespace_hint, node_handler): + namespace_name = open_rpg.get_component('tree').\ + get_namespace_name( + context.namespace_hint.mytree_node) + elif isinstance(context.namespace_hint, (basestring)): + namespace_name = context.namespace_hint + else: + namespace_name = None + if namespace_name: + self.alias_bar.select_alias(namespace_name) - if self.AliasLib.alias[0] != self.defaultAliasName: - return [self.chat_display_name([self.AliasLib.alias[0], - player[1], player[2]]), - self.AliasLib.alias[1]] + if self.alias_bar.alias != self.alias_bar.default_alias: + return [self.chat_display_name([self.alias_bar.alias, + player[1], player[2]]), + self.alias_bar.alias_color] - return [self.chat_display_name(player), "Default"] + return [self.chat_display_name(player), 'Default'] @debugging def GetFilteredText(self, text): advregex = re.compile('\"(.*?)\"', re.I|re.M) - self.AliasLib = open_rpg.get_component('alias') - if self.AliasLib != None: - self.AliasLib.filter = self.filterList.GetSelection()-1; - - for rule in self.AliasLib.filterRegEx: - if not self.advancedFilter: - text = re.sub(rule[0], rule[1], text) - else: - for m in advregex.finditer(text): - match = m.group(0) - newmatch = re.sub(rule[0], rule[1], match) - text = text.replace(match, newmatch) + for match, sub in self.alias_bar.filter_rules: + if not self.advancedFilter: + text = re.sub(match, sub, text) + else: + for m in advregex.finditer(text): + section = m.group(0) + text = text.replace(section, re.sub(match, sub, + m.group(0))) return text @debugging
--- a/orpg/main.py Mon Mar 22 23:56:51 2010 -0600 +++ b/orpg/main.py Thu Mar 25 14:36:32 2010 -0600 @@ -31,23 +31,25 @@ from orpg.orpg_wx import * from orpg.orpgCore import * from orpg_version import * -from orpg.orpg_windows import * +#from orpg.orpg_windows import * import orpg.player_list -import orpg.tools.pluginui as pluginUI -import orpg.tools.aliaslib -import orpg.tools.toolBars import orpg.tools.passtool import orpg.tools.orpg_sound import orpg.tools.rgbhex import orpg.gametree.gametree import orpg.chat.chatwnd import orpg.networking.mplay_client -import orpg.networking.gsclient import orpg.mapper.map import orpg.mapper.images + +import orpg.networking.gsclient +import orpg.tools.pluginui as pluginUI +import orpg.tools.toolBars import orpg.tools.orpg_settings +from orpg.ui import AliasLib +from orpg.ui.toolbars import StatusBar from orpg.dieroller import roller_manager from orpg.dirpath import dir_struct from orpg.tools.settings import settings @@ -497,17 +499,11 @@ def OnMB_WindowsMenu(self, event): menuid = event.GetId() name = self.mainwindows[menuid] - if name == 'Alias Lib': - if self.aliaslib.IsShown() == True: - self.aliaslib.Hide() - else: - self.aliaslib.Show() + if self._mgr.GetPane(name).IsShown() == True: + self._mgr.GetPane(name).Hide() else: - if self._mgr.GetPane(name).IsShown() == True: - self._mgr.GetPane(name).Hide() - else: - self._mgr.GetPane(name).Show() - self._mgr.Update() + self._mgr.GetPane(name).Show() + self._mgr.Update() #OpenRPG Menu @debugging @@ -756,7 +752,7 @@ self.build_window(c, self) # status window - self.status = status_bar(self) + self.status = StatusBar(self) wndinfo = AUI.AuiPaneInfo() wndinfo.DestroyOnClose(False) wndinfo.Name('Status Window') @@ -782,20 +778,6 @@ self._mgr.AddPane(self.dieToolBar, wndinfo) logger.debug("Dice Tool Bar Created") - #Create the Map tool bar - self.mapToolBar = orpg.tools.toolBars.MapToolBar(self, - callBack=self.map.MapBar) - wndinfo = AUI.AuiPaneInfo() - wndinfo.DestroyOnClose(False) - wndinfo.Name('Map Tool Bar') - wndinfo.Caption('Map Tool Bar') - wndinfo.Float() - wndinfo.FloatingPosition((50,50)) - wndinfo.ToolbarPane() - wndinfo.Hide() - self._mgr.AddPane(self.mapToolBar, wndinfo) - logger.debug("Map Tool Bar Created") - #Create the Browse Server Window self.gs = orpg.networking.gsclient.game_server_panel(self) wndinfo = AUI.AuiPaneInfo() @@ -811,8 +793,17 @@ logger.debug("Game Server Window Created") #Create the Alias Lib Window - self.aliaslib = orpg.tools.aliaslib.AliasLib() - self.aliaslib.Hide() + self.aliaslib = AliasLib(self) + wndinfo = AUI.AuiPaneInfo() + wndinfo.DestroyOnClose(False) + wndinfo.Name('Alias Lib') + wndinfo.Caption('Alias Lib') + wndinfo.Float() + wndinfo.FloatingPosition((50,50)) + wndinfo.Dockable(True) + wndinfo.MinSize(wx.Size(250,100)) + wndinfo.Hide() + self._mgr.AddPane(self.aliaslib, wndinfo) logger.debug("Alias Window Created") menuid = wx.NewId() self.windowsmenu.Append(menuid, 'Alias Lib', kind=wx.ITEM_CHECK) @@ -1030,7 +1021,7 @@ id = evt.get_id() status = evt.get_data() if id == orpg.networking.mplay_client.STATUS_SET_URL: - self.status.set_url(status) + self.status.url = status @debugging def on_player_event(self, evt): @@ -1104,7 +1095,7 @@ self.chat.SystemPost("Game disconnected!") self.players.reset() self.gs.set_connected(0) - self.status.set_connect_status('Not Connected') + self.status.connect_status = 'Not Connected' ####Begin changes for Custom Exit Message by mDuo13###### elif id == orpg.networking.mplay_client.MPLAY_DISCONNECTING: @@ -1134,7 +1125,7 @@ @debugging def closed_confirmed(self): self.activeplugins = open_rpg.get_component('plugins') - self.aliaslib.OnMB_FileSave(None) + self.aliaslib._on_file_save(None) #following lines added by mDuo13 #########plugin_disabled()#########
--- a/orpg/tools/aliaslib.py Mon Mar 22 23:56:51 2010 -0600 +++ b/orpg/tools/aliaslib.py Thu Mar 25 14:36:32 2010 -0600 @@ -30,7 +30,9 @@ from orpg.orpg_wx import * from orpg.orpgCore import * -from orpg.orpg_windows import createMaskedButton, orpgMultiCheckBoxDlg +from orpg.ui.util.misc import create_masked_button +from orpg.ui.util.dlg import MultiCheckBoxDlg +from orpg.ui.toolbars import TextFormatToolBar from orpg.tools.rgbhex import RGBHex from orpg.tools.orpg_log import logger from orpg.dirpath import dir_struct @@ -384,31 +386,47 @@ self.topBtnSizer = wx.BoxSizer(wx.HORIZONTAL) self.middleBtnSizer = wx.BoxSizer(wx.HORIZONTAL) self.bottomBtnSizer = wx.BoxSizer(wx.HORIZONTAL) - self.addFromMapBtn = createMaskedButton(self, dir_struct["icon"] + 'install.gif', 'Add temporary aliases from map', wx.ID_ANY, "#C0C0C0") - self.newAliasBtn = createMaskedButton(self, dir_struct["icon"] + 'player.gif', 'Add a new Alias', wx.ID_ANY) - self.delAliasBtn = createMaskedButton(self, dir_struct["icon"] + 'noplayer.gif', 'Delete selected Alias', wx.ID_ANY) - self.editAliasBtn = createMaskedButton(self, dir_struct["icon"] + 'note.gif', 'Edit selected Alias', wx.ID_ANY) + self.addFromMapBtn = create_masked_button(self, + dir_struct["icon"] + 'install.gif', + 'Add temporary aliases from map', + wx.ID_ANY, "#C0C0C0") + self.newAliasBtn = create_masked_button(self, + dir_struct["icon"] + 'player.gif', + 'Add a new Alias', wx.ID_ANY) + self.delAliasBtn = create_masked_button(self, + dir_struct["icon"] + 'noplayer.gif', + 'Delete selected Alias', wx.ID_ANY) + self.editAliasBtn = create_masked_button(self, + dir_struct["icon"] + 'note.gif', + 'Edit selected Alias', wx.ID_ANY) self.Bind(wx.EVT_BUTTON, self.OnMB_AliasNew, self.newAliasBtn) self.Bind(wx.EVT_BUTTON, self.OnMB_AliasAddTemporary, self.addFromMapBtn) self.Bind(wx.EVT_BUTTON, self.OnMB_AliasEdit, self.editAliasBtn) self.Bind(wx.EVT_BUTTON, self.OnMB_AliasDelete, self.delAliasBtn) - self.newFilterBtn = createMaskedButton(self, dir_struct["icon"] + 'add_filter.gif', 'Add a new Filter', wx.ID_ANY, "#0000FF") - self.editFilterBtn = createMaskedButton(self, dir_struct["icon"] + 'edit_filter.gif', 'Edit selected Filter', wx.ID_ANY, "#FF0000") - self.delFilterBtn = createMaskedButton(self, dir_struct["icon"] + 'delete_filter.gif', 'Delete selected Filter', wx.ID_ANY, "#0000FF") + + self.newFilterBtn = create_masked_button(self, + dir_struct["icon"] + 'add_filter.gif', + 'Add a new Filter', wx.ID_ANY, + "#0000FF") + self.editFilterBtn = create_masked_button(self, + dir_struct["icon"] + 'edit_filter.gif', + 'Edit selected Filter', wx.ID_ANY, + "#FF0000") + self.delFilterBtn = create_masked_button(self, + dir_struct["icon"] + 'delete_filter.gif', + 'Delete selected Filter', wx.ID_ANY, + "#0000FF") self.Bind(wx.EVT_BUTTON, self.OnMB_FilterNew, self.newFilterBtn) self.Bind(wx.EVT_BUTTON, self.OnMB_FilterEdit, self.editFilterBtn) self.Bind(wx.EVT_BUTTON, self.OnMB_FilterDelete, self.delFilterBtn) - self.textBoldBtn = createMaskedButton(self, dir_struct["icon"] + 'bold.gif', 'Bold', wx.ID_ANY, "#BDBDBD") - self.textItalicBtn = createMaskedButton(self, dir_struct["icon"] + 'italic.gif', 'Italic', wx.ID_ANY, "#BDBDBD") - self.textUnderlineBtn = createMaskedButton(self, dir_struct["icon"] + 'underlined.gif', 'Underline', wx.ID_ANY, "#BDBDBD") - self.textColorBtn = wx.Button(self, wx.ID_ANY, "Color") - self.textColorBtn.SetForegroundColour(wx.BLACK) - self.exportBtn = createMaskedButton(self, dir_struct["icon"] + 'grid.gif', 'Export to Tree', wx.ID_ANY) - self.Bind(wx.EVT_BUTTON, self.FormatText, self.textBoldBtn) - self.Bind(wx.EVT_BUTTON, self.FormatText, self.textItalicBtn) - self.Bind(wx.EVT_BUTTON, self.FormatText, self.textUnderlineBtn) - self.Bind(wx.EVT_BUTTON, self.FormatText, self.textColorBtn) + + self.format_bar = TextFormatToolBar(self, self.textWnd) + + self.exportBtn = create_masked_button(self, + dir_struct["icon"] + 'grid.gif', + 'Export to Tree', wx.ID_ANY) self.Bind(wx.EVT_BUTTON, self.OnMB_FileExportToTree, self.exportBtn) + self.topBtnSizer.Add(self.newAliasBtn, 0, wx.EXPAND) self.topBtnSizer.Add(self.addFromMapBtn, 0, wx.EXPAND) self.topBtnSizer.Add(self.editAliasBtn, 0, wx.EXPAND) @@ -416,13 +434,11 @@ self.topBtnSizer.Add(self.newFilterBtn, 0, wx.EXPAND) self.topBtnSizer.Add(self.editFilterBtn, 0, wx.EXPAND) self.topBtnSizer.Add(self.delFilterBtn, 0, wx.EXPAND) - self.topBtnSizer.Add(self.textBoldBtn, 0, wx.EXPAND) - self.topBtnSizer.Add(self.textItalicBtn, 0, wx.EXPAND) - self.topBtnSizer.Add(self.textUnderlineBtn, 0, wx.EXPAND) - self.topBtnSizer.Add(self.textColorBtn, 0, wx.EXPAND) + self.topBtnSizer.Add(self.format_bar, 0, wx.EXPAND) self.topBtnSizer.Add(self.exportBtn, 0, wx.EXPAND|wx.ALIGN_RIGHT) self.checkFilterText = wx.CheckBox(self, wx.ID_ANY, "Filter Text") - self.Bind(wx.EVT_CHECKBOX, self.FilterTextChecked, self.checkFilterText) + self.Bind(wx.EVT_CHECKBOX, self.FilterTextChecked, + self.checkFilterText) self.checkClearText = wx.CheckBox(self, wx.ID_ANY, "Auto Clear Text") self.middleBtnSizer.Add(self.checkFilterText, 0, wx.EXPAND) self.middleBtnSizer.Add(self.checkClearText, 0, wx.EXPAND) @@ -442,18 +458,30 @@ @debugging def buildGUI(self): self.sizer = wx.BoxSizer(wx.VERTICAL) - rightwnd = wx.SplitterWindow(self, wx.ID_ANY, style=wx.SP_LIVE_UPDATE|wx.SP_NO_XP_THEME|wx.SP_3DSASH) - leftwnd = wx.SplitterWindow(rightwnd, wx.ID_ANY, style=wx.SP_LIVE_UPDATE|wx.SP_NO_XP_THEME|wx.SP_3DSASH) - self.selectAliasWnd = wx.ListCtrl(leftwnd, wx.ID_ANY, style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES) - self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.NewAliasSelection, self.selectAliasWnd) - self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.NoAliasSelection, self.selectAliasWnd) - self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnMB_AliasEdit, self.selectAliasWnd) - self.selectFilterWnd = wx.ListCtrl(leftwnd, wx.ID_ANY, style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES) - self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.NewFilterSelection, self.selectFilterWnd) - self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.NoFilterSelection, self.selectFilterWnd) - self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnMB_FilterEdit, self.selectFilterWnd) - self.textWnd = wx.TextCtrl(rightwnd, wx.ID_ANY, style=wx.TE_MULTILINE|wx.TE_BESTWRAP) - leftwnd.SplitHorizontally(self.selectAliasWnd, self.selectFilterWnd) + rightwnd = wx.SplitterWindow(self, wx.ID_ANY, + style=wx.SP_LIVE_UPDATE|wx.SP_NO_XP_THEME|wx.SP_3DSASH) + leftwnd = wx.SplitterWindow(rightwnd, wx.ID_ANY, + style=wx.SP_LIVE_UPDATE|wx.SP_NO_XP_THEME|wx.SP_3DSASH) + self.selectAliasWnd = wx.ListCtrl(leftwnd, wx.ID_ANY, + style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES) + self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.NewAliasSelection, + self.selectAliasWnd) + self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.NoAliasSelection, + self.selectAliasWnd) + self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnMB_AliasEdit, + self.selectAliasWnd) + self.selectFilterWnd = wx.ListCtrl(leftwnd, wx.ID_ANY, + style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES) + self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.NewFilterSelection, + self.selectFilterWnd) + self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.NoFilterSelection, + self.selectFilterWnd) + self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnMB_FilterEdit, + self.selectFilterWnd) + self.textWnd = wx.TextCtrl(rightwnd, wx.ID_ANY, + style=wx.TE_MULTILINE|wx.TE_BESTWRAP) + leftwnd.SplitHorizontally(self.selectAliasWnd, + self.selectFilterWnd) rightwnd.SplitVertically(leftwnd, self.textWnd) self.sizer.Add(self.topBtnSizer, 0, wx.EXPAND) self.sizer.Add(rightwnd, 1, wx.EXPAND) @@ -484,7 +512,8 @@ flist.append(filter.get("name")) sub = [] for rule in filter.findall("rule"): - sub.append([self.MakeSafeHTML(rule.get("match", '')), self.MakeSafeHTML(rule.get("sub", ''))]) + sub.append([self.MakeSafeHTML(rule.get("match", '')), + self.MakeSafeHTML(rule.get("sub", ''))]) self.regExList.append(sub) self.filterList = flist self.alias = -1 @@ -492,11 +521,15 @@ @debugging def MakeSafeHTML(self, str): - return str.replace("&", "&").replace("<", "<").replace(""", '"').replace(">", ">").replace("'", "'") + return str.replace("&", "&").replace("<", "<").\ + replace(""", '"').replace(">", ">").\ + replace("'", "'") @debugging def MakeHTMLSafe(self, str): - return str.replace("&", "&").replace("<", "<").replace('"', """).replace(">", ">").replace("'", "'") + return str.replace("&", "&").replace("<", "<").\ + replace('"', """).replace(">", ">").\ + replace("'", "'") @debugging def ImportFromTree(self, xml): @@ -518,7 +551,7 @@ self.OnMB_FileSave(None, oldfilename) with open(dir_struct["user"] + self.filename, "w") as f: f.write(ET.tostring(xml).replace('nodehandler', - 'aliaslib').replace('voxchat.', '')) + 'aliaslib').replace('voxchat.', '')) wx.CallAfter(self.loadFile) @@ -536,8 +569,9 @@ def GetSelectedAlias(self): self.InitSetup() if self.aliasIdx != -1: - return [self.selectAliasWnd.GetItem(self.aliasIdx, 0).GetText(), self.selectAliasWnd.GetItem(self.aliasIdx, 1).GetText()] - return [self.chat.defaultAliasName, "Default"] + return [self.selectAliasWnd.GetItem(self.aliasIdx, 0).GetText(), + self.selectAliasWnd.GetItem(self.aliasIdx, 1).GetText()] + return [self.chat.alias_bar.default_alias, "Default"] @debugging def SetSelectedAlias(self, alias): @@ -589,14 +623,14 @@ l1 = len(self.aliasList) l2 = len(self.filterList) if self.chat != None: - tmp = self.chat.aliasList.GetStringSelection() + tmp = self.chat.alias_bar.alias self.alias = tmp aidx = self.aliasIdx+1 if len(self.aliasList) <= aidx: aidx = 0 self.chat.aliasList.Clear() for n in xrange(l1): - self.chat.aliasList.Insert(self.aliasList[n], n) + self.chat.alias_bar._alias_list.Insert(self.aliasList[n], n) self.chat.aliasList.SetStringSelection(self.aliasList[aidx]) fidx = self.chat.filterList.GetSelection() if len(self.filterList) <= fidx:
--- a/orpg/tools/rgbhex.py Mon Mar 22 23:56:51 2010 -0600 +++ b/orpg/tools/rgbhex.py Thu Mar 25 14:36:32 2010 -0600 @@ -32,7 +32,7 @@ ## RPGHex Tool ##################### -class RGBHex: +class RGBHex(object): "Tools for Converting from hex to rgb and versa vicea" def rgb_tuple(self,hexnum):
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/ui/__init__.py Thu Mar 25 14:36:32 2010 -0600 @@ -0,0 +1,3 @@ +__all__ = ['util', 'toolbars', 'AliasLib'] + +from ._alias_lib import AliasLib \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/ui/_alias_lib.py Thu Mar 25 14:36:32 2010 -0600 @@ -0,0 +1,645 @@ +from __future__ import with_statement + +import operator + +import wx +from wx.lib.newevent import NewEvent + +from orpg.orpgCore import open_rpg +from orpg.ui.util.misc import create_masked_button +from orpg.ui.util.dlg import MultiCheckBoxDlg +from orpg.ui.toolbars import TextFormatToolBar +from orpg.tools.rgbhex import RGBHex +from orpg.tools.orpg_log import logger +from orpg.dirpath import dir_struct +from orpg.tools.validate import validate +from orpg.tools.settings import settings +from orpg.tools.decorators import debugging +from orpg.tools.events import (orpgEVT_ALIAS_LIST_CHANGED, + orpgEVT_FILTER_LIST_CHANGED) +from orpg.tools.pubsub import Publisher +from orpg.external.etree.ElementTree import ElementTree, Element +from orpg.external.etree.ElementTree import fromstring, tostring + + +class AliasLib(wx.Panel): + _filename = settings.get('aliasfile') + '.alias' + _alist_list = [] + _filter_list = [] + + @debugging + def __init__(self, parent): + wx.Panel.__init__(self, parent, wx.ID_ANY) + + validate.config_file(self._filename, "default_alias.alias") + + self.Freeze() + self._sizer = wx.BoxSizer(wx.VERTICAL) + self._build_gui() + self._on_file_open(None, False) + self.SetSizer(self._sizer) + self.SetAutoLayout(True) + self.Fit() + self.Thaw() + + def refresh_aliases(self): + self._trigger_alias_list_changed() + self._trigger_filter_list_changed() + + #Private Methods + def _build_gui(self): + rightwnd = wx.SplitterWindow(self, wx.ID_ANY, + style=wx.SP_LIVE_UPDATE|wx.SP_NO_XP_THEME|wx.SP_3DSASH) + leftwnd = wx.SplitterWindow(rightwnd, wx.ID_ANY, + style=wx.SP_LIVE_UPDATE|wx.SP_NO_XP_THEME|wx.SP_3DSASH) + + self._select_alias_wnd = wx.ListCtrl(leftwnd, wx.ID_ANY, + style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES) + self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._on_alias_select, + self._select_alias_wnd) + self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self._on_alias_deselect, + self._select_alias_wnd) + self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self._on_alias_edit, + self._select_alias_wnd) + + self._select_filter_wnd = wx.ListCtrl(leftwnd, wx.ID_ANY, + style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES) + self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._on_filter_select, + self._select_filter_wnd) + self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self._on_filter_deselect, + self._select_filter_wnd) + self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self._on_filter_edit, + self._select_filter_wnd) + + self._text_wnd = wx.TextCtrl(rightwnd, wx.ID_ANY, + style=wx.TE_MULTILINE|wx.TE_BESTWRAP) + + leftwnd.SplitHorizontally(self._select_alias_wnd, + self._select_filter_wnd) + rightwnd.SplitVertically(leftwnd, self._text_wnd) + + #Create top buttons + sizer = wx.BoxSizer(wx.HORIZONTAL) + + btn = create_masked_button(self, dir_struct["icon"] + 'book.gif', + 'New Alias Lib', wx.ID_ANY, '#C0C0C0') + self.Bind(wx.EVT_BUTTON, self._on_file_new, btn) + sizer.Add(btn, 0, wx.EXPAND) + + btn = create_masked_button(self, dir_struct["icon"] + 'open.gif', + 'Open an existing Alias Lib', wx.ID_ANY, + '#C0C0C0') + self.Bind(wx.EVT_BUTTON, self._on_file_open, btn) + sizer.Add(btn, 0, wx.EXPAND) + + btn = create_masked_button(self, dir_struct["icon"] + 'save.gif', + 'Save Alias Lib', wx.ID_ANY, '#C0C0C0') + self.Bind(wx.EVT_BUTTON, self._on_file_save, btn) + sizer.Add(btn, 0, wx.EXPAND) + sizer.Add(wx.StaticLine(self, wx.ID_ANY, style=wx.LI_VERTICAL), 0, + wx.EXPAND) + + btn = create_masked_button(self, dir_struct["icon"] + 'player.gif', + 'Add a new Alias', wx.ID_ANY) + self.Bind(wx.EVT_BUTTON, self._on_alias_new, btn) + sizer.Add(btn, 0, wx.EXPAND) + + btn = create_masked_button(self, dir_struct["icon"] + 'note.gif', + 'Edit selected Alias', wx.ID_ANY) + self.Bind(wx.EVT_BUTTON, self._on_alias_edit, btn) + sizer.Add(btn, 0, wx.EXPAND) + + btn = create_masked_button(self, dir_struct["icon"] + 'noplayer.gif', + 'Delete selected Alias', wx.ID_ANY) + self.Bind(wx.EVT_BUTTON, self._on_alias_delete, btn) + sizer.Add(btn, 0, wx.EXPAND) + sizer.Add(wx.StaticLine(self, wx.ID_ANY, style=wx.LI_VERTICAL), 0, + wx.EXPAND) + + btn = create_masked_button(self, dir_struct["icon"] + 'add_filter.gif', + 'Add a new Filter', wx.ID_ANY, '#0000FF') + self.Bind(wx.EVT_BUTTON, self._on_filter_new, btn) + sizer.Add(btn, 0, wx.EXPAND) + + btn = create_masked_button(self, dir_struct["icon"] + 'edit_filter.gif', + 'Edit selected Filter', wx.ID_ANY, + '#FF0000') + self.Bind(wx.EVT_BUTTON, self._on_filter_edit, btn) + sizer.Add(btn, 0, wx.EXPAND) + + btn = create_masked_button(self, + dir_struct["icon"] + 'delete_filter.gif', + 'Delete selected Filter', wx.ID_ANY, + '#0000FF') + self.Bind(wx.EVT_BUTTON, self._on_filter_delete, btn) + sizer.Add(btn, 0, wx.EXPAND) + sizer.Add(wx.StaticLine(self, wx.ID_ANY, style=wx.LI_VERTICAL), 0, + wx.EXPAND) + + sizer.Add(TextFormatToolBar(self, self._text_wnd), 0, wx.EXPAND) + + #Add the Top and middle sections to the main sizer + self._sizer.Add(sizer, 0, wx.EXPAND) + self._sizer.Add(rightwnd, 1, wx.EXPAND) + + #Build the check boxes + sizer = wx.BoxSizer(wx.HORIZONTAL) + self._auto_clear_text = wx.CheckBox(self, wx.ID_ANY, "Auto Clear Text") + sizer.Add(self._auto_clear_text, 0, wx.EXPAND) + + #Add check boxes to the main sizer + self._sizer.Add(sizer, 0, wx.EXPAND) + + #Build the Bottom Buttons + sizer = wx.BoxSizer(wx.HORIZONTAL) + btn = wx.Button(self, wx.ID_ANY, "Say") + self.Bind(wx.EVT_BUTTON, self._on_transmit_send, btn) + sizer.Add(btn, 0, wx.EXPAND) + + btn = wx.Button(self, wx.ID_ANY, "Emote") + self.Bind(wx.EVT_BUTTON, self._on_transmit_emote, btn) + sizer.Add(btn, 0, wx.EXPAND) + + btn = wx.Button(self, wx.ID_ANY, "Whisper") + self.Bind(wx.EVT_BUTTON, self._on_transmit_whisper, btn) + sizer.Add(btn, 0, wx.EXPAND) + + #Add the final section to the main sizer + self._sizer.Add(sizer, 0, wx.EXPAND) + + def _set_alias_list_wnd(self): + self._select_alias_wnd.ClearAll() + self._select_alias_wnd.InsertColumn(0, "Alias") + self._select_alias_wnd.InsertColumn(1, "Chat Color") + for name, color in self._alias_list: + i = self._select_alias_wnd.InsertStringItem( + self._select_alias_wnd.GetItemCount(), name) + self._select_alias_wnd.SetStringItem(i, 1, color) + if color != 'Default': + self._select_alias_wnd.SetItemTextColour(i, color) + self._select_alias_wnd.RefreshItem(i) + + def _set_filter_list_wnd(self): + self._select_filter_wnd.ClearAll() + self._select_filter_wnd.InsertColumn(0, "Filter") + self._select_filter_wnd.InsertColumn(1, "# Rules") + for name, rules in self._filter_list: + i = self._select_filter_wnd.InsertStringItem( + self._select_filter_wnd.GetItemCount(), name) + self._select_filter_wnd.SetStringItem(i, 1, str(len(rules))) + self._select_filter_wnd.RefreshItem(i) + + + #Events + def _on_file_new(self, evt): + dlg = wx.TextEntryDialog(self, "Please Name This Alias Lib", + "New Alias Lib") + try: + if dlg.ShowModal() == wx.ID_OK: + new_filename = dlg.GetValue() + '.alias' + else: + return + finally: + dlg.Destroy() + + if self._filename == new_filename: + return + + self._on_file_save(None) + + self._filename = new_filename + self._alias_list = [] + self._filter_list = [] + + self._on_file_save(None) + settings.set('aliasfile', self._filename[:-6]) + self._set_alias_list_wnd() + self._set_filter_list_wnd() + + self._trigger_alias_list_changed() + self._trigger_filter_list_changed() + + def _on_file_open(self, evt, do_dlg=True): + if do_dlg: + dlg = wx.FileDialog(self, "Select an Alias Lib to Open", + dir_struct["user"], wildcard="*.alias", + style=wx.HIDE_READONLY|wx.OPEN) + if dlg.ShowModal() == wx.ID_OK: + new_filename = dlg.GetFilename() + + dlg.Destroy() + + if self._filename == new_filename: + return + + self._on_file_save(None) + + self._filename = new_filename + settings.set('aliasfile', self._filename[:-6]) + + xml = ElementTree().parse(dir_struct["user"] + self._filename) + self.alias = None + self.filter = None + self._alias_list = [] + for alias in xml.findall('alias'): + if alias.get('color'): + color = alias.get('color') + else: + color = 'Default' + aname = alias.get("name", '') + self._alias_list.append([aname, color]) + self._alias_list.sort(key=operator.itemgetter(0)) + self._set_alias_list_wnd() + + self._filter_list = [] + for filter in xml.findall('filter'): + sub = [] + for rule in filter.findall("rule"): + sub.append([rule.get("match", ''), rule.get("sub", '')]) + + self._filter_list.append([filter.get("name"), sub]) + self._set_filter_list_wnd() + + self._trigger_alias_list_changed() + self._trigger_filter_list_changed() + + def _on_file_save(self, evt): + root = Element('aliaslib') + for name, color in self._alias_list: + alias = Element('alias') + alias.set('color', color) + alias.set('name', name) + root.append(alias) + + for name, rules in self._filter_list: + filter = Element('filter') + filter.set('name', name) + for r in rules: + rule = Element('rule') + rule.set('match', r[0]) + rule.set('sub', r[1]) + filter.append(rule) + root.append(filter) + + with open(dir_struct["user"] + self._filename, "w") as f: + f.write(tostring(root)) + + def _on_alias_select(self, evt): + alias = self._select_alias_wnd.GetItem(evt.GetIndex(), + 0).GetText() + Publisher.sendMessage('aliaslib.set_alias', alias) + + def _on_alias_deselect(self, evt): + Publisher.sendMessage('aliaslib.set_alias', None) + + def _on_alias_new(self, evt): + with AliasEditDlg('New') as dlg: + if dlg.ShowModal() == wx.ID_OK: + alias = dlg.Result() + else: + return + + self._alias_list.append(alias) + self._set_alias_list_wnd() + self._trigger_alias_list_changed() + + def _on_alias_edit(self, evt): + idx = self._select_alias_wnd.GetNextItem(-1, wx.LIST_NEXT_ALL, + wx.LIST_STATE_SELECTED) + + if idx == -1: + return + + alias = self._alias_list[idx] + + with AliasEditDlg('Edit', alias) as dlg: + if dlg.ShowModal() == wx.ID_OK: + alias = dlg.Result() + else: + return + + self._alias_list[idx] = alias + self._set_alias_list_wnd() + self._trigger_alias_list_changed() + + def _on_alias_delete(self, evt): + idx = self._select_alias_wnd.GetNextItem(-1, wx.LIST_NEXT_ALL, + wx.LIST_STATE_SELECTED) + if idx == -1: + return + + alias = self._alias_list[idx] + self._alias_list.remove(alias) + self._set_alias_list_wnd() + + self._trigger_alias_list_changed() + + def _on_filter_select(self, evt): + filter = self._select_filter_wnd.GetItem(evt.GetIndex(), + 0).GetText() + Publisher.sendMessage('aliaslib.set_filter', filter) + + def _on_filter_deselect(self, evt): + Publisher.sendMessage('aliaslib.set_filter', None) + + def _on_filter_new(self, evt): + dlg = wx.TextEntryDialog(self, 'Filter Name: ', + 'Please name this filter') + try: + if dlg.ShowModal() != wx.ID_OK: + return + filterName = dlg.GetValue() + finally: + dlg.Destroy() + + i = self._select_filter_wnd.InsertStringItem( + self._select_filter_wnd.GetItemCount(), + filterName) + self._select_filter_wnd.SetItemState(i, wx.LIST_STATE_SELECTED, + wx.LIST_STATE_SELECTED) + self._filter_list.append([filterName, []]) + self._on_filter_edit(None) + + def _on_filter_edit(self, evt): + idx = self._select_filter_wnd.GetNextItem(-1, wx.LIST_NEXT_ALL, + wx.LIST_STATE_SELECTED) + + if idx == -1: + return + + filter = self._filter_list[idx] + + with FilterEditDlg(filter) as dlg: + if dlg.ShowModal() == wx.ID_OK: + rules = dlg.Result() + else: + return + + self._filter_list[idx][1] = rules + self._set_filter_list_wnd() + self._trigger_filter_list_changed() + + def _on_filter_delete(self, evt): + idx = self._select_filter_wnd.GetNextItem(-1, wx.LIST_NEXT_ALL, + wx.LIST_STATE_SELECTED) + if idx == -1: + return + + filter = self._filter_list[idx] + self._filter_list.remove(filter) + self._set_filter_list_wnd() + self._trigger_filter_list_changed() + + def _on_transmit_send(self, evt): + chat = open_rpg.get('chat') + chat.submit_chat_text(self._text_wnd.Value) + if self._auto_clear_text.IsChecked(): + self._text_wnd.Value = '' + + def _on_transmit_emote(self, evt): + chat = open_rpg.get('chat') + if not self._text_wnd.Value.startswith('/me '): + self._text_wnd.Value = '/me ' + self._text_wnd.Value + chat.submit_chat_text(self._text_wnd.Value) + if self._auto_clear_text.IsChecked(): + self._text_wnd.Value = '' + + def _on_transmit_whisper(self, evt): + session = open_rpg.get('session') + chat = open_rpg.get('chat') + players = session.get_players() + opts = [] + myid = session.get_id() + for p in players: + if p[2] != myid: + opts.append("(" + p[2] + ") " + chat.html_strip(p[0])) + with MultiCheckBoxDlg(self, opts, "Select Players:", "Whisper To", []) as dlg: + sendto = [] + if dlg.ShowModal() == wx.ID_OK: + selections = dlg.get_selections() + for s in selections: + sendto.append(players[s][2]) + else: + return + + self._text_wnd.Value = '/w ' + ','.join(sendto) + '=' + self._text_wnd.Value + chat.submit_chat_text(self._text_wnd.Value) + if self._auto_clear_text.IsChecked(): + self._text_wnd.Value = '' + + def _trigger_alias_list_changed(self): + Publisher.sendMessage('aliaslib.alias_list', self._alias_list) + + def _trigger_filter_list_changed(self): + Publisher.sendMessage('aliaslib.filter_list', self._filter_list) + +class AliasEditDlg(wx.Dialog): + _color = 'Default' + + def __init__(self, type_, alias=None): + wx.Dialog.__init__(self, None, wx.ID_ANY, type_ + " Alias", + style=wx.DEFAULT_DIALOG_STYLE|wx.STAY_ON_TOP) + self.txt = wx.TextCtrl(self, wx.ID_ANY) + if type_ == 'Edit': + self.txt.SetValue(alias[0]) + + self.colorbtn = wx.Button(self, wx.ID_ANY, "Default Color") + self.Bind(wx.EVT_BUTTON, self._on_change_color, self.colorbtn) + + if alias and alias[1] != 'Default': + self.colorbtn.SetLabel("Chat Color") + self.colorbtn.SetForegroundColour(alias[1]) + + okbtn = wx.Button(self, wx.ID_OK) + sizer = wx.BoxSizer(wx.HORIZONTAL) + sizer.Add(wx.StaticText(self, wx.ID_ANY, "Alias: "), 0, wx.EXPAND) + sizer.Add(self.txt, 1, wx.EXPAND) + sizer.Add(self.colorbtn, 0, wx.EXPAND) + sizer.Add(okbtn, 0, wx.EXPAND) + self.SetSizer(sizer) + self.SetAutoLayout(True) + self.Fit() + + def Result(self): + return self.txt.Value, self._color + + def _on_change_color(self, evt): + hexcolor = RGBHex().do_hex_color_dlg(self) + self.colorbtn.SetLabel("Chat Color") + self.colorbtn.SetForegroundColour(hexcolor) + self._color = hexcolor + + def __enter__(self, *args, **kwargs): + return self + def __exit__(self, *args, **kwargs): + self.Destroy() + +class RuleEditDlg(wx.Dialog): + def __init__(self, type_, rule=None): + wx.Dialog.__init__(self, None, wx.ID_ANY, type_ + " Filter Rule", + style=wx.DEFAULT_DIALOG_STYLE|wx.STAY_ON_TOP) + + sizer = wx.BoxSizer(wx.HORIZONTAL) + sizer.Add(wx.StaticText(self, wx.ID_ANY, 'Replace: '), 0, wx.EXPAND) + self.match = wx.TextCtrl(self, wx.ID_ANY) + sizer.Add(self.match, 0, wx.EXPAND) + sizer.Add(wx.StaticText(self, wx.ID_ANY, 'With: '), 0, wx.EXPAND) + self.sub = wx.TextCtrl(self, wx.ID_ANY) + sizer.Add(self.sub, 0, wx.EXPAND) + sizer.Add(wx.Button(self, wx.ID_OK, 'Ok'), 0, wx.EXPAND) + sizer.Add(wx.Button(self, wx.ID_CANCEL, 'Cancel'), 0, wx.EXPAND) + + self.SetSizer(sizer) + self.SetAutoLayout(True) + self.Fit() + + if rule: + self.match.Value = rule[0] + self.sub.Value = rule[1] + + def Result(self): + return self.match.Value, self.sub.Value + + def __enter__(self, *args, **kwargs): + return self + def __exit__(self, *args, **kwargs): + self.Destroy() + +class FilterEditDlg(wx.Dialog): + _rules = [] + def __init__(self, filter): + wx.Dialog.__init__(self, None, wx.ID_ANY, "Edit Filter: " + filter[0], + style=wx.DEFAULT_DIALOG_STYLE|wx.STAY_ON_TOP) + + self._rules = filter[1] + + self.Freeze() + self._build_gui() + self._populate_rules() + self.Thaw() + + def Result(self): + return self._rules + + def _build_gui(self): + + bsizer = wx.BoxSizer(wx.VERTICAL) + self.panel = wx.Panel(self, wx.ID_ANY) + bsizer.Add(self.panel, 1, wx.EXPAND) + self.SetSizer(bsizer) + self.SetAutoLayout(True) + + self.grid = wx.ListCtrl(self.panel, wx.ID_ANY, + style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES) + self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self._on_rule_edit, self.grid) + + btsizer = wx.BoxSizer(wx.VERTICAL) + + btn = wx.Button(self.panel, wx.ID_ANY, 'Add') + self.Bind(wx.EVT_BUTTON, self._on_rule_add, btn) + btsizer.Add(btn, 0, wx.EXPAND) + + btn = wx.Button(self.panel, wx.ID_ANY, 'Edit') + self.Bind(wx.EVT_BUTTON, self._on_rule_edit, btn) + btsizer.Add(btn, 0, wx.EXPAND) + + btn = wx.Button(self.panel, wx.ID_ANY, 'Delete') + self.Bind(wx.EVT_BUTTON, self._on_rule_delete, btn) + btsizer.Add(btn, 0, wx.EXPAND) + + btn = wx.Button(self.panel, wx.ID_OK, 'Done') + btsizer.Add(btn, 0, wx.EXPAND) + + sizer = wx.GridBagSizer(5,5) + + sizer.Add(self.grid, (0,0), flag=wx.EXPAND) + sizer.Add(btsizer, (0,1), flag=wx.EXPAND) + + sizer.AddGrowableCol(0) + sizer.AddGrowableRow(0) + sizer.SetEmptyCellSize((0,0)) + + self.panel.SetSizer(sizer) + self.panel.SetAutoLayout(True) + + def _populate_rules(self): + self.grid.ClearAll() + self.grid.InsertColumn(0, "Replace") + self.grid.InsertColumn(1, "With") + for match, sub in self._rules: + i = self.grid.InsertStringItem(self.grid.GetItemCount(), match) + self.grid.SetStringItem(i, 1, sub) + + self.grid.SetColumnWidth(0, wx.LIST_AUTOSIZE) + self.grid.SetColumnWidth(1, wx.LIST_AUTOSIZE) + + def _on_rule_add(self, evt): + with RuleEditDlg('New') as dlg: + if dlg.ShowModal() == wx.ID_OK: + rule = dlg.Result() + else: + return + + self._rules.append(rule) + self._populate_rules() + pass + + def _on_rule_edit(self, evt): + idx = self.grid.GetNextItem(-1, wx.LIST_NEXT_ALL, + wx.LIST_STATE_SELECTED) + if idx == -1: + return + + rule = self._rules[idx] + with RuleEditDlg('Edit', rule) as dlg: + if dlg.ShowModal() == wx.ID_OK: + rule = dlg.Result() + else: + return + + self._rules[idx] = rule + self._populate_rules() + + def _on_rule_delete(self, evt): + idx = self.grid.GetNextItem(-1, wx.LIST_NEXT_ALL, + wx.LIST_STATE_SELECTED) + if idx == -1: + return + + rule = self._rules[idx] + self._rules.remove(rules) + self._populate_rules() + + def __enter__(self, *args, **kwargs): + return self + def __exit__(self, *args, **kwargs): + self.Destroy() + +class AliasLibEvent(wx.PyCommandEvent): + def __init__(self, eventType, id=1, list_=[]): + wx.PyCommandEvent.__init__(self, eventType, id) + self._eventType = eventType + + self._list = list_ + + self.notify = wx.NotifyEvent(eventType, id) + + def GetNotifyEvent(self): + """Returns the actual wx.NotifyEvent.""" + return self.notify + + def IsAllowed(self): + """Returns whether the event is allowed or not.""" + return self.notify.IsAllowed() + + def Veto(self): + """Vetos the event.""" + self.notify.Veto() + + def Allow(self): + """The event is allowed.""" + self.notify.Allow() + + def _get_list(self): + return self._list + list = property(_get_list) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/ui/toolbars/__init__.py Thu Mar 25 14:36:32 2010 -0600 @@ -0,0 +1,7 @@ +__all__ = ['StatusBar', 'status_bar', 'DiceToolBar', 'TextFormatToolBar', + 'AliasToolBar'] + +from ._status import StatusBar, status_bar +from ._dice import DiceToolBar +from ._text import TextFormatToolBar +from ._alias import AliasToolBar \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/ui/toolbars/_alias.py Thu Mar 25 14:36:32 2010 -0600 @@ -0,0 +1,114 @@ +import wx + +from orpg.orpgCore import open_rpg +from orpg.dirpath import dir_struct +from orpg.ui.util.misc import create_masked_button +from orpg.tools.pubsub import Publisher + +class AliasToolBar(wx.Panel): + """ + The Alias Toolbar + """ + + def __init__(self, parent): + wx.Panel.__init__(self, parent, wx.ID_ANY) + + self._colors = [] + self._rules = [] + + self.sizer = wx.BoxSizer(wx.HORIZONTAL) + + btn = create_masked_button(self, dir_struct["icon"] + 'player.gif', '', + wx.ID_ANY, '#bdbdbd') + self.sizer.Add(btn, 0, wx.EXPAND) + + self._alias_list = wx.Choice(self, wx.ID_ANY, size=(100, 25), + choices=[self.default_alias]) + self._alias_list.SetSelection(0) + self._colors.append('Default') + self.sizer.Add(self._alias_list, 0, wx.EXPAND) + + btn = create_masked_button(self, dir_struct["icon"] + 'add_filter.gif', + '', wx.ID_ANY, '#bdbdbd') + self.sizer.Add(btn, 0, wx.EXPAND) + + self._filter_list = wx.Choice(self, wx.ID_ANY, size=(100, 25), + choices=[self.default_filter]) + self._rules = [[]] + self._filter_list.SetSelection(0) + self.sizer.Add(self._filter_list, 0, wx.EXPAND) + + self.SetSizer(self.sizer) + self.SetAutoLayout(True) + self.Fit() + + Publisher.subscribe(self._on_alias_changed, 'aliaslib.alias_list') + Publisher.subscribe(self._on_filter_changed, 'aliaslib.filter_list') + Publisher.subscribe(self._on_set_alias, 'aliaslib.set_alias') + Publisher.subscribe(self._on_set_filter, 'aliaslib.set_filter') + + def select_alias(self, name): + try: + self._alias_list.StringSelection = name + except Exception: + self._alias_list.Selection = 0 + + #Events + def _on_alias_changed(self, evt): + current = self._alias_list.StringSelection + self._alias_list.Clear() + self._alias_list.Append(self.default_alias) + self._colors = ['Default'] + for name, color in evt.data: + self._alias_list.Append(name) + self._colors.append(color) + + self._alias_list.StringSelection = current + + def _on_filter_changed(self, evt): + current = self._filter_list.StringSelection + self._filter_list.Clear() + self._filter_list.Append(self.default_filter) + self._rules = [[]] + for name, rules in evt.data: + self._filter_list.Append(name) + self._rules.append(rules) + + self._filter_list.StringSelection = current + + def _on_set_alias(self, evt): + self._alias_list.StringSelection = evt.data or self.default_alias + + def _on_set_filter(self, evt): + self._filter_list.StringSelection = evt.data or self.default_filter + + #Properties + def _get_alias(self): + return self._alias_list.StringSelection + alias = property(_get_alias) + + def _get_alias_color(self): + try: + return self._colors[self._alias_list.CurrentSelection] + except IndexError: + return 'Default' + alias_color = property(_get_alias_color) + + def _get_filter(self): + return self._filter_list.StringSelection + filter = property(_get_filter) + + def _get_filter_rules(self): + try: + return self._rules[self._filter_list.CurrentSelection] + except IndexError: + return [] + filter_rules = property(_get_filter_rules) + + def _get_default_alias(self): + return 'Use Real Name' + default_alias = property(_get_default_alias) + + def _get_default_filter(self): + return 'No Filter' + default_filter = property(_get_default_filter) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/ui/toolbars/_dice.py Thu Mar 25 14:36:32 2010 -0600 @@ -0,0 +1,79 @@ +import wx + +from orpg.dirpath import dir_struct +from orpg.tools.inputValidator import MathOnlyValidator +from orpg.ui.util.misc import create_masked_button + +class DiceToolBar(wx.Panel): + """ + This is where all of the dice related tools belong for quick reference. + """ + _callback = None + + def __init__(self, parent, title="Dice Tool Bar", + size=wx.Size(300, 45), callback=None): + wx.Panel.__init__(self, parent, wx.ID_ANY, size=size) + # Save our post callback + self._callback = callback + + # Make a sizer for everything to belong to + self.sizer = wx.BoxSizer(wx.HORIZONTAL) + # Build the toolbar now + self.numDieText = wx.TextCtrl(self, wx.ID_ANY, "1", + size= wx.Size(50, 25), + validator=MathOnlyValidator()) + self.sizer.Add(self.numDieText, 1, wx.EXPAND | wx.ALIGN_LEFT) + + btns = ['d4', 'd6', 'd8', 'd10', 'd12', 'd20', 'd100'] + for die in btns: + btn = create_masked_button(self, + dir_struct['icon'] + 'b_{die}.gif'.\ + format(die=die), + 'Roll {die}'.format(die=die), + wx.ID_ANY, wx.WHITE) + self.sizer.Add(btn, 0, wx.ALIGN_CENTER) + evt_method = getattr(self, '_{die}_clicked'.format(die=die)) + self.Bind(wx.EVT_BUTTON, evt_method, btn) + + # Add our other text control to the sizer + self.dieModText = wx.TextCtrl(self, wx.ID_ANY, "+0", + size=wx.Size(50, 25), + validator=MathOnlyValidator()) + self.sizer.Add(self.dieModText, 1, wx.EXPAND | wx.ALIGN_RIGHT) + + # Now, attach the sizer to the panel and tell it to do it's magic + self.SetSizer(self.sizer) + self.SetAutoLayout(True) + self.Fit() + + #Events + def _d4_clicked(self, evt): + self._do_roll('d4') + + def _d6_clicked(self, evt): + self._do_roll('d6') + + def _d8_clicked(self, evt): + self._do_roll('d8') + + def _d10_clicked(self, evt): + self._do_roll('d10') + + def _d12_clicked(self, evt): + self._do_roll('d12') + + def _d20_clicked(self, evt): + self._do_roll('d20') + + def _d100_clicked(self, evt): + self._do_roll('d100') + + def _do_roll(self, sides): + die = self.numDieText.GetValue() + mod = self.dieModText.GetValue() + + rollString = '[{die}{sides}{mod}]'.format(die=die, + sides=sides, + mod=mod) + if self._callback != None: + self._callback(rollString, 1, 1) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/ui/toolbars/_status.py Thu Mar 25 14:36:32 2010 -0600 @@ -0,0 +1,97 @@ +import time + +import wx + +from orpg.tools.decorators import debugging, deprecated + +class StatusBar(wx.StatusBar): + _connect_status = "Not Connected" + _url = "" + _window = 1 + + @debugging + def __init__(self, parent): + wx.StatusBar.__init__(self, parent, wx.ID_ANY) + + self.menu = wx.Menu("Switch layout to...") + item = wx.MenuItem(self.menu, wx.ID_ANY, "General", "General", + wx.ITEM_CHECK) + self.Bind(wx.EVT_MENU, self.OnM_SwitchlayouttoGeneral, item) + self.menu.AppendItem(item) + item = wx.MenuItem(self.menu, wx.ID_ANY, "Url Display", "Url Display", + wx.ITEM_CHECK) + self.Bind(wx.EVT_MENU, self.OnM_SwitchlayouttoUrlDisplay, item) + self.menu.AppendItem(item) + self.Bind(wx.EVT_RIGHT_DOWN, self.onPopup) + self.SetFieldsCount(2) + self.timer = wx.Timer(self, wx.NewId()) + self.Bind(wx.EVT_TIMER, self.Notify) + self.timer.Start(3000) + + @debugging + def onPopup(self, evt): + self.PopupMenu(self.menu) + + @debugging + def OnM_SwitchlayouttoUrlDisplay(self, evt): + self._window = 2 + self.bar1() + + @debugging + def OnM_SwitchlayouttoGeneral(self, evt): + self._window = 1 + self.bar0() + + def Notify(self, event): + if self._window == 1: + self.bar0() + elif self._window == 2: + self.bar1() + + def bar1(self): + self.SetFieldsCount(1) + self.SetStatusWidths([-1]) + self.SetStatusText("URL: " + self.urlis, 0) + + def bar0(self): + self.SetFieldsCount(2) + t = time.gmtime(time.time()) + st = time.strftime("GMT: %d-%b-%Y %I:%M:%S", t) + (x,y) = self.GetTextExtent(st) + self.SetStatusWidths([-1, x+10]) + self.SetStatusText(self.connect_status, 0) + self.SetStatusText(st, 1) + + def __del__(self): + self.timer.Stop() + del self.timer + + #Depreciated Mthods + @deprecated("set the url with the url property") + def set_url(self, url): + self.url = url + + @deprecated("set the connect_status with the connect_status property") + def set_connect_status(self, connect): + self.connect_status = connect + + #Property Methods + def _get_url(self): + return _url + def _set_url(self, value): + if not isinstance(value, basestring): + raise TypeError("url must be a string") + self._url = value + url = property(_get_url, _set_url) + + def _get_connect_status(self): + return self._connect_status + def _set_connect_status(self, value): + if not isinstance(value, basestring): + raise TypeError("connect_status must be a string") + self._connect_status = value + connect_status = property(_get_connect_status, _set_connect_status) + +@deprecated("Please use the StatusBar class") +def status_bar(parent): + return StatusBar(parent) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/ui/toolbars/_text.py Thu Mar 25 14:36:32 2010 -0600 @@ -0,0 +1,102 @@ +import wx + +from orpg.dirpath import dir_struct +from orpg.tools.settings import settings +from orpg.tools.rgbhex import RGBHex +from orpg.ui.util.misc import create_masked_button + +class TextFormatToolBar(wx.Panel): + """ + Toolbar that adds formating buttons + """ + _text_field = None + _rgb = RGBHex() + + def __init__(self, parent, text_field): + wx.Panel.__init__(self, parent, wx.ID_ANY) + + self._text_field = text_field + + self.sizer = wx.BoxSizer(wx.HORIZONTAL) + + btn = create_masked_button(self, dir_struct['icon'] + 'bold.gif', + 'Make the selected text Bold', wx.ID_ANY, + '#bdbdbd') + self.sizer.Add(btn, 0, wx.ALIGN_CENTER) + self.Bind(wx.EVT_BUTTON, self._bold_clicked, btn) + + btn = create_masked_button(self, dir_struct["icon"]+'italic.gif', + 'Italicize the selected text', wx.ID_ANY, + '#bdbdbd') + self.sizer.Add(btn, 0, wx.ALIGN_CENTER) + self.Bind(wx.EVT_BUTTON, self._italics_clicked, btn) + + btn = create_masked_button(self, dir_struct['icon'] + 'underlined.gif', + 'Underline the selected text', wx.ID_ANY, + '#bdbdbd') + self.sizer.Add(btn, 0, wx.ALIGN_CENTER) + self.Bind(wx.EVT_BUTTON, self._underline_clicked, btn) + + self.color_btn = create_masked_button(self, dir_struct['icon'] + 'textcolor.gif', + 'Set the Text Color for the selected text', + wx.ID_ANY, '#bdbdbd') + self.sizer.Add(self.color_btn, 0, wx.ALIGN_CENTER) + self.Bind(wx.EVT_BUTTON, self._color_clicked, self.color_btn) + + # Now, attach the sizer to the panel and tell it to do it's magic + self.SetSizer(self.sizer) + self.SetAutoLayout(True) + self.Fit() + + #Update btn + self._update_color_button(settings.get('mytextcolor')) + + #Events + def _bold_clicked(self, evt): + self._do_replacemnt('b') + + + def _italics_clicked(self, evt): + self._do_replacemnt('i') + + def _underline_clicked(self, evt): + self._do_replacemnt('u') + + def _color_clicked(self, evt): + hexcolor = self._rgb.do_hex_color_dlg(self) + + start, end = self._text_field.GetSelection() + + if hexcolor != None: + if start != end: + self._do_replacemnt('font color="{hexcolor}"'.format( + hexcolor=hexcolor)) + else: + self._update_color_button(hexcolor) + settings.set('mytextcolor', hexcolor) + + def _do_replacemnt(self, format_type): + txt = self._text_field.Value + start, end = self._text_field.GetSelection() + + pre = txt[:start] + selection = txt[start:end] + post = txt[end:] + + txt = '{pre}<{format_type}>{selection}</{format_type}>{post}'.\ + format(pre=pre, + format_type=format_type, + selection=selection, + post=post) + + self._text_field.Value = txt + self._text_field.SetInsertionPointEnd() + self._text_field.SetFocus() + + def _update_color_button(self, color): + """ + Dynamically Generates a properly colored background for the text color + button to maintain uniform look on buttons + """ + self.color_btn.BackgroundColour = color +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/ui/util/dlg/__init__.py Thu Mar 25 14:36:32 2010 -0600 @@ -0,0 +1,3 @@ +__all__ = ['MultiCheckBoxDlg'] + +from ._checkbox import MultiCheckBoxDlg \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/ui/util/dlg/_checkbox.py Thu Mar 25 14:36:32 2010 -0600 @@ -0,0 +1,49 @@ +import wx + +from orpg.tools.decorators import debugging + +class MultiCheckBoxDlg(wx.Dialog): + """ notes """ + @debugging + def __init__(self, parent, opts, text, caption, selected=[], + pos=wx.DefaultPosition): + wx.Dialog.__init__(self, parent, wx.ID_ANY, caption, pos, + wx.DefaultSize) + sizers = {'ctrls': wx.BoxSizer(wx.VERTICAL), + 'buttons': wx.BoxSizer(wx.HORIZONTAL)} + self.opts = opts + self.list = wx.CheckListBox(self, wx.ID_ANY, wx.DefaultPosition, + wx.DefaultSize, opts) + for s in selected: + self.list.Check(s, 1) + + sizers['ctrls'].Add(wx.StaticText(self, -1, text), 0, 0) + sizers['ctrls'].Add(wx.Size(10,10)) + sizers['ctrls'].Add(self.list, 1, wx.EXPAND) + sizers['buttons'].Add(wx.Button(self, wx.ID_OK, "OK"), 1, wx.EXPAND) + sizers['buttons'].Add(wx.Size(10,10)) + sizers['buttons'].Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, + wx.EXPAND) + sizers['ctrls'].Add(sizers['buttons'], 0, wx.EXPAND) + self.SetSizer(sizers['ctrls']) + self.SetAutoLayout(True) + self.Fit() + self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK) + + @debugging + def on_ok(self,evt): + checked = [] + for i in xrange(len(self.opts)): + if self.list.IsChecked(i): + checked.append(i) + self.checked = checked + self.EndModal(wx.ID_OK) + + @debugging + def get_selections(self): + return self.checked + + def __enter__(self, *args, **kwargs): + return self + def __exit__(self, *args, **kwargs): + self.Destroy() \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/ui/util/misc/__init__.py Thu Mar 25 14:36:32 2010 -0600 @@ -0,0 +1,3 @@ +__all__ = ['create_masked_button'] + +from ._buttons import create_masked_button \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/ui/util/misc/_buttons.py Thu Mar 25 14:36:32 2010 -0600 @@ -0,0 +1,10 @@ +import wx + +def create_masked_button(parent, image, tooltip, id, mask_color=wx.WHITE, + image_type=wx.BITMAP_TYPE_GIF): + gif = wx.Image(image, image_type).ConvertToBitmap() + mask = wx.Mask(gif, mask_color) + gif.SetMask(mask) + btn = wx.BitmapButton(parent, id, gif) + btn.SetToolTip(wx.ToolTip(tooltip)) + return btn \ No newline at end of file