Пример #1
0
    def __init__(self, **kwargs):
        DockPanel.__init__(self, **kwargs)
        self.grid = Grid(StyleName="datagrid")
        self.sp = ScrollPanel(self.grid, Width="100%", Height="100%")
        self.header = Grid(Height="50px")
        self.add(self.header, DockPanel.NORTH)
        self.add(self.sp, DockPanel.CENTER)
        cf = self.setCellHeight(self.header, "50px")
        cf = self.setCellHeight(self.sp, "100%")

        self.sortcol = 0
Пример #2
0
    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)

                self.g.add(blogPanel, y, x)

        self.absolultutePanel.add(self.g)
Пример #3
0
    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 = []
Пример #4
0
  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)
Пример #5
0
	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()
Пример #6
0
    def drawGrid(self, month, year):
        # draw the grid in the middle of the calendar

        daysInMonth = self.getDaysInMonth(month, year)
        # first day of the month & year
        secs = time.mktime((year, month, 1, 0, 0, 0, 0, 0, -1))
        struct = time.localtime(secs)
        # 0 - sunday for our needs instead 0 = monday in tm_wday
        startPos = (struct.tm_wday + 1) % 7
        slots = startPos + daysInMonth - 1
        rows = int(slots / 7) + 1
        grid = Grid(rows + 1, 7)  # extra row for the days in the week
        grid.setWidth("100%")
        grid.addTableListener(self)
        self.middlePanel.setWidget(grid)
        #
        # put some content into the grid cells
        #
        for i in range(7):
            grid.setText(0, i, self.getDaysOfWeek()[i])
            grid.cellFormatter.addStyleName(0, i, "calendar-header")
        #
        # draw cells which are empty first
        #
        day = 0
        pos = 0
        while pos < startPos:
            grid.setText(1, pos, " ")
            grid.cellFormatter.setStyleAttr(1, pos, "background", "#f3f3f3")
            grid.cellFormatter.addStyleName(1, pos, "calendar-blank-cell")
            pos += 1
        # now for days of the month
        row = 1
        day = 1
        col = startPos
        while day <= daysInMonth:
            if pos % 7 == 0 and day <> 1:
                row += 1
            col = pos % 7
            grid.setText(row, col, str(day))
            if self.currentYear == self.todayYear and \
               self.currentMonth == self.todayMonth and day == self.todayDay:
                grid.cellFormatter.addStyleName(row, col,
                                                "calendar-cell-today")
            else:
                grid.cellFormatter.addStyleName(row, col, "calendar-day-cell")
            day += 1
            pos += 1
        #
        # now blank lines on the last row
        #
        col += 1
        while col < 7:
            grid.setText(row, col, " ")
            grid.cellFormatter.setStyleAttr(row, col, "background", "#f3f3f3")
            grid.cellFormatter.addStyleName(row, col, "calendar-blank-cell")
            col += 1

        return grid
Пример #7
0
    def __init__(self):

        # layed out in a grid with odd rows a different color for
        # visual separation
        grid = Grid(4, 3, CellPadding=50, CellSpacing=0)
        rf = grid.getRowFormatter()
        rf.setStyleName(1, 'oddrow')
        rf.setStyleName(3, 'oddrow')

        # the clock
        clock = Clock()
        grid.setWidget(
            0, 0, CaptionPanel('Using notify()',
                               clock.button,
                               StyleName='left'))
        grid.setWidget(0, 1, clock.datelabel)
        grid.setWidget(0, 2, HTML(Clock.__doc__, StyleName='desc'))

        # popup timer buttons
        ptb = PopupTimerButton(5)
        grid.setWidget(
            1, 0, CaptionPanel('Subclassing Timer()', ptb, StyleName='left'))
        grid.setWidget(1, 1, ptb.box)
        grid.setWidget(1, 2, HTML(PopupTimerButton.__doc__, StyleName='desc'))

        # the second instance
        ptb = PopupTimerButton(15)
        grid.setWidget(
            2, 0,
            CaptionPanel('Subclassing Timer()&nbsp;&nbsp;(<em>again</em>)',
                         ptb,
                         StyleName='left'))
        grid.setWidget(2, 1, ptb.box)
        grid.setWidget(
            2, 2,
            HTML('''This is the same as the previous
                                  example and is here to demonstrate
                                  creating multiple timers (each with
                                  their own state) which is difficult
                                  to do without sublcassing''',
                 StyleName='desc'))

        # random color
        randomcolor = RandomColor()
        grid.setWidget(
            3, 0,
            CaptionPanel('Using onTimer()',
                         randomcolor.hpanel,
                         StyleName='left'))
        grid.setWidget(3, 1, randomcolor.colorpanel)
        grid.setWidget(3, 2, HTML(RandomColor.__doc__, StyleName='desc'))

        # add it all to the root panel
        RootPanel().add(grid)

        # kickstart the slider handle (see above concerning a
        # potential bug)
        randomcolor.initialize()
