Example #1
0
    def __init__(self, networkDialog, parent):
        self.__networkDialog = networkDialog

        # Load the UI
        self.__gui = gtkui.loadUIFile('network_new_server.ui')
        self.__gui.connect_signals(self)

        self.__gui.get_object('add_account_dialog').set_transient_for(parent)

        # FIXME: Hard-coded servers
        # name, host, port
        self.serverModel = gtk.ListStore(str, str, int)
        # Translators: Add Network Profile Dialog: Connect to the GGZ Gaming Zone server (the default)
        self.serverModel.set(self.serverModel.append(), 0,
                             _("GGZ Gaming Zone"), 1,
                             "gnome.ggzgamingzone.org", 2, 5688)
        # Translators: Add Network Profile Dialog: Use a custom server
        self.serverModel.set(self.serverModel.append(), 0, _("Custom"), 1, "",
                             2, 5688)

        widget = self.__gui.get_object('server_combo')
        widget.set_model(self.serverModel)
        cell = gtk.CellRendererText()
        widget.pack_start(cell, False)
        widget.add_attribute(cell, 'text', 0)
        widget.set_model(self.serverModel)
        widget.set_active(0)
Example #2
0
    def __init__(self, mainUI, view, path = None):
        """
        """
        self.__mainUI = mainUI
        self.__view = view
        
        # Load the UI
        self.__gui = gtkui.loadUIFile('save_game.ui')

        self.window = self.__gui.get_object('save_dialog')
        self.window.set_transient_for(mainUI.mainWindow)
        
        self.infobar = gtk.InfoBar()
        self.window.get_content_area().pack_start(self.infobar, False, True, 0)
        vbox = gtk.VBox()
        self.infobar.add(vbox)
        vbox.show()
        self.infoTitleLabel = gtk.Label()
        vbox.pack_start(self.infoTitleLabel, False, True, 0)
        self.infoTitleLabel.show()
        self.infoDescriptionLabel = gtk.Label()
        vbox.pack_start(self.infoDescriptionLabel, False, True, 0);
        self.infoDescriptionLabel.show()

        self.__gui.connect_signals(self)
        
        chooser = self.__gui.get_object('filechooser')
        
        try:
            directory = str(glchess.config.get('save_directory'))
        except glchess.config.Error:
            pass
        else:
            chooser.set_current_folder(directory)       
        
        # Filter out non PGN files by default
        pgnFilter = gtk.FileFilter()
        # Translators: Save Game Dialog: Name of filter to show only PGN files
        pgnFilter.set_name(_('PGN files'))
        pgnFilter.add_pattern('*.pgn')
        chooser.add_filter(pgnFilter)
        
        allFilter = gtk.FileFilter()
        # Translators: Save Game Dialog: Name of filter to show all files
        allFilter.set_name(_('All files'))
        allFilter.add_pattern('*')
        chooser.add_filter(allFilter)
        
        if path is not None:
            chooser.set_current_name(path)
Example #3
0
    def __init__(self, ui, feedback, moveFormat='human', showComments=False):
        """Constructor for a view.
        
        'feedback' is the feedback object for this view (extends ui.ViewFeedback).
        'moveFormat' is the format name to display moves in (string).
        """
        self.ui = ui
        self.feedback = feedback
        self.moveFormat = moveFormat
        self.showComments = showComments
        self.editingComment = False
        self.hasFile = False
        self.selectedMove = -1
        self.requireAttention = False
        self.gameResult = None
        self.whiteTime = None
        self.blackTime = None
        self.title = ''
        self.needsSaving = False

        # The GTK+ elements
        self.gui = gtkui.loadUIFile('chess_view.ui', 'chess_view')
        self.gui.connect_signals(self)
        self.widget = self.gui.get_object('chess_view')

        self.viewWidget = GtkViewArea(self)
        self.gui.get_object('view_container').add(self.viewWidget)

        self.ui.setTooltipStyle(self.gui.get_object('info_panel'))

        # Make a model for navigation (move object, number, description)
        model = gtk.ListStore(gobject.TYPE_PYOBJECT, int, str)
        iter = model.append()
        # Translators: Move History Combo: Go to the start of the game
        model.set(iter, 0, None, 1, 0, 2, _('Game Start'))
        self.moveModel = model

        # Tabs are enabled to make editing the UI easier
        self.gui.get_object('comment_notebook').set_show_tabs(False)

        self.updateInfoPanel()

        self.widget.show()
        self.viewWidget.show_all()

        self.ui.updateTitle()
Example #4
0
    def __init__(self, ui, feedback, moveFormat = 'human', showComments = False):
        """Constructor for a view.
        
        'feedback' is the feedback object for this view (extends ui.ViewFeedback).
        'moveFormat' is the format name to display moves in (string).
        """
        self.ui = ui
        self.feedback = feedback
        self.moveFormat = moveFormat
        self.showComments = showComments
        self.editingComment = False
        self.hasFile = False
        self.selectedMove = -1
        self.requireAttention = False
        self.gameResult = None
        self.whiteTime = None
        self.blackTime = None
        self.title = ''
        self.needsSaving = False
        
        # The GTK+ elements
        self.gui = gtkui.loadUIFile('chess_view.ui', 'chess_view')
        self.gui.connect_signals(self)
        self.widget = self.gui.get_object('chess_view')

        self.viewWidget = GtkViewArea(self)
        self.gui.get_object('view_container').add(self.viewWidget)

        self.ui.setTooltipStyle(self.gui.get_object('info_panel'))

        # Make a model for navigation (move object, number, description) 
        model = gtk.ListStore(gobject.TYPE_PYOBJECT, int, str)
        iter = model.append()
        # Translators: Move History Combo: Go to the start of the game
        model.set(iter, 0, None, 1, 0, 2, _('Game Start'))
        self.moveModel = model

        # Tabs are enabled to make editing the UI easier
        self.gui.get_object('comment_notebook').set_show_tabs(False)
        
        self.updateInfoPanel()

        self.widget.show()
        self.viewWidget.show_all()
        
        self.ui.updateTitle()
