def __init__(self, baseURL): DialogBox.__init__(self, glass=True) self.setText("Sample DialogBox with embedded Frame") iframe = Frame(baseURL + "rembrandt/LaMarcheNocturne.html") closeButton = Button("Close", self) msg = HTML( "<center>This is an example of a standard dialog box component.<br> You can put pretty much anything you like into it,<br>such as the following IFRAME:</center>", True) dock = DockPanel() dock.setSpacing(4) dock.add(closeButton, DockPanel.SOUTH) dock.add(msg, DockPanel.NORTH) dock.add(iframe, DockPanel.CENTER) dock.setCellHorizontalAlignment(closeButton, HasAlignment.ALIGN_RIGHT) dock.setCellWidth(iframe, "100%") dock.setWidth("100%") iframe.setWidth("36em") iframe.setHeight("20em") self.setWidget(dock) # Work around for IE/MSHTML Issue 511 self.initURL = iframe.getUrl() self.iframe = iframe
class HelpAboutDlg(DialogBox): def __init__(self, left = 50, top = 50): try: DialogBox.__init__(self, modal = False) self.setPopupPosition(left, top) self.dockPanel = DockPanel() self.dockPanel.setSpacing(4) self.setText("About") msg = HTML("""\ This is an example application, which uses PureMVC<br/> <br/> """, True) self.dockPanel.add(msg, DockPanel.CENTER) self.closeBtn = Button("Close", self) self.dockPanel.add(self.closeBtn, DockPanel.SOUTH) self.setWidget(self.dockPanel) except: raise def onClick(self, sender): self.hide()
def __init__(self, app): self.app = app DialogWindow.__init__( self, modal=False, minimize=True, maximize=True, close=True, ) self.closeButton = Button("Close", self) self.saveButton = Button("Save", self) self.setText("Sample DialogWindow with embedded image") self.msg = HTML("", True) global _editor_id _editor_id += 1 editor_id = "editor%d" % _editor_id #self.ht = HTML("", ID=editor_id) self.txt = TextArea(Text="", VisibleLines=30, CharacterWidth=80, ID=editor_id) dock = DockPanel() dock.setSpacing(4) hp = HorizontalPanel(Spacing="5") hp.add(self.saveButton) hp.add(self.closeButton) dock.add(hp, DockPanel.SOUTH) dock.add(self.msg, DockPanel.NORTH) dock.add(self.txt, DockPanel.CENTER) dock.setCellHorizontalAlignment(hp, HasAlignment.ALIGN_RIGHT) dock.setCellWidth(self.txt, "100%") dock.setWidth("100%") self.setWidget(dock) self.editor_id = editor_id self.editor_created = False
def __init__(self, baseURL): DialogBox.__init__(self, glass=True) self.setText("Sample DialogBox with embedded Frame") iframe = Frame(baseURL + "rembrandt/LaMarcheNocturne.html") closeButton = Button("Close", self) msg = HTML("<center>This is an example of a standard dialog box component.<br> You can put pretty much anything you like into it,<br>such as the following IFRAME:</center>", True) dock = DockPanel() dock.setSpacing(4) dock.add(closeButton, DockPanel.SOUTH) dock.add(msg, DockPanel.NORTH) dock.add(iframe, DockPanel.CENTER) dock.setCellHorizontalAlignment(closeButton, HasAlignment.ALIGN_RIGHT) dock.setCellWidth(iframe, "100%") dock.setWidth("100%") iframe.setWidth("36em") iframe.setHeight("20em") self.setWidget(dock) # Work around for IE/MSHTML Issue 511 self.initURL = iframe.getUrl() self.iframe = iframe
def __init__(self, baseURL): DialogWindow.__init__( self, modal=False, minimize=True, maximize=True, close=True, ) closeButton = Button("Close", self) imgname = self.images.pop(0) self.images.append(imgname) self.setText("Sample DialogWindow with embedded image") img = Image("%srembrandt/%s" % (baseURL, imgname)) msg = HTML( "<center>This is an example of a standard dialog box component.<br> You can put pretty much anything you like into it,<br>such as the following image '%s':</center>" % imgname, True) dock = DockPanel() dock.setSpacing(4) dock.add(closeButton, DockPanel.SOUTH) dock.add(msg, DockPanel.NORTH) dock.add(img, DockPanel.CENTER) dock.setCellHorizontalAlignment(closeButton, HasAlignment.ALIGN_RIGHT) dock.setCellWidth(img, "100%") dock.setWidth("100%") self.setWidget(dock)
def __init__(self, operations,after,type='rel'): DialogWindow.__init__(self, modal=True, close=True) self.formula = Formula([]) self.after=after left = 100 top = 100 self.ops_with_buttons = [{"op": op, "button": Button(op.name, self)} for op in operations if op.available] dock = DockPanel() dock.setSpacing(3) for owb in self.ops_with_buttons: dock.add(owb['button'], DockPanel.NORTH) dock.setWidth("300") self.image = Image(latex_to_url(self.formula.fill_with_placeholders().to_latex())) dock.add(self.image, DockPanel.EAST) dock.setCellHorizontalAlignment(self.image, HasAlignment.ALIGN_TOP) self.doneButton=Button("Done",self) self.doneButton.setEnabled(False) dock.add(self.doneButton,DockPanel.SOUTH) dock.add(HTML(""),DockPanel.CENTER) self.setText("opkop") self.setPopupPosition(left, top) self.setStyleAttribute("background-color", "#ffffff") self.setStyleAttribute("color", "blue") self.setStyleAttribute("border-width", "5px") self.setStyleAttribute("border-style", "solid") self.setWidget(dock)
class HelpAboutDlg(DialogBox): def __init__(self, left=50, top=50): try: DialogBox.__init__(self, modal=False) self.setPopupPosition(left, top) self.dockPanel = DockPanel() self.dockPanel.setSpacing(4) self.setText("About") msg = HTML( """\ This is an example application, which uses PureMVC<br/> <br/> """, True) self.dockPanel.add(msg, DockPanel.CENTER) self.closeBtn = Button("Close", self) self.dockPanel.add(self.closeBtn, DockPanel.SOUTH) self.setWidget(self.dockPanel) except: raise def onClick(self, sender): self.hide()
def onModuleLoad(self): self.singleton = self topPanel = TopPanel() rightPanel = VerticalPanel() self.mailDetail = MailDetail() self.shortcuts = Shortcuts() topPanel.setWidth("100%") # MailList uses Mail.get() in its constructor, so initialize it after # 'singleton'. mailList = MailList(self.singleton) mailList.setWidth("100%") # Create the right panel, containing the email list & details. rightPanel.add(mailList) rightPanel.add(self.mailDetail) mailList.setWidth("100%") self.mailDetail.setWidth("100%") # Create a dock panel that will contain the menu bar at the top, # the shortcuts to the left, and the mail list & details taking the rest. outer = DockPanel() outer.add(topPanel, DockPanel.NORTH) outer.add(self.shortcuts, DockPanel.WEST) outer.add(rightPanel, DockPanel.CENTER) outer.setWidth("100%") outer.setSpacing(4) outer.setCellWidth(rightPanel, "100%") # Hook the window resize event, so that we can adjust the UI. #FIXME need implementation # Window.addWindowResizeListener(this) Window.addWindowResizeListener(self) # Get rid of scrollbars, and clear out the window's built-in margin, # because we want to take advantage of the entire client area. Window.enableScrolling(False) Window.setMargin("0px") # Finally, add the outer panel to the RootPanel, so that it will be # displayed. #RootPanel.get().add(outer) # FIXME get# RootPanel().add(outer) RootPanel().add(Logger()) # Call the window resized handler to get the initial sizes setup. Doing # this in a deferred command causes it to occur after all widgets' sizes # have been computed by the browser. DeferredCommand.add(self)
def __init__(self, sink): SimplePanel.__init__(self) self.sink = sink self.caption = HTML() self.child = None self.showing = False self.dragging = False self.dragStartX = 0 self.dragStartY = 0 self.panel = FlexTable() self.collapse = Image("./images/cancel.png") self.collapse.addClickListener(self) dock = DockPanel() dock.setSpacing(0) dock.add(self.collapse, DockPanel.EAST) dock.add(self.caption, DockPanel.WEST) dock.setCellHorizontalAlignment(self.collapse, HasAlignment.ALIGN_RIGHT) dock.setCellVerticalAlignment(self.collapse, HasAlignment.ALIGN_TOP) dock.setCellHorizontalAlignment(self.caption, HasAlignment.ALIGN_LEFT) dock.setCellWidth(self.caption, "100%") dock.setWidth("100%") dock.setHeight("100%") self.panel.setWidget(0, 0, dock) self.panel.setHeight("100%") self.panel.setWidth("100%") self.panel.setBorderWidth(0) self.panel.setCellPadding(0) self.panel.setCellSpacing(0) self.panel.getCellFormatter().setHeight(1, 0, "100%") self.panel.getCellFormatter().setWidth(1, 0, "100%") self.panel.getCellFormatter().setAlignment( 1, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP) SimplePanel.setWidget(self, self.panel) self.setStyleName("gwt-DialogBox") self.caption.setStyleName("Caption") self.collapse.setStyleName("Close") dock.setStyleName("Header") #self.caption.addMouseListener(self) self.collapsed = False self.collapsed_width = "15px" self.uncollapsed_width = "100%"
def __init__(self, sink): SimplePanel.__init__(self) self.sink = sink self.caption = HTML() self.child = None self.showing = False self.dragging = False self.dragStartX = 0 self.dragStartY = 0 self.panel = FlexTable() self.collapse = Image("./images/cancel.png") self.collapse.addClickListener(self) dock = DockPanel() dock.setSpacing(0) dock.add(self.collapse, DockPanel.EAST) dock.add(self.caption, DockPanel.WEST) dock.setCellHorizontalAlignment(self.collapse, HasAlignment.ALIGN_RIGHT) dock.setCellVerticalAlignment(self.collapse, HasAlignment.ALIGN_TOP) dock.setCellHorizontalAlignment(self.caption, HasAlignment.ALIGN_LEFT) dock.setCellWidth(self.caption, "100%") dock.setWidth("100%") dock.setHeight("100%") self.panel.setWidget(0, 0, dock) self.panel.setHeight("100%") self.panel.setWidth("100%") self.panel.setBorderWidth(0) self.panel.setCellPadding(0) self.panel.setCellSpacing(0) self.panel.getCellFormatter().setHeight(1, 0, "100%") self.panel.getCellFormatter().setWidth(1, 0, "100%") self.panel.getCellFormatter().setAlignment(1, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP) SimplePanel.setWidget(self, self.panel) self.setStyleName("gwt-DialogBox") self.caption.setStyleName("Caption") self.collapse.setStyleName("Close") dock.setStyleName("Header") #self.caption.addMouseListener(self) self.collapsed = False self.collapsed_width = "15px" self.uncollapsed_width = "100%"
def __init__(self, identifier, autoHide=None, modal=False, rootpanel=None): PopupPanel.__init__(self, autoHide, modal, rootpanel) self.identifier = identifier self.caption = HTML() self.child = None self.showing = False self.dragging = False self.dragStartX = 0 self.dragStartY = 0 self.panel = FlexTable() self.closeButton = Image('cancel.png') self.closeButton.addClickListener(self) dock = DockPanel() dock.setSpacing(0) dock.add(self.closeButton, DockPanel.EAST) dock.add(self.caption, DockPanel.WEST) dock.setCellHorizontalAlignment(self.closeButton, HasAlignment.ALIGN_RIGHT) dock.setCellHorizontalAlignment(self.caption, HasAlignment.ALIGN_LEFT) dock.setCellWidth(self.caption, '100%') dock.setWidth('100%') self.panel.setWidget(0, 0, dock) self.panel.setHeight('100%') self.panel.setBorderWidth(0) self.panel.setCellPadding(0) self.panel.setCellSpacing(0) self.panel.getCellFormatter().setHeight(1, 0, '100%') self.panel.getCellFormatter().setWidth(1, 0, '100%') #self.panel.getCellFormatter().setAlignment(1, 0, # HasHorizontalAlignment.ALIGN_CENTER, # HasVerticalAlignment.ALIGN_MIDDLE) PopupPanel.setWidget(self, self.panel) self.setStyleName('gwt-DialogBox') self.caption.setStyleName('Caption') self.closeButton.setStyleName('Close') dock.setStyleName('Header') self.caption.addMouseListener(self)
def __init__(self, name, html): DialogBox.__init__(self) self.setText(name) closeButton = Button("Close", self) htp = HTMLPanel(html) self.sp = ScrollPanel(htp) dock = DockPanel() dock.setSpacing(4) dock.add(closeButton, DockPanel.SOUTH) dock.add(self.sp, DockPanel.CENTER) dock.setCellHorizontalAlignment(closeButton, HasAlignment.ALIGN_RIGHT) dock.setCellWidth(self.sp, "100%") dock.setWidth("100%") self.setWidget(dock)
class PopupFrame(DialogBoxModal): def __init__(self, identifier, title, iframe): if modal_popups.has_key(identifier): return modal_popups[identifier] = self DialogBoxModal.__init__(self, identifier) self.setText(title) self.iframe = iframe #closeButton = Button("Close", self) #msg = HTML("<center>IFRAME:</center>", True) self.iframe.setStyleName("gwt-DialogFrame") self.dock = DockPanel() self.dock.setSpacing(4) #dock.add(closeButton, DockPanel.SOUTH) #dock.add(msg, DockPanel.NORTH) self.dock.add(self.iframe, DockPanel.CENTER) #dock.setCellHorizontalAlignment(closeButton, HasAlignment.ALIGN_RIGHT) self.dock.setCellWidth(self.iframe, "100%") self.dock.setWidth("100%") #self.iframe.setWidth("320px") #self.iframe.setHeight("200px") self.setWidget(self.dock) def setUrl(self, url): self.iframe.setUrl(url) def onClick(self, sender): self.hide() def set_width(self, width): self.iframe.setWidth("%dpx" % width) def set_height(self, height): self.iframe.setHeight("%dpx" % height)
def __init__(self, identifier, autoHide=None, modal=False, rootpanel=None): PopupPanel.__init__(self, autoHide, modal, rootpanel) self.identifier = identifier self.caption = HTML() self.child = None self.showing = False self.dragging = False self.dragStartX = 0 self.dragStartY = 0 self.panel = FlexTable() self.closeButton = Image("images/cancel.png") self.closeButton.addClickListener(self) dock = DockPanel() dock.setSpacing(0) dock.add(self.closeButton, DockPanel.EAST) dock.add(self.caption, DockPanel.WEST) dock.setCellHorizontalAlignment(self.closeButton, HasAlignment.ALIGN_RIGHT) dock.setCellHorizontalAlignment(self.caption, HasAlignment.ALIGN_LEFT) dock.setCellWidth(self.caption, "100%") dock.setWidth("100%") self.panel.setWidget(0, 0, dock) self.panel.setHeight("100%") self.panel.setBorderWidth(0) self.panel.setCellPadding(0) self.panel.setCellSpacing(0) self.panel.getCellFormatter().setHeight(1, 0, "100%") self.panel.getCellFormatter().setWidth(1, 0, "100%") #self.panel.getCellFormatter().setAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE) PopupPanel.setWidget(self, self.panel) self.setStyleName("gwt-DialogBox") self.caption.setStyleName("Caption") self.closeButton.setStyleName("Close") dock.setStyleName("Header") self.caption.addMouseListener(self)
def __init__(self, url): DialogBox.__init__(self) self.setText("Upload Files") iframe = Frame(url) closeButton = Button("Close", self) msg = HTML("<center>Upload files, here. Please avoid spaces in file names.<br />(rename the file before uploading)</center>", True) dock = DockPanel() dock.setSpacing(4) dock.add(closeButton, DockPanel.SOUTH) dock.add(msg, DockPanel.NORTH) dock.add(iframe, DockPanel.CENTER) dock.setCellHorizontalAlignment(closeButton, HasAlignment.ALIGN_RIGHT) dock.setCellWidth(iframe, "100%") dock.setWidth("100%") iframe.setWidth("800px") iframe.setHeight("600px") self.setWidget(dock)
class HelpContentsDlg(DialogBox): def __init__(self, left = 50, top = 50): try: DialogBox.__init__(self, modal = False) self.setPopupPosition(left, top) self.dockPanel = DockPanel() self.dockPanel.setSpacing(4) self.setText("Help Contents") self.setWidth('80%') msg = HTML("""\ <h2>Introduction</h2> This application can be used to maintain a timesheet. <p/> On startup, it tries to open the last opened timesheet. <p/> There are two modes: Edit and Summary (see menu). In edit mode the user can enter/modify his timescheet. There's some inteligence built in. The 'From' is filled in automatically when the previous line has a 'To'. The 'To' can be filled in as time span, or as end-time. The 'Project' is mandatory (as the 'From' and 'To' are). The user can walk around with the cursor keys. <h2>Opening and saving sheets</h2> The sheet can be loaded and saved from a local file. There might be some issues with Firefox, which might refuse access to the document in an iframe. <br/> """, True) self.dockPanel.add(msg, DockPanel.CENTER) self.closeBtn = Button("Close", self) self.dockPanel.add(self.closeBtn, DockPanel.SOUTH) self.setWidget(self.dockPanel) except: raise def onClick(self, sender): self.hide()
class HelpContentsDlg(DialogBox): def __init__(self, left=50, top=50): try: DialogBox.__init__(self, modal=False) self.setPopupPosition(left, top) self.dockPanel = DockPanel() self.dockPanel.setSpacing(4) self.setText("Help Contents") self.setWidth('80%') msg = HTML( """\ <h2>Introduction</h2> This application can be used to maintain a timesheet. <p/> On startup, it tries to open the last opened timesheet. <p/> There are two modes: Edit and Summary (see menu). In edit mode the user can enter/modify his timescheet. There's some inteligence built in. The 'From' is filled in automatically when the previous line has a 'To'. The 'To' can be filled in as time span, or as end-time. The 'Project' is mandatory (as the 'From' and 'To' are). The user can walk around with the cursor keys. <h2>Opening and saving sheets</h2> The sheet can be loaded and saved from a local file. There might be some issues with Firefox, which might refuse access to the document in an iframe. <br/> """, True) self.dockPanel.add(msg, DockPanel.CENTER) self.closeBtn = Button("Close", self) self.dockPanel.add(self.closeBtn, DockPanel.SOUTH) self.setWidget(self.dockPanel) except: raise def onClick(self, sender): self.hide()
def __init__(self, baseURL): DialogWindow.__init__( self, modal=False, minimize=True, maximize=True, close=True, ) closeButton = Button("Close", self) imgname = self.images.pop(0) self.images.append(imgname) self.setText("Sample DialogWindow with embedded image") img = Image("%srembrandt/%s" % (baseURL, imgname)) msg = HTML("<center>This is an example of a standard dialog box component.<br> You can put pretty much anything you like into it,<br>such as the following image '%s':</center>" % imgname, True) dock = DockPanel() dock.setSpacing(4) dock.add(closeButton, DockPanel.SOUTH) dock.add(msg, DockPanel.NORTH) dock.add(img, DockPanel.CENTER) dock.setCellHorizontalAlignment(closeButton, HasAlignment.ALIGN_RIGHT) dock.setCellWidth(img, "100%") dock.setWidth("100%") self.setWidget(dock)
def __init__(self, url): DialogBox.__init__(self) self.setText("Upload Files") iframe = Frame(url) closeButton = Button("Close", self) msg = HTML( "<center>Upload files, here. Please avoid spaces in file names.<br />(rename the file before uploading)</center>", True) dock = DockPanel() dock.setSpacing(4) dock.add(closeButton, DockPanel.SOUTH) dock.add(msg, DockPanel.NORTH) dock.add(iframe, DockPanel.CENTER) dock.setCellHorizontalAlignment(closeButton, HasAlignment.ALIGN_RIGHT) dock.setCellWidth(iframe, "100%") dock.setWidth("100%") iframe.setWidth("800px") iframe.setHeight("600px") self.setWidget(dock)
def __init__(self): DialogBox.__init__(self) # Use this opportunity to set the dialog's caption. self.setText("About the Mail Sample") # Create a DockPanel to contain the 'about' label and the 'OK' button. outer = DockPanel() outer.setSpacing(4) outer.add(Image(AboutDialog.LOGO_IMAGE), DockPanel.WEST) # Create the 'OK' button, along with a listener that hides the dialog # when the button is clicked. Adding it to the 'south' position within # the dock causes it to be placed at the bottom. buttonPanel = HorizontalPanel() buttonPanel.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT) buttonPanel.add(Button("Close", self)) outer.add(buttonPanel, DockPanel.SOUTH) # Create the 'about' label. Placing it in the 'rest' position within the # dock causes it to take up any remaining space after the 'OK' button # has been laid out. textplain = "This sample application demonstrates the construction " textplain += "of a complex user interface using pyjamas' built-in widgets. Have a look " textplain += "at the code to see how easy it is to build your own apps!" text = HTML(textplain) text.setStyleName("mail-AboutText") outer.add(text, DockPanel.CENTER) # Add a bit of spacing and margin to the dock to keep the components from # being placed too closely together. outer.setSpacing(8) self.setWidget(outer)
class LoginWindow (DialogBox, ZillaWindow): def __init__ (self, **kwargs): ZillaWindow.__init__(self, kwargs) DialogBox.__init__(self, kwargs) self.dockPanel = DockPanel() self.dockPanel.setSpacing(4) self.setText ("Logowanie") hpanel1 = HorizontalPanel() login = TextBox() login.setText("Login") #hpanel1.add(login) passwd = TextBox() passwd.setText("Hasło") self.dockPanel.add(login, DockPanel.NORTH) self.dockPanel.add(passwd, DockPanel.NORTH) #hpanel1.add(passwd) #self.add(hpanel1) self.add(login) self.add(passwd) def login(self): return True def join_game (self): return True def quit (self): return True
class LoginWindow(DialogBox, ZillaWindow): def __init__(self, **kwargs): ZillaWindow.__init__(self, kwargs) DialogBox.__init__(self, kwargs) self.dockPanel = DockPanel() self.dockPanel.setSpacing(4) self.setText("Logowanie") hpanel1 = HorizontalPanel() login = TextBox() login.setText("Login") #hpanel1.add(login) passwd = TextBox() passwd.setText("Hasło") self.dockPanel.add(login, DockPanel.NORTH) self.dockPanel.add(passwd, DockPanel.NORTH) #hpanel1.add(passwd) #self.add(hpanel1) self.add(login) self.add(passwd) def login(self): return True def join_game(self): return True def quit(self): return True
class FileOpenDlg(DialogBox): files = None def __init__(self, left = 50, top = 50, fileLocation = None): global has_getAsText try: DialogBox.__init__(self, modal = False) self.filename = None self.data = None self.setPopupPosition(left, top) self.dockPanel = DockPanel() self.dockPanel.setSpacing(4) self.setText("File Open") if not fileLocation is None: msg = HTML("Loading file...", True) self.dockPanel.add(msg, DockPanel.NORTH) location = fileLocation if fileLocation.find("://") < 0: base = Window.getLocation().getHref() if base.find('/') >= 0: sep = '/' else: sep = '\\' base = sep.join(base.split(sep)[:-1]) + sep location = base + fileLocation self.iframe = Frame(location) self.dockPanel.add(self.iframe, DockPanel.CENTER) else: msg = HTML("Choose a file", True) self.browseFile = FileUpload() elem = self.browseFile.getElement() if False and has_getAsText and hasattr(elem, 'files'): self.iframe = None self.files = elem.files self.dockPanel.add(self.browseFile, DockPanel.CENTER) else: self.browseFile = None self.files = None base = '' + doc().location if base.find('/') >= 0: sep = '/' else: sep = '\\' if not base.lower()[:5] == "file:": base = "file:///C:/" msg = HTML("You'll have to place the application on a local file system, otherwise the browser forbids access.", True) else: base = sep.join(base.split(sep)[:-1]) + sep self.iframe = Frame(base) self.dockPanel.add(self.iframe, DockPanel.CENTER) self.dockPanel.add(msg, DockPanel.NORTH) if self.iframe: self.iframe.setWidth("36em") hpanel = HorizontalPanel() self.openBtn = Button("Open", self.onClickOpen) hpanel.add(self.openBtn) self.cancelBtn = Button("Cancel", self.onClickCancel) hpanel.add(self.cancelBtn) self.dockPanel.add(hpanel, DockPanel.SOUTH) self.setWidget(self.dockPanel) except: raise def onClickCancel(self, sender): self.hide() def onClickOpen(self, sender): global has_getAsText data = None filename = None if self.files: if self.files.length == 0: return if self.files.length > 1: alert("Cannot open more than one file") return file = self.files.item(0) filename = file.fileName try: data = file.getAsText("") except AttributeError, e: has_getAsText = False alert("Sorry. cannot retrieve file in this browser.\nTry again.") else:
class FormulaBuilder(DialogWindow): def __init__(self, operations, after, **kwargs): DialogWindow.__init__(self, modal=True, close=True) self.formula = Formula([]) self.after = after if "type" in kwargs: self.type = kwargs["type"] else: self.type = 'rel' self.set_styles() def op_button_click(op): def aio(): self.add_op(op) return aio self.ops_with_buttons = [{ "op": op, "button": Button(op.name, op_button_click(op)) } for op in operations] for owb in self.ops_with_buttons: self.add_button(owb["button"]) self.var = list() self.is_clicked = list() self.textbox = list() self.set_variables((0 if self.type == 'exp' else 5)) def set_variables(self, no_of_vars, x=True): def name(n): return "var" + str(n) def print_scheme(n): return ["\\alpha", "\\beta", "\\gamma", "\\delta", "\\epsilon"][n] def button_click(n): def sopa(): if not self.is_clicked[n]: v = Operation(name(n), 0, self.textbox[n].getText(), name(n), Operation.VARIABLE) self.var[n] = v self.textbox[n].setEnabled(False) self.is_clicked[n] = True self.add_op(self.var[n]) return sopa for i in range(no_of_vars): h = HorizontalPanel() b = Button("variable", button_click(i)) h.add(b) self.is_clicked.append(False) self.var.append(None) t = TextBox() self.textbox.append(t) t.setText(print_scheme(i)) h.add(t) self.add_button(h) def set_styles(self): self.dock = DockPanel() self.dock.setSpacing(3) self.dock.setWidth("300") self.image = Image( latex_to_url(self.formula.fill_with_placeholders().to_latex())) self.dock.add(self.image, DockPanel.EAST) self.dock.setCellHorizontalAlignment(self.image, HasAlignment.ALIGN_TOP) self.backspaceButton_add() self.doneButton_add() self.dock.add(HTML(""), DockPanel.CENTER) left = 100 top = 100 self.setText("opkop") self.setPopupPosition(left, top) self.setStyleAttribute("background-color", "#ffffff") self.setStyleAttribute("color", "blue") self.setStyleAttribute("border-width", "5px") self.setStyleAttribute("border-style", "solid") self.setWidget(self.dock) def doneButton_add(self): def doneButton_click(): self.hide() self.after(self.formula) self.doneButton = Button("Done", doneButton_click) self.doneButton.setEnabled(False) self.dock.add(self.doneButton, DockPanel.SOUTH) def backspaceButton_add(self): def backspaceButton_click(): self.formula = Formula(self.formula.body[:-1]) self.refresh() self.backspaceButton = Button("Backspace", backspaceButton_click) self.backspaceButton.setEnabled(False) self.dock.add(self.backspaceButton, DockPanel.SOUTH) def refresh(self): self.image.setUrl( latex_to_url(self.formula.fill_with_placeholders().to_latex())) self.doneButton.setEnabled(self.formula.is_closed()) self.backspaceButton.setEnabled(len(self.formula.body) >= 0) def add_button(self, b): self.dock.add(b, DockPanel.NORTH) def add_op(self, op): if not self.formula.is_closed(): self.formula.add_one_op(op, self.type) self.refresh()
def indent(contents, all=None, left=None, right=None, top=None, bottom=None, hIndent=None, vIndent=None): """ Add a wrapper around the given contents to indent it. The parameters are as follows: 'contents' The contents to indent. This should be a widget or a panel. 'all' The indent to use for all four sides. This is the first argument, allowing you to call indent(c, 20) to indent the contents on all sides by the same amount. 'left' The left indent to use. 'right' The right indent to use. 'top' The top indent to use. 'bottom' The bottom indent to use. 'hIndent' The indent to use for the left and right sides. 'vIndent' The indent to use for the top and bottom. The contents will be wrapped in a panel which include whitespace on each side of the panel as specified. Upon completion, we return a Panel object contained the wrapped-up contents. """ if all is not None: left = all right = all top = all bottom = all if hIndent is not None: left = hIndent right = hIndent if vIndent is not None: top = vIndent bottom = vIndent wrapper = DockPanel() wrapper.setSpacing(0) wrapper.add(contents, DockPanel.CENTER) if left > 0: padding = Whitespace(width=left) wrapper.add(padding, DockPanel.WEST) if top > 0: padding = Whitespace(height=top) wrapper.add(padding, DockPanel.NORTH) if right > 0: padding = Whitespace(width=right) wrapper.add(padding, DockPanel.EAST) if bottom > 0: padding = Whitespace(height=bottom) wrapper.add(padding, DockPanel.SOUTH) return wrapper
class FileOpenDlg(DialogBox): files = None def __init__(self, left=50, top=50, fileLocation=None): global has_getAsText try: DialogBox.__init__(self, modal=False) self.setPopupPosition(left, top) self.dockPanel = DockPanel() self.dockPanel.setSpacing(4) self.setText("File Open") if not fileLocation is None: msg = HTML("Loading file...", True) self.dockPanel.add(msg, DockPanel.NORTH) location = fileLocation if fileLocation.find("://") < 0: base = Window.getLocation().getHref() print base if base.find("/") >= 0: sep = "/" else: sep = "\\" base = sep.join(base.split(sep)[:-1]) + sep location = base + fileLocation self.iframe = Frame(location) self.dockPanel.add(self.iframe, DockPanel.CENTER) else: msg = HTML("Choose a file", True) self.browseFile = FileUpload() elem = self.browseFile.getElement() if False and has_getAsText and hasattr(elem, "files"): self.iframe = None self.files = elem.files self.dockPanel.add(self.browseFile, DockPanel.CENTER) else: self.browseFile = None self.files = None base = "" + doc().location if base.find("/") >= 0: sep = "/" else: sep = "\\" if not base.lower()[:5] == "file:": base = "file:///C:/" msg = HTML( "You'll have to place the application on a local file system, otherwise the browser forbids access.", True, ) else: base = sep.join(base.split(sep)[:-1]) + sep self.iframe = Frame(base) self.dockPanel.add(self.iframe, DockPanel.CENTER) self.dockPanel.add(msg, DockPanel.NORTH) if self.iframe: self.iframe.setWidth("36em") hpanel = HorizontalPanel() self.openBtn = Button("Open", self) hpanel.add(self.openBtn) self.cancelBtn = Button("Cancel", self) hpanel.add(self.cancelBtn) self.dockPanel.add(hpanel, DockPanel.SOUTH) self.setWidget(self.dockPanel) except: raise def onClick(self, sender): global has_getAsText if sender == self.cancelBtn: self.hide() elif sender == self.openBtn: data = None filename = None if self.files: if self.files.length == 0: return if self.files.length > 1: alert("Cannot open more than one file") return file = self.files.item(0) filename = file.fileName try: data = file.getAsText("") except AttributeError, e: has_getAsText = False alert("Sorry. cannot retrieve file in this browser.\nTry again.") else: elem = self.iframe.getElement() # On firefox, this runs into: # Permission denied to get property Window.document # when the file is not in the current domain body = elem.contentWindow.document.body try: filename = "" + elem.contentWindow.location except: filename = None if body.childNodes.length == 1: data = "" + body.childNodes.item(0).innerHTML else: data = "" + body.innerHTML self.hide() if data: self.mediator.sendNotification(Notification.FILE_LOADED, (filename, data))
class IntroPage: DiceInstance = 0 VarTempScore = 0 #Temporary Score Variable VarTotScore = [] #Total Score Variable CountTurn = 1 #Count to display player number in Temporary Score Board def __init__(self): self.DPanel = DockPanel(HorizontalAlignment = HasAlignment.ALIGN_CENTER, Spacing=10) # Creates the Docker Panel Instance self.VPanel = VerticalPanel() # Creates the Vertical Panel Instance self.VPanel1 = VerticalPanel() # Creates the Vertical Panel Instance self.HPanel = HorizontalPanel() # Creates a Horizontal Panel Instance self.HPanel1 = HorizontalPanel()# Creates a Horizontal Panel Instance self.image=Image()#Creates the Image instance to embed the images of dice self.DummyUrl = self.image.getUrl() self.timer = Timer(notify=self.StillImage)#Timer for display of gif animation self.timerRButton = Timer(notify=self.OneAlert)#Timer for controlling states of Roll button #whenever the output of the dice is 1 self.RollButton = Button("Roll", getattr(self, "RollButtonPressed")) #Initially Disabled self.RollButton.setEnabled(False) self.BankButton = Button("Bank", getattr(self, "BankButtonPressed")) #Initially Disabled self.BankButton.setEnabled(False) #The start button controls both the number players as well the winning score self.StartButton = Button("Start", getattr(self, "StartButtonPressed")) #Intially Enabled self.StartButton.setEnabled(True) self.PlayerNum = TextBox() #Enter the Number of Players self.WinScore = TextBox() #Enter the Target Score self.PlayerNum.setText("0") self.WinScore.setText("0") # self.OK = Button("OK", getattr(self, "okButtonPressed")) self.NameScore = FlexTable() #main score board self.NameScore.setStyleName("NameScore") self.TempBoard = FlexTable() #Temporary score board self.TempBoard.setStyleName("TempBoard") self.TxtInstructions = HTML() def StartButtonPressed(self): self.CountTurn = 1 if int(self.PlayerNum.getText()) >= 2 and int(self.PlayerNum.getText()) <= 6 and int(self.WinScore.getText()) >= 10 and int(self.WinScore.getText()) <= 100: self.DPanel.remove(self.TxtInstructions, DockPanel.CENTER) self.BankButton.setVisible(True) self.RollButton.setVisible(True) # self.image.setVisible(True) self.TempBoard.setVisible(True) self.NameScore.setVisible(True) self.image = Image( self.DummyUrl + "images/0.png") self.image.setSize("200px", "300px") self.DPanel.add(self.image, DockPanel.CENTER) RootPanel().add(self.DPanel) self.StartButton.setEnabled(False) self.PlayerNum.setEnabled(False) self.WinScore.setEnabled(False) self.RollButton.setEnabled(True) self.TempBoard.setText(1,0,"Player"+str(1)) self.TempBoard.setText(1, 1, "0") self.NameScore.getRowFormatter().addStyleName(self.CountTurn,"Rows") else: Window.alert("Please Enter Correct Parameters " ) #Command for alert window return 0 VarPlayer = ["Player" + str(i) for i in xrange(1,int(self.PlayerNum.getText())+1)] i = 0 while i < int(self.PlayerNum.getText()): self.NameScore.setText(i+1, 0, VarPlayer[i]) self.NameScore.setText(i+1, 1, "0") self.VarTotScore.append(0) #m*1 vector of zeros indicating the initial scores i += 1 def OneAlert(self): AlrtTxt = " Sorry, your turn is over" Window.alert(AlrtTxt) self.timerRButton.cancel() self.RollButton.setEnabled(True) def StillImage(self): self.DPanel.remove(self.image, DockPanel.CENTER) self.image = Image( self.DummyUrl + "images/" +str(self.DiceInstance)+".png") self.image.setSize("300px", "300px") self.DPanel.add(self.image, DockPanel.CENTER) self.DPanel.setCellHeight(self.image, "300px") self.DPanel.setCellWidth(self.image, "600px") RootPanel().add(self.DPanel) self.timer.cancel() if self.DiceInstance != 1: self.TempBoard.setText(1, 1, self.DiceInstance + int(self.TempBoard.getText(1, 1))) self.BankButton.setEnabled(True) self.RollButton.setEnabled(True) else: self.NameScore.getRowFormatter().removeStyleName(self.CountTurn,"Rows") self.RollButton.setEnabled(False) self.timerRButton.schedule(1500) self.CountTurn += 1 if self.CountTurn % int(self.PlayerNum.getText()) == 1: self.CountTurn = 1 self.TempBoard.setText(1,0,"Player"+str(self.CountTurn)) self.TempBoard.setText(1, 1, "0") self.NameScore.getRowFormatter().addStyleName(self.CountTurn,"Rows"); else: self.TempBoard.setText(1,0,"Player"+str(self.CountTurn)) self.TempBoard.setText(1, 1, "0") self.NameScore.getRowFormatter().addStyleName(self.CountTurn,"Rows"); def RollButtonPressed(self): self.DiceInstance = random.randint(1, 6) # value turned after rolling the dice self.DPanel.remove(self.image, DockPanel.CENTER) self.image = Image("http://www.animatedimages.org/data/media/710/animated-dice-image-0064.gif") self.image.setSize("100px", "200px") self.DPanel.add(self.image, DockPanel.CENTER) self.DPanel.setCellHeight(self.image, "300px") self.DPanel.setCellWidth(self.image, "600px") RootPanel().add(self.DPanel) self.BankButton.setEnabled(False) self.RollButton.setEnabled(False) self.timer.schedule(3000) def BankButtonPressed(self): self.BankButton.setEnabled(False) self.NameScore.setText(self.CountTurn, 1, int(self.NameScore.getText(self.CountTurn, 1)) + int(self.TempBoard.getText(1,1))) if int(self.NameScore.getText(self.CountTurn, 1)) >= int(self.WinScore.getText()): AlrtTxt = "Congratulation!!! Player"+ str(self.CountTurn) + " wins !!!!" Window.alert(AlrtTxt) self.DPanel.remove(self.image, DockPanel.CENTER) self.DPanel.add(self.TxtInstructions, DockPanel.CENTER) self.BankButton.setVisible(False) self.RollButton.setVisible(False) # self.image.setVisible(False) self.TempBoard.setVisible(False) self.NameScore.setVisible(False) i = int(self.PlayerNum.getText()) while i > 0: self.NameScore. removeRow(i) i -= 1 self.TempBoard.setText(1,0,"X") self.TempBoard.setText(1, 1, "0") self.StartButton.setEnabled(True) # self.OK.setEnabled(True) self.PlayerNum.setEnabled(True) self.WinScore.setEnabled(True) self.RollButton.setEnabled(False) self.BankButton.setEnabled(False) self.NameScore.getRowFormatter().removeStyleName(self.CountTurn,"Rows"); self.DPanel.remove(self.image, DockPanel.CENTER) self.image = Image( self.DummyUrl + "images/0.png") self.image.setSize("200px", "300px") self.DPanel.add(self.image, DockPanel.CENTER) self.DPanel.setCellHeight(self.image, "200px") self.DPanel.setCellWidth(self.image, "400px") RootPanel().add(self.DPanel) else: self.NameScore.getRowFormatter().removeStyleName(self.CountTurn,"Rows"); self.CountTurn += 1 if self.CountTurn % int(self.PlayerNum.getText()) == 1: self.CountTurn = 1 self.TempBoard.setText(1,0,"Player"+str(self.CountTurn)) self.TempBoard.setText(1, 1, "0") self.NameScore.getRowFormatter().addStyleName(self.CountTurn,"Rows"); else: self.TempBoard.setText(1,0,"Player"+str(self.CountTurn)) self.TempBoard.setText(1, 1, "0") self.NameScore.getRowFormatter().addStyleName(self.CountTurn,"Rows"); def OnGameLoad(self): self.NameScore.setText(0, 0, "Player ID") self.NameScore.setText(0, 1, "Score") self.NameScore.setCellSpacing(10) self.NameScore.setCellPadding(10) self.NameScore.setBorderWidth(2) self.NameScore.setVisible(False) self.TempBoard.setText(0, 0, "Player's Turn") self.TempBoard.setText(0, 1, "Temporary Score") self.TempBoard.setText(1, 0, "X") self.TempBoard.setText(1, 1, "0") self.TempBoard.setCellSpacing(10) self.TempBoard.setCellPadding(10) self.TempBoard.setBorderWidth(2) self.TempBoard.setVisible(False) #Adding StartButton to Dock panel self.DPanel.add(self.StartButton, DockPanel.EAST) self.DPanel.setCellHeight(self.StartButton, "200px") self.DPanel.setCellWidth(self.StartButton, "20px") Txt = HTML("<center><b>Enter Number of Players (between 2 & 6)</b><center>")#Adding playernumber and winscore textbox to Horizontal Panel Txt1 = HTML("<left><b>Enter Target Score (between 10 & 100)</b><left>") self.HPanel1.add(Txt) self.HPanel1.add(self.PlayerNum) self.HPanel1.add(Txt1) self.HPanel1.add(self.WinScore) self.HPanel1.add(self.StartButton) self.HPanel1.setSpacing(20) #Adding Horizontal panel containing playernumber and winscore textbox to Dock Panel self.DPanel.add(self.HPanel1, DockPanel.NORTH) self.DPanel.setCellHeight(self.HPanel1, "30px") self.DPanel.setCellWidth(self.HPanel1, "2000px") self.TxtInstructions = HTML("<b><u><center>Instructions</center></u><ul><li>Pig is game for 2 to 6 Players.</li><li>Players take turns rolling a dice as many times as they like. </li><li>If a roll is 2, 3, 4, 5 or 6, the player adds that many points to their score for the turn. </li><li>A player may choose to end their turn at any time and 'bank' their points.</li><li>If a player rolls a 1, they lose all their unbanked points and their turn is over.</li><li>The first player to score the target or more wins.</li></ul></b>") self.TxtInstructions.setStyleName("TxtInstructions") self.DPanel.add(self.TxtInstructions, DockPanel.CENTER) self.DPanel.add(self.NameScore, DockPanel.WEST) #Adding main scoreboard to Dock Panel self.DPanel.setCellHeight(self.NameScore, "300px") self.DPanel.setCellWidth(self.NameScore, "100px") self.DPanel.setSpacing(10) self.DPanel.setPadding(2) #Adding Tempboard and BankButton to Horizontal Panel self.HPanel.add(self.TempBoard) #Adding BankButton and RollButton to vertical panel self.VPanel.add(self.RollButton) self.RollButton.setVisible(False) self.VPanel.add(self.BankButton) self.BankButton.setVisible(False) self.VPanel.setSpacing(10) #Adding Vertical panel containing BankButton and RollButton to Horizontal Panel self.HPanel.add(self.VPanel) self.HPanel.setSpacing(40) #Adding Horizontal panel containing Tempboard and vertical panel containing BankButton and RollButton to Dock Panel self.DPanel.add(self.HPanel, DockPanel.SOUTH) self.DPanel.setCellHeight(self.HPanel, "20px") self.DPanel.setCellWidth(self.HPanel, "2000px") RootPanel().add(self.DPanel)
class FileOpenDlg(DialogBox): files = None def __init__(self, left=50, top=50, fileLocation=None): global has_getAsText try: DialogBox.__init__(self, modal=False) self.filename = None self.data = None self.setPopupPosition(left, top) self.dockPanel = DockPanel() self.dockPanel.setSpacing(4) self.setText("File Open") if not fileLocation is None: msg = HTML("Loading file...", True) self.dockPanel.add(msg, DockPanel.NORTH) location = fileLocation if fileLocation.find("://") < 0: base = Window.getLocation().getHref() if base.find('/') >= 0: sep = '/' else: sep = '\\' base = sep.join(base.split(sep)[:-1]) + sep location = base + fileLocation self.iframe = Frame(location) self.dockPanel.add(self.iframe, DockPanel.CENTER) else: msg = HTML("Choose a file", True) self.browseFile = FileUpload() elem = self.browseFile.getElement() if False and has_getAsText and hasattr(elem, 'files'): self.iframe = None self.files = elem.files self.dockPanel.add(self.browseFile, DockPanel.CENTER) else: self.browseFile = None self.files = None base = '' + doc().location if base.find('/') >= 0: sep = '/' else: sep = '\\' if not base.lower()[:5] == "file:": base = "file:///C:/" msg = HTML( "You'll have to place the application on a local file system, otherwise the browser forbids access.", True) else: base = sep.join(base.split(sep)[:-1]) + sep self.iframe = Frame(base) self.dockPanel.add(self.iframe, DockPanel.CENTER) self.dockPanel.add(msg, DockPanel.NORTH) if self.iframe: self.iframe.setWidth("36em") hpanel = HorizontalPanel() self.openBtn = Button("Open", self.onClickOpen) hpanel.add(self.openBtn) self.cancelBtn = Button("Cancel", self.onClickCancel) hpanel.add(self.cancelBtn) self.dockPanel.add(hpanel, DockPanel.SOUTH) self.setWidget(self.dockPanel) except: raise def onClickCancel(self, sender): self.hide() def onClickOpen(self, sender): global has_getAsText data = None filename = None if self.files: if self.files.length == 0: return if self.files.length > 1: alert("Cannot open more than one file") return file = self.files.item(0) filename = file.fileName try: data = file.getAsText("") except AttributeError, e: has_getAsText = False alert( "Sorry. cannot retrieve file in this browser.\nTry again.") else: