def __init__(self, parent): AbsolutePanel.__init__(self) self.userGrid = Grid() self.userGrid.createGrid(6, 6) self.userGrid.addTableListener(self) self.userGrid.setBorderWidth(2) self.userGrid.setCellPadding(4) self.userGrid.setCellSpacing(1) self.userGrid.setColLabelValue(0, "Username") self.userGrid.setColLabelValue(1, "First Name") self.userGrid.setColLabelValue(2, "Last Name") self.userGrid.setColLabelValue(3, "Email") self.userGrid.setColLabelValue(4, "Department") self.userGrid.setColLabelValue(5, "Password") self.newBtn = Button("New") self.deleteBtn = Button("Delete") self.deleteBtn.setEnabled(False) self.add(self.userGrid) self.add(self.newBtn) self.add(self.deleteBtn) return
def __init__(self,parent): AbsolutePanel.__init__(self) self.userGrid = Grid() self.userGrid.createGrid(6, 6) self.userGrid.addTableListener(self) self.userGrid.setBorderWidth(2) self.userGrid.setCellPadding(4) self.userGrid.setCellSpacing(1) self.userGrid.setColLabelValue(0,"Username") self.userGrid.setColLabelValue(1,"First Name") self.userGrid.setColLabelValue(2,"Last Name") self.userGrid.setColLabelValue(3,"Email") self.userGrid.setColLabelValue(4,"Department") self.userGrid.setColLabelValue(5,"Password") self.newBtn = Button("New") self.deleteBtn = Button("Delete") self.deleteBtn.setEnabled(False) self.add(self.userGrid) self.add(self.newBtn) self.add(self.deleteBtn) return
def remove(self, widget): if self.getWidget(0) == widget: self._container1.remove(widget) elif self.getWidget(1) == widget: self._container2.remove(widget) else: AbsolutePanel.remove(self, widget)
def __init__(self, key, title, content): AbsolutePanel.__init__(self) self.edit_header = Label("Edit a Post", StyleName="header_label") self.edit_title_label = Label("Title:") self.edit_title = TextBox() self.edit_title.setMaxLength(255) self.edit_content = TextArea() self.edit_content.setVisibleLines(2) self.edit_button = Button("Save") self.edit_cancel_button = Button("Cancel") self.edit_hidden_key = Hidden() self.error_message_label = Label("", StyleName="error_message_label") edit_contents = VerticalPanel(StyleName="Contents", Spacing=4) edit_contents.add(self.edit_header) edit_contents.add(self.edit_title_label) edit_contents.add(self.edit_title) edit_contents.add(self.edit_content) edit_contents.add(self.edit_button) edit_contents.add(self.edit_cancel_button) edit_contents.add(self.error_message_label) edit_contents.add(self.edit_hidden_key) self.edit_dialog = DialogBox(glass=True) self.edit_dialog.setHTML('<b>Blog Post Form</b>') self.edit_dialog.setWidget(edit_contents) left = (Window.getClientWidth() - 900) / 2 + Window.getScrollLeft() top = (Window.getClientHeight() - 600) / 2 + Window.getScrollTop() self.edit_dialog.setPopupPosition(left, top) self.edit_dialog.hide()
def __init__(self,parent): AbsolutePanel.__init__(self) self.roleList = ListBox() self.roleList.setWidth('300px') self.roleList.setVisibleItemCount(6) self.roleList.addChangeListener(self.onListChange) #self.roleList.addKeyboardListener(self) self.roleCombo = ListBox() self.roleCombo.addKeyboardListener(self) self.roleCombo.addChangeListener(self.onComboChange) self.addBtn = Button("Add") self.addBtn.setEnabled(False) self.removeBtn = Button("Remove") self.removeBtn.setEnabled(False) vpanel = VerticalPanel() vpanel.add(self.roleList) hpanel = HorizontalPanel() hpanel.add(self.roleCombo) hpanel.add(self.addBtn) hpanel.add(self.removeBtn) vpanel.add(hpanel) self.add(vpanel) self.clearForm() return
def __init__(self): AbsolutePanel.__init__(self) StyleSheetCssText(margins) # initialize css... header = """<div><H2 align="center">Welcome to Unbeatable Tic-Tac-Toe!</H2><br>My <a href="https://github.com/chetweger/min-max-games/blob/master/ttt/ttt.py">implementation</a> uses the min-max search algorithm with alpha beta pruning and a transposition table!</div>""" header = HTML(header, StyleName='margins_both') self.add(header) self.ai_first = Button("AI first.", self, StyleName='margins_left') self.add(self.ai_first) self.new_game = Button("New game", self, StyleName='margins_left') self.add(self.new_game) self.g=Grid(StyleName='margins_left') self.g.resize(3, 3) self.g.setBorderWidth(2) self.g.setCellPadding(4) self.g.setCellSpacing(1) self.init() self.add(self.g) self.state = State() self.game_resolution=Label("", StyleName='margins_left') self.add(self.game_resolution)
def setWidth(self, width): self.fontsize = math.floor(width / self.cols) AbsolutePanel.setWidth(self, "%dpx" % (self.cols * self.fontsize)) ratio = self.fontsize / self.fontheight DOM.setStyleAttribute(self.getElement(), 'fontSizeAdjust', str(ratio))
def setHeight(self, height): self.fontheight = math.floor(height / self.rows) AbsolutePanel.setHeight(self, "%dpx" % (self.rows * self.fontheight)) DOM.setStyleAttribute(self.getElement(), 'fontSize', "%dpx" % self.fontheight)
def setWidth(self, width): self.fontsize = math.floor(width / self.cols) AbsolutePanel.setWidth(self, "%dpx" % (self.cols*self.fontsize)) ratio = self.fontsize / self.fontheight DOM.setStyleAttribute(self.getElement(), 'fontSizeAdjust', str(ratio))
def __init__(self, parent): AbsolutePanel.__init__(self) self.roleList = ListBox() self.roleList.setWidth('300px') self.roleList.setVisibleItemCount(6) self.roleList.addChangeListener(self.onListChange) #self.roleList.addKeyboardListener(self) self.roleCombo = ListBox() self.roleCombo.addKeyboardListener(self) self.roleCombo.addChangeListener(self.onComboChange) self.addBtn = Button("Add") self.addBtn.setEnabled(False) self.removeBtn = Button("Remove") self.removeBtn.setEnabled(False) vpanel = VerticalPanel() vpanel.add(self.roleList) hpanel = HorizontalPanel() hpanel.add(self.roleCombo) hpanel.add(self.addBtn) hpanel.add(self.removeBtn) vpanel.add(hpanel) self.add(vpanel) self.clearForm() return
def __init__(self): AbsolutePanel.__init__(self) self.app = CompaniesApp() self.history = [] self.save = Button("save", self) self.selectDepartment = Button("select", self) self.selectEmployee = Button("select", self) self.edit = Button("edit", self) self.cut = Button("cut", self) self.back = Button("back", self) self.name = TextBox() self.address = TextBox() self.manager = TextBox() self.departments = ListBox(Size=("100%"), VisibleItemCount="5") self.employees = ListBox(Size=("100%"), VisibleItemCount="5") self.total = TextBox() self.errors = VerticalPanel() self.grid = Grid() self.allPanels = VerticalPanel() self.allPanels.add(self.grid) self.allPanels.add(self.errors) self.add(self.allPanels) self.initCompanyGUI()
def __init__(self, width, height): AbsolutePanel.__init__(self) self.setWidth(width) self.setHeight(height) self.window = {} self.window_zindex = {}
def __init__(self,parent): AbsolutePanel.__init__(self) ftable = FlexTable() ftable.setWidget(0, 0, Label("First Name", wordWrap=False)) ftableFormatter = ftable.getFlexCellFormatter() self.firstInput = TextBox() self.firstInput.addChangeListener(self.checkValid) self.firstInput.addKeyboardListener(self) ftable.setWidget(0, 1, self.firstInput) ftable.setWidget(1, 0, Label("Last Name", wordWrap=False)) self.lastInput = TextBox() self.lastInput.addChangeListener(self.checkValid) self.lastInput.addKeyboardListener(self) ftable.setWidget(1, 1, self.lastInput) ftable.setWidget(2, 0, Label("Email", wordWrap=False)) self.emailInput = TextBox() self.emailInput.addChangeListener(self.checkValid) self.emailInput.addKeyboardListener(self) ftable.setWidget(2, 1, self.emailInput) ftable.setWidget(3, 0, Label("Username", wordWrap=False)) self.usernameInput = TextBox() self.usernameInput.addChangeListener(self.checkValid) self.usernameInput.addKeyboardListener(self) ftable.setWidget(3, 1, self.usernameInput) ftable.setWidget(4, 0, Label("Password", wordWrap=False)) self.passwordInput = PasswordTextBox() self.passwordInput.addChangeListener(self.checkValid) self.passwordInput.addKeyboardListener(self) ftable.setWidget(4, 1, self.passwordInput) ftable.setWidget(5, 0, Label("Confirm", wordWrap=False)) self.confirmInput = PasswordTextBox() self.confirmInput.addChangeListener(self.checkValid) self.confirmInput.addKeyboardListener(self) ftable.setWidget(5, 1, self.confirmInput) ftable.setWidget(6, 0, Label("Department", wordWrap=False)) self.departmentCombo = ListBox() self.departmentCombo.addChangeListener(self.checkValid) self.departmentCombo.addKeyboardListener(self) ftable.setWidget(6, 1, self.departmentCombo) hpanel = HorizontalPanel() self.addBtn = Button("Add User", self.onAdd) self.addBtn.setEnabled(False) hpanel.add(self.addBtn) self.cancelBtn = Button("Cancel", self.onCancel) hpanel.add(self.cancelBtn) ftable.setWidget(7, 0, hpanel) ftableFormatter.setColSpan(7, 0, 2) self.add(ftable) return
def __init__(self,parent): AbsolutePanel.__init__(self) ftable = FlexTable() ftable.setWidget(0, 0, Label("First Name", wordWrap=False)) ftableFormatter = ftable.getFlexCellFormatter() self.firstInput = TextBox() self.firstInput.addChangeListener(self.checkValid) self.firstInput.addKeyboardListener(self) ftable.setWidget(0, 1, self.firstInput) ftable.setWidget(1, 0, Label("Last Name", wordWrap=False)) self.lastInput = TextBox() self.lastInput.addChangeListener(self.checkValid) self.lastInput.addKeyboardListener(self) ftable.setWidget(1, 1, self.lastInput) ftable.setWidget(2, 0, Label("Email", wordWrap=False)) self.emailInput = TextBox() self.emailInput.addChangeListener(self.checkValid) self.emailInput.addKeyboardListener(self) ftable.setWidget(2, 1, self.emailInput) ftable.setWidget(3, 0, Label("Username", wordWrap=False)) self.usernameInput = TextBox() self.usernameInput.addChangeListener(self.checkValid) self.usernameInput.addKeyboardListener(self) ftable.setWidget(3, 1, self.usernameInput) ftable.setWidget(4, 0, Label("Password", wordWrap=False)) self.passwordInput = PasswordTextBox() self.passwordInput.addChangeListener(self.checkValid) self.passwordInput.addKeyboardListener(self) ftable.setWidget(4, 1, self.passwordInput) ftable.setWidget(5, 0, Label("Confirm", wordWrap=False)) self.confirmInput = PasswordTextBox() self.confirmInput.addChangeListener(self.checkValid) self.confirmInput.addKeyboardListener(self) ftable.setWidget(5, 1, self.confirmInput) ftable.setWidget(6, 0, Label("Department", wordWrap=False)) self.departmentCombo = ListBox() self.departmentCombo.addChangeListener(self.checkValid) self.departmentCombo.addKeyboardListener(self) ftable.setWidget(6, 1, self.departmentCombo) hpanel = HorizontalPanel() self.addBtn = Button("Add User") self.addBtn.setEnabled(False) hpanel.add(self.addBtn) self.cancelBtn = Button("Cancel") hpanel.add(self.cancelBtn) ftable.setWidget(7, 0, hpanel) ftableFormatter.setColSpan(7, 0, 2) self.add(ftable) return
def __init__(self, Element=None, **kwargs): if Element is not None: kwargs['Element'] = Element AbsolutePanel.__init__(self, **kwargs) if Element is None: # avoid having CSS styles position:relative and hidden set on body Element = self.getBodyElement() self.setElement(Element) self.onAttach()
def __init__(self): self.panel = AbsolutePanel() self.edit_panel = EditPanel(self) self.home_panel = HomePanel(self) self.write_panel = WritePanel(self) self.panel.add(self.edit_panel) self.panel.add(self.home_panel) self.panel.add(self.write_panel) RootPanel().add(self.panel)
def __init__(self): SimplePanel.__init__(self) panel = AbsolutePanel(Width="100%", Height="100px") panel.add(self.makeBox("Child 1"), 20, 10) panel.add(self.makeBox("Child 2"), 30, 30) self.add(panel)
def __init__(self, parent): AbsolutePanel.__init__(self) self.home_header = Label("Blogjamas", StyleName="header_label") self.write_button = Button("Write a Post") self.edit_hidden_button = Button("", StyleName="hidden_button") self.delete_hidden_button = Button("", StyleName="hidden_button") self.add(self.home_header) self.add(self.write_button) self.add(self.edit_hidden_button) self.add(self.delete_hidden_button)
def __init__(self, dragController): Example.__init__(self, dragController) self.addStyleName(self.CSS_DEMO_ABSOLUTE_POSITION_EXAMPLE) # use the drop target as this composite's widget positioningDropTarget = AbsolutePanel() positioningDropTarget.setPixelSize(400, 200) self.setWidget(positioningDropTarget) # instantiate our drop controller self.absposdc = AbsolutePositionDropController(positioningDropTarget) dragController.registerDropController(self.absposdc)
class AppFrame(object): edit_panel = None home_panel = None write_panel = None def __init__(self): self.panel = AbsolutePanel() self.edit_panel = EditPanel(self) self.home_panel = HomePanel(self) self.write_panel = WritePanel(self) self.panel.add(self.edit_panel) self.panel.add(self.home_panel) self.panel.add(self.write_panel) RootPanel().add(self.panel)
def __init__(self, cols, rows, width, height): AbsolutePanel.__init__(self) self.rows = rows self.cols = cols self.setStyleName("gwt-TextWindow") DOM.setStyleAttribute(self.getElement(), 'fontFamily', 'monospace') self.setHeight(height) self.setWidth(width) self.text = {} for x in range(self.cols): self.text[x] = {}
def __init__(self): SimplePanel.__init__(self) panel = AbsolutePanel() panel.add(self.makeBox("Child 1"), 20, 10) panel.add(self.makeBox("Child 2"), 30, 30) panel.setWidth("100%") panel.setHeight("100px") self.add(panel)
def __init__(self, **kwargs): """ setMatchPattern - defaults to '' to match everything match pattern examples: '^[0-9]*$' is for digits only '^[0-9,A-Z]*$' is for digits and uppercase setMaxLength setText OB """ kwargs['MatchPattern'] = kwargs.pop('MatchPattern', '') cs = kwargs.pop('CursorStyle', "inputbox-cursor") gs = kwargs.pop('StyleName', 'gwt-inputbox') ap = AbsolutePanel(StyleName="inputbox") self.tp = Grid(StyleName=gs, Width="100%", Height="100%", CellPadding=0, CellSpacing=0) self.cursor = HTML(StyleName=cs) ap.add(self.tp) ap.add(self.cursor, 0, 0) self.cf = self.tp.getCellFormatter() FocusPanel.__init__(self, Widget=ap, **kwargs) self.addTableListener(self) self.addKeyboardListener(self) self.addFocusListener(self) self.word_selected_pos = 0 self.ctimer = Timer(notify=self.cursorFlash) self.focusset = False self.cstate = False self._keypressListeners = []
def __init__(self, vertical=False, **kwargs): # set defaults if not 'StyleName' in kwargs: if vertical: # vertical split panel kwargs['StyleName'] = "gwt-VerticalSplitPanel" else: kwargs['StyleName'] = "gwt-HorizontalSplitPanel" # splitter drag state vars self._drag_start = None self._pos = "50%" # orientation self._vertical = vertical # now init the bases AbsolutePanel.__init__(self, **kwargs) MouseHandler.__init__(self) # add our event support? self.addListenedEvent("Resize") # create the top/left widget container self._container1 = ScrollPanel() # create the bottom/right widget container self._container2 = ScrollPanel() # create the splitter self._splitter = SplitPanelSplitter(self) # add splitter handling self._splitter.addMouseListener(self) # add mouse event handling self.addMouseListener(self) # add the parts AbsolutePanel.add(self, self._container1, 0, 0) AbsolutePanel.add(self, self._splitter, 0, 0) AbsolutePanel.add(self, self._container2, 0, 0) # set the layout if vertical: # vertical split panel self._splitter.setStyleName("vsplitter") self._splitter.setWidth("100%") self._container1.setWidth("100%") self._container2.setWidth("100%") # set drag cursor DOM.setStyleAttribute(self._splitter.getElement(), "cursor", "n-resize") else: # horizontal split panel self._splitter.setStyleName("hsplitter") self._splitter.setHeight("100%") self._container1.setHeight("100%") self._container2.setHeight("100%") # set drag cursor DOM.setStyleAttribute(self._splitter.getElement(), "cursor", "e-resize")
def __init__(self): AbsolutePanel.__init__(self) self.page = 0 self.min_page = 1 self.max_page = 10 self.addb = Button("Next >", self) self.subb = Button("< Prev", self) self.g = Grid() self.g.resize(5, 5) self.g.setHTML(0, 0, "<b>Grid Test</b>") self.g.setBorderWidth(2) self.g.setCellPadding(4) self.g.setCellSpacing(1) self.updatePageDisplay() self.add(self.subb) self.add(self.addb) self.add(self.g)
def __init__(self): AbsolutePanel.__init__(self) self.page=0 self.min_page=1 self.max_page=10 self.addb=Button("Next >", self) self.subb=Button("< Prev", self) self.g=Grid() self.g.resize(5, 5) self.g.setHTML(0, 0, "<b>Grid Test</b>") self.g.setBorderWidth(2) self.g.setCellPadding(4) self.g.setCellSpacing(1) self.updatePageDisplay() self.add(self.subb) self.add(self.addb) self.add(self.g)
def __init__(self, parent): AbsolutePanel.__init__(self) self.post_header = Label("Write a Post", StyleName="header_label") self.post_write_title_label = Label("Title:") self.post_title = TextBox() self.post_content = TextArea() self.post_button = Button("Post") self.cancel_button = Button("Cancel") self.error_message_label = Label("", StyleName="error_message_label") contents = VerticalPanel(StyleName="Contents", Spacing=4) contents.add(self.post_header) contents.add(self.post_write_title_label) contents.add(self.post_title) contents.add(self.post_content) contents.add(self.post_button) contents.add(self.cancel_button) contents.add(self.error_message_label) self.dialog = DialogBox(glass=True) self.dialog.setHTML('<b>Blog Post Form</b>') self.dialog.setWidget(contents) left = (Window.getClientWidth() - 900) / 2 + Window.getScrollLeft() top = (Window.getClientHeight() - 600) / 2 + Window.getScrollTop() self.dialog.setPopupPosition(left, top) self.dialog.hide()
def __init__(self): self.state = State() self.game_round = 0 self.TD_CONSTS = {'c3': 1., 'c2': 1., 'c1': 1., 'c6': 1., 'c5': 1., 'c4': 1.} self.CONSTS = {'c3': .5, 'c2': 1., 'c1': 3., 'c6': .5, 'c5': .5, 'c4': .5} self.BEST_CONSTANTS = {'c3': 0.767944, 'c2': 1.049451, 'c1': 3.074038, 'c6': 0.220823, 'c5': 0.281883, 'c4': 0.605861} self.ONES_CONSTS = {'c3': 1., 'c2': 1., 'c1': 1., 'c6': 1., 'c5': 1., 'c4': 1.} AbsolutePanel.__init__(self) self.welcome_label = HTML('<H2 align="center">Welcome to Meta-Tic-Tac-Toe!</H2>To watch the AI play itself, press either "begin game" button. Note: if there is a pop-up saying that the script is taking a long time to complete, this is not a bug - the AI is just taking a while to find the next move. Select the option to continue the script.', StyleName='margins_both') self.add(self.welcome_label) self.depth_limit = 2 self.train_td = Button("Begin game. Learning AI first!", self, StyleName='margins_left') self.add(self.train_td) self.train_static = Button("Begin game. Static AI first!", self, StyleName='margins_left') self.add(self.train_static) self.score_label = Label("CURRENT SCORE: Learning AI: %d | Static AI: %d"% (0,0), StyleName='margins_left') self.add(self.score_label) self.game_over_message = Label("", StyleName='margins_left') self.add(self.game_over_message) StyleSheetCssText(margins) self.increase_depth = Button("Increase ply search depth.", self) self.decrease_depth = Button("Decrease ply search depth.", self) self.depth_label = Label("Current depth is " + str(self.depth_limit) +".") self.depth_grid = Grid(StyleName='margins_left') self.depth_grid.resize(1, 3) self.depth_grid.setBorderWidth(2) self.depth_grid.setCellPadding(9) self.depth_grid.setCellSpacing(1) self.add(self.depth_grid) self.depth_grid.setWidget(0, 0, self.decrease_depth) self.depth_grid.setWidget(0, 1, self.depth_label) self.depth_grid.setWidget(0, 2, self.increase_depth) # initialize the board grid: self.g=Grid(StyleName='margins_left') self.g.resize(3, 3) self.g.setBorderWidth(2) self.g.setCellPadding(9) self.g.setCellSpacing(1) self.init() self.add(self.g) # initialize the contstants adjustment grid: self.adj_grid = Grid(StyleName='margins_left') self.adj_grid.resize(7, 4) self.adj_grid.setBorderWidth(2) self.adj_grid.setCellPadding(9) self.adj_grid.setCellSpacing(1) self.init_constants_adj_grid() self.add(self.adj_grid) self.reset_constants = Button("Reset all of Learning AI's constants to 1.", self, StyleName='margins_left') self.add(self.reset_constants) self.state_to_grid()
def getElement(self, index=None): if index is None: return AbsolutePanel.getElement(self) return self.getWidget(index).getElement()
class Home: def onModuleLoad(self): loggedInUser = getCookie("LoggedInUser") self.loggedInUserJsonData = json.loads(loggedInUser) self.remote_py = MyBlogService() dockPanel = DockPanel(BorderWidth=0, Padding=0, HorizontalAlignment=HasAlignment.ALIGN_LEFT, VerticalAlignment=HasAlignment.ALIGN_TOP) dockPanel.setSize('100%', '100%') headerDockPanel = DockPanel( BorderWidth=0, Padding=0, HorizontalAlignment=HasAlignment.ALIGN_LEFT, VerticalAlignment=HasAlignment.ALIGN_CENTER) headerDockPanel.setStyleName('header') headerDockPanel.setWidth('100%') dockPanel.add(headerDockPanel, DockPanel.NORTH) dockPanel.setCellHeight(headerDockPanel, '60px') self.siteImage = Image("/images/Testware_logo.png") self.siteImage.setStyleName('logo-image') headerDockPanel.add(self.siteImage, DockPanel.WEST) headerDockPanel.setCellWidth(self.siteImage, '30%') self.pageTitle = Label('All Blogs') self.pageTitle.setStyleName('center-header') headerDockPanel.add(self.pageTitle, DockPanel.CENTER) headerDockPanel.setCellWidth(self.pageTitle, '40%') rightHeaderPanel = VerticalPanel(StyleName='right-header') headerDockPanel.add(rightHeaderPanel, DockPanel.EAST) headerDockPanel.setCellWidth(rightHeaderPanel, '30%') welcomeNoteLabel = Label('Hi %s %s!' % (self.loggedInUserJsonData["first_name"], self.loggedInUserJsonData["last_name"])) rightHeaderPanel.add(welcomeNoteLabel) logoutAnchor = Anchor(Widget=HTML('Logout'), Href='/', Title='Logout') logoutAnchor.setStyleName('logout') rightHeaderPanel.add(logoutAnchor) newBlogAnchor = Anchor(Widget=HTML('Create New Blog'), Href='/newblog.html', Title='NewBlog') newBlogAnchor.setStyleName('logout') rightHeaderPanel.add(newBlogAnchor) tree = Tree() tree.addTreeListener(self) tree.setStyleName('side-menu') dockPanel.add(tree, DockPanel.WEST) dockPanel.setCellWidth(tree, '60px') s1 = self.createItem("Blogs") allItem = self.createItem("All", value=0) self.selectedItem = allItem s1.addItem(allItem) s1.addItem(self.createItem("Published", value=1)) s1.addItem(self.createItem("Unpublished", value=2)) s2 = self.createItem("Other's Blog") s1.setState(True, fireEvents=False) tree.addItem(s1) tree.addItem(s2) self.absolultutePanel = AbsolutePanel(StyleName='detail-style') dockPanel.add(self.absolultutePanel, DockPanel.CENTER) self.blogs = [] self.g = Grid() RootPanel().add(dockPanel) self.remote_py.callMethod('getBlogs', [self.loggedInUserJsonData["username"]], self) def updatePageDisplay(self): self.g.removeFromParent() self.g = Grid() self.g.setStyleName('content-style') self.g.addTableListener(self) for y in range(len(self.blogs)): for x in range(1): json_data = json.loads(self.blogs[y]) blogPanel = VerticalPanel() blogTitleAnchor = Anchor(Widget=HTML('%s' % json_data["blog_name"]), Href='/blogdetail.html') blogTitleAnchor.setStyleName('blog-search-title') blogPanel.add(blogTitleAnchor) blogDetails = Label() blogDetails.setStyleName('blog-details') blogContent = json_data["blog_content"] if len(blogContent) > 200: blogContent = blogContent[0:200] + '......' blogDetails.setText('%s' % (blogContent)) blogPanel.add(blogDetails) value = self.selectedItem.getUserObject() if self.selectedItem.getText() == "All" and value == 0: blogStatus = Label() blogStatus.setStyleName('blog-details') if json_data["is_published"] == True: blogStatus.setText('Published') else: blogStatus.setText('Unpublished') blogPanel.add(blogStatus) self.g.add(blogPanel, y, x) self.absolultutePanel.add(self.g) def createItem(self, label, value=None): item = TreeItem(label) DOM.setStyleAttribute(item.getElement(), "cursor", "pointer") if value is not None: item.setUserObject(value) return item def onTreeItemSelected(self, item): self.selectedItem = item if item.getText() == "Other's Blog": self.remote_py.callMethod('getOthersPublishedBlogs', [self.loggedInUserJsonData["username"]], self) else: value = item.getUserObject() if value == 0: self.remote_py.callMethod( 'getBlogs', [self.loggedInUserJsonData["username"]], self) elif value == 1: self.remote_py.callMethod( 'getPublishedBlogs', [self.loggedInUserJsonData["username"]], self) elif value == 2: self.remote_py.callMethod( 'getUnPublishedBlogs', [self.loggedInUserJsonData["username"]], self) def onTreeItemStateChanged(self, item): pass # We ignore this. def onRemoteResponse(self, response, requestInfo): self.blogs = response self.updatePageDisplay() if self.selectedItem.getText() == "Other's Blog": self.pageTitle.setText("Other's Blog") else: value = self.selectedItem.getUserObject() if value == 0: self.pageTitle.setText('All Blogs') elif value == 1: self.pageTitle.setText('Published Blogs') elif value == 2: self.pageTitle.setText('Unpublished Blogs') def onRemoteError(self, code, error_dict, requestInfo): pass def onCellClicked(self, sender, row, col): setCookie("SelectedBlog", self.blogs[row], 10000, path='/') setCookie("ShowPublishButton", 'False', 10000, path='/')
def onAttach(self): AbsolutePanel.onAttach(self) self.setSplitPosition()
def setHeight(self, height): self.fontheight = math.floor(height / self.rows) AbsolutePanel.setHeight(self, "%dpx" % (self.rows*self.fontheight)) DOM.setStyleAttribute(self.getElement(), 'fontSize', "%dpx" % self.fontheight)
def onModuleLoad(self): loggedInUser = getCookie("LoggedInUser") self.loggedInUserJsonData = json.loads(loggedInUser) self.remote_py = MyBlogService() dockPanel = DockPanel(BorderWidth=0, Padding=0, HorizontalAlignment=HasAlignment.ALIGN_LEFT, VerticalAlignment=HasAlignment.ALIGN_TOP) dockPanel.setSize('100%', '100%') headerDockPanel = DockPanel( BorderWidth=0, Padding=0, HorizontalAlignment=HasAlignment.ALIGN_LEFT, VerticalAlignment=HasAlignment.ALIGN_CENTER) headerDockPanel.setStyleName('header') headerDockPanel.setWidth('100%') dockPanel.add(headerDockPanel, DockPanel.NORTH) dockPanel.setCellHeight(headerDockPanel, '60px') self.siteImage = Image("/images/Testware_logo.png") self.siteImage.setStyleName('logo-image') headerDockPanel.add(self.siteImage, DockPanel.WEST) headerDockPanel.setCellWidth(self.siteImage, '30%') self.pageTitle = Label('All Blogs') self.pageTitle.setStyleName('center-header') headerDockPanel.add(self.pageTitle, DockPanel.CENTER) headerDockPanel.setCellWidth(self.pageTitle, '40%') rightHeaderPanel = VerticalPanel(StyleName='right-header') headerDockPanel.add(rightHeaderPanel, DockPanel.EAST) headerDockPanel.setCellWidth(rightHeaderPanel, '30%') welcomeNoteLabel = Label('Hi %s %s!' % (self.loggedInUserJsonData["first_name"], self.loggedInUserJsonData["last_name"])) rightHeaderPanel.add(welcomeNoteLabel) logoutAnchor = Anchor(Widget=HTML('Logout'), Href='/', Title='Logout') logoutAnchor.setStyleName('logout') rightHeaderPanel.add(logoutAnchor) newBlogAnchor = Anchor(Widget=HTML('Create New Blog'), Href='/newblog.html', Title='NewBlog') newBlogAnchor.setStyleName('logout') rightHeaderPanel.add(newBlogAnchor) tree = Tree() tree.addTreeListener(self) tree.setStyleName('side-menu') dockPanel.add(tree, DockPanel.WEST) dockPanel.setCellWidth(tree, '60px') s1 = self.createItem("Blogs") allItem = self.createItem("All", value=0) self.selectedItem = allItem s1.addItem(allItem) s1.addItem(self.createItem("Published", value=1)) s1.addItem(self.createItem("Unpublished", value=2)) s2 = self.createItem("Other's Blog") s1.setState(True, fireEvents=False) tree.addItem(s1) tree.addItem(s2) self.absolultutePanel = AbsolutePanel(StyleName='detail-style') dockPanel.add(self.absolultutePanel, DockPanel.CENTER) self.blogs = [] self.g = Grid() RootPanel().add(dockPanel) self.remote_py.callMethod('getBlogs', [self.loggedInUserJsonData["username"]], self)
def __init__(self): self.state = State() self.game_over = False self.TD_CONSTS = {'c3': 0.767944, 'c2': 1.049451, 'c1': 3.074038, 'c6': 0.220823, 'c5': 0.281883, 'c4': 0.605861} AbsolutePanel.__init__(self) StyleSheetCssText(margins) # initialize css... self.welcome_label = HTML('<H2 align="center">Welcome to Meta-Tic-Tac-Toe!</H2><p>Play first by clicking on one of the positions in the middle board or let the AI go first by clicking on "AI first". To change the difficulty click on "Increase/Decrease search depth". Note: if there is a pop-up saying that the script is taking a long time to complete, this is not a bug - the AI is just taking a while to find the next move. Select the option to continue the script.</p>', StyleName='margins_both') self.add(self.welcome_label) self.depthLimit = 3 self.human_first = True self.ai_first = Button("AI first.", self, StyleName='margins_left') self.add(self.ai_first) self.increase_depth = Button("Increase search depth", self) self.decrease_depth = Button("Decrease search depth", self) self.depth_label = HTML("""AI will search to a <a href="#depth_explanation">depth</a> of """ + str(self.depthLimit) +".") self.depth_grid = Grid(StyleName='margins_left') self.depth_grid.resize(1, 3) self.depth_grid.setBorderWidth(2) self.depth_grid.setCellPadding(9) self.depth_grid.setCellSpacing(1) self.add(self.depth_grid) self.depth_grid.setWidget(0, 0, self.decrease_depth) self.depth_grid.setWidget(0, 1, self.depth_label) self.depth_grid.setWidget(0, 2, self.increase_depth) self.new_game = Button("New game", self, StyleName='margins_left') self.add(self.new_game) self.score_label = Label("CURRENT SCORE: Human: %d | AI: %d"% (0,0), StyleName='margins_left') self.add(self.score_label) self.game_over_msg = HTML("", StyleName='margins_left') self.add(self.game_over_msg) # initialize the board grid: self.g=Grid(StyleName='margins_left') self.g.resize(3, 3) self.g.setBorderWidth(2) self.g.setCellPadding(9) self.g.setCellSpacing(1) self.init() self.add(self.g) # initialize the contstants adjustment grid: self.adj_grid = Grid(StyleName='margins_left') self.adj_grid.resize(7, 3) self.adj_grid.setBorderWidth(2) self.adj_grid.setCellPadding(9) self.adj_grid.setCellSpacing(1) self.init_constants_adj_grid() self.add(self.adj_grid) self.max_player = '-1' self.min_player = '-1' self.state_to_grid()
findMovie(result['movie_id']) findRating(result['movie_id']) mainpage.mid = result['movie_id'] class Site: def __init__(self): self.mid = None HTTPRequest().asyncGet("http://student02.cse.nd.edu:40001/recommendations/156", getRec(self)) if __name__=='__main__': pyjd.setup("public/primer.html") mainpage = Site() l = Label("Enter movie ID:") movie = Label("Movie Title Displayed Here if Found") movieRating = Label("Movie Rating Displayed Here if Found") poster = Image() b1 = Button("Up",upvote) b2 = Button("Down", downvote) absolute = AbsolutePanel() absolute.add(poster,50,25) absolute.add(b1,0,100) absolute.add(b2,250,100) absolute.add(movie,50,0) absolute.add(movieRating,50,315) absolute.setWidth("100%") absolute.setHeight("100%") RootPanel().add(absolute) pyjd.run()
def __init__(self): self.state = State() self.game_round = 0 self.TD_CONSTS = { 'c3': 1., 'c2': 1., 'c1': 1., 'c6': 1., 'c5': 1., 'c4': 1. } self.CONSTS = { 'c3': .5, 'c2': 1., 'c1': 3., 'c6': .5, 'c5': .5, 'c4': .5 } self.BEST_CONSTANTS = { 'c3': 0.767944, 'c2': 1.049451, 'c1': 3.074038, 'c6': 0.220823, 'c5': 0.281883, 'c4': 0.605861 } self.ONES_CONSTS = { 'c3': 1., 'c2': 1., 'c1': 1., 'c6': 1., 'c5': 1., 'c4': 1. } AbsolutePanel.__init__(self) self.welcome_label = HTML( '<H2 align="center">Welcome to Meta-Tic-Tac-Toe!</H2>To watch the AI play itself, press either "begin game" button. Note: if there is a pop-up saying that the script is taking a long time to complete, this is not a bug - the AI is just taking a while to find the next move. Select the option to continue the script.', StyleName='margins_both') self.add(self.welcome_label) self.depth_limit = 2 self.train_td = Button("Begin game. Learning AI first!", self, StyleName='margins_left') self.add(self.train_td) self.train_static = Button("Begin game. Static AI first!", self, StyleName='margins_left') self.add(self.train_static) self.score_label = Label( "CURRENT SCORE: Learning AI: %d | Static AI: %d" % (0, 0), StyleName='margins_left') self.add(self.score_label) self.game_over_message = Label("", StyleName='margins_left') self.add(self.game_over_message) StyleSheetCssText(margins) self.increase_depth = Button("Increase ply search depth.", self) self.decrease_depth = Button("Decrease ply search depth.", self) self.depth_label = Label("Current depth is " + str(self.depth_limit) + ".") self.depth_grid = Grid(StyleName='margins_left') self.depth_grid.resize(1, 3) self.depth_grid.setBorderWidth(2) self.depth_grid.setCellPadding(9) self.depth_grid.setCellSpacing(1) self.add(self.depth_grid) self.depth_grid.setWidget(0, 0, self.decrease_depth) self.depth_grid.setWidget(0, 1, self.depth_label) self.depth_grid.setWidget(0, 2, self.increase_depth) # initialize the board grid: self.g = Grid(StyleName='margins_left') self.g.resize(3, 3) self.g.setBorderWidth(2) self.g.setCellPadding(9) self.g.setCellSpacing(1) self.init() self.add(self.g) # initialize the contstants adjustment grid: self.adj_grid = Grid(StyleName='margins_left') self.adj_grid.resize(7, 4) self.adj_grid.setBorderWidth(2) self.adj_grid.setCellPadding(9) self.adj_grid.setCellSpacing(1) self.init_constants_adj_grid() self.add(self.adj_grid) self.reset_constants = Button( "Reset all of Learning AI's constants to 1.", self, StyleName='margins_left') self.add(self.reset_constants) self.state_to_grid()
context.dropController.onMove(context) def dragStart(self): super.dragStart() WidgetLocation currentDraggableLocation = WidgetLocation(context.draggable, context.boundaryPanel) if getBehaviorDragProxy(): movablePanel = newDragProxy(context) context.boundaryPanel.add(movablePanel, currentDraggableLocation.getLeft(), currentDraggableLocation.getTop()) else: saveSelectedWidgetsLocationAndStyle() AbsolutePanel container = AbsolutePanel() DOM.setStyleAttribute(container.getElement(), "overflow", "visible") container.setPixelSize(context.draggable.getOffsetWidth(), context.draggable.getOffsetHeight()) context.boundaryPanel.add(container, currentDraggableLocation.getLeft(), currentDraggableLocation.getTop()) int draggableAbsoluteLeft = context.draggable.getAbsoluteLeft() int draggableAbsoluteTop = context.draggable.getAbsoluteTop() for Iterator iterator = context.selectedWidgets.iterator(); iterator.hasNext();: Widget widget = (Widget) iterator.next() if widget != context.draggable: int relativeX = widget.getAbsoluteLeft() - draggableAbsoluteLeft int relativeY = widget.getAbsoluteTop() - draggableAbsoluteTop container.add(widget, relativeX, relativeY)
mainpage.mid = result['movie_id'] class Site: def __init__(self): self.mid = None HTTPRequest().asyncGet( "http://student02.cse.nd.edu:40001/recommendations/156", getRec(self)) if __name__ == '__main__': pyjd.setup("public/primer.html") mainpage = Site() l = Label("Enter movie ID:") movie = Label("Movie Title Displayed Here if Found") movieRating = Label("Movie Rating Displayed Here if Found") poster = Image() b1 = Button("Up", upvote) b2 = Button("Down", downvote) absolute = AbsolutePanel() absolute.add(poster, 50, 25) absolute.add(b1, 0, 100) absolute.add(b2, 250, 100) absolute.add(movie, 50, 0) absolute.add(movieRating, 50, 315) absolute.setWidth("100%") absolute.setHeight("100%") RootPanel().add(absolute) pyjd.run()