[tictactoe] Fix some pylint errors
This commit is contained in:
@@ -42,7 +42,6 @@ from gajim import chat_control
|
|||||||
|
|
||||||
from gajim.common import app
|
from gajim.common import app
|
||||||
from gajim.common import ged
|
from gajim.common import ged
|
||||||
from gajim.common import helpers
|
|
||||||
from gajim.common.connection_handlers_events import InformationEvent
|
from gajim.common.connection_handlers_events import InformationEvent
|
||||||
|
|
||||||
from gajim.gtk.dialogs import DialogButton
|
from gajim.gtk.dialogs import DialogButton
|
||||||
@@ -78,7 +77,7 @@ class TictactoePlugin(GajimPlugin):
|
|||||||
self.config_dialog = partial(TicTacToeConfigDialog, self)
|
self.config_dialog = partial(TicTacToeConfigDialog, self)
|
||||||
self.events_handlers = {
|
self.events_handlers = {
|
||||||
'decrypted-message-received': (
|
'decrypted-message-received': (
|
||||||
ged.PREGUI, self._nec_decrypted_message_received),
|
ged.PREGUI, self._on_message_received),
|
||||||
}
|
}
|
||||||
|
|
||||||
self.gui_extension_points = {
|
self.gui_extension_points = {
|
||||||
@@ -97,7 +96,7 @@ class TictactoePlugin(GajimPlugin):
|
|||||||
self.announce_caps = True
|
self.announce_caps = True
|
||||||
|
|
||||||
@log_calls('TictactoePlugin')
|
@log_calls('TictactoePlugin')
|
||||||
def _update_caps(self, account, features):
|
def _update_caps(self, _account, features):
|
||||||
if not self.announce_caps:
|
if not self.announce_caps:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -131,7 +130,7 @@ class TictactoePlugin(GajimPlugin):
|
|||||||
base.enable_action(True)
|
base.enable_action(True)
|
||||||
|
|
||||||
@log_calls('TictactoePlugin')
|
@log_calls('TictactoePlugin')
|
||||||
def disconnect_from_chat_control(self, chat_control):
|
def disconnect_from_chat_control(self, _chat_control):
|
||||||
for base in self.controls:
|
for base in self.controls:
|
||||||
base.disconnect_from_chat_control()
|
base.disconnect_from_chat_control()
|
||||||
self.controls = []
|
self.controls = []
|
||||||
@@ -176,19 +175,19 @@ class TictactoePlugin(GajimPlugin):
|
|||||||
transient_for=app.app.get_active_window()).show()
|
transient_for=app.app.get_active_window()).show()
|
||||||
|
|
||||||
@log_calls('TictactoePlugin')
|
@log_calls('TictactoePlugin')
|
||||||
def _nec_decrypted_message_received(self, obj):
|
def _on_message_received(self, event):
|
||||||
if isinstance(obj.session, TicTacToeSession):
|
if isinstance(event.session, TicTacToeSession):
|
||||||
obj.session.received(obj.stanza)
|
event.session.received(event.stanza)
|
||||||
game_invite = obj.stanza.getTag('invite', namespace=NS_GAMES)
|
game_invite = event.stanza.getTag('invite', namespace=NS_GAMES)
|
||||||
if game_invite:
|
if game_invite:
|
||||||
game = game_invite.getTag('game')
|
game = game_invite.getTag('game')
|
||||||
if game and game.getAttr('var') == NS_GAMES_TICTACTOE:
|
if game and game.getAttr('var') == NS_GAMES_TICTACTOE:
|
||||||
session = obj.conn.make_new_session(
|
session = event.conn.make_new_session(
|
||||||
obj.fjid, obj.properties.thread, cls=TicTacToeSession)
|
event.fjid, event.properties.thread, cls=TicTacToeSession)
|
||||||
self.show_request_dialog(obj, session)
|
self.show_request_dialog(event, session)
|
||||||
|
|
||||||
|
|
||||||
class Base(object):
|
class Base():
|
||||||
def __init__(self, plugin, chat_control):
|
def __init__(self, plugin, chat_control):
|
||||||
self.plugin = plugin
|
self.plugin = plugin
|
||||||
self.chat_control = chat_control
|
self.chat_control = chat_control
|
||||||
@@ -239,10 +238,10 @@ class Base(object):
|
|||||||
|
|
||||||
def disconnect_from_chat_control(self):
|
def disconnect_from_chat_control(self):
|
||||||
menu = self.chat_control.control_menu
|
menu = self.chat_control.control_menu
|
||||||
for i in range(menu.get_n_items()):
|
for item in range(menu.get_n_items()):
|
||||||
label = menu.get_item_attribute_value(i, 'label')
|
label = menu.get_item_attribute_value(item, 'label')
|
||||||
if label.get_string() == 'Tic Tac Toe':
|
if label.get_string() == 'Tic Tac Toe':
|
||||||
menu.remove(i)
|
menu.remove(item)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
@@ -250,7 +249,7 @@ class InvalidMove(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TicTacToeSession(object):
|
class TicTacToeSession():
|
||||||
def __init__(self, conn, jid, thread_id, type_):
|
def __init__(self, conn, jid, thread_id, type_):
|
||||||
self.conn = conn
|
self.conn = conn
|
||||||
self.jid = jid
|
self.jid = jid
|
||||||
@@ -271,7 +270,8 @@ class TicTacToeSession(object):
|
|||||||
self.control = None
|
self.control = None
|
||||||
self.enable_encryption = False
|
self.enable_encryption = False
|
||||||
|
|
||||||
def is_loggable(self):
|
@staticmethod
|
||||||
|
def is_loggable():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def send(self, msg):
|
def send(self, msg):
|
||||||
@@ -288,7 +288,8 @@ class TicTacToeSession(object):
|
|||||||
jid += '/' + self.resource
|
jid += '/' + self.resource
|
||||||
return jid
|
return jid
|
||||||
|
|
||||||
def generate_thread_id(self):
|
@staticmethod
|
||||||
|
def generate_thread_id():
|
||||||
return ''.join(
|
return ''.join(
|
||||||
[f(string.ascii_letters) for f in itertools.repeat(
|
[f(string.ascii_letters) for f in itertools.repeat(
|
||||||
random.choice, 32)]
|
random.choice, 32)]
|
||||||
@@ -413,9 +414,9 @@ class TicTacToeSession(object):
|
|||||||
None,
|
None,
|
||||||
conn=self.conn,
|
conn=self.conn,
|
||||||
level='info',
|
level='info',
|
||||||
pri_txt=_('Invitation refused'),
|
pri_txt=_('Invitation Declined'),
|
||||||
sec_txt=_('%(name)s refused your invitation to play tic '
|
sec_txt=_('%(name)s declined your invitation to play Tic '
|
||||||
'tac toe.') % {'name': self.name}))
|
'Tac Toe.') % {'name': self.name}))
|
||||||
self.conn.delete_session(str(self.jid), self.thread_id)
|
self.conn.delete_session(str(self.jid), self.thread_id)
|
||||||
|
|
||||||
def decline_invitation(self):
|
def decline_invitation(self):
|
||||||
@@ -457,7 +458,7 @@ class TicTacToeSession(object):
|
|||||||
id_ = int(move.getAttr('id'))
|
id_ = int(move.getAttr('id'))
|
||||||
|
|
||||||
if id_ != self.next_move_id:
|
if id_ != self.next_move_id:
|
||||||
log.warn('unexpected move id, lost a move somewhere?')
|
log.warning('unexpected move id, lost a move somewhere?')
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -496,7 +497,7 @@ class TicTacToeSession(object):
|
|||||||
try:
|
try:
|
||||||
self.board.mark(row, col, self.role_s)
|
self.board.mark(row, col, self.role_s)
|
||||||
except InvalidMove:
|
except InvalidMove:
|
||||||
log.warn('You made an invalid move')
|
log.warning('You made an invalid move')
|
||||||
return
|
return
|
||||||
|
|
||||||
self.send_move(row, col)
|
self.send_move(row, col)
|
||||||
@@ -634,7 +635,7 @@ class TicTacToeBoard:
|
|||||||
draw = DrawBoard()
|
draw = DrawBoard()
|
||||||
self.win.add(draw)
|
self.win.add(draw)
|
||||||
|
|
||||||
self.title_prefix = 'tic-tac-toe with %s' % self.session.name
|
self.title_prefix = _('Tic Tac Toe with %s') % self.session.name
|
||||||
self.set_title()
|
self.set_title()
|
||||||
|
|
||||||
self.win.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
|
self.win.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
|
||||||
@@ -660,7 +661,7 @@ class TicTacToeBoard:
|
|||||||
self.session.move(row, column)
|
self.session.move(row, column)
|
||||||
|
|
||||||
# This actually draws the board
|
# This actually draws the board
|
||||||
def do_draw(self, widget, cr):
|
def do_draw(self, _widget, cr):
|
||||||
cr.set_source_rgb(1.0, 1.0, 1.0)
|
cr.set_source_rgb(1.0, 1.0, 1.0)
|
||||||
|
|
||||||
layout = PangoCairo.create_layout(cr)
|
layout = PangoCairo.create_layout(cr)
|
||||||
@@ -684,9 +685,9 @@ class TicTacToeBoard:
|
|||||||
cr.move_to(0, height - text_height)
|
cr.move_to(0, height - text_height)
|
||||||
if self.state == 'None':
|
if self.state == 'None':
|
||||||
if self.session.is_my_turn():
|
if self.session.is_my_turn():
|
||||||
txt = _('It\'s your turn')
|
txt = _('It’s your turn')
|
||||||
else:
|
else:
|
||||||
txt = _('It\'s %(name)s\'s turn') % {'name': self.session.name}
|
txt = _('It’s %(name)s\'s turn') % {'name': self.session.name}
|
||||||
elif self.state == 'won':
|
elif self.state == 'won':
|
||||||
txt = _('You won!')
|
txt = _('You won!')
|
||||||
elif self.state == 'lost':
|
elif self.state == 'lost':
|
||||||
@@ -696,7 +697,7 @@ class TicTacToeBoard:
|
|||||||
elif self.state == 'cheated': # Other part cheated
|
elif self.state == 'cheated': # Other part cheated
|
||||||
txt = _('%(name)s cheated') % {'name': self.session.name}
|
txt = _('%(name)s cheated') % {'name': self.session.name}
|
||||||
else: # Draw
|
else: # Draw
|
||||||
txt = _('It\'s a draw')
|
txt = _('It’s a draw')
|
||||||
layout.set_text(txt, -1)
|
layout.set_text(txt, -1)
|
||||||
# Inform Pango to re-layout the text with the new transformation
|
# Inform Pango to re-layout the text with the new transformation
|
||||||
PangoCairo.update_layout(cr, layout)
|
PangoCairo.update_layout(cr, layout)
|
||||||
@@ -755,7 +756,6 @@ class TicTacToeBoard:
|
|||||||
def mark(self, row, column, player):
|
def mark(self, row, column, player):
|
||||||
if self.board[row-1][column-1]:
|
if self.board[row-1][column-1]:
|
||||||
raise InvalidMove
|
raise InvalidMove
|
||||||
else:
|
|
||||||
self.board[row-1][column-1] = player
|
self.board[row-1][column-1] = player
|
||||||
|
|
||||||
self.win.queue_draw()
|
self.win.queue_draw()
|
||||||
@@ -770,17 +770,17 @@ class TicTacToeBoard:
|
|||||||
|
|
||||||
def won(self):
|
def won(self):
|
||||||
self.state = 'won'
|
self.state = 'won'
|
||||||
self.set_title('you won!')
|
self.set_title(_('You won!'))
|
||||||
self.win.queue_draw()
|
self.win.queue_draw()
|
||||||
|
|
||||||
def lost(self):
|
def lost(self):
|
||||||
self.state = 'lost'
|
self.state = 'lost'
|
||||||
self.set_title('you lost.')
|
self.set_title(_('You’ve lost.'))
|
||||||
self.win.queue_draw()
|
self.win.queue_draw()
|
||||||
|
|
||||||
def drawn(self):
|
def drawn(self):
|
||||||
self.state = 'drawn'
|
self.state = 'drawn'
|
||||||
self.win.set_title(self.title_prefix + ': a draw.')
|
self.win.set_title(_('%s: it’s a draw.') % self.title_prefix)
|
||||||
self.win.queue_draw()
|
self.win.queue_draw()
|
||||||
|
|
||||||
def cheated(self):
|
def cheated(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user