# HG changeset patch # User souliane # Date 1381850343 -7200 # Node ID 63e9b680d3e7bb34f16ef94d0c3ccddbf4b1fa86 # Parent a25aa882e09a3c98bb23e3a4136c32f9127e838b browser_side, blog: better PEP8 compliance diff -r a25aa882e09a -r 63e9b680d3e7 browser_side/base_widget.py --- a/browser_side/base_widget.py Fri Oct 18 11:14:55 2013 +0200 +++ b/browser_side/base_widget.py Tue Oct 15 17:19:03 2013 +0200 @@ -19,7 +19,7 @@ along with this program. If not, see . """ -import pyjd # this is dummy in pyjs +import pyjd # this is dummy in pyjs from pyjamas.ui.SimplePanel import SimplePanel from pyjamas.ui.AbsolutePanel import AbsolutePanel from pyjamas.ui.VerticalPanel import VerticalPanel @@ -62,10 +62,10 @@ def onDragLeave(self, event): if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\ - event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth() - 1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight() - 1: - # We check that we are inside widget's box, and we don't remove the style in this case because - # if the mouse is over a widget inside the DropWidget, if will leave the DropWidget, and we - # don't want that + event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth() - 1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight() - 1: + # We check that we are inside widget's box, and we don't remove the style in this case because + # if the mouse is over a widget inside the DropWidget, if will leave the DropWidget, and we + # don't want that self.removeStyleName('dragover') def onDragOver(self, event): @@ -77,7 +77,6 @@ row = DOM.getParent(cell) return (row.rowIndex, cell.cellIndex) - def onDrop(self, event): DOM.eventPreventDefault(event) dt = event.dataTransfer @@ -137,6 +136,7 @@ DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width)""" #FIXME: delete object ? Check the right way with pyjamas + class WidgetHeader(AbsolutePanel, LiberviaDragWidget): def __init__(self, parent, title): @@ -566,6 +566,7 @@ cellFormatter = self.flextable.getFlexCellFormatter() return cellFormatter.setRowSpan(row, col, value) + class DropTab(Label, DropWidget): def __init__(self, tab_panel, text): @@ -581,7 +582,6 @@ # XXX: awful hack, but seems the only way to get index return self.tab_panel.tabBar.panel.getWidgetIndex(self.getParent().getParent()) - 1 - def onDragEnter(self, event): #if self == LiberviaDragWidget.current: # return @@ -633,6 +633,7 @@ widgets_panel = self.tab_panel.getWidget(self._getIndex()) widgets_panel.addWidget(_new_panel) + class MainTabPanel(TabPanel): def __init__(self, host): @@ -657,8 +658,8 @@ tab_bar_h = _elts.item(0).offsetHeight ideal_height = height - DOM.getAbsoluteTop(tab_panel_elt) - tab_bar_h - 5 ideal_width = width - DOM.getAbsoluteLeft(tab_panel_elt) - 5 - self.setWidth("%s%s" % (ideal_width, "px")); - self.setHeight("%s%s" % (ideal_height, "px")); + self.setWidth("%s%s" % (ideal_width, "px")) + self.setHeight("%s%s" % (ideal_height, "px")) def add(self, widget, text=''): tab = DropTab(self, text) @@ -677,4 +678,3 @@ self.selectTab(0) else: self.selectTab(widgets_count - 1) - diff -r a25aa882e09a -r 63e9b680d3e7 browser_side/card_game.py --- a/browser_side/card_game.py Fri Oct 18 11:14:55 2013 +0200 +++ b/browser_side/card_game.py Tue Oct 15 17:19:03 2013 +0200 @@ -19,7 +19,7 @@ along with this program. If not, see . """ -import pyjd # this is dummy in pyjs +import pyjd # this is dummy in pyjs from pyjamas.ui.AbsolutePanel import AbsolutePanel from pyjamas.ui.VerticalPanel import VerticalPanel from pyjamas.ui.HorizontalPanel import HorizontalPanel @@ -43,16 +43,17 @@ from datetime import datetime from time import time from games import TarotCard +from logging import error import re - CARD_WIDTH = 74 CARD_HEIGHT = 136 CARD_DELTA_Y = 30 -MIN_WIDTH = 950 #Minimum size of the panel +MIN_WIDTH = 950 # Minimum size of the panel MIN_HEIGHT = 500 + class ContratChooser(DialogBox): def __init__(self, parent): @@ -78,21 +79,22 @@ button_panel.add(self.choose_button) content.add(button_panel) self.setHTML("Please select your contrat") - self.setWidget(content) + self.setWidget(content) def onChoose(self, button): self.hide() self._parent.contratSelected(self.contrats_list.getSelectedItemText()[0]) + class CardWidget(TarotCard, Image, MouseHandler): """This class is used to represent a card, graphically and logically""" - def __init__(self, parent, file): + def __init__(self, parent, file_): """@param file: path of the PNG file""" self._parent = parent - Image.__init__(self,file) - root_name = file[file.rfind("/")+1:-4] - suit,value = root_name.split('_') + Image.__init__(self, file_) + root_name = file_[file_.rfind("/") + 1:-4] + suit, value = root_name.split('_') TarotCard.__init__(self, (suit, value)) MouseHandler.__init__(self) self.addMouseListener(self) @@ -104,7 +106,7 @@ def onMouseLeave(self, sender): if not self in self._parent.hand: return - if not self in list(self._parent.selected): #FIXME: Workaround pyjs bug, must report it + if not self in list(self._parent.selected): # FIXME: Workaround pyjs bug, must report it DOM.setStyleAttribute(self.getElement(), "top", "%dpx" % CARD_DELTA_Y) def onMouseUp(self, sender, x, y): @@ -116,13 +118,14 @@ elif self._parent.state == "play": self._parent.playCard(self) + class CardPanel(DockPanel, ClickHandler): def __init__(self, parent, referee, players, player_nick): DockPanel.__init__(self) ClickHandler.__init__(self) self._parent = parent - self._autoplay = None #XXX: use 0 to activate fake play, None else + self._autoplay = None # XXX: use 0 to activate fake play, None else self.referee = referee self.players = players self.player_nick = player_nick @@ -135,42 +138,38 @@ idx = (idx + 1) % len(self.players) self.left_nick = self.players[idx] self.bottom_nick = player_nick - self.selected = set() #Card choosed by the player (e.g. during ecart) - self.hand_size = 13 #number of cards in a hand + self.selected = set() # Card choosed by the player (e.g. during ecart) + self.hand_size = 13 # number of cards in a hand self.hand = [] self.to_show = [] self.state = None self.setSize("%dpx" % MIN_WIDTH, "%dpx" % MIN_HEIGHT) self.setStyleName("cardPanel") - + # Now we set up the layout _label = Label(self.top_nick) _label.setStyleName('cardGamePlayerNick') self.add(_label, DockPanel.NORTH) self.setCellWidth(_label, '100%') - self.setCellHorizontalAlignment(_label, HasAlignment.ALIGN_CENTER) - - + self.setCellHorizontalAlignment(_label, HasAlignment.ALIGN_CENTER) + self.hand_panel = AbsolutePanel() self.add(self.hand_panel, DockPanel.SOUTH) self.setCellWidth(self.hand_panel, '100%') self.setCellHorizontalAlignment(self.hand_panel, HasAlignment.ALIGN_CENTER) - _label = Label(self.left_nick) _label.setStyleName('cardGamePlayerNick') self.add(_label, DockPanel.WEST) self.setCellHeight(_label, '100%') - self.setCellVerticalAlignment(_label, HasAlignment.ALIGN_MIDDLE) - + self.setCellVerticalAlignment(_label, HasAlignment.ALIGN_MIDDLE) _label = Label(self.right_nick) _label.setStyleName('cardGamePlayerNick') self.add(_label, DockPanel.EAST) self.setCellHeight(_label, '100%') - self.setCellHorizontalAlignment(_label, HasAlignment.ALIGN_RIGHT) - self.setCellVerticalAlignment(_label, HasAlignment.ALIGN_MIDDLE) - + self.setCellHorizontalAlignment(_label, HasAlignment.ALIGN_RIGHT) + self.setCellVerticalAlignment(_label, HasAlignment.ALIGN_MIDDLE) self.center_panel = DockPanel() self.inner_left = SimplePanel() @@ -185,19 +184,19 @@ self.center_panel.add(self.inner_right, DockPanel.EAST) self.center_panel.setCellHeight(self.inner_right, '100%') self.center_panel.setCellVerticalAlignment(self.inner_right, HasAlignment.ALIGN_MIDDLE) - + self.inner_top = SimplePanel() self.inner_top.setSize("%dpx" % CARD_WIDTH, "%dpx" % CARD_HEIGHT) self.center_panel.add(self.inner_top, DockPanel.NORTH) self.center_panel.setCellHorizontalAlignment(self.inner_top, HasAlignment.ALIGN_CENTER) self.center_panel.setCellVerticalAlignment(self.inner_top, HasAlignment.ALIGN_BOTTOM) - + self.inner_bottom = SimplePanel() self.inner_bottom.setSize("%dpx" % CARD_WIDTH, "%dpx" % CARD_HEIGHT) self.center_panel.add(self.inner_bottom, DockPanel.SOUTH) self.center_panel.setCellHorizontalAlignment(self.inner_bottom, HasAlignment.ALIGN_CENTER) self.center_panel.setCellVerticalAlignment(self.inner_bottom, HasAlignment.ALIGN_TOP) - + self.inner_center = SimplePanel() self.center_panel.add(self.inner_center, DockPanel.CENTER) self.center_panel.setCellHorizontalAlignment(self.inner_center, HasAlignment.ALIGN_CENTER) @@ -210,29 +209,28 @@ self.setCellHorizontalAlignment(self.center_panel, HasAlignment.ALIGN_CENTER) self.loadCards() - self.mouse_over_card = None #contain the card to highlight - self.visible_size = CARD_WIDTH/2 #number of pixels visible for cards + self.mouse_over_card = None # contain the card to highlight + self.visible_size = CARD_WIDTH / 2 # number of pixels visible for cards self.addClickListener(self) - def loadCards(self): """Load all the cards in memory""" def _getTarotCardsPathsCb(paths): print "_getTarotCardsPathsCb" - for file in paths: - print "path:", file - card = CardWidget(self, file) + for file_ in paths: + print "path:", file_ + card = CardWidget(self, file_) print "card:", card - self.cards[(card.suit, card.value)]=card + self.cards[(card.suit, card.value)] = card self.deck.append(card) self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee) - self.cards={} - self.deck=[] - self.cards["atout"]={} #As Tarot is a french game, it's more handy & logical to keep french names - self.cards["pique"]={} #spade - self.cards["coeur"]={} #heart - self.cards["carreau"]={} #diamond - self.cards["trefle"]={} #club + self.cards = {} + self.deck = [] + self.cards["atout"] = {} # As Tarot is a french game, it's more handy & logical to keep french names + self.cards["pique"] = {} # spade + self.cards["coeur"] = {} # heart + self.cards["carreau"] = {} # diamond + self.cards["trefle"] = {} # club self._parent.host.bridge.call('getTarotCardsPaths', _getTarotCardsPathsCb) def onClick(self, sender): @@ -259,18 +257,18 @@ def updateHand(self): """Show the cards in the hand in the hand_panel (SOUTH panel)""" self.hand_panel.clear() - self.hand_panel.setSize("%dpx" % (self.visible_size * (len(self.hand)+1)), "%dpx" % (CARD_HEIGHT + CARD_DELTA_Y + 10)) + self.hand_panel.setSize("%dpx" % (self.visible_size * (len(self.hand) + 1)), "%dpx" % (CARD_HEIGHT + CARD_DELTA_Y + 10)) x_pos = 0 y_pos = CARD_DELTA_Y for card in self.hand: self.hand_panel.add(card, x_pos, y_pos) - x_pos+=self.visible_size - + x_pos += self.visible_size + def updateToShow(self): """Show cards in the center panel""" if not self.to_show: _widget = self.inner_center.getWidget() - if _widget: + if _widget: self.inner_center.remove(_widget) return panel = AbsolutePanel() @@ -279,7 +277,7 @@ y_pos = 0 for card in self.to_show: panel.add(card, x_pos, y_pos) - x_pos+=CARD_WIDTH + 5 + x_pos += CARD_WIDTH + 5 self.inner_center.setWidget(panel) def _ecartConfirm(self, confirm): @@ -293,7 +291,7 @@ self._parent.host.bridge.call('tarotGamePlayCards', None, self.player_nick, self.referee, ecart) self.state = "wait" self.updateHand() - + def addToSelection(self, card): self.selected.add(card) if len(self.selected) == 6: @@ -310,11 +308,11 @@ elif phase == "ecart": self.state = "ecart" else: - error ('INTERNAL ERROR: unmanaged game phase') - + error('INTERNAL ERROR: unmanaged game phase') + for suit, value in played_cards: self.hand.append(self.cards[(suit, value)]) - + self.hand.sort() self.updateHand() Window.alert('Cards played are invalid !') @@ -350,8 +348,8 @@ def getPlayerLocation(self, nick): """return player location (top,bottom,left or right)""" - for location in ['top','left','bottom','right']: - if getattr(self,'%s_nick' % location) == nick: + for location in ['top', 'left', 'bottom', 'right']: + if getattr(self, '%s_nick' % location) == nick: return location print ("ERROR: This line should not be reached") @@ -371,13 +369,13 @@ if player_panel.getWidget() != None: #We have already cards on the table, we remove them - for pos in ['top','left','bottom','right']: + for pos in ['top', 'left', 'bottom', 'right']: getattr(self, "inner_%s" % pos).setWidget(None) - + card = self.cards[(suit, value)] DOM.setElemAttribute(card.getElement(), "style", "") player_panel.setWidget(card) - + def tarotGameYourTurn(self): """Called when we have to play :)""" if self.state == "chien": @@ -404,7 +402,7 @@ self.updateHand() #nothing on the table self.updateToShow() - for pos in ['top','left','bottom','right']: + for pos in ['top', 'left', 'bottom', 'right']: getattr(self, "inner_%s" % pos).setWidget(None) self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee) @@ -415,5 +413,5 @@ title = "You win !" else: title = "You loose :(" - body = re.sub(r'<.*?>',lambda x:'
' if '/elem' in x.group(0) else '', xml_data) #Q&D conversion to simple HTML text + body = re.sub(r'<.*?>', lambda x: '
' if '/elem' in x.group(0) else '', xml_data) # Q&D conversion to simple HTML text InfoDialog(title, body, _new_game).show() diff -r a25aa882e09a -r 63e9b680d3e7 browser_side/radiocol.py --- a/browser_side/radiocol.py Fri Oct 18 11:14:55 2013 +0200 +++ b/browser_side/radiocol.py Tue Oct 15 17:19:03 2013 +0200 @@ -19,7 +19,7 @@ along with this program. If not, see . """ -import pyjd # this is dummy in pyjs +import pyjd # this is dummy in pyjs from pyjamas.ui.VerticalPanel import VerticalPanel from pyjamas.ui.HorizontalPanel import HorizontalPanel from pyjamas.ui.SimplePanel import SimplePanel @@ -45,24 +45,24 @@ def __init__(self): FlexTable.__init__(self) - title_lbl = Label("title:") + title_lbl = Label("title:") title_lbl.setStyleName('radiocol_metadata_lbl') artist_lbl = Label("artist:") artist_lbl.setStyleName('radiocol_metadata_lbl') album_lbl = Label("album:") album_lbl.setStyleName('radiocol_metadata_lbl') - self.title = Label("") + self.title = Label("") self.title.setStyleName('radiocol_metadata') self.artist = Label("") self.artist.setStyleName('radiocol_metadata') self.album = Label("") self.album.setStyleName('radiocol_metadata') - self.setWidget(0,0,title_lbl) - self.setWidget(1,0,artist_lbl) - self.setWidget(2,0,album_lbl) - self.setWidget(0,1,self.title) - self.setWidget(1,1,self.artist) - self.setWidget(2,1,self.album) + self.setWidget(0, 0, title_lbl) + self.setWidget(1, 0, artist_lbl) + self.setWidget(2, 0, album_lbl) + self.setWidget(0, 1, self.title) + self.setWidget(1, 1, self.artist) + self.setWidget(2, 1, self.album) self.setStyleName("radiocol_metadata_pnl") def setTitle(self, title): @@ -74,6 +74,7 @@ def setAlbum(self, album): self.album.setText(album) + class ControlPanel(FormPanel): """Panel used to show controls to add a song, or vote for the current one""" @@ -98,20 +99,20 @@ hPanel.add(self.status) vPanel.add(hPanel) - + #We need to know the referee referee_field = Hidden('referee', referee) vPanel.add(referee_field) self.add(vPanel) self.addFormHandler(self) - + def _timeCb(self, timer): self.status.setText('') def onBtnClick(self): self.submit() - + def onSubmit(self, event): pass @@ -123,7 +124,6 @@ self.file_upload.setVisible(True) self.upload_btn.setEnabled(True) - def onSubmitComplete(self, event): result = event.getResults() if result == "OK": @@ -136,17 +136,18 @@ else: Window.alert('Submit error: %s' % result) + class Player(HTML): def __init__(self, player_id, metadata_panel): HTML.__init__(self) self._id = player_id self.metadata = metadata_panel - self.title="" - self.artist="" - self.album="" + self.title = "" + self.artist = "" + self.album = "" self.filename = None - self.played = False #True when song is playing/played, become False on preload + self.played = False # True when song is playing/played, become False on preload def preload(self, filename, title, artist, album): """preload the song but doesn't play it""" @@ -157,7 +158,7 @@ self.played = False self.setHTML('