本文整理汇总了Python中pyjamas.ui.ListBox.ListBox.getSelectedIndex方法的典型用法代码示例。如果您正苦于以下问题:Python ListBox.getSelectedIndex方法的具体用法?Python ListBox.getSelectedIndex怎么用?Python ListBox.getSelectedIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.ui.ListBox.ListBox
的用法示例。
在下文中一共展示了ListBox.getSelectedIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ListBoxDemo
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class ListBoxDemo(SimplePanel):
def __init__(self):
SimplePanel.__init__(self)
hPanel = HorizontalPanel()
hPanel.setSpacing(10)
self.list1 = ListBox()
self.list1.setVisibleItemCount(10)
self.list1.addItem("Item 1")
self.list1.addItem("Item 2")
self.list1.addItem("Item 3")
self.list1.addChangeListener(getattr(self, "onList1ItemSelected"))
self.list2 = ListBox()
self.list2.setVisibleItemCount(1)
self.list2.addItem("Item A")
self.list2.addItem("Item B")
self.list2.addItem("Item C")
self.list2.addChangeListener(getattr(self, "onList2ItemSelected"))
hPanel.add(self.list1)
hPanel.add(self.list2)
self.add(hPanel)
def onList1ItemSelected(self, event):
item = self.list1.getItemText(self.list1.getSelectedIndex())
Window.alert("You selected " + item + " from list 1")
def onList2ItemSelected(self, event):
item = self.list2.getItemText(self.list2.getSelectedIndex())
Window.alert("You selected " + item + " from list 2")
示例2: TheoremPanel
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class TheoremPanel(ScrollPanel):
def __init__(self, after):
ScrollPanel.__init__(self, Size=("630px", "500px"))
self.after = after
self.pok = VerticalPanel()
self.add(self.pok)
self.images = list()
def onItemSelected():
item = self.list2.getItemText(self.list2.getSelectedIndex())
self.refresh_theorems(item)
self.list2 = ListBox()
self.list2.setVisibleItemCount(1)
for f in Theorem.get_all_folders():
self.list2.addItem(f)
self.pok.add(self.list2)
self.list2.addChangeListener(onItemSelected)
self.refresh_theorems(self.list2.getItemText(self.list2.getSelectedIndex()))
def remove_images(self):
for im in self.images:
self.pok.remove(im)
self.images = list()
def refresh_theorems(self, folder):
self.remove_images()
def onClick(theorem):
def name(n):
return "var" + str(n + 1)
def print_scheme(n):
return ["\\alpha", "\\beta", "\\gamma", "\\delta", "\\epsilon"][n]
def poas(sender):
if len(theorem.operations) == 1:
constants = [Operation("const" + str(i + 1), 0, print_scheme(i), name(i), Operation.EXPRESSION)
for i in range(theorem.operations[0].no_of_args)]
def after1(f):
self.after(
theorem.formula.substitute_definition(Formula([theorem.operations[0]] + constants), f),
predecessors=[], rule_name="insert")
request_formula([op for op in proof.get_operations()] + constants,
after1, type=('rel' if theorem.operations[0].type == Operation.RELATION else 'exp'))
else:
self.after(theorem.formula, predecessors=[], rule_name="insert")
return poas
for ax in [x for x in Theorem.theorems if x.folder == folder]:
im = Image()
im.addClickListener(onClick(ax))
im.setUrl(latex_to_url(ax.formula.to_latex()))
self.pok.add(im)
self.images.append(im)
示例3: SaveDialog
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class SaveDialog(DialogWindow):
def __init__(self, theorem, **kwargs):
DialogWindow.__init__(self, modal=True, close=True)
self.theorem=theorem
v = VerticalPanel()
v.setWidth(300)
# v.setHeight(500)
self.setText("save")
self.setPopupPosition(100, 100)
self.setStyleAttribute("background-color", "#ffffff")
self.setStyleAttribute("color", "red")
self.setStyleAttribute("border-width", "5px")
self.setStyleAttribute("border-style", "solid")
self.im=Image()
self.im.setUrl(latex_to_url(self.theorem.formula.to_latex()))
v.add(self.im)
h=HorizontalPanel()
self.radio=RadioButton("group1", "Existing folder:")
h.add(self.radio)
self.list = ListBox()
self.list.setVisibleItemCount(1)
for f in Theorem.get_all_folders():
self.list.addItem(f)
h.add(self.list)
v.add(h)
h=HorizontalPanel()
h.add(RadioButton("group1", "New folder:"))
self.radio.setChecked(True)
self.textbox=TextBox()
h.add(self.textbox)
v.add(h)
v.add(Button("Done",self.done_click))
self.add(v)
def get_folder_name(self):
if self.radio.getChecked():
return self.list.getItemText(self.list.getSelectedIndex())
else:
return self.textbox.getText()
def done_click(self):
self.theorem.folder=self.get_folder_name()
Theorem.theorems.append(self.theorem)
IO.save()
self.hide()
示例4: Projects_Editor
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class Projects_Editor(SimplePanel):
'''
Create and edit projects
'''
def __init__(self):
# We need to use old form of inheritance because of pyjamas
SimplePanel.__init__(self)
self.hpanel = HorizontalPanel(Width='475px')
self.hpanel.setVerticalAlignment(HasAlignment.ALIGN_BOTTOM)
self.name = TextBox()
self.name.setStyleName('form-control')
self.status = ListBox()
self.status.addItem('Active')
self.status.addItem('Inactive')
self.status.setVisibleItemCount(0)
self.status.setStyleName('form-control input-lg')
self.status.setSize('100px', '34px')
lbl = Label('', Width='10px')
self.add_btn = Button('Add')
self.add_btn.setStyleName('btn btn-primary')
self.del_btn = Button('Delete')
self.del_btn.setStyleName('btn btn-danger')
self.hpanel.add(self.name)
self.hpanel.add(lbl)
self.hpanel.add(self.status)
self.hpanel.add(self.add_btn)
self.hpanel.add(self.del_btn)
def get_name_txt(self):
'''Return project name.
'''
return self.name.getText()
def get_status(self):
'''Return project status.
'''
return self.status.getItemText(self.status.getSelectedIndex())
示例5: RecipeViewer
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class RecipeViewer(Sink):
recipeDict = None
def __init__(self, parent=None):
Sink.__init__(self, parent)
self.RVDock = HorizontalPanel(Spacing=5)
self.RList = ListBox()
self.RList.addClickListener(getattr(self, "onRecipeSelected"))
self.RView = HTML()
HTTPRequest().asyncGet("recipes.xml", RecipeListLoader(self))
self.RVDock.add(self.RList)
self.RVDock.add(self.RView)
self.initWidget(self.RVDock)
def onRecipeSelected(self, item):
recipe = self.RList.getItemText(self.RList.getSelectedIndex())
HTTPRequest().asyncGet("/recipecontent?recipe=%s" % recipe, RecipeViewLoader(self))
def onShow(self):
pass
示例6: onModuleLoad
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
#.........这里部分代码省略.........
self.mainPanel.setStyleName("mainPanel")
self.mainPanel.setSpacing(25)
# Associate panels with the HTML host page
RootPanel('addPanel').add(self.addPanel)
RootPanel('main').add(self.mainPanel)
# Move cursor focus to the input box
self.newMovieNameTextBox.setFocus(True)
# Load the movies
self.remote.getMovies(self)
def verifyInputs(self, name, category):
if len(name) == 0:
Window.alert("Movie name cannot be empty.")
return False
if len(name) > 100:
Window.alert("Movie name is too long. Maximum length is 100 characters.")
return False
if len(category) == 0:
Window.alert("Category cannot be empty.")
return False
p = re.compile('^[0-9A-Za-z\\.\\-\\(\\) ]{1,100}$')
if p.match(category) == None:
Window.alert('"%s" is not a valid category.' % category)
return False
return True
def addMovieButton_Click(self, event):
name = self.newMovieNameTextBox.getText().trim()
cat = self.newMovieCategoryTextBox.getText().trim().lower()
category = cat[0].upper() + cat[1:]
rating = self.newMovieRatingListBox.getSelectedIndex()
if not self.verifyInputs(name, category):
return
movie = Movie(name, category, rating)
if movie in self.movies:
Window.alert("'" + name + "' is already in table.")
self.newMovieNameTextBox.selectAll()
return
self.remote.addMovie((name, category, rating), self)
self.newMovieNameTextBox.setText('')
def addMovie(self, sender, movie):
self.movies.append(movie)
row = self.moviesFlexTable.getRowCount()
self.moviesFlexTable.setText(row, 1, movie.category)
self.moviesFlexTable.setText(row, 2, movie.name)
self.moviesFlexTable.setText(row, 3, movie.rating)
# Adds buttons for remove, edit, save and cancel
removeMovieButton = Button("x")
editMovieButton = Button("Edit")
saveButton = Button("Save")
cancelButton = Button("Cancel")
# Save and cancel are hidden by default
saveButton.setVisible(False)
cancelButton.setVisible(False)
示例7: CompaniesAppGUI
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class CompaniesAppGUI(AbsolutePanel):
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 onClick(self, sender):
self.errors.clear()
if sender == self.cut:
self.current.cut()
self.total.setText(self.current.total())
if sender == self.save:
if self.current.__class__.__name__ == "Employee":
if self.validateEmployee(self.current.id, self.name.getText(), self.address.getText(), self.total.getText()) == True:
self.current.save(self.name.getText(), self.address.getText(), float(self.total.getText()))
else:
if self.validateDepartment(self.current.id, self.name.getText()) == True:
self.current.save(self.name.getText())
if sender == self.selectDepartment:
if (self.departments.getSelectedIndex() > -1):
self.history.append(self.current)
self.current = self.app.getDepartment(self.departments.getValue(self.departments.getSelectedIndex()))
self.initDepartmentGUI()
if sender == self.selectEmployee:
if (self.employees.getSelectedIndex() > -1):
self.history.append(self.current)
self.current = self.app.getEmployee(self.employees.getValue(self.employees.getSelectedIndex()))
self.initEmployeeGUI()
if sender == self.edit:
self.history.append(self.current)
self.current = self.current.getManager()
self.initEmployeeGUI()
if sender == self.back:
if len(self.history) > 0:
self.current = self.history.pop()
if self.current.__class__.__name__ == "Company":
self.initCompanyGUI()
else:
self.initDepartmentGUI()
def validateDepartment(self, index, name):
valid = True
if name == "":
self.errors.add(Label("- Enter a valid name, please."))
valid = False
for item in self.app.departments:
if item.id != index and name == item.name:
self.errors.add(Label("- There is already a department with the same name. Enter a valid name, please."))
valid = False
return valid
def validateEmployee(self, index, name, address, salary):
valid = True
if name == "":
self.errors.add(Label("- Enter a valid name, please."))
valid = False
if address == "":
self.errors.add(Label("- Enter a valid address, please."))
valid = False
if salary == "":
self.errors.add(Label("- Enter a valid salary, please."))
valid = False
try:
float(salary)
except ValueError:
self.errors.add(Label("- The salary must be a number. Enter a valid salary, please."))
valid = False
#.........这里部分代码省略.........
示例8: ParamGroup
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class ParamGroup(object):
def __init__(self, container, kind, parent=None, level=0, draw=True, title=None):
self.container = container
self.kind = kind
self.parent = parent
self.level = level
self.title = title
self.panel = SimplePanel(StyleName='aur-search-advanced-group')
if level % 2 == 0: self.panel.addStyleName('aur-search-advanced-group-nested')
self.childPanel = VerticalPanel(StyleName='aur-search-advanced-group-list', Width='100%')
self.paramPanel = VerticalPanel(StyleName='aur-search-advanced-param-list', Width='100%')
self.listPanel = VerticalPanel(StyleName='aur-search-advanced-list-boundary', Width='100%', Visible=False)
self.paramChooser = ListBox()
self.children = []
self.parameters = []
self.isInverted = False
self.operator = 'and'
# assigned by parent, visual use only
self.op = None if parent else Label('and')
if draw: self.draw()
def draw(self):
cont = VerticalPanel(Width='100%')
header = HorizontalPanel(Width='100%', VerticalAlignment='middle', StyleName='aur-search-advanced-group-header')
params = self.paramChooser
addParam = Image(url='/ico/tick.png', Title='Add parameter to this group')
addGroup = Image(url='/ico/table_add.png', Title='Nest group within this group')
addGroupFull = Image(url='/ico/table_lightning.png', Title='Nest group within this group; all parameters')
invertSelf = Image(url='/ico/exclamation.png', Title='Invert this parameter group')
self.container.add(self.panel)
self.panel.setWidget(cont)
cont.add(header)
if self.parent:
d = Image(url='/ico/cross.png', Title='Delete this parameter group')
d.addStyleName('aur-search-advanced-delete')
header.add(d)
header.setCellWidth(d, '1px')
d.addClickListener(getattr(self, 'delSelf'))
if self.title:
t = Label(self.title, StyleName='aur-search-advanced-group-header-title')
header.add(t)
header.setCellWidth(t, '1px')
header.add(params)
header.add(addParam)
header.add(addGroup)
header.add(addGroupFull)
header.add(invertSelf)
header.setCellWidth(params, '1px')
header.setCellWidth(addGroup, '1px')
header.setCellWidth(addGroupFull, '1px')
header.setCellWidth(invertSelf, '1px')
for x in self.kind:
params.addItem(x['item'], x['index'])
cont.add(self.listPanel)
self.listPanel.add(self.paramPanel)
self.listPanel.add(self.childPanel)
addParam.addClickListener(getattr(self, 'addParam'))
addGroup.addClickListener(getattr(self, 'addGroup'))
addGroupFull.addClickListener(getattr(self, 'addGroupFull'))
invertSelf.addClickListener(getattr(self, 'invertSelf'))
def addGroup(self, sender):
self.listPanel.setVisible(True)
op = Label(self.operator, Title='Invert group operator', StyleName='aur-search-advanced-group-op', Visible=False)
op.addClickListener(getattr(self, 'invertOperator'))
if len(self.children) > 0 or len(self.parameters) > 0: op.setVisible(True)
self.childPanel.add(op)
self.childPanel.setCellHorizontalAlignment(op, 'right')
g = ParamGroup(self.childPanel, self.kind, self, self.level+1)
g.op = op
self.children.append(g)
def addGroupFull(self, sender):
# this is a little hacky, but it's so fast you don't see it
self.addGroup(None)
group = self.children[len(self.children)-1]
for x in range(group.paramChooser.getItemCount()):
group.paramChooser.setSelectedIndex(x)
group.addParam(None)
group.paramChooser.setSelectedIndex(0)
def addParam(self, sender):
self.listPanel.setVisible(True)
op = Label(self.operator, Title='Invert group operator', StyleName='aur-search-advanced-param-op', Visible=False)
op.addClickListener(getattr(self, 'invertOperator'))
if len(self.parameters) > 0: op.setVisible(True)
self.paramPanel.add(op)
self.paramPanel.setCellHorizontalAlignment(op, 'right')
k = self.kind[self.paramChooser.getSelectedValues()[0]]
p = Param(self.paramPanel, k, self)
p.op = op
self.parameters.append(p)
if len(self.children) > 0:
self.children[0].op.setVisible(True)
def addParamFull(self, sender):
# this is a little hacky, but it's so fast you don't see it
old = self.paramChooser.getSelectedIndex()
for x in range(self.paramChooser.getItemCount()):
self.paramChooser.setSelectedIndex(x)
#.........这里部分代码省略.........
示例9: Trees
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
#.........这里部分代码省略.........
for i in range(0, self.reduceFiles.getItemCount()):
fname = self.reduceFiles.getItemText(i)
if fname == tfile:
return
self.reduceFiles.addItem(tfile)
self.updateReduceCL()
filename = tfile
if filename in pathdict:
if pathdict[filename]["filetype"] == "fileEntry":
HTTPRequest().asyncGet("adinfo?filename=%s" % self.pathdict[item.getText()]["path"],
ADInfoLoader(self),
)
else:
self.adInfo.setHTML("""
<b style="font-size:200%%">%s</b>""" % pathdict[filename]["filetype"])
else:
self.adInfo.setHTML("unknown node")
return
# self.prepareReduce.setHTML('<a href="runreduce?p=-r&p=callen&p=%(fname)s">reduce -r callen %(fname)s</a>' %
# {"fname":item.getText()})
pass
def onRecipeSelected(self, event):
self.updateReduceCL()
def onClearReduceFiles(self, event):
self.reduceFiles.clear()
self.adInfo.setHTML("file info...")
self.updateReduceCL()
def updateReduceCL(self):
recipe = self.recipeList.getItemText(self.recipeList.getSelectedIndex())
if recipe=="None":
rstr = ""
else:
rstr = "-r "+recipe
rfiles = []
for i in range(0, self.reduceFiles.getItemCount()):
fname = self.reduceFiles.getItemText(i)
rfiles.append(fname)
filesstr = " ".join(rfiles)
self.prepareReduce.setHTML('<b>reduce</b> %(recipe)s %(files)s' %
{ "recipe":rstr,
"files":filesstr})
def onRunReduce(self):
recipe = self.recipeList.getItemText(self.recipeList.getSelectedIndex())
if recipe=="None":
rstr = ""
else:
rstr = "p=-r"+recipe
rfiles = []
for i in range(0, self.reduceFiles.getItemCount()):
fname = self.reduceFiles.getItemText(i)
rfiles.append(quote(self.pathdict[fname]["path"]))
filesstr = "&p=".join(rfiles)
cl = "/runreduce?%s&p=%s" % (rstr, filesstr)
JS("window.open(cl)")
示例10: DirectionsSimple
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class DirectionsSimple(DockPanel):
def __init__(self):
DockPanel.__init__(self)
self.setSize('100%', '100%')
# widgets
topPanel = HorizontalPanel()
self.add(topPanel, DockPanel.NORTH)
places = {
"chicago, il": "Chicago",
"st louis, mo": "St Louis",
"joplin, mo": "Joplin, MO",
"oklahoma city, ok": "Oklahoma City",
"amarillo, tx": "Amarillo",
"gallup, nm": "Gallup, NM",
"flagstaff, az": "Flagstaff, AZ",
"winona, az": "Winona",
"kingman, az": "Kingman",
"barstow, ca": "Barstow",
"san bernardino, ca": "San Bernardino",
"los angeles, ca": "Los Angeles"}
self.start = ListBox()
self.end = ListBox()
for value in places:
self.start.addItem(places[value], value)
self.end.addItem(places[value], value)
self.start.addChangeListener(self.calcRoute)
self.end.addChangeListener(self.calcRoute)
topPanel.add(self.start)
topPanel.add(self.end)
# now, the map
mapPanel = SimplePanel()
mapPanel.setSize('800', '500')
self.add(mapPanel, DockPanel.CENTER)
chigado = LatLng(41.850033, -87.6500523)
options = MapOptions(zoom=7, center=chigado,
mapTypeId=MapTypeId.ROADMAP)
self.map = Map(mapPanel.getElement(), options)
# initialize the renderer
self.directionsDisplay = DirectionsRenderer()
self.directionsDisplay.setMap(self.map)
self.directionsService = DirectionsService()
def calcRoute(self):
start = self.start.getValue(self.start.getSelectedIndex())
end = self.end.getValue(self.end.getSelectedIndex())
print "calcRoute start:", start, "end:", end
request = DirectionsRequest(origin=start, destination=end, \
travelMode=DirectionsTravelMode.DRIVING)
self.directionsService.route(request, self.directionsResult)
def directionsResult(self, response, status):
print "directionsResult:"
if status == DirectionsStatus.OK:
for trip in response.trips:
print "copyrights:", trip.copyrights
for route in trip.routes:
print route.start_geocode.formatted_address
print route.end_geocode.formatted_address
print route.steps[0].start_point
print route.steps[0].end_point
print "\n"
self.directionsDisplay.setDirections(response)
示例11: Lists
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class Lists(Sink):
def __init__(self):
Sink.__init__(self)
self.sStrings=[["foo0", "bar0", "baz0", "toto0", "tintin0"],
["foo1", "bar1", "baz1", "toto1", "tintin1"],
["foo2", "bar2", "baz2", "toto2", "tintin2"],
["foo3", "bar3", "baz3", "toto3", "tintin3"],
["foo4", "bar4", "baz4", "toto4", "tintin4"]]
self.combo=ListBox(VisibleItemCount=1)
self.list=ListBox(MultipleSelect=True, VisibleItemCount=10)
self.echo=Label()
self.combo.addChangeListener(self)
for i in range(len(self.sStrings)):
txt = "List %d" % i
self.combo.addItem(txt)
# test setItemText
self.combo.setItemText(i, txt + " using set text")
self.combo.setSelectedIndex(0)
self.fillList(0)
self.list.setItemSelected(0, False)
self.list.setItemSelected(1, True)
self.list.addChangeListener(self)
horz = HorizontalPanel(VerticalAlignment=HasAlignment.ALIGN_TOP,
Spacing=8)
horz.add(self.combo)
horz.add(self.list)
panel = VerticalPanel(HorizontalAlignment=HasAlignment.ALIGN_LEFT)
panel.add(horz)
panel.add(self.echo)
self.initWidget(panel)
self.echoSelection()
def onChange(self, sender):
if sender == self.combo:
self.fillList(self.combo.getSelectedIndex())
elif sender == self.list:
self.echoSelection()
def onShow(self):
pass
def fillList(self, idx):
self.list.clear()
strings = self.sStrings[idx]
for i in range(len(strings)):
self.list.addItem(strings[i])
self.echoSelection()
def echoSelection(self):
msg = "Selected items: "
for i in range(self.list.getItemCount()):
if self.list.isItemSelected(i):
msg += self.list.getItemText(i) + " "
self.echo.setText(msg)
示例12: Milestones_Editor
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class Milestones_Editor(SimplePanel):
'''
Create and edit projects
'''
def __init__(self):
# We need to use old form of inheritance because of pyjamas
SimplePanel.__init__(self)
self.hpanel = HorizontalPanel(Width='755px')
self.hpanel.setVerticalAlignment(HasAlignment.ALIGN_TOP)
self.name = TextBox()
self.name.setStyleName('form-control')
self.start = Report_Date_Field(cal_ID='start')
self.start.getTextBox().setStyleName('form-control')
self.start.setRegex(DATE_MATCHER)
self.start.appendValidListener(self._display_ok)
self.start.appendInvalidListener(self._display_error)
self.start.validate(None)
self.end = Report_Date_Field(cal_ID='end')
self.end.getTextBox().setStyleName('form-control')
self.end.setRegex(DATE_MATCHER)
self.end.appendValidListener(self._display_ok)
self.end.appendInvalidListener(self._display_error)
self.end.validate(None)
self.status = ListBox()
self.status.addItem('Active')
self.status.addItem('Inactive')
self.status.setVisibleItemCount(0)
self.status.setStyleName('form-control input-lg')
self.status.setSize('100px', '34px')
spacer1 = Label(Width='10px')
spacer2 = Label(Width='10px')
spacer3 = Label(Width='10px')
self.add_btn = Button('Add')
self.add_btn.setStyleName('btn btn-primary')
self.del_btn = Button('Delete')
self.del_btn.setStyleName('btn btn-danger')
self.hpanel.add(self.name)
self.hpanel.add(spacer1)
self.hpanel.add(self.status)
self.hpanel.add(spacer2)
self.hpanel.add(self.start)
#self.hpanel.add(spacer3)
self.hpanel.add(self.end)
self.hpanel.add(self.add_btn)
self.hpanel.add(Label(Width='10px'))
self.hpanel.add(self.del_btn)
def get_name_txt(self):
'''Return project name.
'''
return self.name.getText()
def get_status(self):
'''Return project status.
'''
return self.status.getItemText(self.status.getSelectedIndex())
def get_milestone_data(self):
'''Return all data for a milestone and validation result.
'''
valid = False
name_txt = self.get_name_txt()
status_txt = self.get_status()
start_txt = self.start.getTextBox().getText()
end_txt = self.end.getTextBox().getText()
data = [name_txt, status_txt, start_txt, end_txt]
# We are only valid if these conditions are met
if len(name_txt.strip()) > 0 and self.start.valid == True and self.end.valid == True:
valid = True
return (valid, data)
def _display_ok(self, obj):
obj.setStyleName('form-input')
def _display_error(self, obj):
if len(obj.getTextBox().getText()) > 0:
obj.setStyleName('form-group has-error')
示例13: __init__
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class SongFrequency:
def __init__(self):
self.artist =''
self.start_date = ''
self.end_date = ''
self.period_search =''
self.search_option = 1
#declare the general interface widgets
self.panel = DockPanel(StyleName = 'background')
self.ret_area = TextArea()
self.ret_area.setWidth("350px")
self.ret_area.setHeight("90px")
self.options = ListBox()
self.search_button = Button("Search", getattr(self, "get_result"), StyleName = 'button')
#set up the date search panel; it has different text boxes for
#to and from search dates
self.date_search_panel = VerticalPanel()
self.date_search_start = TextBox()
self.date_search_start.addInputListener(self)
self.date_search_end = TextBox()
self.date_search_end.addInputListener(self)
self.date_search_panel.add(HTML("Enter as month/day/year", True, StyleName = 'text'))
self.date_search_panel.add(HTML("From:", True, StyleName = 'text'))
self.date_search_panel.add(self.date_search_start)
self.date_search_panel.add(HTML("To:", True, StyleName = 'text'))
self.date_search_panel.add(self.date_search_end)
#set up the artist search panel
self.artist_search = TextBox()
self.artist_search.addInputListener(self)
self.artist_search_panel = VerticalPanel()
self.artist_search_panel.add(HTML("Enter artist's name:",True,
StyleName = 'text'))
self.artist_search_panel.add(self.artist_search)
#Put together the list timespan search options
self.period_search_panel = VerticalPanel()
self.period_search_panel.add(HTML("Select a seach period:",True,
StyleName = 'text'))
self.period_search = ListBox()
self.period_search.setVisibleItemCount(1)
self.period_search.addItem("last week")
self.period_search.addItem("last month")
self.period_search.addItem("last year")
self.period_search.addItem("all time")
self.period_search_panel.add(self.period_search)
#add the listeners to the appropriate widgets
self.options.addChangeListener(self)
self.period_search.addChangeListener(self)
self.ret_area_scroll = ScrollPanel()
self.search_panel = HorizontalPanel()
self.options_panel = VerticalPanel()
# A change listener for the boxes
def onChange(self, sender):
#switch the list box options
if sender == self.options:
self.search_panel.remove(self.period_search_panel)
self.search_panel.remove(self.date_search_panel)
self.search_panel.remove(self.artist_search_panel)
index = self.options.getSelectedIndex()
if index == 0:
self.search_panel.add(self.artist_search_panel)
self.search_option = 1
elif index == 1:
self.search_panel.add(self.date_search_panel)
self.search_option = 2
elif index == 2:
self.search_panel.add(self.period_search_panel)
self.search_option = 3
elif sender == self.period_search:
index = self.period_search.getSelectedIndex()
if index == 0:
self.period_search = "last week"
elif index == 1:
self.period_search = "last month"
elif index == 2:
self.period_search = "last year"
elif index == 3:
self.period_search = "all time"
#A listener for the text boxes
def onInput(self, sender):
if sender == self.artist_search:
self.artist = sender.getText()
elif sender == self.date_search_end:
self.end_date = sender.getText()
elif sender == self.date_search_start:
self.start_date = sender.getText()
#A listener for the buttons that, when the button is clicked, looks up the results and outputs them
def get_result(self):
return_str = " "
if self.search_option == 1:
#.........这里部分代码省略.........
示例14: ReducePanelIFACE
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class ReducePanelIFACE(PanelIFACE):
def __init__(self, parent = None):
PanelIFACE.__init__(self, parent)
self.panel = VerticalPanel()
self.panel.setBorderWidth(1)
self.panel.setWidth("100%")
# prepare panel
self.prepareReduce = HTML("<tt> .. none yet .. </tt>", True, )
self.recipeList = ListBox()
self.recipeList.addChangeListener(getattr(self, "onRecipeSelected"))
self.recipeList.addItem("None")
HTTPRequest().asyncGet("recipes.xml",
RecipeListLoader(self))
#EO prepare panel
self.reduceCLPanel = DockPanel(Spacing = 5)
self.reduceCLPanel.add(HTML("<i>Reduce Command Line</i>:"), DockPanel.NORTH)
self.reduceCLPanel.add(self.prepareReduce, DockPanel.NORTH)
self.reduceFilesPanel = DockPanel(Spacing = 5)
self.reduceFilesPanel.add(HTML("<b>Datasets</b>:"), DockPanel.WEST)
self.reduceFiles = ListBox()
self.reduceFiles.setVisibleItemCount(5)
self.reduceFilesPanel.add(self.reduceFiles, DockPanel.WEST)
self.clearReduceFilesButton = Button("<b>Clear List</b>", listener = getattr(self, "onClearReduceFiles"))
self.reduceFilesPanel.add(self.clearReduceFilesButton, DockPanel.SOUTH)
self.recipeListPanel = DockPanel(Spacing = 5)
self.recipeListPanel.add(HTML("<b>Recipes List</b>:"),DockPanel.WEST)
self.recipeListPanel.add(self.recipeList, DockPanel.WEST)
self.runReduceButton = Button("<b>RUN REDUCE</b>", listener = getattr(self, "onRunReduce"))
self.adInfo = HTML("file info...")
# major sub panels
self.panel.add(self.reduceCLPanel)
self.panel.add(self.reduceFilesPanel)
self.panel.add(self.recipeListPanel)
self.panel.add(self.runReduceButton)
self.panel.add(self.adInfo)
def onRecipeSelected(self, event):
self.updateReduceCL()
def onClearReduceFiles(self, event):
self.reduceFiles.clear()
self.adInfo.setHTML("file info...")
self.updateReduceCL()
def updateReduceCL(self):
recipe = self.recipeList.getItemText(self.recipeList.getSelectedIndex())
if recipe=="None":
rstr = ""
else:
rstr = "-r "+recipe
rfiles = []
for i in range(0, self.reduceFiles.getItemCount()):
fname = self.reduceFiles.getItemText(i)
rfiles.append(fname)
filesstr = " ".join(rfiles)
self.prepareReduce.setHTML('<b>reduce</b> %(recipe)s %(files)s' %
{ "recipe":rstr,
"files":filesstr})
def onRunReduce(self):
recipe = self.recipeList.getItemText(self.recipeList.getSelectedIndex())
if recipe=="None":
rstr = ""
else:
rstr = "p=-r"+recipe
rfiles = []
for i in range(0, self.reduceFiles.getItemCount()):
fname = self.reduceFiles.getItemText(i)
rfiles.append(quote(self.pathdict[fname]["path"]))
filesstr = "&p=".join(rfiles)
cl = "/runreduce?%s&p=%s" % (rstr, filesstr)
# @@TEST
# cl = "/recipes.xml"
if False:
msg = repr(self.parent)+repr(dir(self.parent))
JS("alert(msg)")
if hasattr(self.parent, "roFrame"):
self.parent.roFrame.setUrl(cl)
self.parent.tabPanel.selectTab(self.parent.tabIFACEdict["rogui"])
else:
JS("window.open(cl)")
def onTreeItemSelected(self, item):
pathdict = self.pathdict
tfile = item.getText()
#check if already in
#.........这里部分代码省略.........
示例15: onModuleLoad
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import getSelectedIndex [as 别名]
class SoftChordApp:
def onModuleLoad(self):
"""
Gets run when the page is first loaded.
Creates the widgets.
"""
self.remote = DataService()
main_layout = VerticalPanel()
h_layout = HorizontalPanel()
h_layout.setPadding(10)
songlist_layout = VerticalPanel()
songlist_layout.add(Label("Add New Song:"))
self.newSongTextBox = TextBox()
self.newSongTextBox.addKeyboardListener(self)
songlist_layout.add(self.newSongTextBox)
self.addSongButton = Button("Add Song")
self.addSongButton.addClickListener(self)
songlist_layout.add(self.addSongButton)
#songlist_layout.add(Label("Click to Remove:"))
self.songListBox = ListBox()
self.songListBox.setVisibleItemCount(7)
self.songListBox.setWidth("300px")
self.songListBox.setHeight("400px")
self.songListBox.addClickListener(self)
songlist_layout.add(self.songListBox)
self.deleteSongButton = Button("Delete")
self.deleteSongButton.addClickListener(self)
songlist_layout.add(self.deleteSongButton)
h_layout.add(songlist_layout)
#self.textArea = TextArea()
#self.textArea.setCharacterWidth(30)
#self.textArea.setVisibleLines(50)
#h_layout.add(self.textArea)
#self.scrollPanel = ScrollPanel(Size=("400px", "500px"))
self.songHtml = HTML("<b>Please select a song in the left table</b>")
#self.scrollPanel.add(self.songHtml)
#h_layout.add(self.scrollPanel)
h_layout.add(self.songHtml)
main_layout.add(h_layout)
self.status = Label()
main_layout.add(self.status)
RootPanel().add(main_layout)
# Populate the song table:
self.remote.getAllSongs(self)
def onKeyUp(self, sender, keyCode, modifiers):
pass
def onKeyDown(self, sender, keyCode, modifiers):
pass
def onKeyPress(self, sender, keyCode, modifiers):
"""
This functon handles the onKeyPress event
"""
if keyCode == KeyboardListener.KEY_ENTER and sender == self.newSongTextBox:
id = self.remote.addSong(self.newSongTextBox.getText(), self)
self.newSongTextBox.setText("")
if id<0:
self.status.setText("Server Error or Invalid Response")
def onClick(self, sender):
"""
Gets called when a user clicked in the <sender> widget.
Currently deletes the song on which the user clicked.
"""
if sender == self.songListBox:
song_id = self.songListBox.getValue(self.songListBox.getSelectedIndex())
self.status.setText("selected song_id: %s" % song_id)
id = self.remote.getSong(song_id, self)
if id<0:
self.status.setText("Server Error or Invalid Response")
elif sender == self.addSongButton:
id = self.remote.addSong(self.newSongTextBox.getText(), self)
self.newSongTextBox.setText("")
if id<0:
self.status.setText("Server Error or Invalid Response")
elif sender == self.deleteSongButton:
#.........这里部分代码省略.........