示例#1
0
文件: TopPanel.py 项目: Afey/pyjs
    def __init__(self):

        Composite.__init__(self)

        self.signOutLink = HTML("<a href='javascript:;'>Sign Out</a>")
        self.aboutLink = HTML("<a href='javascript:;'>About</a>")

        outer = HorizontalPanel()
        inner = VerticalPanel()

        outer.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT)
        inner.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT)

        links = HorizontalPanel()
        links.setSpacing(4)
        links.add(self.signOutLink)
        links.add(self.aboutLink)

        outer.add(inner)
        inner.add(HTML("<b>Welcome back, [email protected]</b>"))
        inner.add(links)

        self.signOutLink.addClickListener(self)
        self.aboutLink.addClickListener(self)

        self.initWidget(outer)
        inner.setStyleName("mail-TopPanel")
        links.setStyleName("mail-TopPanelLinks")
示例#2
0
 def setControls(self, minimize, maximize, close):
     if minimize is True:
         self.minimizeWidget = self.createDefaultControl('minimize')
     elif isinstance(minimize, basestring):
         self.minimizeWidget = Image(minimize)
     else:
         self.minimizeWidget = minimize
     if maximize is True:
         self.maximizeWidget = self.createDefaultControl('maximize')
     elif isinstance(maximize, basestring):
         self.maximizeWidget = Image(maximize)
     else:
         self.maximizeWidget = maximize
     if close is True:
         self.closeWidget = self.createDefaultControl('close')
     elif isinstance(close, basestring):
         self.closeWidget = Image(close)
     else:
         self.closeWidget = close
     if (isinstance(self.minimizeWidget, UIObject) or
         isinstance(self.maximizeWidget, UIObject) or
         isinstance(self.closeWidget, UIObject)):
         cf = self.panel.getCellFormatter()
         captionStyle = self.caption.getStyleName()
         captionPanel = FlexTable(
             Width="99%",
             BorderWidth="0",
             CellPadding="0",
             CellSpacing="0",
         )
         controls = HorizontalPanel()
         controls.setStyleName("Controls")
         controls.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
         if isinstance(self.minimizeWidget, UIObject):
             self.minimizeWidget.setStyleName("Minimize")
             controls.add(self.minimizeWidget)
             self.minimizeWidget.addClickListener(
                 getattr(self, "onMinimize"),
             )
         if isinstance(self.maximizeWidget, UIObject):
             self.maximizeWidget.setStyleName("Maximize")
             controls.add(self.maximizeWidget)
             self.maximizeWidget.addClickListener(
                 getattr(self, "onMaximize"),
             )
         if isinstance(self.closeWidget, UIObject):
             self.closeWidget.setStyleName("Close")
             controls.add(self.closeWidget)
             self.closeWidget.addClickListener(
                 getattr(self, "onClose"),
             )
             self.closeable = True
         self.caption.removeStyleName(captionStyle)
         self.panel.setWidget(0, 0, captionPanel)
         captionPanel.setWidget(0, 0, self.caption)
         captionPanel.setWidget(0, 1, controls)
         captionPanel.setStyleName(captionStyle)
         cf = captionPanel.getCellFormatter()
         cf.setWidth(0, 1, '1%')
示例#3
0
class pjBallot:
    
    def __init__(self):
        self.mainPanel = VerticalPanel()
        self.contest = HorizontalPanel()
        self.contest.setStyleName('words')
        self.selection = HorizontalPanel()
        self.selection.setStyleName('words')
        self.button = Button('test', self.test)
        self.x = 1
    
    def test(self):
        self.button.setText("No, really click me!")
#        Window.alert("Hello, AJAAAX!")
        self.contest.add(HTML('yay'))

    def nextContest(self):
        self.x += 1
        self.contest.clear()
        self.contest.add(HTML('<b /> Contest: %d' % self.x))

    def nextSelection(self):
        self.x += 1
        self.selection.clear()
        self.selection.add(HTML('<b /> Selection: %d' % self.x))
    
    def onKeyDown(self, sender, keycode, modifiers):
        pass

    def onKeyUp(self, sender, keycode, modifiers):
        pass

    def onKeyPress(self, sender, keycode, modifiers):
        DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) #not needed
        if keycode == KeyboardListener.KEY_UP:
            self.nextContest()
        if keycode == KeyboardListener.KEY_DOWN:
            self.nextContest()
        if keycode == KeyboardListener.KEY_LEFT:
            self.nextSelection()
        if keycode == KeyboardListener.KEY_RIGHT:
            self.nextSelection()

    def onModuleLoad(self):
        h = HTML("<b />Contest: ")
        self.contest.add(h)
        l = HTML("<b />Selection: ")
        self.selection.add(l)
#        self.mainPanel.add(self.button)
        self.mainPanel.add(self.contest)
        self.mainPanel.add(self.selection)
        
        panel = FocusPanel(Widget=self.mainPanel)
        gp = RootPanelListener(panel)
        manageRootPanel(gp)
        RootPanel().add(panel)
        panel.setFocus(True)