Example #5
0
    def __init__(self, window, title, executable, description):
        """
        """
        self.window = window
        self.__gui = gtkui.loadUIFile('log.ui')
        self.__gui.get_object('executable_label').set_text(executable)
        self.__gui.get_object('game_label').set_text(description)

        # Add into the notebook
        self.root = self.__gui.get_object('log_table')
        notebook = window.notebook
        notebook.append_page(self.root, gtk.Label(title))
                
        # Create styles for the buffer
        buffer = self.__gui.get_object('comms_textview').get_buffer()
        buffer.create_tag('input', family='Monospace')
        buffer.create_tag('output', family='Monospace', weight = pango.WEIGHT_BOLD)
        buffer.create_tag('move', family='Monospace', foreground = 'blue')
        buffer.create_tag('info', family='Monospace', foreground = 'green')
        buffer.create_tag('error', family='Monospace', foreground = 'red')
        buffer.create_mark('end', buffer.get_end_iter())
Example #6
0
    def __init__(self, mainUI, view, path=None):
        """
        """
        self.__mainUI = mainUI
        self.__view = view

        # Load the UI
        self.__gui = gtkui.loadUIFile('save_game.ui')
        self.__gui.connect_signals(self)

        # Set style of error panel
        mainUI.setTooltipStyle(self.__gui.get_object('error_box'))

        self.window = self.__gui.get_object('save_dialog')
        self.window.set_transient_for(mainUI.mainWindow)
        chooser = self.__gui.get_object('filechooser')

        try:
            directory = str(glchess.config.get('save_directory'))
        except glchess.config.Error:
            pass
        else:
            chooser.set_current_folder(directory)

        # Filter out non PGN files by default
        pgnFilter = gtk.FileFilter()
        # Translators: Save Game Dialog: Name of filter to show only PGN files
        pgnFilter.set_name(_('PGN files'))
        pgnFilter.add_pattern('*.pgn')
        chooser.add_filter(pgnFilter)

        allFilter = gtk.FileFilter()
        # Translators: Save Game Dialog: Name of filter to show all files
        allFilter.set_name(_('All files'))
        allFilter.add_pattern('*')
        chooser.add_filter(allFilter)

        if path is not None:
            chooser.set_current_name(path)
Example #7
0
    def __init__(self, mainUI, view, path = None):
        """
        """
        self.__mainUI = mainUI
        self.__view = view
        
        # Load the UI
        self.__gui = gtkui.loadUIFile('save_game.ui')
        self.__gui.connect_signals(self)
        
        # Set style of error panel
        mainUI.setTooltipStyle(self.__gui.get_object('error_box'))

        self.window = self.__gui.get_object('save_dialog')
        self.window.set_transient_for(mainUI.mainWindow)
        chooser = self.__gui.get_object('filechooser')
        
        try:
            directory = str(glchess.config.get('save_directory'))
        except glchess.config.Error:
            pass
        else:
            chooser.set_current_folder(directory)       
        
        # Filter out non PGN files by default
        pgnFilter = gtk.FileFilter()
        # Translators: Save Game Dialog: Name of filter to show only PGN files
        pgnFilter.set_name(_('PGN files'))
        pgnFilter.add_pattern('*.pgn')
        chooser.add_filter(pgnFilter)
        
        allFilter = gtk.FileFilter()
        # Translators: Save Game Dialog: Name of filter to show all files
        allFilter.set_name(_('All files'))
        allFilter.add_pattern('*')
        chooser.add_filter(allFilter)
        
        if path is not None:
            chooser.set_current_name(path)
Example #8
0
    def __init__(self, mainUI):
        """
        """
        self.__mainUI = mainUI
        
        # Load the UI
        self.__gui = gtkui.loadUIFile('load_game.ui')
        self.__gui.connect_signals(self)
        
        self.window = self.__gui.get_object('game_load_dialog')
        self.window.set_transient_for(mainUI.mainWindow)
        
        # Set style of error panel
        mainUI.setTooltipStyle(self.__gui.get_object('error_box'))
        
        fileChooser = self.__gui.get_object('filechooserwidget')
        
        try:
            directory = str(glchess.config.get('load_directory'))
        except glchess.config.Error:
            pass
        else:
            fileChooser.set_current_folder(directory)

        # Filter out non PGN files by default
        pgnFilter = gtk.FileFilter()
        # Translators: Load Game Dialog: Name of filter to show only PGN files
        pgnFilter.set_name(_('PGN files'))
        pgnFilter.add_pattern('*.pgn')
        fileChooser.add_filter(pgnFilter)
        
        allFilter = gtk.FileFilter()
        # Translators: Load Game Dialog: Name of filter to show all files
        allFilter.set_name(_('All files'))
        allFilter.add_pattern('*')
        fileChooser.add_filter(allFilter)
        
        self.window.present()
Example #9
0
    def __init__(self, mainUI):
        """
        """
        self.__mainUI = mainUI

        # Load the UI
        self.__gui = gtkui.loadUIFile('load_game.ui')
        self.__gui.connect_signals(self)

        self.window = self.__gui.get_object('game_load_dialog')
        self.window.set_transient_for(mainUI.mainWindow)

        # Set style of error panel
        mainUI.setTooltipStyle(self.__gui.get_object('error_box'))

        fileChooser = self.__gui.get_object('filechooserwidget')

        try:
            directory = str(glchess.config.get('load_directory'))
        except glchess.config.Error:
            pass
        else:
            fileChooser.set_current_folder(directory)

        # Filter out non PGN files by default
        pgnFilter = gtk.FileFilter()
        # Translators: Load Game Dialog: Name of filter to show only PGN files
        pgnFilter.set_name(_('PGN files'))
        pgnFilter.add_pattern('*.pgn')
        fileChooser.add_filter(pgnFilter)

        allFilter = gtk.FileFilter()
        # Translators: Load Game Dialog: Name of filter to show all files
        allFilter.set_name(_('All files'))
        allFilter.add_pattern('*')
        fileChooser.add_filter(allFilter)

        self.window.present()
