Example #1
0
 def set_label(self, letter):
     '''
     Set the Letter/score label on the Tile
     
     @param letter: Letter
     @see: L{pyscrabble.game.pieces.Letter}
     '''
     widget = self.get_child()
     if (widget == None):
         widget = gtk.Label()
     else:
         self.remove(widget)
     
     if letter == None:
         return
     
     l = letter.getLetter()
     s = str(letter.getScore())
     o = manager.OptionManager()
     if o.get_default_bool_option(USE_COLOR_TEXT, True):
         l = """<span foreground="%s">%s</span>""" % (o.get_default_option(COLOR_TEXT, DEFAULT_COLOR_TEXT), l)
         s = """<span foreground="%s">%s</span>""" % (o.get_default_option(COLOR_TEXT, DEFAULT_COLOR_TEXT), s)
     
     if o.get_default_bool_option(OPTION_TEXT_BOLD, False):
         l = """<span weight="bold">%s</span>""" % l
         s = """<span weight="bold">%s</span>""" % s
     
     if len(str(letter.getScore())) == 2:
         widget.set_markup("""%s <sub><span size="xx-small">%s</span></sub>""" % (l, s))
     else:
         widget.set_markup("""%s <sub><span size="x-small">%s</span></sub>""" % (l, s))
     
     self.add(widget)
     self.show_all()
Example #2
0
def createColorPreference(optionVal, defaultOptionVal, enableOptionVal, label, tips, tipText):
    '''
    Create color preference box
    
    @param optionVal:
    @param defaultOptionVal:
    @param enableOptionVal:
    @param label:
    @param tips:
    @param tipText:
    '''
    o = manager.OptionManager()
    opt = o.get_default_option(optionVal, defaultOptionVal) #option,default
    
    enable = gtk.CheckButton(_('Enable'))
    enable.connect("toggled", toggleOption_cb, enableOptionVal) #enable option
    enable.set_active(o.get_default_bool_option(enableOptionVal, True)) #enable option
    cb = gtk.ColorButton(gtk.gdk.color_parse(opt))
    cb.connect("color-set", colorSet_cb, optionVal, enable) #option
    b = gtk.Button(stock=gtkconstants.STOCK_RESET_DEFAULT)
    b.connect("clicked", colorReset_cb, optionVal, defaultOptionVal, cb, enable)
    bbox = gtk.HButtonBox()
    bbox.add( cb )
    bbox.add( b )
    bbox.add( enable )
    hbox = gtk.HBox(False, 5)
    l = createLeftJustifiedLabel( label ) # label
    hbox.pack_start( l, True, True, 5 )
    hbox.pack_start( bbox, False, False, 5)
    tips.set_tip(cb,tipText) #tips
    return hbox
Example #3
0
    def putLetter(self, letter, x, y, set_bg):
        '''
        Put a Letter on a Tile on the board
        
        This is different from adding a new Widget to the board.
        
        This assumes that a GameTile already exists at (x,y) and that
        we are going to change the Letter on that Tile
        
        @param letter: Letter
        @param x: x position
        @param y: y position
        @param set_bg: True to set COLOR_RECENT_TILE as background color
        @see: L{pyscrabble.gui.pieces.GameTile}
        @see: L{pyscrabble.game.pieces.Letter}
        '''

        self.empty = False
        self.tiles[(x, y)].putLetter(letter)
        self.tiles[(x, y)].deactivate()

        if set_bg:
            o = manager.OptionManager()
            self.tiles[(x, y)].setBackground(
                o.get_default_option(COLOR_RECENT_TILE, DEFAULT_RECENT_TILE))
Example #4
0
    def deleteHost_cb(self, button, view):
        '''
        Delete an additional host

        @param button:
        @param view:
        '''

        sel = view.get_selection()
        model, iter = sel.get_selected()

        if (iter == None):
            return None

        host = model.get_value(iter, 0)
        model.remove(iter)

        o = manager.OptionManager(section=HOSTS_SECTION)
        data = o.get_default_option(OPTION_HOSTS, None)
        result = ''
        if data is not None:
            chunks = data.split('/')
            for chunk in chunks:
                if not chunk.startswith(host):
                    result = '%s/%s' % (result, chunk)
        o.set_option(OPTION_HOSTS, result)