示例#4
0
	def fieldPanel(self, widgets):
		h = HorizontalPanel()
		h.setStyleName('field')
		l = Label()
		for i in range(len(widgets)):
			if i==0:
				if 'name' in widgets[0]['kwargs']:
					l = Label(widgets[0]['kwargs']['name'])
				h.add(l)
			_i = i
			if isinstance(widgets[i], int): 
				_i = widgets[i]
			w = LWidget.make(widgets[_i]['w'], **widgets[_i]['kwargs'])
			h.add(w)
		return h 
示例#5
0
    def __init__(self, mailObject):
        Composite.__init__(self)

        self.countLabel = HTML()
        self.newerButton = HTML("<a href='javascript:;'>&lt; newer</a>", True)
        self.olderButton = HTML("<a href='javascript:;'>older &gt;</a>", True)
        self.startIndex = 0
        self.selectedRow = -1
        self.table = FlexTable()
        self.navBar = HorizontalPanel()
        self.mailObject = mailObject

        # Setup the table.
        self.table.setCellSpacing(0)
        self.table.setCellPadding(2)
        self.table.setWidth("100%")

        # Hook up events.
        self.table.addTableListener(self)
        self.newerButton.addClickListener(self)
        self.olderButton.addClickListener(self)

        # Create the 'navigation' bar at the upper-right.
        innerNavBar = HorizontalPanel()
        innerNavBar.setStyleName("mail-ListNavBar")
        innerNavBar.setSpacing(8)
        innerNavBar.add(self.newerButton)
        innerNavBar.add(self.countLabel)
        innerNavBar.add(self.olderButton)

        self.navBar.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT)
        self.navBar.add(innerNavBar)
        self.navBar.setWidth("100%")

        self.initWidget(self.table)
        self.setStyleName("mail-List")

        self.initTable()
        self.update()
示例#6
0
class MailList(Composite):

    VISIBLE_EMAIL_COUNT = 10

    def __init__(self, mailObject):
        Composite.__init__(self)

        self.countLabel = HTML()
        self.newerButton = HTML("<a href='javascript:;'>&lt; newer</a>", True)
        self.olderButton = HTML("<a href='javascript:;'>older &gt;</a>", True)
        self.startIndex = 0
        self.selectedRow = -1
        self.table = FlexTable()
        self.navBar = HorizontalPanel()
        self.mailObject = mailObject

        # Setup the table.
        self.table.setCellSpacing(0)
        self.table.setCellPadding(2)
        self.table.setWidth("100%")

        # Hook up events.
        self.table.addTableListener(self)
        self.newerButton.addClickListener(self)
        self.olderButton.addClickListener(self)

        # Create the 'navigation' bar at the upper-right.
        innerNavBar = HorizontalPanel()
        innerNavBar.setSpacing(8)
        innerNavBar.add(self.newerButton)
        innerNavBar.add(self.countLabel)
        innerNavBar.add(self.olderButton)

        self.navBar.setStyleName("mail-ListNavBar")
        self.navBar.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT)
        self.navBar.add(innerNavBar)
        self.navBar.setWidth("100%")

        self.initWidget(self.table)
        self.setStyleName("mail-List")

        self.initTable()
        self.update()

    def onCellDoubleClicked(self, sender, row, cell):
    	pass

    def onCellClicked(self, sender, row, cell):
        # Select the row that was clicked (-1 to account for header row).
        if (row > 0):
            self.selectRow(row - 1)

    def onClick(self, sender):
        if (sender == self.olderButton):
            # Move forward a page.
            self.startIndex = self.startIndex + MailList.VISIBLE_EMAIL_COUNT
            if (self.startIndex >= MailItems().getMailItemCount()):
                self.startIndex = self.startIndex - MailList.VISIBLE_EMAIL_COUNT
            else:
                self.styleRow(self.selectedRow, False)
                self.selectedRow = -1
                self.update()

        elif (sender == self.newerButton):
            # Move back a page.
            self.startIndex = self.startIndex - MailList.VISIBLE_EMAIL_COUNT
            if (self.startIndex < 0):
                self.startIndex = 0
            else:
                self.styleRow(self.selectedRow, False)
                self.selectedRow = -1
                self.update()

    def initTable(self):
        # Create the header row.
        self.table.setText(0, 0, "sender")
        self.table.setText(0, 1, "email")
        self.table.setText(0, 2, "subject")
        self.table.setWidget(0, 3, self.navBar)
        self.table.getRowFormatter().setStyleName(0, "mail-ListHeader")

        # Initialize the rest of the rows.
        i = 0
        while i < MailList.VISIBLE_EMAIL_COUNT:
            self.table.setText(i + 1, 0, "")
            self.table.setText(i + 1, 1, "")
            self.table.setText(i + 1, 2, "")
            self.table.getCellFormatter().setWordWrap(i + 1, 0, False)
            self.table.getCellFormatter().setWordWrap(i + 1, 1, False)
            self.table.getCellFormatter().setWordWrap(i + 1, 2, False)
            self.table.getFlexCellFormatter().setColSpan(i + 1, 2, 2)
            i = i + 1


    def selectRow(self, row):
        # When a row (other than the first one, which is used as a header) is
        # selected, display its associated MailItem.
        item = MailItems().getMailItem(self.startIndex + row)
        if item is None:
            return

        self.styleRow(self.selectedRow, False)
        self.styleRow(row, True)

        item.read = True
        self.selectedRow = row
        self.mailObject.get().displayItem(item)


    def styleRow(self, row, selected):
        if (row != -1):
            if (selected):
                self.table.getRowFormatter().addStyleName(row + 1, "mail-SelectedRow")
            else:
                self.table.getRowFormatter().removeStyleName(row + 1, "mail-SelectedRow")

    def update(self):
        # Update the older/newer buttons & label.
        count = MailItems().getMailItemCount()
        max = self.startIndex + MailList.VISIBLE_EMAIL_COUNT
        if (max > count):
            max = count

        self.newerButton.setVisible(self.startIndex != 0)
        self.olderButton.setVisible(self.startIndex + MailList.VISIBLE_EMAIL_COUNT < count)
        startIndexPlusOne = self.startIndex + 1
        self.countLabel.setText("%d - %d of %d" % (startIndexPlusOne, max, count))

        # Show the selected emails.
        i = 0
        while (i < MailList.VISIBLE_EMAIL_COUNT):
            # Don't read past the end.
            if (self.startIndex + i >= MailItems().getMailItemCount()):
                break

            item = MailItems().getMailItem(self.startIndex + i)

            # Add a row to the table, then set each of its columns to the
            # email's sender and subject values.

            self.table.setText(i + 1, 0, item.sender)
            self.table.setText(i + 1, 1, item.email)
            self.table.setText(i + 1, 2, item.subject)

            i = i + 1

        # Clear any remaining slots.
        while (i < MailList.VISIBLE_EMAIL_COUNT):
            self.table.setHTML(i + 1, 0, "&nbsp;")
            self.table.setHTML(i + 1, 1, "&nbsp;")
            self.table.setHTML(i + 1, 2, "&nbsp;")
            i = i + 1

        # Select the first row if none is selected.
        if (self.selectedRow == -1):
            self.selectRow(0)