Example #10
0
    def __init__(self, window, title, executable, description):
        """
        """
        self.window = window
        self.__gui = gtkui.loadUIFile('log.ui')
        self.__gui.get_object('executable_label').set_text(executable)
        self.__gui.get_object('game_label').set_text(description)

        # Add into the notebook
        self.root = self.__gui.get_object('log_table')
        notebook = window.notebook
        notebook.append_page(self.root, gtk.Label(title))

        # Create styles for the buffer
        buffer = self.__gui.get_object('comms_textview').get_buffer()
        buffer.create_tag('input', family='Monospace')
        buffer.create_tag('output',
                          family='Monospace',
                          weight=pango.WEIGHT_BOLD)
        buffer.create_tag('move', family='Monospace', foreground='blue')
        buffer.create_tag('info', family='Monospace', foreground='green')
        buffer.create_tag('error', family='Monospace', foreground='red')
        buffer.create_mark('end', buffer.get_end_iter())
Example #11
0
    def __init__(self, networkDialog, parent):
        self.__networkDialog = networkDialog

        # Load the UI
        self.__gui = gtkui.loadUIFile('network_new_server.ui')
        self.__gui.connect_signals(self)
        
        self.__gui.get_object('add_account_dialog').set_transient_for(parent)
        
        # FIXME: Hard-coded servers       
        # name, host, port
        self.serverModel = gtk.ListStore(str, str, int)
        # Translators: Add Network Profile Dialog: Connect to the GGZ Gaming Zone server (the default)
        self.serverModel.set(self.serverModel.append(), 0, _("GGZ Gaming Zone"), 1, "gnome.ggzgamingzone.org", 2, 5688)
        # Translators: Add Network Profile Dialog: Use a custom server
        self.serverModel.set(self.serverModel.append(), 0, _("Custom"), 1, "", 2, 5688)
        
        widget = self.__gui.get_object('server_combo')
        widget.set_model(self.serverModel)
        cell = gtk.CellRendererText()
        widget.pack_start(cell, False)
        widget.add_attribute(cell, 'text', 0)
        widget.set_model(self.serverModel)
        widget.set_active(0)
Example #12
0
    def __init__(self, mainUI, feedback):
        """Constructor for a new game dialog.
        
        'mainUI' is the main UI.
        'feedback' is the object to feedback events with.
        """
        self.__mainUI = mainUI
        self.feedback = feedback

        # Load the UI
        self.__gui = gtkui.loadUIFile('network_game.ui')
        self.__gui.connect_signals(self)

        # Selected profile
        self.__profile = None

        self.profileModel = gtk.ListStore(gobject.TYPE_PYOBJECT,
                                          gobject.TYPE_PYOBJECT, str)
        # Translators: Server Combo Box: Not connected to a server
        self.profileModel.set(self.profileModel.append(), 0, None, 1,
                              self._set_profile, 2, _('Disconnected'))
        self.profileModelSuffixCount = 0
        self.profileModel.set(self.profileModel.append(), 1, None)
        self.profileModelSuffixCount += 1
        # Translators: Server Combo Box: Add new profile
        self.profileModel.set(self.profileModel.append(), 0, None, 1,
                              self._new_profile, 2, _('New profile...'))
        self.profileModelSuffixCount += 1

        widget = self.__gui.get_object('server_combo')
        widget.set_model(self.profileModel)
        widget.set_active(0)
        widget.set_row_separator_func(self._is_profile_model_separator)
        cell = gtk.CellRendererText()
        widget.pack_start(cell, False)
        widget.add_attribute(cell, 'text', 2)

        # room object, index, name, num players, description, font weight, font style, icon_name
        self.roomModel = gtk.TreeStore(gobject.TYPE_PYOBJECT, int, str, str,
                                       str, int, int, str)
        self.firstNonChessIter = None
        self.roomIters = {}
        view = self.__gui.get_object('room_list')
        view.set_model(self.roomModel)
        cell = gtk.CellRendererText()
        column = gtk.TreeViewColumn('', cell)
        column.add_attribute(cell, 'text', 3)
        view.append_column(column)
        cell = gtk.CellRendererPixbuf()
        column = gtk.TreeViewColumn('', cell)
        column.add_attribute(cell, 'icon-name', 7)
        view.append_column(column)
        cell = gtk.CellRendererText()
        column = gtk.TreeViewColumn('', cell)
        column.add_attribute(cell, 'text', 2)
        column.add_attribute(cell, 'weight', 5)
        column.add_attribute(cell, 'style', 6)
        view.append_column(column)
        cell = gtk.CellRendererText()
        column = gtk.TreeViewColumn('', cell)
        column.add_attribute(cell, 'text', 4)
        #view.append_column(column)
        view.connect('row-activated', self._on_room_changed)

        # player, name, icon
        self.playerModel = gtk.ListStore(gobject.TYPE_PYOBJECT, str, str)
        view = self.__gui.get_object('player_list')
        view.set_model(self.playerModel)
        cell = gtk.CellRendererPixbuf()
        column = gtk.TreeViewColumn('', cell)
        column.add_attribute(cell, 'icon-name', 2)
        view.append_column(column)
        cell = gtk.CellRendererText()
        column = gtk.TreeViewColumn('', cell)
        column.add_attribute(cell, 'text', 1)
        view.append_column(column)

        # table, number, seats, description, seat model, can connect
        self.tableModel = gtk.ListStore(gobject.TYPE_PYOBJECT, str, str, str,
                                        gobject.TYPE_PYOBJECT,
                                        gobject.TYPE_BOOLEAN)
        self.tableIters = {}

        view = self.__gui.get_object('table_list')
        view.get_selection().connect('changed', self._on_table_selected)
        view.set_model(self.tableModel)

        cell = gtk.CellRendererText()
        # Translators: Available GGZ Tables: Table name column title
        column = gtk.TreeViewColumn(_('Table'), cell)
        column.add_attribute(cell, 'text', 1)
        view.append_column(column)
        cell = gtk.CellRendererText()
        # Translators: Available GGZ Tables: Seat status column title
        column = gtk.TreeViewColumn(_('Seats'), cell)
        column.add_attribute(cell, 'text', 2)
        view.append_column(column)
        cell = gtk.CellRendererText()
        # Translators: Available GGZ Tables: Table description column title
        column = gtk.TreeViewColumn(_('Description'), cell)
        column.add_attribute(cell, 'text', 3)
        view.append_column(column)

        view = self.__gui.get_object('seat_list')
        cell = gtk.CellRendererText()
        # Translators: Current GGZ Table: Seat name column title
        column = gtk.TreeViewColumn(_('Seat'), cell)
        column.add_attribute(cell, 'text', 2)
        view.append_column(column)
        # Translators: Current GGZ Table: Player name column title
        column = gtk.TreeViewColumn(_('Player'), cell)
        column.add_attribute(cell, 'text', 3)
        column.add_attribute(cell, 'style', 4)
        view.append_column(column)

        self.__loadThrobber()

        # Create styles for the buffer
        buffer = self.__gui.get_object('chat_textview').get_buffer()
        buffer.create_tag('motd', family='Monospace', foreground='red')
        buffer.create_tag('chat', family='Monospace')
        #buffer.create_tag('output', family='Monospace', weight = pango.WEIGHT_BOLD)
        #buffer.create_tag('move', family='Monospace', foreground = 'blue')
        buffer.create_tag('info', family='Monospace', foreground='gray')
        #buffer.create_tag('error', family='Monospace', foreground = 'red')
        buffer.create_mark('end', buffer.get_end_iter())

        mainUI.setTooltipStyle(self.__gui.get_object('info_panel'))
        self.__addProfileDialog = GtkNetworkAddDialog(
            self, self.__gui.get_object('network_game_dialog'))
