当前位置: 首页>>代码示例>>Python>>正文


Python FlexTable.getWidget方法代码示例

本文整理汇总了Python中pyjamas.ui.FlexTable.FlexTable.getWidget方法的典型用法代码示例。如果您正苦于以下问题:Python FlexTable.getWidget方法的具体用法?Python FlexTable.getWidget怎么用?Python FlexTable.getWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyjamas.ui.FlexTable.FlexTable的用法示例。


在下文中一共展示了FlexTable.getWidget方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: onModuleLoad

# 需要导入模块: from pyjamas.ui.FlexTable import FlexTable [as 别名]
# 或者: from pyjamas.ui.FlexTable.FlexTable import getWidget [as 别名]

#.........这里部分代码省略.........
		
		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)
开发者ID:FloorLamp,项目名称:CS3300-HW4,代码行数:70,代码来源:MovieRatings.py

示例2: onModuleLoad

# 需要导入模块: from pyjamas.ui.FlexTable import FlexTable [as 别名]
# 或者: from pyjamas.ui.FlexTable.FlexTable import getWidget [as 别名]

#.........这里部分代码省略.........
        def _removeStockButton_Click(event):
            if symbol not in self.stocks:
                return
            removedIndex = self.stocks.index(symbol)
            self.remote.deleteStock(symbol, self)
            self.stocks.remove(symbol)
            self.stocksFlexTable.removeRow(removedIndex + 1)
        removeStockButton = Button('x', _removeStockButton_Click)
        removeStockButton.addStyleDependentName('remove')
        self.stocksFlexTable.setWidget(row, 3, removeStockButton)
        
        # Get the stock price
        self.refreshWatchlist()
    
    def refreshWatchlist(self):
        '''
        Update the price change for each stock
        '''
        
        MAX_PRICE = 100.0
        MAX_PRICE_CHANGE = 0.02
        
        prices = []
        for i in range(len(self.stocks)):
            price = random.random() * MAX_PRICE
            change = price * MAX_PRICE_CHANGE * (random.random() * 2.0 - 1.0)
            prices.append(StockPrice(self.stocks[i], price, change))
        
        self.updateTable(prices)
    
    def updateTable(self, prices):
        '''
        Update the price and change fields of all the rows in the stock table
        
        prices -- List of StockPrice objects for all rows
        '''
        
        # Type checking
        assert isinstance(prices, list)
        for price in prices:
            assert isinstance(price, StockPrice)
        
        # Nothing to do...
        if len(prices) == 0:
            return
        
        # Update each individual row
        for i in range(len(prices)):
            self.updateRow(prices[i])
        
        # Display timestamp showing last refresh
        self.lastUpdatedLabel.setText("Last update: %s" % datetime.datetime.now().strftime("%m/%d/%Y %I:%M:%S %p"))
    
    def updateRow(self, price):
        '''
        Update a single row in the stock table
        
        price -- StockPrice object for a single row
        '''
        
        # Type checking
        assert isinstance(price, StockPrice)
        
        # Make sure the stock is still in the stock table
        if price.symbol not in self.stocks:
            return
        
        # Find the index of 
        row = self.stocks.index(price.symbol) + 1
        
        # Populate the price and change fields with new data
        self.stocksFlexTable.setText(row, 1, '%.2f' % price.price)
        changeWidget = self.stocksFlexTable.getWidget(row, 2)
        changeWidget.setText('%.2f (%.2f%%)' % (price.change, price.getChangePercent()))
        
        # Change the color of the text in the Change field based on its value
        changeStyleName = 'noChange'
        if price.getChangePercent() < -0.1:
            changeStyleName = 'negativeChange'
        else:
            changeStyleName = 'positiveChange'
        
        changeWidget.setStyleName(changeStyleName)
    
    def onRemoteResponse(self, response, request_info):
        '''
        Called when a response is received from a RPC.
        '''
        if request_info.method in DataService.methods:
            # Compare self.stocks and the stocks in response
            stocks_set = set(self.stocks)
            response_set = set(response)
            # Add the differences
            for symbol in list(response_set.difference(stocks_set)):
                self.addStock(None, symbol)
        else:
            Window.alert('Unrecognized JSONRPC method.')
            
    def onRemoteError(self, code, message, request_info):
        Window.alert(message)
开发者ID:fedenko,项目名称:StockWatcher2,代码行数:104,代码来源:StockWatcher.py

示例3: DialogBox

# 需要导入模块: from pyjamas.ui.FlexTable import FlexTable [as 别名]
# 或者: from pyjamas.ui.FlexTable.FlexTable import getWidget [as 别名]
class DialogBox(PopupPanel):
    _props = [
        ("caption", "Caption", "HTML", None),
    ]

    def __init__(self, autoHide=None, modal=True, centered=False,
                 **kwargs):
        # Init section
        self.dragging = False
        self.dragStartX = 0
        self.dragStartY = 0
        self.child = None
        self.panel = FlexTable(
            Height="100%",
            BorderWidth="0",
            CellPadding="0",
            CellSpacing="0",
        )

        cf = self.panel.getCellFormatter()
        rf = self.panel.getRowFormatter()

        # Arguments section
        self.modal = modal
        self.caption = HTML()
        self.caption.setStyleName("Caption")
        self.caption.addMouseListener(self)

        # Make the DialogBox a 3x3 table, like GWT does, with
        # empty elements with specific style names. These can be
        # used with CSS to, for example, create border around the
        # dialog box.
        self.generate_gwt15 = kwargs.pop('gwt15', False) and True

        if not self.generate_gwt15:
            cf.setHeight(1, 0, "100%")
            cf.setWidth(1, 0, "100%")
            cf.setAlignment(
                1, 0,
                HasHorizontalAlignment.ALIGN_CENTER,
                HasVerticalAlignment.ALIGN_MIDDLE,
            )
            self.panel.setWidget(0, 0, self.caption)
        else:
            row_labels = ['Top', 'Middle', 'Bottom']
            col_labels = ['Left', 'Center', 'Right']

            for r in range(3):
                rf.setStyleName(r, 'dialog%s' % row_labels[r])
                for c in range(3):
                    cf.setStyleName(r, c, 'dialog%s%s' % (row_labels[r],
                                                          col_labels[c]))
                    sp = SimplePanel()
                    sp.setStyleName('dialog%s%sInner' % (row_labels[r],
                                                         col_labels[c]))
                    self.panel.setWidget(r, c, sp)

            cf.setAlignment(
                1, 1,
                HasHorizontalAlignment.ALIGN_CENTER,
                HasVerticalAlignment.ALIGN_MIDDLE,
            )

            self.dialog_content = SimplePanel()
            self.dialog_content.setStyleName('dialogContent')

            self.panel.getWidget(0, 1).add(self.caption)
            self.panel.getWidget(1, 1).add(self.dialog_content)

        # Finalize
        kwargs['StyleName'] = kwargs.get('StyleName', "gwt-DialogBox")
        PopupPanel.__init__(self, autoHide, modal, **kwargs)
        PopupPanel.setWidget(self, self.panel)

        self.centered = centered

    def onWindowResized(self, width, height):
        super(DialogBox, self).onWindowResized(width, height)
        if self.centered:
            self.centerBox()

    def show(self):
        super(DialogBox, self).show()
        if self.centered:
            self.centerBox()

    @classmethod
    def _getProps(self):
        return PopupPanel._getProps() + self._props

    def onEventPreview(self, event):
        # preventDefault on mousedown events, outside of the
        # dialog, to stop text-selection on dragging
        type = DOM.eventGetType(event)
        if type == 'mousedown':
            target = DOM.eventGetTarget(event)
            elem = self.caption.getElement()
            event_targets_popup = target and DOM.isOrHasChild(elem, target)
            if event_targets_popup:
                DOM.eventPreventDefault(event)
#.........这里部分代码省略.........
开发者ID:Afey,项目名称:pyjs,代码行数:103,代码来源:DialogBox.py


注:本文中的pyjamas.ui.FlexTable.FlexTable.getWidget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。