Пример #8
0
 def start_game(self):
     dim = self.level
     grid = Grid(dim, dim)
     grid.setStyleName("grid")
     for i in range(dim):
         for j in range(dim):
             gc = GridCell(i, j)
             grid.setWidget(i, j, gc)
     self.add(grid)
Пример #9
0
 def start_game(self, level=None):
     if level is not None:
         self.level = level
     dim = self.level
     grid = Grid(dim, dim)
     grid.setStyleName("grid")
     for i in range(dim):
         for j in range(dim):
             gc = GridCell(i, j)
             grid.setWidget(i, j, gc)
     self.add(grid)
Пример #10
0
 def __init__(self):
     DockPanel.__init__(self)
     self.grids = {}
     self.g = Grid()
     self.g.setCellSpacing("0px")
     self.g.setCellPadding("8px")
     self.title = HTML("&nbsp;")
     self.title.setStyleName("rightpanel-title")
     self.add(self.title, DockPanel.NORTH)
     self.setCellWidth(self.title, "100%")
     self.setCellHorizontalAlignment(self.title,
                                     HasHorizontalAlignment.ALIGN_LEFT)
     self.add(self.g, DockPanel.CENTER)
Пример #11
0
    def __init__(self):
        SimplePanel.__init__(self)

        grid = Grid(5, 5, BorderWidth=2, CellPadding=4, CellSpacing=1)
        grid.setHTML(0, 0, '<b>Hello, World!</b>')

        for row in range(1, 5):
            for col in range(1, 5):
                grid.setText(
                    row, col,
                    str(row) + "*" + str(col) + " = " + str(row * col))

        self.add(grid)
Пример #12
0
    def state_to_grid(self,
                      prev_x_board=-1,
                      prev_y_board=-1,
                      prev_x_cell=-1,
                      prev_y_cell=-1):
        board = self.state.boards
        for y_board in range(3):
            for x_board in range(3):

                # for this mini-grid, do i make buttons or dashes?
                will_make_buttons = self.will_buttons(y_board, x_board)

                g = Grid()
                g.resize(3, 3)
                g.setBorderWidth(2)
                g.setCellPadding(9)
                g.setCellSpacing(1)
                for y_cell in range(3):
                    for x_cell in range(3):

                        if board[y_board][x_board][y_cell][x_cell][
                                'cell'] == 0:
                            if will_make_buttons:
                                b = HTML(
                                    '<p style="color:blue">AI %d could<br>play here.</p>'
                                    % (self.state.next_piece[2]), self)
                            else:
                                b = HTML('-')

                        elif board[y_board][x_board][y_cell][x_cell][
                                'cell'] == 1:
                            if (prev_x_cell == x_cell and prev_y_cell == y_cell
                                    and prev_y_board == y_board
                                    and prev_x_board == x_board):
                                b = HTML('<p style="color:red">1</p>')
                            else:
                                b = HTML('1')
                        elif board[y_board][x_board][y_cell][x_cell][
                                'cell'] == 2:
                            if (prev_x_cell == x_cell and prev_y_cell == y_cell
                                    and prev_y_board == y_board
                                    and prev_x_board == x_board):
                                b = HTML('<p style="color:red">2</p>')
                            else:
                                b = HTML('2')
                        g.setWidget(y_cell, x_cell, b)

                self.add(g)
                self.g.setWidget(y_board, x_board, g)