Example #13
0
    def __init__(self, mainUI, feedback):
        """Constructor for a new game dialog.
        
        'mainUI' is the main UI.
        'feedback' is the object to feedback events with.
        """
        self.__mainUI = mainUI
        self.feedback = feedback

        # Load the UI
        self.__gui = gtkui.loadUIFile('network_game.ui')
        self.__gui.connect_signals(self)
        
        # Selected profile
        self.__profile = None
        
        self.profileModel = gtk.ListStore(gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, str)
        # Translators: Server Combo Box: Not connected to a server
        self.profileModel.set(self.profileModel.append(), 0, None, 1, self._set_profile, 2, _('Disconnected'))
        self.profileModelSuffixCount = 0
        self.profileModel.set(self.profileModel.append(), 1, None)
        self.profileModelSuffixCount += 1
        # Translators: Server Combo Box: Add new profile
        self.profileModel.set(self.profileModel.append(), 0, None, 1, self._new_profile, 2, _('New profile...'))
        self.profileModelSuffixCount += 1

        widget = self.__gui.get_object('server_combo')
        widget.set_model(self.profileModel)
        widget.set_active(0)
        widget.set_row_separator_func(self._is_profile_model_separator)
        cell = gtk.CellRendererText()
        widget.pack_start(cell, False)
        widget.add_attribute(cell, 'text', 2)

        # room object, index, name, num players, description, font weight, font style, icon_name
        self.roomModel = gtk.TreeStore(gobject.TYPE_PYOBJECT, int, str, str, str, int, int, str)
        self.firstNonChessIter = None
        self.roomIters = {}
        view = self.__gui.get_object('room_list')
        view.set_model(self.roomModel)
        cell = gtk.CellRendererText()
        column = gtk.TreeViewColumn('', cell)
        column.add_attribute(cell, 'text', 3)
        view.append_column(column)
        cell = gtk.CellRendererPixbuf()
        column = gtk.TreeViewColumn('', cell)
        column.add_attribute(cell, 'icon-name', 7)
        view.append_column(column)
        cell = gtk.CellRendererText()
        column = gtk.TreeViewColumn('', cell)
        column.add_attribute(cell, 'text', 2)
        column.add_attribute(cell, 'weight', 5)
        column.add_attribute(cell, 'style', 6)
        view.append_column(column)
        cell = gtk.CellRendererText()
        column = gtk.TreeViewColumn('', cell)
        column.add_attribute(cell, 'text', 4)
        #view.append_column(column)
        view.connect('row-activated', self._on_room_changed)

        # player, name, icon
        self.playerModel = gtk.ListStore(gobject.TYPE_PYOBJECT, str, str)
        view = self.__gui.get_object('player_list')
        view.set_model(self.playerModel)
        cell = gtk.CellRendererPixbuf()
        column = gtk.TreeViewColumn('', cell)
        column.add_attribute(cell, 'icon-name', 2)
        view.append_column(column)
        cell = gtk.CellRendererText()
        column = gtk.TreeViewColumn('', cell)
        column.add_attribute(cell, 'text', 1)
        view.append_column(column)

        # table, number, seats, description, seat model, can connect
        self.tableModel = gtk.ListStore(gobject.TYPE_PYOBJECT, str, str, str, gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN)
        self.tableIters = {}
        
        view = self.__gui.get_object('table_list')
        view.get_selection().connect('changed', self._on_table_selected)
        view.set_model(self.tableModel)
        
        cell = gtk.CellRendererText()
        # Translators: Available GGZ Tables: Table name column title
        column = gtk.TreeViewColumn(_('Table'), cell)
        column.add_attribute(cell, 'text', 1)
        view.append_column(column)
        cell = gtk.CellRendererText()
        # Translators: Available GGZ Tables: Seat status column title
        column = gtk.TreeViewColumn(_('Seats'), cell)
        column.add_attribute(cell, 'text', 2)
        view.append_column(column)
        cell = gtk.CellRendererText()
        # Translators: Available GGZ Tables: Table description column title        
        column = gtk.TreeViewColumn(_('Description'), cell)
        column.add_attribute(cell, 'text', 3)
        view.append_column(column)

        view = self.__gui.get_object('seat_list')
        cell = gtk.CellRendererText()
        # Translators: Current GGZ Table: Seat name column title
        column = gtk.TreeViewColumn(_('Seat'), cell)
        column.add_attribute(cell, 'text', 2)
        view.append_column(column)
        # Translators: Current GGZ Table: Player name column title        
        column = gtk.TreeViewColumn(_('Player'), cell)
        column.add_attribute(cell, 'text', 3)
        column.add_attribute(cell, 'style', 4)
        view.append_column(column)
        
        self.__loadThrobber()

        # Create styles for the buffer
        buffer = self.__gui.get_object('chat_textview').get_buffer()
        buffer.create_tag('motd', family='Monospace', foreground = 'red')
        buffer.create_tag('chat', family='Monospace')
        #buffer.create_tag('output', family='Monospace', weight = pango.WEIGHT_BOLD)
        #buffer.create_tag('move', family='Monospace', foreground = 'blue')
        buffer.create_tag('info', family='Monospace', foreground = 'gray')
        #buffer.create_tag('error', family='Monospace', foreground = 'red')
        buffer.create_mark('end', buffer.get_end_iter())
        
        mainUI.setTooltipStyle(self.__gui.get_object('info_panel'))
        self.__addProfileDialog = GtkNetworkAddDialog(self, self.__gui.get_object('network_game_dialog'))