示例#7
0
import buzz.js

JS('''
var mySound1 = new buzz.sound("http://10.0.10.95/media/finish.wav");
var mySound2 = new buzz.sound("http://10.0.10.95/media/race.wav");
''')

contestPosition = 0
candidatePosition = 0
confirm = 0
currObj = ""
review_path = []

contest = HorizontalPanel()
contest.setStyleName('words')
candidate = HorizontalPanel()
candidate.setStyleName('words')
selection = HorizontalPanel()
selection.setStyleName('words')
status = HorizontalPanel()
status.add(HTML('STATUS'))
status.setStyleName('words')

title = HorizontalPanel()
instructions = HorizontalPanel()

race = Race('', [], '', '')
  
          
def sendRace(srace):
示例#8
0
class MovieRatings:
	def onModuleLoad(self):
        # Setup JSON RPC
		self.remote = DataService()

### Initialize member variables
		self.mainPanel = HorizontalPanel()
		self.rightPanel = VerticalPanel()
		self.moviesPanel = VerticalPanel()
		self.topRatedPanel = VerticalPanel()
		self.categoriesPanel = VerticalPanel()
        
		self.moviesFlexTable = FlexTable()
		self.topRatedMoviesFlexTable = FlexTable()
		self.topCategoryMoviesFlexTable = FlexTable()
        
		self.lessThanFiveLabel = Label('There are less than 5 movies. Add more movies!')
		self.moviesListLabel = Label('Movies List')
        
		self.addPanel = VerticalPanel()
		self.newMovieCategoryTextBox = TextBox()
		self.newMovieNameTextBox = TextBox()
		self.newMovieRatingListBox = ListBox(False)
		self.addMovieButton = Button('Add', self.addMovieButton_Click)
        
		self.movies = []
		self.topRatedMovies = []
		self.categories = {}
		
		self.MAX_RATING = 10
		
###	Add Movie Panel
		# Add ratings to list box
		for i in range(self.MAX_RATING + 1):
			self.newMovieRatingListBox.addItem(str(i))
		
		# Add label and textbox to horizontal panel
		self.labelPanel = HorizontalPanel()
		self.labelPanel.add(Label("Add a movie:"))
		self.categoryPanel = HorizontalPanel()
		self.categoryPanel.add(Label("Category: "))
		self.categoryPanel.add(self.newMovieCategoryTextBox)
		self.namePanel = HorizontalPanel()
		self.namePanel.add(Label("Movie Name: "))
		self.namePanel.add(self.newMovieNameTextBox)
		self.ratingPanel = HorizontalPanel()
		self.ratingPanel.add(Label("Movie Rating: "))
		self.ratingPanel.add(self.newMovieRatingListBox)

		self.labelPanel.addStyleName("addLabel")
		self.labelPanel.setSpacing(5)
		self.categoryPanel.addStyleName("addPanel")
		self.categoryPanel.setSpacing(5)
		self.namePanel.addStyleName("addPanel")
		self.namePanel.setSpacing(5)
		self.ratingPanel.addStyleName("addPanel")
		self.ratingPanel.setSpacing(5)
		self.newMovieCategoryTextBox.addStyleName("addPanel-input")
		self.newMovieNameTextBox.addStyleName("addPanel-input")
		self.newMovieRatingListBox.addStyleName("addPanel-input")
		
		self.addPanel.add(self.labelPanel)
		self.addPanel.add(self.categoryPanel)
		self.addPanel.add(self.namePanel)
		self.addPanel.add(self.ratingPanel)
		self.addPanel.add(self.addMovieButton)
		self.addPanel.addStyleName("addPanel")
		
		self.addMovieButton.addStyleName('addButton')
		self.addPanel.add(self.addMovieButton)
		self.addPanel.addStyleName('addPanel')
		
