Ejemplo n.º 1
0
    def __init__(self):
        '''
        Constructor.
        '''
        resources = manager.ResourceManager()
        self.clients = {}
        self.gameList = {}
        self.dicts = {}
        self.db = db.DB()
        self.maxUsersLoggedIn = 0
        self.startDate = util.Time(seconds=time.time(), dispDate=True)

        dir = resources["resources"][constants.DICT_DIR].path
        for lang in os.listdir(dir):
            if not lang.islower(): continue  # Avoids CVS directories
            self.dicts[lang] = set()
            for file in os.listdir(os.path.join(dir, lang)):
                if not file.islower(): continue  # Avoids CVS directories
                path = os.path.join(dir, lang, file)

                f = codecs.open(path, encoding='utf-8', mode='rb')
                lines = f.read().split()
                f.close()

                l = []
                for line in lines:
                    l.append(line.upper())
                x = set(l)

                self.dicts[lang] = self.dicts[lang].union(x)

        for game in self.db.games.values():
            self.gameList[game.getGameId()] = game
Ejemplo n.º 2
0
def setupStockItems():
    '''
    Setup stock images
    '''
    widget = gtk.DrawingArea()
    
    factory = gtk.IconFactory()
    
    r = manager.ResourceManager()
    
    buf = gtk.gdk.pixbuf_new_from_file( r["resources"]["images"][gtkconstants.STOCK_SEND_IM_FILE] )
    icon = gtk.IconSet(buf)
    factory.add( gtkconstants.STOCK_SEND_IM, icon )
    
    factory.add( gtkconstants.STOCK_COPY_URL, gtk.IconSet(widget.render_icon(gtk.STOCK_COPY, gtk.ICON_SIZE_MENU)) )
    factory.add( gtkconstants.STOCK_COPY_EMAIL, gtk.IconSet(widget.render_icon(gtk.STOCK_COPY, gtk.ICON_SIZE_MENU)) )
    factory.add( gtkconstants.STOCK_OPEN_URL, gtk.IconSet(widget.render_icon(gtk.STOCK_JUMP_TO, gtk.ICON_SIZE_MENU)) )
    factory.add( gtkconstants.STOCK_OFFLINE_MESSAGE, gtk.IconSet(widget.render_icon(gtk.STOCK_NETWORK, gtk.ICON_SIZE_MENU)) )
    factory.add( gtkconstants.STOCK_DEFINE, gtk.IconSet(widget.render_icon(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU)) )
    factory.add( gtkconstants.STOCK_SEND_MOVE, gtk.IconSet(widget.render_icon(gtk.STOCK_YES, gtk.ICON_SIZE_MENU)) )
    factory.add( gtkconstants.STOCK_RESET_DEFAULT, gtk.IconSet(widget.render_icon(gtk.STOCK_UNDO, gtk.ICON_SIZE_MENU)) )
    factory.add( gtkconstants.STOCK_PASS, gtk.IconSet(widget.render_icon(gtk.STOCK_NO, gtk.ICON_SIZE_MENU)) )
    factory.add( gtkconstants.STOCK_TRADE_LETTERS, gtk.IconSet(widget.render_icon(gtk.STOCK_UNDO, gtk.ICON_SIZE_MENU)) )
    factory.add( gtkconstants.STOCK_SHUFFLE, gtk.IconSet(widget.render_icon(gtk.STOCK_REFRESH, gtk.ICON_SIZE_MENU)) )
    factory.add( gtkconstants.STOCK_REGISTER, gtk.IconSet(widget.render_icon(gtk.STOCK_ADD, gtk.ICON_SIZE_MENU)) )
    factory.add( gtkconstants.STOCK_ADD_HOSTNAME, gtk.IconSet(widget.render_icon(gtk.STOCK_COPY, gtk.ICON_SIZE_MENU)) )
    
    factory.add_default()
    
    widget.destroy()
    widget = None
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
    def __init__(self, original, ctx, factory):
        self.factory = factory
        self.user = self.factory.getUser(original)
        rend.Page.__init__(self, original)

        r = manager.ResourceManager()
        UserAdmin.docFactory = loaders.xmlfile(
            r["resources"]["web"]["user_admin.html"])