Example #14
0
    def __init__(self, mainUI, aiModel, game = None):
        """Constructor for a new game dialog.
        
        'mainUI' is the main UI.
        'aiModel' is the AI models to use.
        'game' is the game properties to use (ui.Game).
        """
        self.__mainUI = mainUI
        self.game = game
        
        self.__checking = True
        self.__customName = False

        # Load the UI
        self.__gui = gtkui.loadUIFile('new_game.ui')
        self.__gui.connect_signals(self)

        self.window = self.__gui.get_object('new_game_dialog')
        self.window.set_transient_for(mainUI.mainWindow)

        # Set style of error panel
        mainUI.setTooltipStyle(self.__gui.get_object('info_box'))
        
        # Make all the labels the same width
        group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
        i = 1
        while True:
            widget = self.__gui.get_object('label%i' % i)
            if widget is None:
                break
            group.add_widget(widget)
            i += 1

        # Make all the images the same width
        group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
        i = 1
        while True:
            widget = self.__gui.get_object('image%i' % i)
            if widget is None:
                break
            group.add_widget(widget)
            i += 1
            
        # Create model for game time
        defaultTime = glchess.config.get('new_game_dialog/move_time')
                  # Translators: Time Combo: There is no time limit
        times = [(_('Unlimited'),       0),
                  # Translators: Time Combo: Game will last one minute
                 (_('One minute'),     60),
                  # Translators: Time Combo: Game will last five minutes
                 (_('Five minutes'),  300),
                  # Translators: Time Combo: Game will last 30 minutes
                 (_('30 minutes'),   1800),
                  # Translators: Time Combo: Game will last one hour
                 (_('One hour'),     3600),
                  # Translators: Time Combo: User will configure game duration
                 (_('Custom'),         -1)]
        timeModel = gtk.ListStore(str, int)
        activeIter = None
        for (name, time) in times:
            iter = timeModel.append()
            if time == defaultTime:
                activeIter = iter
            timeModel.set(iter, 0, name, 1, time)

        widget = self.__gui.get_object('time_combo')
        widget.set_model(timeModel)
        if activeIter is None:
            widget.set_active_iter(iter)
        else:
            widget.set_active_iter(activeIter)
        cell = gtk.CellRendererText()
        widget.pack_start(cell, False)
        widget.add_attribute(cell, 'text', 0)

        model = gtk.ListStore(str, int)
                  # Translators: Custom Time Combo: User specifying number of seconds for game duration
        units = [(_('seconds'),  1),
                  # Translators: Custom Time Combo: User specifying number of minutes for game duration
                 (_('minutes'), 60),
                  # Translators: Custom Time Combo: User specifying number of hours for game duration
                 (_('hours'), 3600)]
        for (name, multiplier) in units:
            iter = model.append()
            model.set(iter, 0, name, 1, multiplier)

        # FIXME: Handle time units
        self.__gui.get_object('custom_time_spin').set_value(defaultTime)

        widget = self.__gui.get_object('custom_time_units_combo')
        widget.set_model(model)
        cell = gtk.CellRendererText()
        widget.pack_start(cell, False)
        widget.add_attribute(cell, 'text', 0)
        widget.set_active(0)

        # Create the model for difficulty options
        levelModel = gtk.ListStore(str, str, str)
                  # Translators: AI Difficulty Combo: AI set to easy difficulty
        levels = [('easy',   _('Easy'),   'weather-few-clouds'),
                  # Translators: AI Difficulty Combo: AI set to normal diffuculty
                  ('normal', _('Normal'), 'weather-overcast'),
                  # Translators: AI Difficulty Combo: AI set to hard diffuculty
                  ('hard',   _('Hard'),   'weather-storm')]
        for (key, label, icon) in levels:
            iter = levelModel.append()
            levelModel.set(iter, 0, key, 1, icon, 2, label)

        # Set the difficulty settings
        for name in ['black_difficulty_combo', 'white_difficulty_combo']:
            widget = self.__gui.get_object(name)
            if widget is None:
                continue
            
            widget.set_model(levelModel)
            
            cell = gtk.CellRendererPixbuf()
            widget.pack_start(cell, False)
            widget.add_attribute(cell, 'icon-name', 1)
            
            cell = gtk.CellRendererText()
            widget.pack_start(cell, False)
            widget.add_attribute(cell, 'text', 2)
            
            widget.set_active(1)

        # Make all the AI combo boxes use one list of AI types
        firstAIIndex = min(1, len(aiModel))
        for (name, index) in [('white_type_combo', 0), ('black_type_combo', firstAIIndex)]:
            widget = self.__gui.get_object(name)
            if widget is None:
                continue
            
            widget.set_model(aiModel)
            
            cell = gtk.CellRendererPixbuf()
            widget.pack_start(cell, False)
            widget.add_attribute(cell, 'icon-name', 1)
            
            cell = gtk.CellRendererText()
            widget.pack_start(cell, False)
            widget.add_attribute(cell, 'text', 2)
            
            widget.set_active(index)

        # Configure AIs
        try:
            whiteType = glchess.config.get('new_game_dialog/white/type')
            whiteLevel = glchess.config.get('new_game_dialog/white/difficulty')
            blackType = glchess.config.get('new_game_dialog/black/type')
            blackLevel = glchess.config.get('new_game_dialog/black/difficulty')
        except glchess.config.Error:
            pass
        else:
            self.__setCombo('white_type_combo', whiteType)
            self.__setCombo('white_difficulty_combo', whiteLevel)
            self.__setCombo('black_type_combo', blackType)
            self.__setCombo('black_difficulty_combo', blackLevel)

        # Use supplied settings
        errors = []
        g = self.game
        if g is not None:
            self.__gui.get_object('game_name_entry').set_text(g.name)
            self.__customName = True
            # Translators: Error displayed when unable to load a game due to
            # the require game engine not being available. %s is replaced with
            # the name of the missing engine.
            noEngineFormat = _('Unable to find %s engine')
            if not self.__setCombo('white_type_combo', g.white.type):
                errors.append(noEngineFormat % repr(g.white.type))
            self.__setCombo('white_difficulty_combo', g.white.level)
            if not self.__setCombo('black_type_combo', g.black.type):
                errors.append(noEngineFormat % repr(g.black.type))
            self.__setCombo('black_difficulty_combo', g.black.level)
            # TODO: Others
            
            # Change title for loaded games
            if g.path is not None:
                # Translators: New Game Dialog: Title of the dialog when continuing a loaded game
                self.window.set_title(_('Configure loaded game (%i moves)') % len(g.moves))

        # Display warning if missing the AIs
        if len(errors) > 0:
            # Translators: New Game Dialog: Title of error box when loaded game had AI engines missing
            self.__gui.get_object('info_title_label').set_markup('<big><b>%s</b></big>' % _('Game settings changed'))
            self.__gui.get_object('info_description_label').set_markup('<i>%s</i>' % '\n'.join(errors))
            self.__gui.get_object('info_box').show()

        # Show the dialog
        self.window.present()
        self.__checking = False
        self.__testReady()