###	Movies table
		self.moviesFlexTable.setText(0, 1, "Category")
		self.moviesFlexTable.setText(0, 2, "Title")
		self.moviesFlexTable.setText(0, 3, "Rating")

		self.moviesFlexTable.addStyleName("movieList")
		self.moviesFlexTable.getRowFormatter().addStyleName(0, "listHeader")
		self.moviesFlexTable.setCellPadding(6)
		self.moviesFlexTable.getCellFormatter().setStyleName(0, 1, "listHeaderColumn")
		self.moviesFlexTable.getCellFormatter().setStyleName(0, 2, "listHeaderColumn")
		self.moviesListLabel.addStyleName("listLabel")

		self.moviesPanel.add(self.moviesListLabel)
		self.moviesPanel.add(self.moviesFlexTable)
		self.moviesPanel.setStyleName("moviesPanel")
		
###	Top rated movies table
		self.topRatedMoviesFlexTable.setText(0, 0, "Category")
		self.topRatedMoviesFlexTable.setText(0, 1, "Title")
		self.topRatedMoviesFlexTable.setText(0, 2, "Rating")

		self.topRatedMoviesFlexTable.addStyleName("topMoviesList")
		self.topRatedMoviesFlexTable.getRowFormatter().addStyleName(0, "listHeader")
		self.topRatedMoviesFlexTable.setCellPadding(6)
		self.topRatedMoviesFlexTable.getCellFormatter().setStyleName(0, 0, "listHeaderColumn")
		self.topRatedMoviesFlexTable.getCellFormatter().setStyleName(0, 1, "listHeaderColumn")

		self.topRatedLabel = Label("Top 5 Rated Movies")
		self.topRatedLabel.addStyleName("listLabel")
		self.lessThanFiveLabel.addStyleName("noticeLabel")

		self.topRatedPanel.add(self.topRatedLabel)
		self.topRatedPanel.add(self.topRatedMoviesFlexTable)
		self.topRatedPanel.add(self.lessThanFiveLabel)
		self.topRatedPanel.setStyleName("topRatedPanel")
		
###	Categories table
		self.topCategoryMoviesFlexTable.setText(0, 0, "Category")
		self.topCategoryMoviesFlexTable.setText(0, 1, "Top Movie")
		self.topCategoryMoviesFlexTable.setText(0, 2, "Average Rating")

		self.topCategoryMoviesFlexTable.addStyleName("topCategoryMoviesList")
		self.topCategoryMoviesFlexTable.getRowFormatter().addStyleName(0, "listHeader")
		self.topCategoryMoviesFlexTable.setCellPadding(6)
		self.topCategoryMoviesFlexTable.getCellFormatter().setStyleName(0, 0, "listHeaderColumn")
		self.topCategoryMoviesFlexTable.getCellFormatter().setStyleName(0, 1, "listHeaderColumn")

		self.categoriesLabel = Label("Movie Categories")
		self.categoriesLabel.addStyleName("listLabel")

		self.categoriesPanel.add(self.categoriesLabel)
		self.categoriesPanel.add(self.topCategoryMoviesFlexTable)
		self.categoriesPanel.setStyleName("categoriesPanel")
		