Example #5
0
    def setHost(self, button, host, gport, wport, location, dialog, view):
        '''
        Set host info

        @param button:
        @param host:
        @param gport:
        @param wport:
        @param location:
        @param dialog:
        @param view
        '''

        try:
            int(gport.get_text())
            int(gport.get_text())
        except:
            self.error(util.ErrorMessage(_('Port must be a number')))
            return

        dialog.destroy()

        o = manager.OptionManager(section=HOSTS_SECTION)
        data = o.get_default_option(OPTION_HOSTS, '')
        data = '%s%s:%s:%s:%s/' % (data, host.get_text(), gport.get_text(),
                                   wport.get_text(), location.get_text())
        o.set_option(OPTION_HOSTS, data)

        model = view.get_model()
        model.clear()
        for host, gport, wport, location in util.getAdditionalHosts():
            model.append((host, location))
    def getToolbar(self):
        '''
        Get toolbar

        @return: gtk.ButtonBox
        '''

        registerButton = gtkutil.createToolButton(gtkconstants.STOCK_REGISTER, gtkconstants.STOCK_REGISTER)
        registerButton.connect("clicked", self.showCreateUserDialog_cb)

        hostButton = gtkutil.createToolButton(gtkconstants.STOCK_ADD_HOSTNAME, gtkconstants.STOCK_ADD_HOSTNAME)
        hostButton.connect("clicked", self.addHost_cb)

        self.toolBar = gtk.Toolbar()
        self.toolBar.set_style(gtk.TOOLBAR_BOTH)
        self.toolBar.set_show_arrow(False)
        self.toolBar.set_icon_size(gtk.ICON_SIZE_SMALL_TOOLBAR)
        self.toolBar.insert(registerButton, 0)
        self.toolBar.insert(gtk.SeparatorToolItem(), 1)
        self.toolBar.insert(hostButton, 2)
        self.toolBar.insert(gtk.SeparatorToolItem(), 3)
        self.toolBar.set_sensitive(False)

        vbox = gtk.VBox(False, 5)
        vbox.pack_start(self.toolBar, False, False, 0)

        o = manager.OptionManager()

        button = gtk.CheckButton(_('Show public servers at startup'))
        button.set_active( o.get_default_bool_option(constants.OPTION_SHOW_PS, True) )
        button.connect("toggled", self.toggleOption_cb, constants.OPTION_SHOW_PS, o)
        vbox.pack_start(button, False, False, 0)

        return vbox
Example #7
0
    def __init__(self, mainwindow, section=None):
        '''
        Constructor

        @param mainwindow: Mainwindow instance
        '''

        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        self.connect("destroy", self.onDestroy)
        self.connect("delete_event", self.onDelete_event)
        self.set_title(_('Options'))

        self.mainwindow = mainwindow
        self.section = section

        self.optionmanager = manager.OptionManager()

        self.tips = gtk.Tooltips()

        self.set_default_size(OPTION_WINDOW_WIDTH, OPTION_WINDOW_HEIGHT)

        hbox = gtk.HBox(False, 10)
        hbox.pack_start(self.getOptionsMenu(), False, False, 0)
        hbox.pack_start(self.getOptionsFrame(), True, True, 0)

        self.add(hbox)

        #self.set_resizable( False )
        self.set_border_width(10)
        self.show_all()
Example #8
0
 def findStyle(self, x, y):
     '''
     Get the style for this Tile based on the x,y position
     
     @param x:
     @param y:
     '''
     
     
     pos = (x+1, y+1)
     if ( pos in DOUBLE_LETTERS ):
         self.setStyle(TILE_DOUBLE_LETTER, TILE_COLORS[TILE_DOUBLE_LETTER])
         self.board.tileTips.set_tip(self, _('Double Letter Score'))
     elif ( pos in TRIPLE_LETTERS ):
         self.setStyle(TILE_TRIPLE_LETTER, TILE_COLORS[TILE_TRIPLE_LETTER])
         self.board.tileTips.set_tip(self, _('Triple Letter Score'))
     elif ( pos in DOUBLE_WORDS ):
         self.setStyle(TILE_DOUBLE_WORD, TILE_COLORS[TILE_DOUBLE_WORD])
         self.board.tileTips.set_tip(self, _('Double Word Score'))
     elif ( pos in TRIPLE_WORDS ):
         self.setStyle(TILE_TRIPLE_WORD, TILE_COLORS[TILE_TRIPLE_WORD])
         self.board.tileTips.set_tip(self, _('Triple Word Score'))
     elif ( pos in CENTER ):
         if self.board.gameOptions[OPTION_CENTER_TILE]:
             self.setStyle(TILE_DOUBLE_WORD, TILE_COLORS[TILE_DOUBLE_WORD])
             self.board.tileTips.set_tip(self, _('Double Word Score'))
         else:
             self.setStyle(TILE_CENTER, TILE_COLORS[TILE_CENTER])
     else:
         o = manager.OptionManager()
         if o.get_default_bool_option(USE_COLOR_NORMAL_TILE, True):
             self.setStyle(TILE_NORMAL, o.get_default_option(COLOR_NORMAL_TILE, TILE_COLORS[TILE_NORMAL]))
         else:
             self.setStyle(TILE_NORMAL, TILE_COLORS[TILE_NORMAL])
Example #9
0
    def refresh(self):
        '''
        Refresh tile color
        
        @return: True if the tile is active
        '''
        o = manager.OptionManager()
        if self.getLetter() is not None:
            self.set_label(self.getLetter())

            if self.handler_is_connected(self.handler_id):
                if (o.get_default_bool_option(USE_COLOR_NEW_TILE, True)):
                    self.setBackground(
                        o.get_default_option(COLOR_NEW_TILE, DEFAULT_NEW_TILE))
                    return

            if o.get_default_bool_option(USE_COLOR_LETTER, True):
                self.setBackground(
                    o.get_default_option(COLOR_LETTER,
                                         TILE_COLORS[TILE_LETTER]))
            else:
                self.setBackground(TILE_COLORS[TILE_LETTER])
        else:
            if self.getStyle() is TILE_NORMAL:
                if o.get_default_bool_option(USE_COLOR_NORMAL_TILE, True):
                    self.setBackground(
                        o.get_default_option(COLOR_NORMAL_TILE,
                                             TILE_COLORS[TILE_NORMAL]))
                else:
                    self.setBackground(TILE_COLORS[TILE_NORMAL])
Example #10
0
    def loginOK(self):
        '''
        Callback from server if the user is authenticated.
        
        Start the MainWindow
        '''

        h = self.hostname.get_child().get_text()
        if h not in self.history:
            self.history.append(h)

        r = manager.ResourceManager()

        history_file = file(r["config"][SERVER_HISTORY], 'w+')
        for host in self.history:
            history_file.write('%s\n' % host)
        history_file.close()

        o = manager.OptionManager()
        if o.get_default_bool_option(OPTION_SAVE_LOGIN, True):
            o.set_option(OPTION_SAVE_UNAME, self.username.get_text())
            o.set_option(OPTION_SAVE_PWORD, self.password.get_text())
            o.set_option(OPTION_SAVE_HOST, h)

        MainWindow(self.client, util.getUnicode(self.username.get_text()))
        self.destroy()
Example #11
0
 def updateBackground(self, letter):    
     o = manager.OptionManager()
     if letter is not None:
         if o.get_default_bool_option(USE_COLOR_LETTER, True):
             self.setBackground( o.get_default_option(COLOR_LETTER, TILE_COLORS[TILE_LETTER]) )
         else:
             self.setBackground( TILE_COLORS[TILE_LETTER] )
     else:
         self.findStyle(self.x, self.y)
