rendered paste body# -*- coding: utf-8 -*-# This file is part of emesene.## Emesene is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## emesene is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with emesene; if not, write to the Free Software# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USAimport gtkimport Themeimport ConversationUIfrom emesenecommon import * # no paths hereclass PreferenceWindow( gtk.Window ): '''This class display a windows where the user can modify the behaviour of emesene''' def __init__( self, controller, config, parent ): '''Contructor''' gtk.Window.__init__( self ) self.controller = controller self.set_default_size( 300, 250 ) self.set_title( _( 'Preferences' ) ) self.set_role( _( 'Preferences' ) ) self.config = config self.set_transient_for( parent ) self.set_type_hint( gtk.gdk.WINDOW_TYPE_HINT_DIALOG ) self.set_border_width( 12 ) self.set_resizable( False ) vbox = gtk.VBox() vbox.set_spacing( 12 ) hButBox = gtk.HButtonBox() hButBox.set_spacing( 6 ) hButBox.set_layout( gtk.BUTTONBOX_END ) notebook = gtk.Notebook() bClose = gtk.Button( stock=gtk.STOCK_CLOSE ) vbox.pack_start( notebook, False, False) hButBox.pack_start( bClose ) vbox.pack_start( hButBox, False, False ) self.connectionTab = ConnectionTab( self.config ) if self.controller.connected: self.interfaceTab = InterfaceTab( self.controller ) self.themesTab = ThemesTab( self.controller ) self.colorSchemeTab = ColorSchemeTab(self.controller) notebook.append_page( self.interfaceTab, gtk.Label( _( 'Interface' ) ) ) notebook.append_page( self.themesTab, gtk.Label( _( 'Theme' ) ) ) notebook.append_page( self.colorSchemeTab, gtk.Label(_('Color scheme'))) notebook.append_page( self.connectionTab, gtk.Label( _( 'Connection' ) ) ) else: notebook.append_page( self.connectionTab, gtk.Label( _( 'Connection' ) ) ) vbox.show_all() self.add( vbox ) self.connect( 'delete-event', self.close ) bClose.connect( 'clicked', self.close ) def close( self, *args ): '''Close the window''' self.hide() self.save() self.destroy() self.controller.prefsOpen = False def save( self ): '''save the actual setting''' self.connectionTab.save() if self.controller.connected: self.interfaceTab.save() self.themesTab.save() self.colorSchemeTab.save() # TODO: remove preferences-changed self.controller.emit( 'preferences-changed' )class ColorSchemeItem: def __init__(self, tab, configColor,text): self.configColor=configColor self.button = gtk.ColorButton(gtk.gdk.color_parse( tab.config.user[configColor] )) self.button.connect("color-set", tab.save) alignment = gtk.Alignment(0, 0.5, 0, 0) alignment.add(gtk.Label(text)) self.hbox = gtk.HBox() self.hbox.pack_start(alignment, True, True, 3) self.hbox.pack_start(self.button, False, False, 3)class ColorSchemeTab(gtk.VBox): '''This class represent the tab that contain all the configuration about the colors''' def __init__(self, controller): gtk.VBox.__init__(self) self.config = controller.getConfig() self.controller = controller self.items={} self.items["typingColor"] = ColorSchemeItem(self, 'typingColor', \ _("Contact typing")) self.items["messageWaitingColor"] = ColorSchemeItem(self, \ 'messageWaitingColor', _("Message waiting")) self.items["personalMessageColor"] = ColorSchemeItem(self, \ 'personalMessageColor', _("Personal msn message")) self.items["nickColor"] = ColorSchemeItem(self, 'nickColor', \ _("Contact's list")) vbox = gtk.VBox() for i in self.items.keys(): vbox.pack_start(self.items[i].hbox, False, False, 3) #scroll = gtk.ScrolledWindow() #scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) #scroll.add_with_viewport(vbox) #self.pack_start(scroll, True, True, 0) self.pack_start(vbox, True, True, 0) self.pack_start(gtk.HSeparator(), False, True, 2) restoreButton = gtk.Button(stock = gtk.STOCK_CLEAR) restoreButton.connect("clicked", self.restoreColors) alignment = gtk.Alignment(0.5, 0.5, 0.5, 0.5) alignment.add(restoreButton) self.pack_start(alignment, False, True, 2) self.show_all() def restoreColors(self, *args): for i in self.items.keys(): self.items[i].button.set_color(gtk.gdk.color_parse(self.config.getUserDefaultValue(self.items[i].configColor))) def save(self, *args): for i in self.items.keys(): self.config.user[self.items[i].configColor] = rgbToHexa(self.items[i].button.get_color()) class InterfaceTab( gtk.VBox ): '''This class represent the tab that contains all the configurations about the GUI''' def __init__( self, controller ): '''Constructor''' gtk.VBox.__init__( self ) self.controller = controller self.config = controller.config self.set_spacing( 4 ) self.set_border_width( 12 ) self.checks = [] #MainWindowPanel self.MainWindowPanel = MainWindowPanel(controller, self.config) frame = gtk.Frame( _( 'Userlist' ) ) frame.add( self.MainWindowPanel ) self.pack_start( frame ) self.show_all() # conversation panel self.conversationPanel = ConversationPanel(controller, self.config) frame = gtk.Frame( _( 'Conversation' ) ) frame.add( self.conversationPanel ) self.pack_start( frame ) self.show_all() def onToggled( self, radio, option ): self.config.user[option] = radio.get_active() def save( self ): passclass ConnectionTab( gtk.VBox ): '''This class represent the tab that contains the connection options''' def __init__( self, config ): '''Constructor''' gtk.VBox.__init__( self ) self.config = config self.set_spacing( 18 ) self.set_border_width( 12 ) self.debug = gtk.CheckButton( _( '_Show debug in console' ) ) self.debug.set_active( self.config.glob['debug'] ) self.binary = gtk.CheckButton( _( '_Show binary codes in debug' ) ) self.binary.set_active( self.config.glob['binary'] ) self.nodns = gtk.CheckButton( _( '_No DNS mode' ) ) self.nodns.set_active( self.config.glob['nodns'] ) self.httpMethod = gtk.CheckButton( _( '_Use HTTP method' ) ) self.httpMethod.set_active( self.config.glob['httpMethod'] ) self.proxySettings = ProxySettings( self.config ) frame = gtk.Frame( _( 'Proxy settings' ) ) frame.add( self.proxySettings ) self.pack_start( self.debug, False, False ) self.pack_start( self.binary, False, False ) self.pack_start( self.nodns, False, False ) self.pack_start( self.httpMethod, False, False) proxyBox = gtk.VBox( spacing=6 ) proxyBox.pack_start( frame, False, False ) self.pack_start( proxyBox, False, False ) self.show_all() def save( self ): '''save the actual setting''' self.config.glob['debug'] = self.debug.get_active() self.config.glob['binary'] = self.binary.get_active() self.config.glob['nodns'] = self.nodns.get_active() self.config.glob['httpMethod'] = self.httpMethod.get_active() self.proxySettings.save() class ThemesTab( gtk.VBox ): '''This class represent the tab that ...''' def __init__( self, controller ): '''Constructor''' gtk.VBox.__init__( self ) self.controller = controller self.config = controller.getConfig() self.theme = controller.getTheme() self.basetheme = Theme.BaseTheme() self.basetheme.pixbufs = {} self.basetheme.defaults = {} self.basetheme.HOME_PATH = self.theme.HOME_PATH self.basetheme.SYSTEM_WIDE_PATH = self.theme.SYSTEM_WIDE_PATH self.basetheme.defaultPath = self.theme.defaultPath self.set_spacing( 4 ) self.set_border_width( 12 ) self.smallIcons = gtk.CheckButton(_('_Use small icons' )) self.smallIcons.set_active( self.config.user['smallIcons'] ) self.parseSmilies = gtk.CheckButton(_('Display _smiles' )) self.parseSmilies.set_active( self.config.user['parseSmilies'] ) self.pack_start(self.smallIcons, False, False) self.pack_start(self.parseSmilies, False, False) fields = [] fields.append({'name': 'theme', 'label': _( 'Theme' ), 'values': self.config.getThemes(), 'config': None, 'sample': self.getThemeSample, }) fields.append({'name': 'smilieTheme', 'label': _( 'Smilie theme' ), 'values': self.config.getSmilieThemes(), 'config': None, 'sample': self.getSmilieSample, }) fields.append({'name': 'conversationLayout', 'label': _( 'Conversation Layout' ), 'values': self.controller.getConversationLayoutManager().listAvailableThemes(), 'config': None, 'sample': None, }) self.layoutvariantdict={'name': 'layoutvariant', 'label': _( 'Layout Variant' ), 'values': self.controller.getConversationLayoutManager().listAvailableVariants(self.config.user['conversationLayout']), 'config': None, 'sample': None, } fields.append(self.layoutvariantdict) self.fields = fields table = gtk.Table(len(fields), 3, False) table.set_row_spacings( 8 ) table.set_col_spacings( 8 ) row = 0 for field in fields: label = gtk.Label( field['label'] ) label.set_alignment( 0.0, 0.5 ) label.set_use_underline( True ) table.attach( label, 0,1, row,row+1 ) comboModel = gtk.ListStore( str, gtk.gdk.Pixbuf ) combo = gtk.ComboBox( comboModel ) cellRenderer = gtk.CellRendererText() sampleImage = gtk.CellRendererPixbuf() sampleImage.set_property( 'xalign', 1.0 ) combo.pack_start( cellRenderer, False ) combo.add_attribute( cellRenderer, 'markup', 0) combo.pack_start( sampleImage, True ) combo.add_attribute( sampleImage, 'pixbuf', 1) self.fields[row]['combo'] = combo label.set_mnemonic_widget( combo ) combo.connect( 'changed', self.save, field['name'] ) default = self.config.user[field['name']] done = False count = 0 for current in field['values']: sample = None if field['sample']: sample = field['sample'](field['name'], current) if not done: if current == default: done = True else: count += 1 comboModel.append( [ current, sample ] ) combo.set_active( count ) table.attach( combo, 1,2, row,row+1 ) button = gtk.Button( _( 'Edit...' ) ) if field['config'] != None: table.attach( button, 2,3, row,row+1 ) button.connect( 'clicked', field['config'] ) #else: # button.set_sensitive( False ) row += 1 self.pack_start(table, False, False, 3) self.show_all() # Config dialogs def configConversationLayout( self, *args ): dialog = gtk.Dialog( _( "Conversation Layout" ), None, gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT) ) conversationLayoutTab = ConversationLayoutTab(self.controller) dialog.vbox.add(conversationLayoutTab) dialog.show_all() response = dialog.run() dialog.destroy() # do something with the changes here # Samples def getThemeSample( self, label, item ): self.basetheme.setTheme(item) return self.basetheme.getImage("icon") def getSmilieSample( self, label, item ): tempTheme = Theme.SmilieTheme( None, item ) try: icon = tempTheme.getSmiley(":D").get_static_image() del tempTheme return icon except: pass # Other functions def save( self, widget = None, name = 'all' ): self.config.user['parseSmilies'] = self.parseSmilies.get_active() self.config.user['smallIcons'] = self.smallIcons.get_active() try: for field in self.fields: self.config.user[field['name']] = field['combo'].get_active_text() except: pass if name in ('all','conversationLayout'): if 'combo' in self.layoutvariantdict: newmodel = gtk.ListStore( str, gtk.gdk.Pixbuf ) for i in self.controller.getConversationLayoutManager().listAvailableVariants( self.config.user['conversationLayout'] ): newmodel.append([i, None]) self.layoutvariantdict['combo'].set_model( newmodel ) self.layoutvariantdict['combo'].set_active( 0 ) layout = self.config.user['conversationLayout'] self.controller.getConversationLayoutManager().load(layout)#TODO: this is not a tabclass ConversationLayoutTab( gtk.VBox ): '''This class represents the conversation layout config''' def __init__( self, controller ): '''Constructor''' gtk.VBox.__init__( self ) self.controller = controller self.config = controller.getConfig() self.set_spacing( 4 ) self.set_border_width( 12 ) # Preview field self.labelName = gtk.Label() self.labelName.set_alignment( 0.0, 0.5 ) self.labelDescription = gtk.Label() self.labelDescription.set_alignment( 0.0, 0.5 ) self.labelAuthor = gtk.Label() self.labelAuthor.set_alignment( 0.0, 0.5 ) self.labelWebsite = gtk.Label() self.labelWebsite.set_alignment( 0.0, 0.5 ) self.previewScroll = gtk.ScrolledWindow() self.previewScroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.preview = ConversationUI.WebkitRenderer( self.controller.getConversationLayoutManager().theme['basepath'],self.controller.getConversationLayoutManager().theme['header'], self.controller.getConversationLayoutManager().theme['footer'], self.config.user['layoutvariant'] ) self.previewScroll.add(self.preview) self.pack_start(self.labelName, False, False, 3) self.pack_start(self.labelDescription, False, False, 3) self.pack_start(self.labelAuthor, False, False, 3) self.pack_start(self.labelWebsite, False, False, 3) self.pack_start(self.previewScroll, True, True, 3) self.updateInfosFrame() self.show_all() def updateInfosFrame( self ): '''Updates the htmltextview preview.''' mgr = self.controller.getConversationLayoutManager() self.labelName.set_markup('<b>' + _('Name:') + '</b> ' + \ mgr.getName()) self.labelDescription.set_markup('<b>' + _('Description:') + '</b> ' +\ mgr.getDescription()) self.labelAuthor.set_markup('<b>' + _('Author:') + '</b> ' + \ mgr.getAuthor()) self.labelWebsite.set_markup('<b>' + _('Website:') + '</b> ' + \ mgr.getWebsite()) textbuff = self.preview.get_buffer() start, end = textbuff.get_bounds() textbuff.delete(start,end) html = mgr.getPreview() BODY = "<body xmlns='http://www.w3.org/1999/xhtml'>%s</body>" self.preview.display_html(BODY % html)class MainWindowPanel( gtk.VBox ): '''This class represents the panel to configure the mainwindow inside the interface tab''' def __init__( self, controller, config ): '''Contructor''' gtk.VBox.__init__( self ) self.controller = controller self.config = config self.set_spacing( 6 ) self.set_border_width( 12 ) self.checks = [] mkcheck(self, 'showUserPanel', _('Show _user panel')) mkcheck(self, 'showSearchEntry', _('Show _search entry')) mkcheck(self, 'showStatusCombo', _('Show status _combo')) mkcheck(self, 'showMenu', _('Show _menu bar')) mkcheck(self, 'avatarsInUserList', _('Show _avatars')) self.show_all() def onToggled( self, radio, option ): self.config.user[option] = radio.get_active() def save( self ): passclass ConversationPanel( gtk.VBox ): '''This class represents the panel to configure the conversation inside the interface tab''' def __init__( self, controller, config ): '''Contructor''' gtk.VBox.__init__( self ) self.controller = controller self.config = config self.set_spacing( 6 ) self.set_border_width( 12 ) self.checks = [] mkcheck(self, 'windows', _('Use multiple windows') ) mkcheck(self, 'avatarsInTaskbar', _('Show avatars in task_bar')) mkcheck(self, 'showMenubar', _('Show _menu bar') ) mkcheck(self, 'showHeader', _('Show conversation _header') ) mkcheck(self, 'showToolbar', _('Show conversation _toolbar') ) mkcheck(self, 'showAvatars', _('Show _avatars') ) mkcheck(self, 'showTabCloseButton', _('Show close button on _each tab')) self.show_all() def onToggled( self, radio, option ): self.config.user[option] = radio.get_active() def save( self ): passclass ProxySettings( gtk.VBox ): '''This class represents the panel with the proxy variables in the config file''' def __init__( self, config ): '''Constructor''' gtk.VBox.__init__( self ) self.config = config self.set_spacing( 6 ) self.set_border_width( 12 ) self.useProxy = gtk.CheckButton( _('_Use proxy') ) self.useProxy.set_active( self.config.glob['useProxy'] ) self.host = gtk.Entry() self.host.set_text( self.config.glob['proxyHost'] ) self.port = gtk.Entry() self.port.set_text( str(self.config.glob['proxyPort']) ) table = gtk.Table( 2, 2 ) table.set_row_spacings( 6 ) table.set_col_spacings( 12 ) host = gtk.Label( _( '_Host:' ) ) host.set_alignment( 0.0, 0.5 ) host.set_use_underline( True ) host.set_mnemonic_widget( self.host ) port = gtk.Label( _( '_Port:' ) ) port.set_alignment( 0.0, 0.5 ) port.set_use_underline( True ) port.set_mnemonic_widget( self.port ) table.attach( host, 0, 1, 0, 1 ) table.attach( port , 0, 1, 1, 2 ) table.attach( self.host, 1, 2, 0, 1 ) table.attach( self.port, 1, 2, 1, 2 ) self.useProxyToggled(self.useProxy) self.useProxy.connect('toggled', self.useProxyToggled) self.pack_start( self.useProxy ) self.pack_start( table ) self.show_all() def save( self ): '''save the actual setting''' host = self.host.get_text() if host.startswith( "http://" ): host = host.split( "http://" )[1] if host.find( "/" ) != -1: host = host.split( "/" )[0] self.config.glob['useProxy'] = self.useProxy.get_active() self.config.glob['proxyHost'] = host self.config.glob['proxyPort'] = self.port.get_text() def useProxyToggled(self, check): '''callback for the toggled signal''' if self.useProxy.get_active(): self.host.set_sensitive( True ) self.port.set_sensitive( True ) else: self.host.set_sensitive( False ) self.port.set_sensitive( False )def mkcheck( self, id, label ): '''little helper function to add checkbuttons''' check = gtk.CheckButton(label) check.set_active( self.config.user[id] ) check.connect( 'toggled', self.onToggled, id ) self.pack_start(check, expand=True, fill=True, padding=0) setattr(self, id, check) self.checks.append(id)