###	Assemble Main panel
		self.rightPanel.add(self.topRatedPanel)
		self.rightPanel.add(self.categoriesPanel)
		self.mainPanel.add(self.moviesPanel)
		self.mainPanel.add(self.rightPanel)

		self.mainPanel.setStyleName("mainPanel")
		self.mainPanel.setSpacing(25)
		
        # Associate panels with the HTML host page
		RootPanel('addPanel').add(self.addPanel)
		RootPanel('main').add(self.mainPanel)

        # Move cursor focus to the input box
		self.newMovieNameTextBox.setFocus(True)

        # Load the movies
		self.remote.getMovies(self)
	
	def verifyInputs(self, name, category):
		if len(name) == 0:
			Window.alert("Movie name cannot be empty.")
			return False
		if len(name) > 100:
			Window.alert("Movie name is too long. Maximum length is 100 characters.")
			return False
		if len(category) == 0:
			Window.alert("Category cannot be empty.")
			return False
		p = re.compile('^[0-9A-Za-z\\.\\-\\(\\) ]{1,100}$')
		if p.match(category) == None:
			Window.alert('"%s" is not a valid category.' % category)
			return False
		return True
	
	def addMovieButton_Click(self, event):		
		name = self.newMovieNameTextBox.getText().trim()
		cat = self.newMovieCategoryTextBox.getText().trim().lower()
		category = cat[0].upper() + cat[1:]
		rating = self.newMovieRatingListBox.getSelectedIndex()
		
		if not self.verifyInputs(name, category):
			return
			
		movie = Movie(name, category, rating)
			
		if movie in self.movies:
			Window.alert("'" + name + "' is already in table.")
			self.newMovieNameTextBox.selectAll()
			return
			
		self.remote.addMovie((name, category, rating), self)
		self.newMovieNameTextBox.setText('')
		
	def addMovie(self, sender, movie):						
		self.movies.append(movie)
		row = self.moviesFlexTable.getRowCount()
		
		self.moviesFlexTable.setText(row, 1, movie.category)
		self.moviesFlexTable.setText(row, 2, movie.name)
		self.moviesFlexTable.setText(row, 3, movie.rating)
					
		# Adds buttons for remove, edit, save and cancel
		removeMovieButton = Button("x")
		editMovieButton = Button("Edit")
		saveButton = Button("Save")
		cancelButton = Button("Cancel")	
			
		# Save and cancel are hidden by default
		saveButton.setVisible(False)
		cancelButton.setVisible(False)
		
		# Add buttons to row
		buttons = HorizontalPanel()
		buttons.add(removeMovieButton)
		buttons.add(editMovieButton)
		buttons.add(cancelButton)
		buttons.add(saveButton)
		self.moviesFlexTable.setWidget(row, 0, buttons)
		
		def removeMovieButton_Click(sender):
			self.remote.deleteMovie((movie.name, movie.category), self)
		removeMovieButton.addClickListener(removeMovieButton_Click)
		
		def editMovieButton_Click(sender):   		
    	    # Add textboxes and listbox
			editMovieButton.setVisible(False)
			cancelButton.setVisible(True)
			saveButton.setVisible(True)
			editCategory = TextBox()
			editName = TextBox()
			editRating = ListBox(False)
			for i in range(self.MAX_RATING + 1):
				editRating.addItem(str(i))
    		
    		# Variable width textboxes
			catlen = len(movie.category)
			namelen = len(movie.name)    		
			if (catlen > 8):
				editCategory.setWidth(str(catlen*10) + "px")
			else:
				editCategory.setWidth("80px")
			if (namelen > 8):
				editName.setWidth(str(namelen*10) + "px")
			else:
				editName.setWidth("80px")
    		
			self.moviesFlexTable.setWidget(row, 1, editCategory)
			self.moviesFlexTable.setWidget(row, 2, editName)
			self.moviesFlexTable.setWidget(row, 3, editRating)
			editCategory.setText(movie.category)
			editName.setText(movie.name)
			editRating.setSelectedIndex(movie.rating)			
		editMovieButton.addClickListener(editMovieButton_Click)
		
		def saveButton_Click(sender):
			catText = self.moviesFlexTable.getWidget(row, 1)
			nameText = self.moviesFlexTable.getWidget(row, 2)
			ratingList = self.moviesFlexTable.getWidget(row, 3)
			
			newCategory = catText.getText().trim().lower()
			newCategory = newCategory[0].upper() + newCategory[1:]
			newName = nameText.getText().trim()
			newRating = ratingList.getSelectedIndex()

			if not self.verifyInputs(newName, newCategory):
				return
			
			# Removes temporarily to check for duplicates
			self.movies.remove(movie)
			
			newMovie = Movie(newName, newCategory, newRating)			
			if newMovie in self.movies:
				Window.alert("'" + newName + "' is already in table.")
				nameText.selectAll()
				return
    		
			self.remote.editMovie((movie.name, movie.category), (newMovie.name, newMovie.category, newMovie.rating), self)
		saveButton.addClickListener(saveButton_Click)
		
		def cancelButton_Click(sender):			
			self.moviesFlexTable.remove(self.moviesFlexTable.getWidget(row, 1))
			self.moviesFlexTable.remove(self.moviesFlexTable.getWidget(row, 2))
			self.moviesFlexTable.remove(self.moviesFlexTable.getWidget(row, 3))

			# Reverts fields to old movie info
			self.moviesFlexTable.setText(row, 1, movie.category)
			self.moviesFlexTable.setText(row, 2, movie.name)
			self.moviesFlexTable.setText(row, 3, movie.rating)

			cancelButton.setVisible(False)
			saveButton.setVisible(False)
			editMovieButton.setVisible(True)
		cancelButton.addClickListener(cancelButton_Click)
		
	def updateTopRatedMovies(self):
		numTopRated = len(self.topRatedMovies)
				
		self.clearTable(self.topRatedMoviesFlexTable)
			
		for row in range(numTopRated):
			self.topRatedMoviesFlexTable.setText(row+1, 0, self.topRatedMovies[row].category)
			self.topRatedMoviesFlexTable.setText(row+1, 1, self.topRatedMovies[row].name)
			self.topRatedMoviesFlexTable.setText(row+1, 2, self.topRatedMovies[row].rating)
			
		# Label should only be visible if less than 5 movies
		self.lessThanFiveLabel.setVisible(numTopRated < 5)
		
	def updateCategories(self):
		self.clearTable(self.topCategoryMoviesFlexTable)
		
		for row, cat in enumerate(self.categories):
			self.topCategoryMoviesFlexTable.setText(row+1, 0, cat + " (" + str(self.categories[cat][2]) + ")")
			self.topCategoryMoviesFlexTable.setText(row+1, 1, self.categories[cat][0])
			self.topCategoryMoviesFlexTable.setText(row+1, 2, "%.1f" % float(self.categories[cat][1]))
			
	def clearTable(self, table):
		try:
			for i in range(table.getRowCount()):
				table.removeRow(1)
		except:
			pass

	# Called when a response is received from a RPC.
	def onRemoteResponse(self, response, request_info):
		if request_info.method in ['getMovies', 'addMovie', 'deleteMovie', 'editMovie']:
		    # Clear current and add all
			self.movies = []
			self.clearTable(self.moviesFlexTable)
			for m in response:
				movie = Movie(m[0], m[1], m[2])
				self.addMovie(None, movie)
			self.moviesListLabel.setText("Movies List (" + str(len(self.movies)) + ")")
			self.remote.getTopRated(self)
			self.remote.getCategories(self)
			
		if request_info.method == 'getTopRated':
		    # Update top rated
			self.topRatedMovies = []
			for m in response:
				movie = Movie(m[0], m[1], m[2])
				self.topRatedMovies.append(movie)
			self.updateTopRatedMovies()
			
		if request_info.method == 'getCategories':
		    # Update categories
			self.categories = response
			self.updateCategories()