Example #12
0
    def __init__(self, title, text):
        '''
        Toaster popup window
        
        @param title:
        @param text:
        '''
        gtk.Window.__init__(self, gtk.WINDOW_POPUP)

        self.set_default_size(150, 100)
        self.move(gtk.gdk.screen_width(), gtk.gdk.screen_height()
                  )  # Start the window off to the side somewhere
        self.connect("map-event", self.onMapEvent_cb)
        self.connect("destroy", self.onDestroy_cb)
        self.connect("delete-event", self.close_cb)

        o = manager.OptionManager()
        self.timeout = int(
            o.get_default_option(constants.OPTION_POPUP_TIMEOUT,
                                 Popup.TIMEOUT))
        self.intervals = 0

        l = gtk.Label()
        l.set_markup("""<span background="#FFFFFF" weight="bold">%s</span>""" %
                     text)
        hbox = gtk.HBox(False, 5)
        hbox.pack_start(
            gtk.image_new_from_stock(gtk.STOCK_DIALOG_INFO,
                                     gtk.ICON_SIZE_BUTTON), False, False, 5)
        hbox.pack_start(l, False, False, 3)

        box = gtk.EventBox()
        box.add(hbox)
        box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FFFFFF"))
        box.connect("button-press-event", self.close_cb)

        l = gtk.Label()
        l.set_markup("""<span weight="bold" foreground="#FFFFFF">%s</span>""" %
                     title)
        header = gtk.EventBox()
        header.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#6699ff"))
        header.add(l)
        header.connect("button-press-event", self.close_cb)

        vbox = gtk.VBox(False, 0)
        vbox.pack_start(header, False, False, 0)
        vbox.pack_start(gtk.HSeparator(), False, False, 0)
        vbox.pack_start(box, True, True, 0)

        frame = gtk.Frame()
        frame.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        frame.add(vbox)

        self.add(frame)

        self.show_all()
Example #13
0
def getAdditionalHosts():
    result = []
    o = manager.OptionManager(section=constants.HOSTS_SECTION)
    data = o.get_default_option(constants.OPTION_HOSTS, None)
    if data is not None:
        chunks = data.split('/')
        for chunk in chunks:
            if chunk is not '':
                result.append(chunk.split(':'))
    return result
Example #14
0
    def setLetter(self, widget, letter, score, isBlank, showBlank=True):
        '''
        Set letter on this Tile
        
        @param widget: Widget that was dragged
        @param letter: Letter value
        @param score: Score value
        '''
        refresh = True

        # If we have a letter on here there are two cases
        # 1.) A GameTile is being dragged.  If so, we need to remove the old game tile (widget) and put its letter here
        # 2.) A Letter is being dragged.  If so, we need to remove the old letter and put it back in the rack and put the letter here
        #print 'SetLetter called on %s %s %d,%d with %s %s' % ( str(id(self)), str(self),self.x,self.y, str(widget.__class__), str(widget) )
        #print 'SetLetter %s %s %s %s' % ( str(letter), str(score), str(isBlank), str(showBlank) )
        if self.getLetter() is not None and widget is not None:
            if isinstance(widget, GameTile):
                refresh = False
                self.board.removeMove(widget,
                                      widget.x,
                                      widget.y,
                                      refresh=False)
                self.board.removeMove(self, self.x, self.y, refresh=False)
                letter, score = widget.getLetter().getLetter(
                ), widget.getLetter().getScore()
                widget.setLetter(self.getLetter(),
                                 self.getLetter().getLetter(),
                                 self.getLetter().getScore(),
                                 self.getLetter().isBlank())
            if isinstance(widget, GameLetter):
                self.board.removeMove(self, self.x, self.y, refresh=False)
                widget.copyLetter(self.getLetter())
                refresh = False

        else:
            if isinstance(widget, GameTile):
                self.board.removeMove(widget, widget.x, widget.y)
                refresh = False

        l = Letter(letter, score)
        l.setIsBlank(isBlank)
        if l.isBlank() and showBlank:
            l.setLetter("")
        self.putLetter(l, showBlank)
        #print '%s %s %s put on %s %d,%d' % (str(l.getLetter()), str(l.getScore()), str(l.isBlank()), str(id(self)), self.x,self.y)
        self.board.registerMove(self, self.x, self.y, refresh, widget)

        self.source_handler_id = self.connect("drag_data_get", self.dragLetter)
        self.drag_source_set(gtk.gdk.BUTTON1_MASK,
                             [("image/x-xpixmap", 0, 81)], gtk.gdk.ACTION_COPY)

        o = manager.OptionManager()
        if o.get_default_bool_option(USE_COLOR_NEW_TILE, True):
            self.setBackground(
                o.get_default_option(COLOR_NEW_TILE, DEFAULT_NEW_TILE))