Example #15
0
    def __init__(self, mainUI):
        """Constructor for the preferences dialog.
        
        'mainUI' is the main UI.
        """
        # Load the UI
        self.__gui = gtkui.loadUIFile('preferences.ui')
        self.__gui.connect_signals(self)
        
        self.__gui.get_object('preferences').set_transient_for(mainUI.mainWindow)

        # Make model for move format
        moveModel = gtk.ListStore(str, str)
        widget = self.__gui.get_object('move_format_combo')
        widget.set_model(moveModel)
                        # Translators: Move Format Combo: Moves shown in human descriptive notation
        move_formats = [('human', _('Human')),
                        # Translators: Move Format Combo: Moves shown in standard algebraic notation (SAN)
                        ('san', _('Standard Algebraic')),
                        # Translators: Move Format Combo: Moves shown in standard figurine algebraic notation (FAN)
                        ('fan', _('Figurine')),
                        # Translators: Move Format Combo: Moves shown in long algebraic notation (LAN)
                        ('lan', _('Long Algebraic'))]
        for (key, label) in move_formats:
            iter = moveModel.append()
            moveModel.set(iter, 0, label, 1, key)

        # Make model for board orientation
        boardModel = gtk.ListStore(str, str)
        widget = self.__gui.get_object('board_combo')
        widget.set_model(boardModel)
                     # Translators: Board Side Combo: Camera will face white player's side
        view_list = [('white', _('White Side')),
                     # Translators: Board Side Combo: Camera will face black player's side
                     ('black', _('Black Side')),
                     # Translators: Board Side Combo: Camera will face human player's side
                     ('human', _('Human Side')),
                     # Translators: Board Side Combo: Camera will face current player's side
                     ('current', _('Current Player')),
                     # Translators: Board Side Combo: Board will be drawn suitable for players on each side of screen, e.g. handhelds
                     ('facetoface', _('Face to Face'))]
        for (key, label) in view_list:
            iter = boardModel.append()
            boardModel.set(iter, 0, label, 1, key)

        # Make modelfor promotion type
        promotionModel = gtk.ListStore(str, str)
        widget = self.__gui.get_object('promotion_type_combo')
        widget.set_model(promotionModel)
                          # Translators: Promotion Combo: Promote to a queen. Do not translate the 'chess-piece|' text.
        promotion_list = [('queen',  _('chess-piece|Queen')),
                          # Translators: Promotion Combo: Promote to a knight. Do not translate the 'chess-piece|' text.
                          ('knight', _('chess-piece|Knight')),
                          # Translators: Promotion Combo: Promote to a rook. Do not translate the 'chess-piece|' text.
                          ('rook',   _('chess-piece|Rook')),
                          # Translators: Promotion Combo: Promote to a bishop. Do not translate the 'chess-piece|' text.
                          ('bishop', _('chess-piece|Bishop'))]
        for (key, label) in promotion_list:
            try:
                label = label.split('|', 1)[1]
            except IndexError:
                pass
            iter = promotionModel.append()
            promotionModel.set(iter, 0, label, 1, key)
            
        # Watch for config changes
        for key in ['show_3d', 'show_3d_smooth', 'show_toolbar', 'show_history', 
                    'show_move_hints', 'show_numbering',
                    'move_format', 'board_view', 'promotion_type']:
            glchess.config.watch(key, self.__applyConfig)
            try:
                value = glchess.config.get(key)
            except glchess.config.Error:
                pass
            else:
                self.__applyConfig(key, value)
