From 9694e9551ae3c60f9af93eee6bfcfb349a357181 Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Tue, 06 Oct 2009 11:27:27 +0000 Subject: Pylint cleanup --- diff --git a/cardtable.py b/cardtable.py index 8c34177..0a39a62 100644 --- a/cardtable.py +++ b/cardtable.py @@ -16,11 +16,9 @@ # import gtk -import pygtk import pango import svgcard import os -import time import math import gc from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT @@ -60,7 +58,8 @@ class CardTable(gtk.EventBox): self.table.set_resize_mode(gtk.RESIZE_IMMEDIATE) self.set_property('child', self.table) self.load_message = gtk.Label('Loading Game') - self.load_message.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ffffff')) + self.load_message.modify_fg(gtk.STATE_NORMAL, + gtk.gdk.color_parse('#ffffff')) self.load_message.modify_font(pango.FontDescription("10")) self.load_message.show() self.first_load = True @@ -108,7 +107,7 @@ class CardTable(gtk.EventBox): self.table_positions = {} # Build the table - if data['divided']=='1': + if data['divided'] == '1': text1 = str(self.data.get('face1', '')) text2 = str(self.data.get('face2', '')) else: @@ -117,7 +116,7 @@ class CardTable(gtk.EventBox): x = 0 y = 0 - id = 0 + identifier = 0 for card in self.cards_data: if card.get('img', None): @@ -125,30 +124,31 @@ class CardTable(gtk.EventBox): else: jpg = None props = {} - props['front_text']= {'card_text':card.get('char', ''), + props['front_text'] = {'card_text':card.get('char', ''), 'speak': card.get('speak')} - if card['ab']== 'a': - props['back_text']= {'card_text':text1} - elif card['ab']== 'b': - props['back_text']= {'card_text':text2} + if card['ab'] == 'a': + props['back_text'] = {'card_text':text1} + elif card['ab'] == 'b': + props['back_text'] = {'card_text':text2} align = self.data.get('align', '1') - card = svgcard.SvgCard(id, props, jpg, self.card_size, align) + card = svgcard.SvgCard(identifier, props, jpg, + self.card_size, align) card.connect('enter-notify-event', self.mouse_event, [x, y]) - card.connect("button-press-event", self.flip_card_mouse, id) - self.table_positions[(x, y)]=1 - self.cd2id[card] = id - self.id2cd[id] = card + card.connect("button-press-event", self.flip_card_mouse, identifier) + self.table_positions[(x, y)] = 1 + self.cd2id[card] = identifier + self.id2cd[identifier] = card self.cards[(x, y)] = card - self.dict[id] = (x, y) + self.dict[identifier] = (x, y) self.table.attach(card, x, x+1, y, y+1, gtk.SHRINK, gtk.SHRINK) x += 1 if x == self.size: x = 0 - y +=1 - id += 1 + y += 1 + identifier += 1 self.first_load = False if self.load_mode: self._set_load_mode(False) @@ -164,84 +164,84 @@ class CardTable(gtk.EventBox): self.load_game(None, data, grid) def get_card_size(self, size_table): - x = (self._workspace_size+theme.CARD_PAD*(size_table-1)) / size_table \ - - theme.CARD_PAD*2 + x = (self._workspace_size + theme.CARD_PAD * (size_table-1)) / \ + size_table - theme.CARD_PAD * 2 return x def mouse_event(self, widget, event, coord): #self.table.grab_focus() card = self.cards[coord[0], coord[1]] - id = self.cd2id.get(card) - self.emit('card-highlighted', id, True) + identifier = self.cd2id.get(card) + self.emit('card-highlighted', identifier, True) self.selected_card = (coord[0], coord[1]) def key_press_event(self, widget, event): #self.table.grab_focus() - x= self.selected_card[0] - y= self.selected_card[1] + x = self.selected_card[0] + y = self.selected_card[1] if event.keyval in (gtk.keysyms.Left, gtk.keysyms.KP_Left): if self.table_positions.has_key((x-1, y)): card = self.cards[x-1, y] - id = self.cd2id.get(card) - self.emit('card-highlighted', id, False) + identifier = self.cd2id.get(card) + self.emit('card-highlighted', identifier, False) elif event.keyval in (gtk.keysyms.Right, gtk.keysyms.KP_Right): if self.table_positions.has_key((x+1, y)): card = self.cards[x+1, y] - id = self.cd2id.get(card) - self.emit('card-highlighted', id, False) + identifier = self.cd2id.get(card) + self.emit('card-highlighted', identifier, False) elif event.keyval in (gtk.keysyms.Up, gtk.keysyms.KP_Up): if self.table_positions.has_key((x, y-1)): card = self.cards[x, y-1] - id = self.cd2id.get(card) - self.emit('card-highlighted', id, False) + identifier = self.cd2id.get(card) + self.emit('card-highlighted', identifier, False) elif event.keyval in (gtk.keysyms.Down, gtk.keysyms.KP_Down): if self.table_positions.has_key((x, y+1)): card = self.cards[x, y+1] - id = self.cd2id.get(card) - self.emit('card-highlighted', id, False) - + identifier = self.cd2id.get(card) + self.emit('card-highlighted', identifier, False) + elif event.keyval in (gtk.keysyms.space, gtk.keysyms.KP_Page_Down): card = self.cards[x, y] self.card_flipped(card) - def flip_card_mouse(self, widget, event, id): - position = self.dict[id] + def flip_card_mouse(self, widget, event, identifier): + position = self.dict[identifier] card = self.cards[position] self.card_flipped(card) - + def card_flipped(self, card): - id = self.cd2id[card] + identifer = self.cd2id[card] if card.is_flipped(): - self.emit('card-overflipped', id) + self.emit('card-overflipped', identifer) else: - self.emit('card-flipped', id, False) + self.emit('card-flipped', identifer, False) - def set_border(self, widget, id, stroke_color, fill_color): - self.id2cd[id].set_border(stroke_color, fill_color) + def set_border(self, widget, identifer, stroke_color, fill_color): + self.id2cd[identifer].set_border(stroke_color, fill_color) - def flop_card(self, widget, id): - self.id2cd.get(id).flop() + def flop_card(self, widget, identifer): + self.id2cd.get(identifer).flop() - def flip_card(self, widget, id): - self.id2cd.get(id).flip() + def flip_card(self, widget, identifer): + self.id2cd.get(identifer).flip() - def cement_card(self, widget, id): - self.id2cd.get(id).cement() + def cement_card(self, widget, identifer): + self.id2cd.get(identifer).cement() - def highlight_card(self, widget, id, status): + def highlight_card(self, widget, identifer, status): if self.dict != None: - self.selected_card = self.dict.get(id) - self.id2cd.get(id).set_highlight(status) + self.selected_card = self.dict.get(identifer) + self.id2cd.get(identifer).set_highlight(status) def reset(self, widget): - for id in self.id2cd.keys(): - self.id2cd[id].reset() + for identifer in self.id2cd.keys(): + self.id2cd[identifer].reset() - def _set_load_mode(self,mode): + def _set_load_mode(self, mode): if mode: self.remove(self.table) self.set_property('child', self.load_message) diff --git a/createcardpanel.py b/createcardpanel.py index 4ac5c72..d023672 100644 --- a/createcardpanel.py +++ b/createcardpanel.py @@ -19,7 +19,7 @@ import gtk from os import environ -from os.path import join, dirname, basename +from os.path import join, basename import hippo import shutil @@ -28,9 +28,6 @@ from gettext import gettext as _ import svgcard import logging from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT -from xml.dom.minidom import parse -from sugar.graphics.objectchooser import ObjectChooser -from sugar import mime from sugar.graphics import style from sugar.graphics.toolbutton import ToolButton from sugar.graphics.icon import Icon @@ -43,7 +40,6 @@ import theme import speak.espeak import speak.widgets import speak.face -import activity _logger = logging.getLogger('memorize-activity') @@ -218,14 +214,18 @@ class CreateCardPanel(gtk.EventBox): def _update_buttom_status(self): if not self.equal_pairs: - if (self._card1_has_text or self._card1_has_picture or self._card1_has_sound) and (self._card2_has_text or self._card2_has_picture or self._card2_has_sound): + if (self._card1_has_text or self._card1_has_picture \ + or self._card1_has_sound) and (self._card2_has_text + or self._card2_has_picture + or self._card2_has_sound): self._addbutton.set_sensitive(True) self._updatebutton.set_sensitive(self._updatebutton_sensitive) else: self._addbutton.set_sensitive(False) self._updatebutton.set_sensitive(False) else: - if self._card1_has_text or self._card1_has_picture or self._card1_has_sound: + if (self._card1_has_text or self._card1_has_picture \ + or self._card1_has_sound): self._addbutton.set_sensitive(True) self._updatebutton.set_sensitive(self._updatebutton_sensitive) else: diff --git a/face.py b/face.py index fd3effb..64693f6 100644 --- a/face.py +++ b/face.py @@ -51,11 +51,11 @@ def look_at(): return display = gtk.gdk.display_get_default() - screen, x, y, modifiers = display.get_pointer() + screen_, x, y, modifiers_ = display.get_pointer() for i in _cache: if i.parent: - i.face.look_at(x,y) + i.face.look_at(x, y) def acquire(): if not speak.espeak.supported: diff --git a/game.py b/game.py index b33c748..c1922e7 100644 --- a/game.py +++ b/game.py @@ -17,12 +17,9 @@ import logging import gobject -from os.path import join, dirname +from os.path import join from gettext import gettext as _ -from sugar import profile -from dbus.service import method, signal -from dbus.gobject_service import ExportedGObject from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT, GObject, timeout_add from gobject import source_remove @@ -69,6 +66,7 @@ class MemorizeGame(GObject): self.current_player = None self.last_flipped = -1 self.last_highlight = 1 + self._flop_card_timeout = -1 self.messenger = None self.sentitive = True @@ -84,10 +82,11 @@ class MemorizeGame(GObject): self.model.def_grid(size) self.model.data['running'] = 'False' self.model.data['mode'] = mode - logging.debug(' Read setup file %s: %s '%(game_name, self.model.grid)) + logging.debug(' Read setup file %s: %s ', + (game_name, self.model.grid)) self.emit('load_game', self.model.data, self.model.grid) else: - logging.error(' Reading setup file %s'%game_name) + logging.error(' Reading setup file %s', game_name) def load_remote(self, grid, data, mode, signal = False): self.set_load_mode(_('Loading game...')) @@ -118,7 +117,8 @@ class MemorizeGame(GObject): elif card['state'] != '0': stroke_color, fill_color = card['state'].split(',') self.emit('flip-card', self.model.grid.index(card)) - self.emit('set-border', self.model.grid.index(card), stroke_color, fill_color) + self.emit('set-border', self.model.grid.index(card), + stroke_color, fill_color) def add_buddy(self, buddy, score = 0): _logger.debug('Buddy %r was added to game', buddy.props.nick) @@ -135,9 +135,9 @@ class MemorizeGame(GObject): _logger.debug('Buddy %r was removed from game', buddy.props.nick) if self.current_player == buddy and len(self.players) >= 2: if self.last_flipped != -1: - self.emit('flop-card', self.last_flipped) - self.model.grid[self.last_flipped]['state'] = '0' - self.last_flipped = -1 + self.emit('flop-card', self.last_flipped) + self.model.grid[self.last_flipped]['state'] = '0' + self.last_flipped = -1 self.change_turn() index = self.players.index(buddy) del self.players[index] @@ -159,28 +159,31 @@ class MemorizeGame(GObject): elif self.current_player == self.players[-1]: self.current_player = self.players[0] else: - next = self.players[self.players.index(self.current_player)+1] - self.current_player = next + next_player = self.players.index(self.current_player) + 1 + self.current_player = self.players[next_player] self.update_turn() - - def card_overflipped(self, widget, id): - if self._flop_cards and id in self._flop_cards: - self.card_flipped(widget, id) - def card_flipped(self, widget, id, signal = False): + def card_overflipped(self, widget, identifier): + if self._flop_cards and identifier in self._flop_cards: + self.card_flipped(widget, identifier) + + def card_flipped(self, widget, identifier, signal = False): if self._flop_cards: source_remove(self._flop_card_timeout) self.flop_card(self._flop_cards[0], self._flop_cards[1]) # Check if is my turn - if (not self.sentitive and not signal) or self.last_flipped == id: + if (not self.sentitive and not signal) or \ + self.last_flipped == identifier: return # Handle groups if needed if self.model.data.get('divided') == '1': - if self.last_flipped == -1 and id >= (len(self.model.grid)/2): + if self.last_flipped == -1 and identifier \ + >= (len(self.model.grid)/2): return - if self.last_flipped <> -1 and id < (len(self.model.grid)/2): + if self.last_flipped != -1 and identifier \ + < (len(self.model.grid)/2): return # do not process flips when flipping back @@ -191,57 +194,61 @@ class MemorizeGame(GObject): self.model.data['running'] = 'True' - snd = self.model.grid[id].get('snd', None) + snd = self.model.grid[identifier].get('snd', None) if snd != None: sound_file = join(self.model.data.get('pathsnd'), snd) self.audio.play(sound_file) - self.emit('flip-card', id) + self.emit('flip-card', identifier) if not signal: - self.emit('flip-card-signal', id) + self.emit('flip-card-signal', identifier) # First card case if self.last_flipped == -1: - self.last_flipped = id - self.model.grid[id]['state'] = '1' + self.last_flipped = identifier + self.model.grid[identifier]['state'] = '1' self.flip_block = False # Second card case else: # Pair matched pair_key_1 = self.model.grid[self.last_flipped]['pairkey'] - pair_key_2 = self.model.grid[id]['pairkey'] + pair_key_2 = self.model.grid[identifier]['pairkey'] if pair_key_1 == pair_key_2: - stroke_color, fill_color = self.current_player.props.color.split(',') - self.emit('set-border', id, stroke_color, fill_color) - self.emit('set-border', self.last_flipped, stroke_color, fill_color) + stroke_color, fill_color = \ + self.current_player.props.color.split(',') + self.emit('set-border', identifier, stroke_color, fill_color) + self.emit('set-border', self.last_flipped, + stroke_color, fill_color) self.increase_point(self.current_player) - self.model.grid[id]['state'] = self.current_player.props.color - self.model.grid[self.last_flipped]['state'] = self.current_player.props.color + self.model.grid[identifier]['state'] = \ + self.current_player.props.color + self.model.grid[self.last_flipped]['state'] = \ + self.current_player.props.color self.flip_block = False - self.emit('cement-card', id) + self.emit('cement-card', identifier) self.emit('cement-card', self.last_flipped) # Pair didn't match else: - self.model.grid[id]['state'] = '1' + self.model.grid[identifier]['state'] = '1' self.set_sensitive(False) - self._flop_cards = (id, self.last_flipped) + self._flop_cards = (identifier, self.last_flipped) self._flop_card_timeout = timeout_add(theme.FLOP_BACK_TIMEOUT, - self.flop_card, id, self.last_flipped) + self.flop_card, identifier, self.last_flipped) self.last_flipped = -1 - def flop_card(self, id, id2): + def flop_card(self, identifier, identifier2): self._flop_card_timeout = -1 self._flop_cards = None - self.emit('flop-card', id) - self.model.grid[id]['state'] = '0' - self.emit('flop-card', id2) - self.model.grid[id2]['state'] = '0' + self.emit('flop-card', identifier) + self.model.grid[identifier]['state'] = '0' + self.emit('flop-card', identifier2) + self.model.grid[identifier2]['state'] = '0' #if self.model.data['divided'] == '1': # self.card_highlighted(widget, -1, False) @@ -249,26 +256,28 @@ class MemorizeGame(GObject): self.flip_block = False self.change_turn() - def card_highlighted(self, widget, id, mouse): + def card_highlighted(self, widget, identifier, mouse): self.emit('highlight-card', self.last_highlight, False) - self.last_highlight = id + self.last_highlight = identifier - if id == -1 or not self.sentitive: + if identifier == -1 or not self.sentitive: return if self.model.data['divided'] == '1': - if self.last_flipped == -1 and id >= (len(self.model.grid)/2): + if self.last_flipped == -1 and identifier \ + >= (len(self.model.grid)/2): return - if self.last_flipped <> -1 and id < (len(self.model.grid)/2): + if self.last_flipped != -1 and identifier \ + < (len(self.model.grid)/2): return - if mouse and self.model.grid[id]['state']=='0' or not mouse: - self.emit('highlight-card', id, True) + if mouse and self.model.grid[identifier]['state'] == '0' or not mouse: + self.emit('highlight-card', identifier, True) def increase_point(self, buddy, inc=1): self.players_score[buddy] += inc - for i in range(inc): + for i_ in range(inc): self.emit('increase-score', buddy) def get_grid(self): @@ -281,10 +290,11 @@ class MemorizeGame(GObject): self.model.data[str(index)] = str(score) return self.model.data - def change_game(self, widget, game_name, size, mode, title = None, color= None): + def change_game(self, widget, game_name, size, mode, + title = None, color= None): if mode in ['file', 'demo']: if self.model.read(game_name) != 0: - logging.error(' Reading setup file %s'%game_name) + logging.error(' Reading setup file %s', game_name) return if size == None: size = int(self.model.data['size']) @@ -294,7 +304,7 @@ class MemorizeGame(GObject): self.model.data['title'] = title if color != None: self.model.data['color'] = color - self.load_remote(self.model.grid, self.model.data, mode, False) + self.load_remote(self.model.grid, self.model.data, mode, False) def reset_game(self, size = None): if size == None: @@ -322,21 +332,22 @@ class MemorizeGame(GObject): def get_players_data(self): data = [] for player, score in self.players_score.items(): - data.append([player.props.key, player.props.nick, player.props.color, score]) + data.append([player.props.key, player.props.nick, + player.props.color, score]) return data - - def set_wait_list(self, list): - self.waiting_players = list - for w in list: + + def set_wait_list(self, wait_list): + self.waiting_players = wait_list + for w in wait_list: for p in self.players: if w[0] == p.props.key: list.remove(w) - for i in range(w[3]): + for i_ in range(w[3]): self.increase_point(p) - + def set_myself(self, buddy): self.myself = buddy - + def add_to_waiting_list(self, buddy): self.players.remove(buddy) self.waiting_players.append(buddy) @@ -347,8 +358,8 @@ class MemorizeGame(GObject): self.players.append(buddy) self.emit('wait_mode_buddy', buddy, False) - def load_waiting_list(self, list): - for buddy in list: + def load_waiting_list(self, wait_list): + for buddy in wait_list: self.add_to_waiting_list(buddy) def empty_waiting_list(self): -- cgit v0.9.1