Example #15
0
def toggleOption_cb(widget, option):
    '''
    Notification preference toggled.
    
    Set the option name to the value of widget.get_active()
    
    @param widget: Widget that activated this callback
    @param option: Option name
    '''
    o = manager.OptionManager()
    o.set_option(option, int(widget.get_active()))
Example #16
0
    def restoreCredentials(self):
        '''
        If the user has a preference to save their username/password/host, restore it here
        '''
        o = manager.OptionManager()

        if o.get_default_bool_option(OPTION_SAVE_LOGIN, True):
            uname = o.get_default_option(OPTION_SAVE_UNAME, '')
            pword = o.get_default_option(OPTION_SAVE_PWORD, '')
            host = o.get_default_option(OPTION_SAVE_HOST, '')
            self.populateFields_cb(uname, pword, host)
Example #17
0
    def __init__(self):
        '''
        Constructor.
        
        Show the LoginWindow.
        '''

        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        self.connect("delete_event", self.delete_event)

        self.set_title("PyScrabble")
        self.set_default_size(300, 200)

        self.optionWindowShown = False

        left_right = gtk.HBox(False, 20)
        main = gtk.VBox(False, 20)

        left_right.pack_start(self.getLabels(), False, False, 0)
        left_right.pack_start(self.getEntries(), False, False, 0)
        left_right.set_border_width(10)

        main.pack_start(self.createMenuBar(), False, False, 0)
        main.pack_start(self.getHeaderLabel(), False, False, 0)
        main.pack_start(left_right, False, False, 0)
        main.pack_start(self.getButtons(), False, False, 0)

        r = manager.ResourceManager()

        history_file = file(r["config"][SERVER_HISTORY], "ab+")
        self.history = []
        for server in reversed(history_file.read().split()):
            self.hostname.append_text(server)
            self.history.append(server)
        history_file.close()

        pyscrabble_image = os.path.join(r["resources"][IMAGE_DIR].path,
                                        IMAGE_XPM)
        self.set_icon_from_file(pyscrabble_image)

        self.restoreCredentials()

        #self.set_border_width( 10 )
        self.add(main)
        self.show_all()

        self.loggingOut = False

        self.client = None

        o = manager.OptionManager()
        if o.get_default_bool_option(OPTION_SHOW_PS, True):
            self.findServer_cb(None)
Example #18
0
def colorSet_cb(widget, key, enable):
    '''
    Set color preference
    
    @param widget: Color button
    @param key: Preference key
    @param enable: Enable checkbox
    '''
    o = manager.OptionManager()
    enable.set_active(True)
    c = widget.get_color()
    color = util.colorToHexString(c.red,c.green,c.blue)
    o.set_option(key, color)
Example #19
0
    def __repr__(self):
        if self.seconds is not None:
            format = ''
            if self.dispDate:
                format += '%m/%d/%Y '

            o = manager.OptionManager()
            if o.get_default_bool_option(constants.OPTION_24_HOUR, False):
                format += '%H:%M:%S'
            else:
                format += '%I:%M:%S %p'
            return time.strftime(format, time.localtime(self.seconds))
        else:
            return 'N/A'
Example #20
0
 def userJoinChat(self, user):
     '''
     Callback from ScrabbleClient when another user joins the chat room
     
     @param user: User joining chat
     '''
     o = manager.OptionManager()
     if not self.mainwindow.is_active():
         #if o.get_default_bool_option(constants.OPTION_SOUND_NEW_USER, True):
         #    self.mainwindow.soundmanager.play(constants.SOUND_MSG_OPTION)
         if o.get_default_bool_option(constants.OPTION_POPUP_NEW_USER, True):
             p = gtkutil.Popup( title=user, text='%s %s' % (user, lookup.SERVER_MESSAGE_LOOKUP[lookup.LOGGED_IN]))
     
     self.userList.append( [user] )