Example #16
0
    def __init__(self, mainUI):
        """Constructor for the preferences dialog.
        
        'mainUI' is the main UI.
        """
        # Load the UI
        self.__gui = gtkui.loadUIFile('preferences.ui')
        self.__gui.connect_signals(self)

        self.__gui.get_object('preferences').set_transient_for(
            mainUI.mainWindow)

        # Make model for move format
        moveModel = gtk.ListStore(str, str)
        widget = self.__gui.get_object('move_format_combo')
        widget.set_model(moveModel)
        # Translators: Move Format Combo: Moves shown in human descriptive notation
        move_formats = [
            ('human', _('Human')),
            # Translators: Move Format Combo: Moves shown in standard algebraic notation (SAN)
            ('san', _('Standard Algebraic')),
            # Translators: Move Format Combo: Moves shown in standard figurine algebraic notation (FAN)
            ('fan', _('Figurine')),
            # Translators: Move Format Combo: Moves shown in long algebraic notation (LAN)
            ('lan', _('Long Algebraic'))
        ]
        for (key, label) in move_formats:
            iter = moveModel.append()
            moveModel.set(iter, 0, label, 1, key)

        # Make model for board orientation
        boardModel = gtk.ListStore(str, str)
        widget = self.__gui.get_object('board_combo')
        widget.set_model(boardModel)
        # Translators: Board Side Combo: Camera will face white player's side
        view_list = [
            ('white', _('White Side')),
            # Translators: Board Side Combo: Camera will face black player's side
            ('black', _('Black Side')),
            # Translators: Board Side Combo: Camera will face human player's side
            ('human', _('Human Side')),
            # Translators: Board Side Combo: Camera will face current player's side
            ('current', _('Current Player')),
            # Translators: Board Side Combo: Board will be drawn suitable for players on each side of screen, e.g. handhelds
            ('facetoface', _('Face to Face'))
        ]
        for (key, label) in view_list:
            iter = boardModel.append()
            boardModel.set(iter, 0, label, 1, key)

        # Make modelfor promotion type
        promotionModel = gtk.ListStore(str, str)
        widget = self.__gui.get_object('promotion_type_combo')
        widget.set_model(promotionModel)
        # Translators: Promotion Combo: Promote to a queen
        promotion_list = [
            ('queen', C_('chess-piece', 'Queen')),
            # Translators: Promotion Combo: Promote to a knight
            ('knight', C_('chess-piece', 'Knight')),
            # Translators: Promotion Combo: Promote to a rook
            ('rook', C_('chess-piece', 'Rook')),
            # Translators: Promotion Combo: Promote to a bishop
            ('bishop', C_('chess-piece', 'Bishop'))
        ]
        for (key, label) in promotion_list:
            iter = promotionModel.append()
            promotionModel.set(iter, 0, label, 1, key)

        # Watch for config changes
        for key in [
                'show_3d', 'show_3d_smooth', 'show_toolbar', 'show_history',
                'show_move_hints', 'show_numbering', 'move_format',
                'board_view', 'promotion_type'
        ]:
            glchess.config.watch(key, self.__applyConfig)
            try:
                value = glchess.config.get(key)
            except glchess.config.Error:
                pass
            else:
                self.__applyConfig(key, value)