Ejemplo n.º 5
0
 def __init__(self):
     '''
     Initialize the connection to the DB
     '''
     r = manager.ResourceManager()
     path = r["config"][constants.DB_LOCATION]
     
     storage = FileStorage.FileStorage(path)    
     db = _DB(storage)
     self._conn = db.open()
     self._root = self._conn.root()
Ejemplo n.º 6
0
 def __init__(self, factory):
     '''
     Constructor
     
     @param factory: ScrabbleServerFactory
     '''
     rend.Page.__init__(self)
     self.factory = factory
     
     r = manager.ResourceManager()
     ScrabbleSite.docFactory = loaders.xmlfile( r["resources"]["web"]["index.html"] )
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
    def __init__(self, factory):
        '''
        Constructor
        
        @param factory: ScrabbleServerFactory
        '''
        rend.Page.__init__(self)
        self.factory = factory
        flat.registerFlattener(self.flattenTime, util.Time)

        r = manager.ResourceManager()
        ScrabbleSite.child_styles = static.File(r["resources"]["web"].path)
        ScrabbleSite.docFactory = loaders.xmlfile(
            r["resources"]["web"]["index.html"])
Ejemplo n.º 9
0
def showAbout(menu):
    '''
    Show about dialog
    
    @param menu:
    '''
    r = manager.ResourceManager()
    dialog = gtk.AboutDialog()
    dialog.set_name( "PyScrabble" )
    dialog.set_authors( ["Kevin Conaway", "Dennis Harrison -- Testing", "Mark Lee -- Patches", "Jaderi -- Testing"] )
    dialog.set_comments( "For Erin" )
    dialog.set_website( constants.ONLINE_SITE )
    dialog.set_website_label( constants.ONLINE_SITE )
    dialog.set_logo( gtk.gdk.pixbuf_new_from_file(r["resources"]["images"]["py.ico"]) )
    dialog.set_translator_credits(_('translator-credits'))
    gtk.about_dialog_set_url_hook(util.showUrl, data=constants.ONLINE_SITE)
    dialog.set_version(constants.VERSION)
    dialog.show()
Ejemplo n.º 10
0
 def configure(self):
     '''
     Configure the server
     '''
     dist.ensure_config_dir(dist.CONFIG_DIR)
     resources = manager.ResourceManager()
     logging.basicConfig(level=logging.DEBUG,
                 format='%(asctime)s %(name)s %(levelname)s %(message)s',
                 filename=resources["config"][constants.LOG_FILE],
                 filemode='w')
     
     
     config = resources["config"][constants.SERVER_CONSOLE_CONFIG]
     
     if not os.path.exists(config):
         raise IOError, "%s must exist in %s" % (constants.SERVER_CONSOLE_CONFIG, resources["config"].path)
         
     parser = ConfigParser.ConfigParser()
     parser.read( config )
     self.w_port = int(parser.get("pyscrabble","web_port"))
     self.g_port = int(parser.get("pyscrabble","game_port"))
Ejemplo n.º 11
0
'''
Use me to upgrade the old shelve-backed database to ZODB
'''
import shelve
from pyscrabble import db
from pyscrabble import manager

USER_LIST_LOCATION = 'pyscrabble.users.list'
MESSAGES_LOCATION = 'messages.list'
GAME_LIST_LOCATION = 'pyscrabble.games.list'
SERVER_STATS_LOCATION = 'server.stats.list'

r = manager.ResourceManager()
db = db.DB()

s = shelve.open(r["config"][USER_LIST_LOCATION], writeback=True)
for k, v in s.iteritems():
    db.users[k] = v
s.close()

s = shelve.open(r["config"][MESSAGES_LOCATION], writeback=True)
for k, v in s.iteritems():
    db.messages[k] = v
s.close()

s = shelve.open(r["config"][GAME_LIST_LOCATION], writeback=True)
for k, v in s.iteritems():
    db.games[k] = v
s.close()

s = shelve.open(r["config"][SERVER_STATS_LOCATION], writeback=True)
Ejemplo n.º 12
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)

        resources = manager.ResourceManager()
        pyscrabble_image = os.path.join(resources["resources"][IMAGE_DIR].path,
                                        IMAGE_XPM)
        pynotify.init('pyscrabble')
        self.notifier = pynotify.Notification('pyscrabble', 'starting...',
                                              'file://%s' % pyscrabble_image)

        self.set_icon_from_file(pyscrabble_image)
        # 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()

        # Dictionaries
        self.dicts = {}
        self.read_dicts(resources)

        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()