Example #21
0
    def __init__(self, client, username=''):
        '''
        
        Initialize the main window.
        
        @param client: ScrabbleClient reference
        @param username: Username
        '''

        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)

        self.connect("destroy", self.onDestroy)
        self.connect("delete_event", self.onDelete_event)
        self.connect("focus-in-event", self.focus_cb)

        self.add_events(gtk.gdk.KEY_PRESS_MASK)
        self.connect_after("key-press-event", self.keyPress_cb)

        self.isFullScreen = False
        self.username = username
        self.set_title("PyScrabble - %s" % username)
        self.set_default_size(DEFAULT_WIDTH, DEFAULT_HEIGHT)

        # Reference to client socket
        self.client = client
        self.client.setMainWindow(self)

        self.loggingOut = False

        # List of game names
        self.games = {}

        # List of messages
        self.messages = {}

        # Read options
        self.optionmanager = manager.OptionManager()

        #self.soundmanager = manager.SoundManager()

        self.optionWindowShown = False
        vbox = gtk.VBox(False, 1)
        notebook = self.createNotebook()
        self.menubar = self.createMenuBar()
        vbox.pack_start(self.menubar, False, False, 0)
        vbox.pack_start(notebook, True, True, 0)

        self.add(vbox)
        self.maximize()
        self.show_all()
Example #22
0
    def loginOK(self):
        '''
        Callback from server if the user is authenticated.
        
        Start the MainWindow
        '''

        o = manager.OptionManager()
        if o.get_default_bool_option(OPTION_SAVE_LOGIN, True):
            o.set_option(OPTION_SAVE_UNAME, self.username.get_text())
            o.set_option(OPTION_SAVE_PWORD, self.password.get_text())

        MainWindow(self.username.get_text())
        self.destroy()
Example #23
0
def colorReset_cb(widget, key, val, button, enable):
    '''
    Reset a color option to the default option
    
    @param widget:
    @param key:
    @param val:
    @param button:
    @param enable:
    '''
    o = manager.OptionManager()
    enable.set_active(True)
    o.set_option(key, val)
    button.set_color( gtk.gdk.color_parse(val) )
    button.show()
Example #24
0
    def setBackground(self):
        '''
        Set background color according to preference
        '''
        o = manager.OptionManager()
        color = None
        if o.get_default_bool_option(USE_COLOR_LETTER, True):
            color = o.get_default_option(COLOR_LETTER,
                                         TILE_COLORS[TILE_LETTER])
        else:
            color = TILE_COLORS[TILE_LETTER]

        color = gtk.gdk.color_parse(color)
        self.modify_bg(gtk.STATE_NORMAL, color)
        self.modify_bg(gtk.STATE_ACTIVE, color)
        self.modify_bg(gtk.STATE_PRELIGHT, color)
Example #25
0
    def getLocalePrefs(self):
        '''
        Locale prefs

        @return: gtk.Box
        '''
        self.optionFrame.set_label(_("Locale Preferences"))
        box = gtk.VBox(False)
        box.set_border_width(3)

        box.pack_start(gtk.Label(_('Locale:')), False, False, 10)

        l = manager.LocaleManager()
        model = gtk.ListStore(str, str)

        for key in l.getAvailableLocales():
            desc = l.getLocaleDescription(key)
            model.append([_(desc), key])

        cell = gtk.CellRendererText()
        combo = gtk.ComboBox(model)
        combo.pack_start(cell)
        combo.add_attribute(cell, 'text', 0)

        box.pack_start(combo, False, False, 0)

        button = gtk.Button(_("Save"))
        button.connect("clicked", self.saveLocalePrefs_cb, combo)

        bbox = gtk.HButtonBox()
        bbox.add(button)
        box.pack_start(bbox, False, False, 10)

        o = manager.OptionManager()
        opt = o.get_default_option(LOCALE_OPTION, None)

        if not opt:
            combo.set_active_iter(model.get_iter_first())
        else:
            i = model.get_iter_first()
            while i:
                val = model.get_value(i, 1)
                if val == opt:
                    combo.set_active_iter(i)
                i = model.iter_next(i)

        return box