Example #17
0
    def __init__(self, mainUI, aiModel, game=None):
        """Constructor for a new game dialog.
        
        'mainUI' is the main UI.
        'aiModel' is the AI models to use.
        'game' is the game properties to use (ui.Game).
        """
        self.__mainUI = mainUI
        self.game = game

        self.__checking = True
        self.__customName = False

        # Load the UI
        self.__gui = gtkui.loadUIFile('new_game.ui')
        self.__gui.connect_signals(self)

        self.window = self.__gui.get_object('new_game_dialog')
        self.window.set_transient_for(mainUI.mainWindow)

        # Set style of error panel
        mainUI.setTooltipStyle(self.__gui.get_object('info_box'))

        # Make all the labels the same width
        group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
        i = 1
        while True:
            widget = self.__gui.get_object('label%i' % i)
            if widget is None:
                break
            group.add_widget(widget)
            i += 1

        # Make all the images the same width
        group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
        i = 1
        while True:
            widget = self.__gui.get_object('image%i' % i)
            if widget is None:
                break
            group.add_widget(widget)
            i += 1

        # Create model for game time
        defaultTime = glchess.config.get('new_game_dialog/move_time')
        # Translators: Time Combo: There is no time limit
        times = [
            (_('Unlimited'), 0),
            # Translators: Time Combo: Game will last one minute
            (_('One minute'), 60),
            # Translators: Time Combo: Game will last five minutes
            (_('Five minutes'), 300),
            # Translators: Time Combo: Game will last 30 minutes
            (_('30 minutes'), 1800),
            # Translators: Time Combo: Game will last one hour
            (_('One hour'), 3600),
            # Translators: Time Combo: User will configure game duration
            (_('Custom'), -1)
        ]
        timeModel = gtk.ListStore(str, int)
        activeIter = None
        for (name, time) in times:
            iter = timeModel.append()
            if time == defaultTime:
                activeIter = iter
            timeModel.set(iter, 0, name, 1, time)

        widget = self.__gui.get_object('time_combo')
        widget.set_model(timeModel)
        if activeIter is None:
            widget.set_active_iter(iter)
        else:
            widget.set_active_iter(activeIter)
        cell = gtk.CellRendererText()
        widget.pack_start(cell, False)
        widget.add_attribute(cell, 'text', 0)

        model = gtk.ListStore(str, int)
        # Translators: Custom Time Combo: User specifying number of seconds for game duration
        units = [
            (_('seconds'), 1),
            # Translators: Custom Time Combo: User specifying number of minutes for game duration
            (_('minutes'), 60),
            # Translators: Custom Time Combo: User specifying number of hours for game duration
            (_('hours'), 3600)
        ]
        for (name, multiplier) in units:
            iter = model.append()
            model.set(iter, 0, name, 1, multiplier)

        # FIXME: Handle time units
        self.__gui.get_object('custom_time_spin').set_value(defaultTime)

        widget = self.__gui.get_object('custom_time_units_combo')
        widget.set_model(model)
        cell = gtk.CellRendererText()
        widget.pack_start(cell, False)
        widget.add_attribute(cell, 'text', 0)
        widget.set_active(0)

        # Create the model for difficulty options
        levelModel = gtk.ListStore(str, str, str)
        # Translators: AI Difficulty Combo: AI set to easy difficulty
        levels = [
            ('easy', _('Easy'), 'weather-few-clouds'),
            # Translators: AI Difficulty Combo: AI set to normal diffuculty
            ('normal', _('Normal'), 'weather-overcast'),
            # Translators: AI Difficulty Combo: AI set to hard diffuculty
            ('hard', _('Hard'), 'weather-storm')
        ]
        for (key, label, icon) in levels:
            iter = levelModel.append()
            levelModel.set(iter, 0, key, 1, icon, 2, label)

        # Set the difficulty settings
        for name in ['black_difficulty_combo', 'white_difficulty_combo']:
            widget = self.__gui.get_object(name)
            if widget is None:
                continue

            widget.set_model(levelModel)

            cell = gtk.CellRendererPixbuf()
            widget.pack_start(cell, False)
            widget.add_attribute(cell, 'icon-name', 1)

            cell = gtk.CellRendererText()
            widget.pack_start(cell, False)
            widget.add_attribute(cell, 'text', 2)

            widget.set_active(1)

        # Make all the AI combo boxes use one list of AI types
        firstAIIndex = min(1, len(aiModel))
        for (name, index) in [('white_type_combo', 0),
                              ('black_type_combo', firstAIIndex)]:
            widget = self.__gui.get_object(name)
            if widget is None:
                continue

            widget.set_model(aiModel)

            cell = gtk.CellRendererPixbuf()
            widget.pack_start(cell, False)
            widget.add_attribute(cell, 'icon-name', 1)

            cell = gtk.CellRendererText()
            widget.pack_start(cell, False)
            widget.add_attribute(cell, 'text', 2)

            widget.set_active(index)

        # Configure AIs
        try:
            whiteType = glchess.config.get('new_game_dialog/white/type')
            whiteLevel = glchess.config.get('new_game_dialog/white/difficulty')
            blackType = glchess.config.get('new_game_dialog/black/type')
            blackLevel = glchess.config.get('new_game_dialog/black/difficulty')
        except glchess.config.Error:
            pass
        else:
            self.__setCombo('white_type_combo', whiteType)
            self.__setCombo('white_difficulty_combo', whiteLevel)
            self.__setCombo('black_type_combo', blackType)
            self.__setCombo('black_difficulty_combo', blackLevel)

        # Use supplied settings
        errors = []
        g = self.game
        if g is not None:
            self.__gui.get_object('game_name_entry').set_text(g.name)
            self.__customName = True
            # Translators: Error displayed when unable to load a game due to
            # the require game engine not being available. %s is replaced with
            # the name of the missing engine.
            noEngineFormat = _('Unable to find %s engine')
            if not self.__setCombo('white_type_combo', g.white.type):
                errors.append(noEngineFormat % repr(g.white.type))
            self.__setCombo('white_difficulty_combo', g.white.level)
            if not self.__setCombo('black_type_combo', g.black.type):
                errors.append(noEngineFormat % repr(g.black.type))
            self.__setCombo('black_difficulty_combo', g.black.level)
            # TODO: Others

            # Change title for loaded games
            if g.path is not None:
                # Translators: New Game Dialog: Title of the dialog when continuing a loaded game
                self.window.set_title(
                    _('Configure loaded game (%i moves)') % len(g.moves))

        # Display warning if missing the AIs
        if len(errors) > 0:
            # Translators: New Game Dialog: Title of error box when loaded game had AI engines missing
            self.__gui.get_object('info_title_label').set_markup(
                '<big><b>%s</b></big>' % _('Game settings changed'))
            self.__gui.get_object('info_description_label').set_markup(
                '<i>%s</i>' % '\n'.join(errors))
            self.__gui.get_object('info_box').show()

        # Show the dialog
        self.window.present()
        self.__checking = False
        self.__testReady()