示例#9
0
class MailList(Composite):

    VISIBLE_EMAIL_COUNT = 10

    def __init__(self, mailObject):
        Composite.__init__(self)

        self.countLabel = HTML()
        self.newerButton = HTML("<a href='javascript:;'>&lt; newer</a>", True)
        self.olderButton = HTML("<a href='javascript:;'>older &gt;</a>", True)
        self.startIndex = 0
        self.selectedRow = -1
        self.table = FlexTable()
        self.navBar = HorizontalPanel()
        self.mailObject = mailObject

        # Setup the table.
        self.table.setCellSpacing(0)
        self.table.setCellPadding(2)
        self.table.setWidth("100%")

        # Hook up events.
        self.table.addTableListener(self)
        self.newerButton.addClickListener(self)
        self.olderButton.addClickListener(self)

        # Create the 'navigation' bar at the upper-right.
        innerNavBar = HorizontalPanel()
        innerNavBar.setSpacing(8)
        innerNavBar.add(self.newerButton)
        innerNavBar.add(self.countLabel)
        innerNavBar.add(self.olderButton)

        self.navBar.setStyleName("mail-ListNavBar")
        self.navBar.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT)
        self.navBar.add(innerNavBar)
        self.navBar.setWidth("100%")

        self.initWidget(self.table)
        self.setStyleName("mail-List")

        self.initTable()
        self.update()

    def onCellClicked(self, sender, row, cell):
        # Select the row that was clicked (-1 to account for header row).
        if (row > 0):
            self.selectRow(row - 1)

    def onClick(self, sender):
        if (sender == self.olderButton):
            # Move forward a page.
            self.startIndex = self.startIndex + MailList.VISIBLE_EMAIL_COUNT
            if (self.startIndex >= MailItems().getMailItemCount()):
                self.startIndex = self.startIndex - MailList.VISIBLE_EMAIL_COUNT
            else:
                self.styleRow(self.selectedRow, False)
                self.selectedRow = -1
                self.update()

        elif (sender == self.newerButton):
            # Move back a page.
            self.startIndex = self.startIndex - MailList.VISIBLE_EMAIL_COUNT
            if (self.startIndex < 0):
                self.startIndex = 0
            else:
                self.styleRow(self.selectedRow, False)
                self.selectedRow = -1
                self.update()

    def initTable(self):
        # Create the header row.
        self.table.setText(0, 0, "sender")
        self.table.setText(0, 1, "email")
        self.table.setText(0, 2, "subject")
        self.table.setWidget(0, 3, self.navBar)
        self.table.getRowFormatter().setStyleName(0, "mail-ListHeader")

        # Initialize the rest of the rows.
        i = 0
        while i < MailList.VISIBLE_EMAIL_COUNT:
            self.table.setText(i + 1, 0, "")
            self.table.setText(i + 1, 1, "")
            self.table.setText(i + 1, 2, "")
            self.table.getCellFormatter().setWordWrap(i + 1, 0, False)
            self.table.getCellFormatter().setWordWrap(i + 1, 1, False)
            self.table.getCellFormatter().setWordWrap(i + 1, 2, False)
            self.table.getFlexCellFormatter().setColSpan(i + 1, 2, 2)
            i = i + 1

    def selectRow(self, row):
        # When a row (other than the first one, which is used as a header) is
        # selected, display its associated MailItem.
        item = MailItems().getMailItem(self.startIndex + row)
        if item is None:
            return

        self.styleRow(self.selectedRow, False)
        self.styleRow(row, True)

        item.read = True
        self.selectedRow = row
        self.mailObject.get().displayItem(item)

    def styleRow(self, row, selected):
        if (row != -1):
            if (selected):
                self.table.getRowFormatter().addStyleName(
                    row + 1, "mail-SelectedRow")
            else:
                self.table.getRowFormatter().removeStyleName(
                    row + 1, "mail-SelectedRow")

    def update(self):
        # Update the older/newer buttons & label.
        count = MailItems().getMailItemCount()
        max = self.startIndex + MailList.VISIBLE_EMAIL_COUNT
        if (max > count):
            max = count

        self.newerButton.setVisible(self.startIndex != 0)
        self.olderButton.setVisible(
            self.startIndex + MailList.VISIBLE_EMAIL_COUNT < count)
        startIndexPlusOne = self.startIndex + 1
        self.countLabel.setText("%d - %d of %d" %
                                (startIndexPlusOne, max, count))

        # Show the selected emails.
        i = 0
        while (i < MailList.VISIBLE_EMAIL_COUNT):
            # Don't read past the end.
            if (self.startIndex + i >= MailItems().getMailItemCount()):
                break

            item = MailItems().getMailItem(self.startIndex + i)

            # Add a row to the table, then set each of its columns to the
            # email's sender and subject values.

            self.table.setText(i + 1, 0, item.sender)
            self.table.setText(i + 1, 1, item.email)
            self.table.setText(i + 1, 2, item.subject)

            i = i + 1

        # Clear any remaining slots.
        while (i < MailList.VISIBLE_EMAIL_COUNT):
            self.table.setHTML(i + 1, 0, "&nbsp;")
            self.table.setHTML(i + 1, 1, "&nbsp;")
            self.table.setHTML(i + 1, 2, "&nbsp;")
            i = i + 1

        # Select the first row if none is selected.
        if (self.selectedRow == -1):
            self.selectRow(0)