Пример #13
0
    def __init__(self, provider, columns, columnStyles, rowCount):
        Composite.__init__(self)

        self.acceptor = RowDataAcceptorImpl(self)
        self.outer = DockPanel()
        self.startRow = 0
        self.grid = Grid()
        self.navbar = NavBar(self)

        self.provider = provider
        self.initWidget(self.outer)
        self.grid.setStyleName("table")
        self.outer.add(self.navbar, DockPanel.NORTH)
        self.outer.add(self.grid, DockPanel.CENTER)
        self.initTable(columns, columnStyles, rowCount)
        self.setStyleName("DynaTable-DynaTableWidget")
Пример #14
0
 def onRemoteResponse(self, response, request_info):
     method = request_info.method
     if method == 'get_documents':
         grid = Grid()
         grid.resize(len(response) + 1, 8)
         grid.setHTML(0, 0, "Comment")
         grid.setHTML(0, 1, "Episode")
         grid.setHTML(0, 2, "When")
         for (row, item) in enumerate(response):
             grid.setHTML(row + 1, 0, item.comment)
             grid.setHTML(row + 1, 1, item.episode)
             grid.setHTML(row + 1, 2, str(item.clin_when))
         #RootPanel().add(grid)
         self.add(grid)
     else:
         self.status.setText(str(response))
Пример #15
0
    def __init__(self):
        Composite.__init__(self)

        self.albums = []
        self.photos = []
        self.grid = Grid(4, 4, CellPadding=4, CellSpacing=4)
        self.grid.addTableListener(self)
        self.drill = 0
        self.pos = 0
        self.up = Button("Up", self)
        self.next = Button("Next", self)
        self.prev = Button("Prev", self)
        self.timer = Timer(notify=self)
        self.userid = "jameskhedley"
        self.album_url = "http://picasaweb.google.com/data/feed/base/user/" + self.userid + "?alt=json-in-script&kind=album&hl=en_US&callback=restCb"
        self.doRESTQuery(self.album_url, self.timer)

        self.vp = VerticalPanel()
        self.disclosure = DisclosurePanel(
            "Click for boring technical details.")
        self.disclosure.add(
            HTML(
                '''<p>OK so you want to write client JS to do a RESTful HTTP query from picasa right?
				 Well you can't because of the Same Origin Policy. Basically this means that
				 because the domain of the query and the domain of the hosted site are different,
				 then that could well be a cross-site scripting (XSS) attack. So, the workaround is to
				 do the call from a script tag so the JSON we get back is part of the document.
				 But since we don't know what URL to hit yet, once we find out then we have to inject
				 a new script tag dynamically which the browser will run as soon as we append it.
				 To be honest I'm not 100% why Google use RESTful services and not JSON-RPC or somesuch,
				 which would be easier. Well, easier for me.'''))

        self.IDPanel = HorizontalPanel()
        self.IDPanel.add(Label("Enter google account:"))
        self.IDButton = Button("Go", self)

        self.IDBox = TextBox()
        self.IDBox.setText(self.userid)
        self.IDPanel.add(self.IDBox)
        self.IDPanel.add(self.IDButton)
        self.vp.add(self.IDPanel)
        self.vp.add(self.disclosure)
        self.vp.add(self.grid)

        self.initWidget(self.vp)
Пример #16
0
    def __init__(self):
        Sink.__init__(self)
        inner = Grid(10, 5, Width="100%", BorderWidth="1")
        outer = FlexTable(Width="100%", BorderWidth="1")

        outer.setWidget(0, 0, Image(self.baseURL() + "rembrandt/LaMarcheNocturne.jpg"))
        outer.getFlexCellFormatter().setColSpan(0, 0, 2)
        outer.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER)

        outer.setHTML(1, 0, "Look to the right...<br>That's a nested table component ->")
        outer.setWidget(1, 1, inner)
        outer.getCellFormatter().setColSpan(1, 1, 2)

        for i in range(10):
            for j in range(5):
                inner.setText(i, j, "%d" % i + ",%d" % j)

        self.initWidget(outer)