Example #26
0
    def letterDragged(self, widget, context, x, y, selection, targetType,
                      eventType):
        '''
        Callback when a widget is dragged onto this letter.
        
        @param widget:
        @param context:
        @param x:
        @param y:
        @param selection:
        @param targetType:
        @param eventType:
        '''
        letter = context.get_source_widget()

        if isinstance(letter, GameTile):  # Swap from Board to Tile
            tile = letter
            tmp = self.clone()
            tile.board.removeMove(tile, tile.x, tile.y, refresh=False)
            self.copyLetter(tile.getLetter())
            tile.setLetter(None, tmp.getLetter(), tmp.getScore(),
                           tmp.isBlank())
            return

        if isinstance(letter, GameLetter):

            if id(letter) == id(
                    self):  # ignore if widget is dragged onto itself
                return

            o = manager.OptionManager()
            opt = o.get_default_option(OPTION_SWAP, OPTION_LETTER_SWAP)

            if opt == OPTION_LETTER_INSERT:
                letters = self.letterBox.get_children()
                self.letterBox.foreach(lambda w: self.letterBox.remove(w))
                letters = [l for l in letters if id(l) != id(letter)]
                for l in letters:
                    if id(l) == id(widget):
                        self.letterBox.pack_start(letter, False, False, 0)
                    self.letterBox.pack_start(l, False, False, 0)

            if opt == OPTION_LETTER_SWAP:
                l = self.getLetter().clone()
                self.copyLetter(letter.getLetter())
                letter.copyLetter(l)
Example #27
0
    def putLetter(self, letter, showBlank=False):
        '''
        Put a Letter on the tie.
        
        @param letter:
        @param showBlank: True to show blank value
        '''
        o = manager.OptionManager()
        color = None
        if o.get_default_bool_option(USE_COLOR_LETTER, True):
            color = o.get_default_option(COLOR_LETTER,
                                         TILE_COLORS[TILE_LETTER])
        else:
            color = TILE_COLORS[TILE_LETTER]

        self.setStyle(TILE_LETTER, color)
        self.set_label(letter, showBlank)
        Tile.setLetter(self, letter)
Example #28
0
    def saveLocalePrefs_cb(self, widget, combo):
        '''
        Save Locale Prefs

        @param widget: Widget that activated this callback
        @param combo: Combo box
        '''

        model = combo.get_model()
        iter = combo.get_active_iter()
        opt = model.get_value(iter, 1)

        o = manager.OptionManager()
        o.set_option(LOCALE_OPTION, opt)

        l = manager.LocaleManager()
        l.setLocale()

        s = _('Please restart the application for the changes to take effect.')
        self.info(s)
Example #29
0
    def get_protocol(self):
        '''
        Get the appropriate protocol
        '''
        o = manager.OptionManager()
        if (self.isUsingProxy()):
            type = self.getProxyType()
            if (type == OPTION_PROXY_HTTP):
                if not self._sendCredentials:
                    return protocol.ClientCreator(reactor, HttpProxyProtocol,
                                                  self, self._host, self._port,
                                                  None, None)
                else:
                    return protocol.ClientCreator(reactor, HttpProxyProtocol,
                                                  self, self._host, self._port,
                                                  self._user, self._password)
            else:
                self._client.errback(util.ErrorMessage(
                    _("Invalid proxy type")))

        return protocol.ClientCreator(reactor, DefaultProtocol, self)
Example #30
0
    def getButtons(self):
        '''
        Return buttons
        
        @return: gtk.VButtonBox
        '''
        box = gtk.VButtonBox()

        button = gtk.Button(stock=gtk.STOCK_OK)
        button.connect("clicked", self.closeWindow_cb)

        box.add(button)

        o = manager.OptionManager()

        button = gtk.CheckButton(_('Show help at startup'))
        button.set_active(
            o.get_default_bool_option(constants.OPTION_SHOW_TIPS, True))
        button.connect("toggled", self.toggleOption_cb,
                       constants.OPTION_SHOW_TIPS, o)

        box.add(button)

        return box