示例#10
0
from __pyjamas__ import JS
from fysom import Fysom
from ballotTree import Race
from pyjamas.ui import KeyboardListener
from pyjamas.ui.HorizontalPanel import HorizontalPanel
from pyjamas.ui.HTML import HTML

contestPosition = 0
candidatePosition = 0
confirm = 0
currObj = ""

contest = HorizontalPanel()
contest.setStyleName("words")
candidate = HorizontalPanel()
candidate.setStyleName("words")
selection = HorizontalPanel()
selection.setStyleName("words")
status = HorizontalPanel()
status.add(HTML("STATUS"))
status.setStyleName("words")

title = HorizontalPanel()
instructions = HorizontalPanel()

#

JS(
    """
var mainSnd = new Audio();
var snd1 = new Audio();
示例#11
0
    def onModuleLoad(self):
        self.form = FormPanel()
        self.remote_py = MyBlogService()

        self.form.setAction("/index.html")

        vp = VerticalPanel(BorderWidth=0,
                           HorizontalAlignment=HasAlignment.ALIGN_CENTER,
                           VerticalAlignment=HasAlignment.ALIGN_MIDDLE,
                           Width="100%",
                           Height="150px")
        self.form.setWidget(vp)

        header = HTML(
            "<h2>CREATE MY ACCOUNT</h2><h3>Welcome to signup form</h3>")
        part1 = header

        hpn = HorizontalPanel(BorderWidth=0,
                              HorizontalAlignment=HasAlignment.ALIGN_LEFT,
                              VerticalAlignment=HasAlignment.ALIGN_MIDDLE,
                              Width="92%",
                              Height="60px")

        self.fname = TextBox()
        self.fname.setName("fname")
        self.fname.setPlaceholder("First Name")
        hpn.add(self.fname)

        self.lname = TextBox()
        self.lname.setName("lname")
        self.lname.setPlaceholder("Last Name")
        hpn.add(self.lname)
        hpn.setCellWidth(self.fname, "70%")
        hpn.setCellWidth(self.lname, "30%")
        part2 = hpn

        self.uname = TextBox()
        self.uname.setName("uname")
        self.uname.setPlaceholder("User Name")
        part3 = self.uname

        self.password = PasswordTextBox()
        self.password.setName("passsignup")
        self.password.setPlaceholder("Choose a password")
        part4 = self.password

        self.rpassword = PasswordTextBox()
        self.rpassword.setName("rpasssignup")
        self.rpassword.setPlaceholder("Confirm your password")
        part5 = self.rpassword

        self.email = TextBox()
        self.email.setName("emailsignup")
        self.email.setPlaceholder("Enter your email address ")
        part6 = self.email

        self.errorlabel = Label()
        self.errorlabel.setStyleName("errorlabel")
        part7 = self.errorlabel

        hpanel = HorizontalPanel(BorderWidth=0,
                                 HorizontalAlignment=HasAlignment.ALIGN_CENTER,
                                 VerticalAlignment=HasAlignment.ALIGN_MIDDLE,
                                 Width="100%",
                                 Height="50px")

        partb = Button("Signup", self)
        partb.setStyleName('btn')
        image = Label("Already have account! Sign in")
        anchor = Anchor(Widget=image, Href='/index.html')
        parta = anchor

        hpanel.add(partb)
        hpanel.add(parta)
        hpanel.setStyleName("hpanel")

        part8 = hpanel

        vp.add(part1)
        vp.add(part2)
        vp.add(part3)
        vp.add(part4)
        vp.add(part5)
        vp.add(part6)
        vp.add(part7)
        vp.add(part8)

        vp.setCellHeight(part1, "5%")
        vp.setCellHeight(part2, "10%")
        vp.setCellHeight(part3, "10%")
        vp.setCellHeight(part4, "10%")
        vp.setCellHeight(part5, "10%")
        vp.setCellHeight(part6, "10%")
        vp.setCellHeight(part7, "10%")
        vp.setCellHeight(part8, "10%")

        vp.setStyleName("signup")

        self.form.addFormHandler(self)
        RootPanel().add(self.form)
示例#12
0
class pjBallot:
    
    def __init__(self):
        self.mainPanel = VerticalPanel()
        self.contest = HorizontalPanel()
        self.contest.setStyleName('words')
        self.selection = HorizontalPanel()
        self.selection.setStyleName('words')
        self.button = Button('test', self.test)
        self.status = Label('hi')
        self.x = 1
    
    def test(self):
        self.button.setText("No, really click me!")
#        Window.alert("Hello, AJAAAX!")
        self.contest.add(HTML('yay'))

    def nextContest(self):
        self.x += 1
        self.contest.clear()
        self.contest.add(HTML('<b /> Contest: %d' % self.x))

    def nextSelection(self):
        self.x += 1
        self.selection.clear()
        self.selection.add(HTML('<b /> Selection: %d' % self.x))
    
    def onKeyDown(self, sender, keycode, modifiers):
        pass

    def onKeyUp(self, sender, keycode, modifiers):
        pass

    def onKeyPress(self, sender, keycode, modifiers):
        DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) #not needed
        if keycode == KeyboardListener.KEY_UP:
            self.nextContest()
        if keycode == KeyboardListener.KEY_DOWN:
            self.nextContest()
        if keycode == KeyboardListener.KEY_LEFT:
            self.nextSelection()
        if keycode == KeyboardListener.KEY_RIGHT:
            self.nextSelection()


    def onModuleLoad(self):
        self.remote_py = JSONService()
        h = HTML("<b />Contest: ")
        self.contest.add(h)
        l = HTML("<b />Selection: ")
        self.selection.add(l)
#        self.mainPanel.add(self.button)
        self.mainPanel.add(self.contest)
        self.mainPanel.add(self.selection)
        self.mainPanel.add(self.status)
        panel = FocusPanel(Widget=self.mainPanel)
        gp = RootPanelListener(panel)
        manageRootPanel(gp)
        RootPanel().add(panel)
        panel.setFocus(True)
#        self.remote_py.uppercase('yay', self)
        self.remote_py.passBallot(self)
        
#        encoded_object = '[{"__jsonclass__": "Candidate.Candidate", "name": "Barack Obama"}]'
##        test = json2.loads(encoded_object)
##        self.mainPanel.add(HTML("%s" % test))#json.loads(encoded_object)))#, object_hook=self.dict_to_object)))
#        foo = '["foo", {"bar":["baz", null, 1.0, 2]}]'
#        bar = loads(foo, object_hook=tester)
#        self.mainPanel.add(HTML(bar))

 
    def dict_to_object(self,d):
        Window.alert("Hello, AJAAAX!")
        self.mainPanel.add(HTML('whatevs: %s' % 12))
        if '__class__' in d:
            # import pdb
            # pdb.set_trace()
            class_name = d.pop('__class__')
            module_name = d.pop('__module__')
            module = __import__(module_name)
            print 'MODULE:', module
            class_ = getattr(module.ballotTree, class_name) #because module was just audioBallot
            print 'CLASS:', class_
            args = dict( (key.encode('ascii'), value) for key, value in d.items())
            print 'INSTANCE ARGS:', args
            inst = class_(**args)
        else:
            inst = d
        return inst       
    

    
    def onRemoteResponse(self, response, request_info): 
        race = response  
        name = race.works
        self.mainPanel.add(HTML('pleasework %s' % name))
#        self.mainPanel.add(HTML('pleasework2 %s' % JSONResponseTextHandler(response)))
#        test = JSONResponseTextHandler(response)
#        test.request
#        self.mainPanel.add(HTML('pleasework3 %s' % test.name))
#        encoded_object = '[{"__jsonclass__": "Candidate.Candidate", "name": "Barack Obama"}]'
#        foo = loads(response)
#        self.mainPanel.add(HTML(foo))
#        self.mainPanel.add(HTML("not working %s"  % 12 ))#loads(response)))#, object_hook=self.dict_to_object)))
#        bar = loads('["foo", {"bar":["baz", null, 1.0, 2]}]', object_hook=tester)
#        self.mainPanel.add(HTML(bar))
#        self.status.setText(request_info.method)
    
    def onRemoteError(self):
        pass