Пример #17
0
  def init(self):
    '''Initializes the grid on which the game is played.
    '''
    for y_board in range(3):
      for x_board in range(3):

        g=Grid()
        g.resize(3, 3)
        g.setBorderWidth(2)
        g.setCellPadding(9)
        g.setCellSpacing(1)
        for x_cell in range(3):
          for y_cell in range(3):
            b = Button('Play here.', self)
            b.point = {'x_cell':x_cell, 'y_cell':y_cell, 'y_board': y_board, 'x_board': x_board}
            g.setWidget(y_cell, x_cell, b)

        self.add(g)
        self.g.setWidget(y_board, x_board, g)
Пример #18
0
    def onModuleLoad(self):
        
        self.input = TextBox()
        self.input.setEnabled(False)
        self.input.addKeyboardListener(self)

        self.g=Grid()
        self.g.resize(5, 5)
        self.g.setHTML(0, 0, "<b>Grid Edit</b>")
        self.g.setBorderWidth(2)
        self.g.setCellPadding(4)
        self.g.setCellSpacing(1)
        self.g.setWidth("500px")
        self.g.setHeight("120px")
        self.g.addTableListener(self)
        
        self.initGrid()
        RootPanel().add(self.input)
        RootPanel().add(self.g)
Пример #19
0
    def __init__(self):

        self.tb = TextBox()
        self.b = Button("add")
        self.g = Grid()
        self.g.resize(4, 2)

        RootPanel().add(HTML("Add Phrase.  Press Button."))
        RootPanel().add(self.tb)
        RootPanel().add(self.b)
        RootPanel().add(self.g)
        self.b.addClickListener(self)

        try:
            self.db = Factory.createDatabase()
            self.db.open('database-demo')
            self.db.execute('create table if not exists Demo' +
                            ' (Phrase varchar(255), Timestamp int)')
        except ex:
            log("could not create database" + str(ex))
Пример #20
0
    def __init__(self, svc, **kwargs):

        self.describe_listeners = []
        if kwargs.has_key('listener'):
            listener = kwargs.pop('listener')
            self.addDescribeListener(listener)

        if kwargs.has_key('data'):
            data = kwargs.pop('data')
        else:
            data = None

        FormPanel.__init__(self, **kwargs)
        self.svc = svc
        self.grid = Grid()
        self.grid.resize(0, 3)
        self.add(self.grid)
        self.describer = FormDescribeGrid(self)
        self.saver = FormSaveGrid(self)
        self.getter = FormGetGrid(self)
        self.formsetup(data)
Пример #21
0
    def __init__(self):

        self.tb = TextBox()
        self.b = Button("add")
        self.g = Grid()
        self.g.resize(4, 2)

        RootPanel().add(HTML("Add Phrase.  Press Button."))
        RootPanel().add(self.tb)
        RootPanel().add(self.b)
        RootPanel().add(self.g)
        self.b.addClickListener(self)

        try:
            self.db = Factory.createDatabase()
            self.db.open('database-demo')
            self.db.execute('create table if not exists Demo' +
                            ' (Phrase varchar(255), Timestamp int)')
        except:
            alert(
                "Could not create database.\nDo you have the google gears extension installed?"
            )
Пример #22
0
    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)
Пример #23
0
    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)
Пример #24
0
    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)
Пример #25
0
    def onModuleLoad(self):
        dlp = DockPanel(Width="100%", Height="100%")

        self.m_rte = RichTextArea(Width="500px", Height="400px")
        self.m_tb = RichTextToolbar(self.m_rte, self)

        buts = FlowPanel()
        self.m_getCurr = Button("Refresh v", self)
        self.m_setHtml = Button("Set html ^", self)
        self.m_setHtml.setTitle("Set html from the lower left text area")
        self.m_toSCursor = Button("< To Cursor", self)
        self.m_toSCursor.setTitle(
            "Set the selection to be a cursor at the beginning of the current selection"
        )
        self.m_toECursor = Button("To Cursor >", self)
        self.m_toECursor.setTitle(
            "Set the selection to be a cursor at the end of the current selection"
        )
        self.m_surround1 = Button("Surround1", self)
        self.m_surround2 = Button("Surround2", self)
        self.m_font1 = Button("Times New Roman", self)
        self.m_font2 = Button("Arial", self)

        grid = Grid(2, 2)
        self.m_startNode = self.createTextBox(1)
        self.m_startOffset = self.createTextBox(3)
        self.m_endNode = self.createTextBox(4)
        self.m_endOffset = self.createTextBox(5)
        self.m_select = Button("`>Select", self)
        self.m_select.setTitle("Select the texts/offsets in the boxes above")
        self.m_cursor = Button("`>Cursor", self)
        self.m_cursor.setTitle(
            "Set cursor to text/offset of top 2 boxes above")
        grid.setWidget(0, 0, self.m_startNode)
        grid.setWidget(0, 1, self.m_startOffset)
        grid.setWidget(1, 0, self.m_endNode)
        grid.setWidget(1, 1, self.m_endOffset)

        self.m_deleteSel = Button("Delete", self)
        self.m_reset = Button("Reset", self)

        buts.add(self.m_getCurr)
        buts.add(self.m_setHtml)
        buts.add(self.m_toSCursor)
        buts.add(self.m_toECursor)
        buts.add(self.m_font1)
        buts.add(self.m_font2)
        buts.add(self.m_surround1)
        buts.add(self.m_surround2)
        buts.add(grid)
        buts.add(self.m_select)
        buts.add(self.m_cursor)

        buts.add(self.m_deleteSel)
        buts.add(self.m_reset)

        dlp.add(buts, DockPanel.WEST)

        textPanels = DockPanel()

        self.m_html = TextArea()
        self.m_html.setSize("100%", "100%")
        self.m_sel = TextArea()
        self.m_sel.setSize("100%", "100%")

        textPanels.add(self.m_sel, DockPanel.EAST)
        textPanels.add(self.m_html, DockPanel.WEST)

        dlp.add(textPanels, DockPanel.SOUTH)
        dlp.add(self.m_tb, DockPanel.NORTH)
        dlp.add(self.m_rte, DockPanel.CENTER)

        rp = RootPanel.get()
        rp.add(dlp)

        DeferredCommand.add(getattr(self, "set_html_focus"))

        self.reset()
Пример #26
0
  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()
Пример #27
0
    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()
Пример #28
0
    def drawGrid(self, month, year):
        # draw the grid in the middle of the calendar

        self.checkLinks(month, year)

        daysInMonth = self.getDaysInMonth(month, year)
        # first day of the month & year
        secs = time.mktime((year, month, 1, 0, 0, 0, 0, 0, -1))
        struct = time.localtime(secs)
        startPos = (struct.tm_wday + self.dayoffset) % 7
        slots = startPos + daysInMonth - 1
        rows = int(slots/7) + 1
        grid = Grid(rows+1, 7, # extra row for the days in the week
                    StyleName="calendar-grid") 
        grid.setWidth("100%")
        grid.addTableListener(self)
        self.middlePanel.setWidget(grid)
        cf = grid.getCellFormatter()
        #
        # put some content into the grid cells
        #
        for i in range(7):
            grid.setText(0, i, self.getDaysOfWeek()[i])
            cf.addStyleName(0, i, "calendar-header")
        #
        # draw cells which are empty first
        #
        day = 0
        pos = 0
        while pos < startPos:
            self._setCell(grid, 1, pos, BLANKCELL, "calendar-blank-cell")
            pos += 1
        # now for days of the month
        row = 1
        day = 1
        col = startPos
        while day <= daysInMonth:
            if pos % 7 == 0 and day != 1:
                row += 1
            col = pos % 7
            if not self._indaterange(self.currentYear, self.currentMonth, day):
                self._setCell(grid, row, col, BLANKCELL, "calendar-blank-cell")
                day += 1
                pos += 1
                continue
            if self.currentYear == self.todayYear and \
               self.currentMonth == self.todayMonth and day == self.todayDay:
                style = "calendar-cell-today"
            else:
                style = "calendar-day-cell"
            self._setCell(grid, row, col, str(day), style)
            day += 1
            pos += 1
        #
        # now blank lines on the last row
        #
        col += 1
        while col < 7:
            self._setCell(grid, row, col, BLANKCELL, "calendar-blank-cell")
            col += 1

        return grid