def __init__(self): self.rows = [] #self.exampleRows = [] headingRow = Row() headingRow.addLabel(st(670), COLOR_COLUMN, columnspan=2, bold=True) headingRow.addLabel(st(671), BOLD_COLUMN, columnspan=2, bold=True, padX=23) headingRow.addLabel(st(672), ITALIC_COLUMN, columnspan=3, bold=True, padX=23) #headingRow.addLabel( st(653), LOCATION_COLUMN,columnspan=2, bold=True, padX=LOCATION_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) #headingRow.addLabel( st(653), LOCATION_COLUMN,columnspan=2, bold=True, padX=LOCATION_COLUMN_PAD+23, alignment=pyxbmct.ALIGN_LEFT) self.rows.append(headingRow) self.exampleRow = Row() #self.examplesTB = self.exampleRow.addTextBox(SETTING_COLUMN, columnspan=7, padX=SETTING_COLUMN_PAD, rowspan=5) self.exampleList = None self.examples = [] self._assignedValue = False
def __init__(self, attributes, row): super().__init__() self.title("Опции") self.iconbitmap(r'res\ico.ico') self.resizable(False, False) self.row = row self.attributes = attributes.split(', ') self.rows = [] for i in range(len(self.attributes)): self.rows.append(Row(master=self, mw=self)) try: self.rows[-1].append( Label(self, text=self.attributes[i] [:self.attributes[i].index("=")])) except ValueError: self.rows[-1].append(Label(self, text=self.attributes[i])) self.rows[-1].append(Entry(self)) self.rows[-1].grid_option() self.rows.append(Row(master=self, mw=self)) self.rows[-1].append( Button(master=self, text="Отмена", command=lambda *args: self.destroy())) self.rows[-1].append( Button(master=self, text="Принять", command=lambda *args: self.to_main())) xy = pyautogui.position() self.rows[-1].append( Label(master=self, text="x=" + str(xy.x) + ", y=" + str(xy.y))) self.rows[-1][-1].bind("<Motion>", lambda *args: self.xyxy()) self.rows[-1].grid_option()
def addSettingRow(self, label): label = ts.color(LABEL_COLOR, label) row = Row() row.addLabel(label, SETTING_COLUMN, 5, SETTING_COLUMN_PAD, pyxbmct.ALIGN_LEFT, bold=LABELS_BOLD) self.addRow(row) return row
def addBoolFullSpan(self, label, current, default, onSave): row = Row() row.addRadioButton(SETTING_COLUMN, current, default, onSave, label=label, columnspan=self.numColumns - 2) self.addRow(row)
def xml2dict(xml_filename): """returns {page_id:[row],...}""" height_diff_tolerance = 3 tree = ET.parse(xml_filename) root = tree.getroot() pages = defaultdict(list) page_id = 1 for page in root.iter('page'): for textline in page.iter('textline'): line_coord = textline.attrib['bbox'].split( ',') # get the coordinates for the textline r = Row(line_coord[1], line_coord[3], [i for i in textline.iter('text')]) # create a Row if pages[ page_id] == []: # if it is empty means r is the first row add to the page[page_id] pages[page_id].append(r) continue min_diff = 1000 # set a default min_diff for row in pages[ page_id]: # find the nearest existing Row in pages[page_id] diff = abs(row.min_val() - r.min_val()) if diff < min_diff: min_diff = diff which_row = row if min_diff > height_diff_tolerance: # check the y difference between current Row and its existing nearest Row pages[page_id].append( r ) # if difference is larger than tolerance, then the current Row is a single Row else: which_row.add( r ) # if difference is smaller than tolerance, then the current Row should be in the same Row of the existing one for i in pages.keys(): # sort the Rows of each page by their minimum y pages[i].sort(key=lambda x: x.min_val(), reverse=True) page_id += 1 with open('c1.txt', 'w', encoding='utf-8') as newfile: # save as txt for debugging for i in pages.keys(): newfile.write("page id = " + str(i) + '\n') pages[i].sort(key=lambda x: x.min_val(), reverse=True) for j in pages[i]: newfile.write(str(j) + '\n') return pages
def createRows(self, event, clef=r'assets/startrowsigns/g clef.png'): """creates rows """ if len(self.rows) == 0: self.rows.append(Row(START_Y, len(self.rows), self, clef)) self.rows[0].changeTemp(self.panel.numerator, self.panel.denominator) else: if self.rows[-1].y < CANVAS_HEIGH - 2 * DISTANCE_BETWEEN_LINES * 28: self.rows.append(Row(self.rows[-1].y + DISTANCE_BETWEEN_LINES * 28, len(self.rows), self, clef)) self.rows[-1].draw()
def test_case_1(self): sys.stdout.flush() print("First Test") row = Row("5195") expected_minimun = 1 expected_maximun = 9 expected_checksum = 8 result = row.getChecksum() print("Result: " + str(result)) self.assertTrue(result == expected_checksum)
def test_case_2(self): sys.stdout.flush() print("Second Test") row = Row("753") expected_minimun = 3 expected_maximun = 7 expected_checksum = 4 result = row.getChecksum() print("Result: " + str(result)) self.assertTrue(result == expected_checksum)
def test_case_3(self): sys.stdout.flush() print("Third Test") row = Row("2468") expected_minimun = 2 expected_maximun = 8 expected_checksum = 6 result = row.getChecksum() print("Result: " + str(result)) self.assertTrue(result == expected_checksum)
def append(self, dict_data): # TO-DO: append list of dict idx = self.__len__ + 1 try: row_cells = self._get_row_cells(idx=idx) row = Row(wks=self.wks, row_cells=row_cells) row.update(dict_data) self.__len__ = idx self.__dict__[self.__len__] = row except Exception as e: raise RuntimeError('append fails')
def createNewReport(): ingredientsList = Ingredient.getAllIngredients() rowList = [] for ingredient in ingredientsList: row = Row.createNewRow(ingredient) rowList.append(Row.getRowList(row)) #print(rowList) addToSheet(rowList) print("Done writing to sheet.")
def addButton(self, label, onClick, bold=False, columnSpan=3, centered=False): row = Row() if centered: column = self.numColumns / 2 else: column = SETTING_COLUMN button = row.addButton(label, column, onClick, columnspan=columnSpan, padX=-5, alignment=pyxbmct.ALIGN_LEFT, bold=bold) self.addRow(row) return button
def __init__(self, pageNum, tab, window, prevPage=None): self.num = pageNum self.tab = tab self.window = window self.rows = [] self.rowsFilled = 0 if prevPage: self.navRow = Row() self.navRow.addButton(addon.string(603), 8, lambda: self.window.showPage(prevPage), columnspan=1, bold=False) else: self.navRow = None
def main(): tree = ET.parse(filename) root = tree.getroot() lgv_elem = root.find("LIST_G_VESSEL") print_header = True # Print header #gv_elem = lgv_elem.find("G_VESSEL") #string = "" #for e in gv_elem.iter(): # if isLeaf(e): # string += e.tag + sep #print string + "\n" print getHeader() em = root.find("LIST_G_VESSEL") # Print each of the value for gv in em.findall("G_VESSEL"): row = Row(getText(gv, "TRP_ID"), getText(gv, "TRP_ATA"), getText(gv, "TRP_PORT_FROM"), getText(gv, "VES_VESSEL_NAME"), getText(gv, "VES_VESSEL_FLAG"), getText(gv, "TRP_CURRENT_LOCATION"), getText(gv, "AGT_NAME")) lga = gv.find("LIST_G_ACTIVITY") for ga in lga.findall("G_ACTIVITY"): row.addActivity("", getText(ga, "TYPE"), getText(ga, "START_TIME"), getText(ga, "END_TIME"), getText(ga, "ACT"), getText(ga, "LOCATION")) lgn = gv.find("LIST_G_NEXT_PORT") for gn in lgn.findall("G_NEXT_PORT"): row.addNextPort(getText(gn, "CLR_NEXT_PORT")) print row.dump()
def update(self, data_dict): """ input: { 2: { u'蜂蜜棒腿': 123, ...}, 3: { u'麻辣豬肋排': 'sss', ...} } """ try: for idx, data in data_dict.items(): row_cells = self._get_row_cells(idx) row = Row(wks=self.wks, row_cells=row_cells) row.update(data) self.__dict__[idx] = row except Exception as e: return -1 return 0
def __init__(self, width, height, numBlocks, blockHeight, colour): self.topLeftX = (width - numBlocks * blockHeight) / 2 self.topLeftY = height - blockHeight bottomRow = Row(self.topLeftX, self.topLeftY, numBlocks) self.currLevel = 1 self.towerLevels = {self.currLevel: bottomRow} self.colour = colour
def read_file(self): file = open(self.file_name, "r") spreadsheet_data = file.read() spreadsheet_data = spreadsheet_data.replace('\t', " ") for row_data in spreadsheet_data.split(" "): self.row_list.append(Row(row_data)) file.close()
def main(): tree = ET.parse(filename) root = tree.getroot() lgv_elem = root.find("LIST_G_VESSEL") print_header = True # Print header #gv_elem = lgv_elem.find("G_VESSEL") #string = "" #for e in gv_elem.iter(): # if isLeaf(e): # string += e.tag + sep #print string + "\n" print getHeader(); em = root.find("LIST_G_VESSEL") # Print each of the value for gv in em.findall("G_VESSEL"): row = Row(getText(gv, "TRP_ID"), getText(gv, "TRP_ATA"), getText(gv, "TRP_PORT_FROM"), getText(gv, "VES_VESSEL_NAME"), getText(gv, "VES_VESSEL_FLAG"), getText(gv, "TRP_CURRENT_LOCATION"), getText(gv, "AGT_NAME")) lga = gv.find("LIST_G_ACTIVITY") for ga in lga.findall("G_ACTIVITY"): row.addActivity("", getText(ga, "TYPE"), getText(ga, "START_TIME"), getText(ga, "END_TIME"), getText(ga, "ACT"), getText(ga, "LOCATION")) lgn = gv.find("LIST_G_NEXT_PORT") for gn in lgn.findall("G_NEXT_PORT"): row.addNextPort(getText(gn, "CLR_NEXT_PORT")) print row.dump()
def addRow(self, key=None, value=None, row=None): if row is None and key is not None and value is not None: self.key.append(key) self.table.append(Row(key, value)) elif row is not None and key is None and value is None: self.key.append(row.key) self.table.append(row) else: print("Error")
def __init__(self, key=None, value=None): super(Table, self).__init__() self.key = [] self.table = [] self.lenghtE = 0 if key is not None and value is not None: self.key.append(key) self.table.append(Row(key, value)) self.lenghtE = len(self.table[0])
def createButtons(self): buttonRow = Row() def defaultsActions(): for onDefaultCallback in self.currentPage.tab.onDefaultCallbacks: onDefaultCallback() def okAction(): for onSaveCallback in self.onSaveCallbacks: onSaveCallback() if self.saveCallback: self.saveCallback() self.window.close() def cancelAction(): self.window.close() buttonRow.addButton( addon.string(600), 2, okAction, columnspan=2, bold=True) buttonRow.addButton( addon.string(601), 4, cancelAction, columnspan=2, bold=True) buttonRow.addButton( addon.string(602), 6, defaultsActions, columnspan=2, bold=True) self._placeRow(buttonRow, BUTTON_ROW, forceLocation=True) self.buttonRow = buttonRow
class TabPage(): def __init__(self, pageNum, tab, window, prevPage=None): self.num = pageNum self.tab = tab self.window = window self.rows = [] self.rowsFilled = 0 if prevPage: self.navRow = Row() self.navRow.addButton(addon.string(603), 8, lambda: self.window.showPage(prevPage), columnspan=1, bold=False) else: self.navRow = None def addRow(self, row): self.rows.append(row) self.rowsFilled += 1 def addNextPage(self, nextPage): if self.navRow is None: self.navRow = Row() self.navRow.addButton(addon.string(604), 9, lambda: self.window.showPage(nextPage), columnspan=1, bold=False) def placeNavRowIfExists(self): if self.navRow: self.window._placeRow(self.navRow, BUTTON_ROW) def setVisible(self, state): for row in self.rows: row.setVisible(state) if self.navRow: self.navRow.setVisible(state) def hide(self): self.setVisible(False) def unHide(self): self.setVisible(True)
def to_oop(date, sale): final_date_list = [] final_sale_list = [] for i in range(0, len(date)): if date[i] not in final_date_list: # a_row = Row(date[i], sale[i]) final_date_list.append(date[i]) final_sale_list.append(sale[i]) else: if final_sale_list[final_date_list.index(date[i])] < sale[i]: final_sale_list[final_date_list.index(date[i])] = sale[i] final_row_list = [] for i in range(0, len(final_date_list)): a_row = Row(final_date_list[i], final_sale_list[i]) final_row_list.append(a_row) return final_row_list
def to_oop(date, sale): final_date_list = [] final_sale_list = [] for i in range(0, len(date)): if date[i] not in final_date_list: # a_row = Row(date[i], sale[i]) final_date_list.append(date[i]) final_sale_list.append(sale[i]) else: if final_sale_list[final_date_list.index(date[i])] < sale[i]: final_sale_list[final_date_list.index(date[i])] = sale[i] # print("no dull length is: ", len(final_date_list)) final_row_list = [] for i in range(0, len(final_date_list)): a_row = Row(final_date_list[i], final_sale_list[i]) # initialize rows! final_row_list.append(a_row) print("final length is: ", len(final_row_list)) return final_row_list
def __setitem__(self, key, item): if type(key) is int: idx = self.__idx_convert__(key) if idx == 1: raise IndexError('setitem', 'idx shoud not be 1') if idx not in self.__dict__: # Insert if type(item) is dict: self.append(item) elif type(item) is Row: self.__len__ += 1 range_str = 'A%s:%s%s' % (str(self.__len__), Dict_Sheet.alphabet_list[self._width], str(self.__len__)) row_list = self.wks.range(range_str) row = Row(wks=self.wks, row_cells=row_list) row.update(item.kv()) self.__dict__[self.__len__] = row else: raise Exception('setitem', 'type error') else: # Update row = self.__dict__[idx] row.clear() if type(item) is dict: # replace # ds[4] = {'LINE ID': 'test1', 'Email': 'email'} #row = self.__dict__[idx] row.update(item) self.__dict__[idx] = row elif type(item) is Row: #row = self.__dict__[idx] row.update(item.kv()) self.__dict__[idx] = row else: raise Exception('setitem', 'type error') if idx > self.__len__: self.__len__ = idx else: self.__dict__[key] = item
def __init__(self, height, width, blocks=None): self.blocks = blocks self.blocks = { "rows": [[3], [2, 2], [1, 1], [2, 2], [3]], "cols": [[3], [2, 2], [1, 1], [2, 2], [3]] } # self.blocks = {"rows": [[6,3,1,4]], "cols": [[0 for i in range(20)]]} self.height = height self.width = width self.rows = [ Row(width, self.blocks["rows"][i], i) for i in range(self.height) ] self.cols = [ Col(height, self.blocks["cols"][i], i) for i in range(self.width) ] self.board = [[0 for _ in range(height)] for _ in range(width)] # print(len(self.board)) # print(len(self.board[0])) self.queue = self.rows + self.cols
def placeTab(self, tab): pages = [] onDefaultCallbacks = [] currentPage = TabPage(0, tab, self) pages.append(currentPage) for row in tab.rows: #if currentPage.rowsFilled == MAX_PAGE_ROWS: if currentPage.rowsFilled == tab.numRows - 2: lastPage = currentPage currentPage = TabPage(lastPage.num + 1, tab, self, prevPage=lastPage) lastPage.addNextPage(currentPage) pages.append(currentPage) self._placeRow(row, currentPage.rowsFilled, onDefaultCallbacks) currentPage.addRow(row) for page in pages: page.placeNavRowIfExists() page.hide() tab.onDefaultCallbacks = onDefaultCallbacks tab.pages = pages if tab.useGlobalButton: ugbRow = Row() ugb = tab.useGlobalButton label = ts.italic( addon.string(605) ) ugbRow.addRadioButton(7, ugb.current, ugb.default, saveCallback=ugb.saveCallback, label=label, columnspan=2, changeCallback=lambda state: tab.setGlobalEnabled(not state)) self.window.setGeometry(self.width, self.height, 14, 10) self._placeRow(ugbRow, 12, onDefaultCallbacks) ugbRow.hide() tab.ugbRow = ugbRow if ugb.current is True: tab.globalDisable()
def __call__(self, filename): """ Process the file """ print(f"ax3_seconds_stats.py processing {filename}") # Count number of lines in file to get array dimension print("Count lines in file") count = 0 with open(filename, "rt", newline="\n") as self.fh: line = self.fh.readline().strip() while line: row = Row(line) if row.skip: pass else: count += 1 if count % 1000000 == 0: print(f"{count} lines counted") line = self.fh.readline().strip() self.filename = filename self.timestamp = np.array(["(empty)" for _ in range(count)]) self.epoch = np.zeros((count,)) self.x = np.zeros((count,)) self.y = np.zeros((count,)) self.z = np.zeros((count,)) self.tot = np.zeros((count,)) print("Read file") self.firstLine = None with open(filename, "rt", newline="\n") as self.fh: line = self.fh.readline().strip() index = 0 while line: row = Row(line) if row.skip: pass else: if self.firstLine is None: self.firstLine = row.timestamp self.timestamp[index] = row.timestamp self.epoch[index] = row.getEpoch() self.x[index] = row.val[0] self.y[index] = row.val[1] self.z[index] = row.val[2] self.tot[index] = row.getTotAcc() index += 1 if index % 1000000 == 0: print(f"{index} data lines read") line = self.fh.readline().strip()
def getIngredientPrice(ingredientName, amount, unit): averagePrice, perUnit = Row.getAveragePricePerUnit(ingredientName, returnRaw=True) try: averagePrice = Q_(averagePrice, perUnit) requiredAmount = Q_(amount, unit) if averagePrice.units != requiredAmount.units: requiredAmount.ito(averagePrice.units) averagePrice = Q_(averagePrice, "{} / {}".format(1, perUnit)) calculatedPrice = averagePrice * requiredAmount calculatedPrice = str(calculatedPrice).split(" ")[0] return calculatedPrice, False, False except: if unit == perUnit: calculatedPrice = averagePrice * int(amount) return calculatedPrice, False, False else: return False, unit, perUnit
def __call__(self, filename): """ Split the CSV file into per-day files """ outfiles = [] date = None outfile = None with open(filename, "rt", newline="\n") as self.fh: line = self.fh.readline().strip() while line: row = Row(line, True, True) if row.skip: pass else: if row.date != date: date = row.date outputFilename = self.makeOutFile(filename, date) outfiles.append(outputFilename) if outfile is not None: outfile.close() outfile = open(outputFilename, "w") outfile.write(row.rawLine + "\n") line = self.fh.readline().strip() if outfile is not None: outfile.close() return outfiles
def __init__(self): self.rows = [] #self.exampleRows = [] headingRow = Row() headingRow.addLabel( st(670), COLOR_COLUMN, columnspan=2, bold=True) headingRow.addLabel( st(671), BOLD_COLUMN, columnspan=2, bold=True, padX=23) headingRow.addLabel( st(672), ITALIC_COLUMN, columnspan=3, bold=True, padX=23) #headingRow.addLabel( st(653), LOCATION_COLUMN,columnspan=2, bold=True, padX=LOCATION_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) #headingRow.addLabel( st(653), LOCATION_COLUMN,columnspan=2, bold=True, padX=LOCATION_COLUMN_PAD+23, alignment=pyxbmct.ALIGN_LEFT) self.rows.append(headingRow) self.exampleRow = Row() #self.examplesTB = self.exampleRow.addTextBox(SETTING_COLUMN, columnspan=7, padX=SETTING_COLUMN_PAD, rowspan=5) self.exampleList = None self.examples = [] self._assignedValue = False
class ListItemTable(object): def __init__(self): self.rows = [] #self.exampleRows = [] headingRow = Row() headingRow.addLabel(st(670), COLOR_COLUMN, columnspan=2, bold=True) headingRow.addLabel(st(671), BOLD_COLUMN, columnspan=2, bold=True, padX=23) headingRow.addLabel(st(672), ITALIC_COLUMN, columnspan=3, bold=True, padX=23) #headingRow.addLabel( st(653), LOCATION_COLUMN,columnspan=2, bold=True, padX=LOCATION_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) #headingRow.addLabel( st(653), LOCATION_COLUMN,columnspan=2, bold=True, padX=LOCATION_COLUMN_PAD+23, alignment=pyxbmct.ALIGN_LEFT) self.rows.append(headingRow) self.exampleRow = Row() #self.examplesTB = self.exampleRow.addTextBox(SETTING_COLUMN, columnspan=7, padX=SETTING_COLUMN_PAD, rowspan=5) self.exampleList = None self.examples = [] self._assignedValue = False def updateExamples(self): examplesToShow = [] for example in self.examples: if example.visible: examplesToShow.append(example.text) if self.exampleList: self.exampleList.control.reset() for example in examplesToShow: self.exampleList.control.addItem(example) else: self.exampleList = self.exampleRow.addList(examplesToShow, SETTING_COLUMN, space=0, columnspan=7, rowspan=9) #examplesText = '\n'.join(examplesToShow) #self.examplesTB.setText(examplesText) def addCustomItem(self, label, currentTS, defaultTS, saveCallback, showOptions=False, radioPadX=0): assignedTS = TextSettings.fromOther(currentTS) #exampleRow = Row() #example = exampleRow.addLabel(exampleText(), SETTING_COLUMN, columnspan=7, padX=SETTING_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) example = Example(assignedTS.apply(label), self, assignedTS.show) self.examples.append(example) def exampleUpdate(): exampleText = assignedTS.apply(label) example.update(exampleText, assignedTS.show) #example.setLabel(exampleText()) self.addItemRow(label, currentTS, defaultTS, assignedTS, exampleUpdate, showOptions, saveCallback=saveCallback, radioPadX=radioPadX) #self.exampleRows.append(exampleRow) def addFullItem(self, currentFTS, defaultFTS, saveCallback, titleExample, sourceExample=None, countlessTitleExample=None, countlessSourceExample=None): assignedFTS = FullTextSettings.fromOther(currentFTS) _saved = [False] def onSave( assignedTS ): #this function prevents saveCallback to be called more than once by the other TSes if not _saved[0]: saveCallback(assignedFTS) _saved[0] = True count = '14hr' count2 = '562k' maxChars = 4 maxChars2 = 4 #textIfNone =' '*11 textIfNone2 = ' ' * 12 def exampleText(): return assignedFTS.fullText(titleExample, sourceExample, count, maxChars, countNumber2=count2, maxChars2=maxChars2) def countlessExampleText(): return assignedFTS.fullText(countlessTitleExample, countlessSourceExample, count, maxChars, textIfNone2=textIfNone2) # countTS = assignedFTS.countTS # assignedFTS.countTS = None # text = assignedFTS.fullText(countlessTitleExample, countlessSourceExample) # # assignedFTS.countTS = countTS # return text example = Example(exampleText(), self) countlessExample = Example(countlessExampleText(), self) self.examples.append(example) self.examples.append(countlessExample) def exampleUpdate(): example.update(exampleText()) countlessExample.update(countlessExampleText()) radioPadX = 0 #radioPadX = -14 self.addItemRow(st(680), currentFTS.countTS, defaultFTS.countTS, assignedFTS.countTS, exampleUpdate, saveCallback=onSave, showOptions=True, radioPadX=radioPadX, cLocHolder=currentFTS, dLocHolder=defaultFTS, aLocHolder=assignedFTS) self.addItemRow(st(681), currentFTS.count2TS, defaultFTS.count2TS, assignedFTS.count2TS, exampleUpdate, saveCallback=onSave, showOptions=False, radioPadX=radioPadX) radioPadX = 0 #radioPadX = -14 self.addItemRow(st(682), currentFTS.sourceTS, defaultFTS.sourceTS, assignedFTS.sourceTS, exampleUpdate, saveCallback=onSave, showOptions=True, radioPadX=radioPadX) self.addItemRow(st(683), currentFTS.titleTS, defaultFTS.titleTS, assignedFTS.titleTS, exampleUpdate, saveCallback=onSave) #exampleRow = Row() #countlessExampleRow = Row() #example = exampleRow .addLabel(exampleText(), SETTING_COLUMN, columnspan=7, padX=SETTING_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) #countlessExample = countlessExampleRow .addLabel(countlessExampleText(), SETTING_COLUMN, columnspan=7, padX=SETTING_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) #def exampleUpdate(): #example.setLabel(exampleText()) #countlessExample.setLabel(countlessExampleText()) #pass #self.exampleRows.append(exampleRow) #self.exampleRows.append(countlessExampleRow) def addItemRow(self, label, currentTS, defaultTS, assignedTS, exampleUpdate, showOptions=False, saveCallback=None, radioPadX=0, cLocHolder=None, dLocHolder=None, aLocHolder=None): _assignedValue = [False] def assignedValue(): exampleUpdate() _assignedValue[0] = True def colorCallback(color): assignedTS.color = color assignedValue() def boldCallback(state): assignedTS.bold = state assignedValue() def italicCallback(state): assignedTS.italic = state assignedValue() def onSave(value): if _assignedValue[0] and saveCallback: saveCallback(assignedTS) _assignedValue[ 0] = None #so saveCallback doesn't get called again and again from the other controls row = Row() if showOptions: def setButtonsState(state): colorButton.setEnabled(state) boldButton.setEnabled(state) italicButton.setEnabled(state) if locationButton: locationButton.setEnabled(state) def showCallback(state): assignedTS.show = state setButtonsState(state) assignedValue() radioMove = 30 + radioPadX padX = SETTING_COLUMN_PAD - radioMove textOffsetX = radioMove row.addRadioButton(SETTING_COLUMN, assignedTS.show, defaultTS.show, label=label, changeCallback=showCallback, saveCallback=onSave, columnspan=1, padX=padX, textOffsetX=textOffsetX, alignment=pyxbmct.ALIGN_LEFT) #row.addRadioButton(LOCATION_COLUMN, assignedTS.show, defaultTS.show, changeCallback=showCallback, saveCallback=onSave, columnspan=LOCATION_COLUMN_SPAN, padX=LOCATION_COLUMN_PAD) buttonsEnabled = assignedTS.show else: row.addLabel(label, SETTING_COLUMN, columnspan=3, padX=SETTING_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) buttonsEnabled = True colorButton = row.addEnumButton(st(650), colors.loweredColors, currentTS.color, defaultTS.color, COLOR_COLUMN, customLabels=colors.coloredColors, alignment=pyxbmct.ALIGN_LEFT, columnspan=1, changeCallback=colorCallback, saveCallback=onSave, returnValue=True, mode=EnumMode.SELECT, enabled=buttonsEnabled) boldButton = row.addRadioButton(BOLD_COLUMN, currentTS.bold, defaultTS.bold, changeCallback=boldCallback, saveCallback=onSave, enabled=buttonsEnabled) italicButton = row.addRadioButton(ITALIC_COLUMN, currentTS.italic, defaultTS.italic, changeCallback=italicCallback, saveCallback=onSave, enabled=buttonsEnabled) if cLocHolder: def locationCallback(location): aLocHolder.countLocation = location assignedValue() locationButton = row.addEnumButton(st(673), LOCATION_OPTIONS, cLocHolder.countLocation, dLocHolder.countLocation, LOCATION_COLUMN, changeCallback=locationCallback, saveCallback=onSave, customLabels=LOCATION_LABELS, returnValue=True, alignment=pyxbmct.ALIGN_LEFT, columnspan=LOCATION_COLUMN_SPAN, padX=LOCATION_COLUMN_PAD, enabled=buttonsEnabled) else: locationButton = None if showOptions: setButtonsState(assignedTS.show) self.rows.append(row) def addExamples(self): #self.rows.extend(self.exampleRows) self.updateExamples() self.rows.append(self.exampleRow) def addEmptyRow(self): row = Row() self.rows.append(row)
def addItemRow(self, label, currentTS, defaultTS, assignedTS, exampleUpdate, showOptions=False, saveCallback=None, radioPadX=0, cLocHolder=None, dLocHolder=None, aLocHolder=None): _assignedValue = [False] def assignedValue(): exampleUpdate() _assignedValue[0] = True def colorCallback(color): assignedTS.color = color assignedValue() def boldCallback(state): assignedTS.bold = state assignedValue() def italicCallback(state): assignedTS.italic = state assignedValue() def onSave(value): if _assignedValue[0] and saveCallback: saveCallback(assignedTS) _assignedValue[ 0] = None #so saveCallback doesn't get called again and again from the other controls row = Row() if showOptions: def setButtonsState(state): colorButton.setEnabled(state) boldButton.setEnabled(state) italicButton.setEnabled(state) if locationButton: locationButton.setEnabled(state) def showCallback(state): assignedTS.show = state setButtonsState(state) assignedValue() radioMove = 30 + radioPadX padX = SETTING_COLUMN_PAD - radioMove textOffsetX = radioMove row.addRadioButton(SETTING_COLUMN, assignedTS.show, defaultTS.show, label=label, changeCallback=showCallback, saveCallback=onSave, columnspan=1, padX=padX, textOffsetX=textOffsetX, alignment=pyxbmct.ALIGN_LEFT) #row.addRadioButton(LOCATION_COLUMN, assignedTS.show, defaultTS.show, changeCallback=showCallback, saveCallback=onSave, columnspan=LOCATION_COLUMN_SPAN, padX=LOCATION_COLUMN_PAD) buttonsEnabled = assignedTS.show else: row.addLabel(label, SETTING_COLUMN, columnspan=3, padX=SETTING_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) buttonsEnabled = True colorButton = row.addEnumButton(st(650), colors.loweredColors, currentTS.color, defaultTS.color, COLOR_COLUMN, customLabels=colors.coloredColors, alignment=pyxbmct.ALIGN_LEFT, columnspan=1, changeCallback=colorCallback, saveCallback=onSave, returnValue=True, mode=EnumMode.SELECT, enabled=buttonsEnabled) boldButton = row.addRadioButton(BOLD_COLUMN, currentTS.bold, defaultTS.bold, changeCallback=boldCallback, saveCallback=onSave, enabled=buttonsEnabled) italicButton = row.addRadioButton(ITALIC_COLUMN, currentTS.italic, defaultTS.italic, changeCallback=italicCallback, saveCallback=onSave, enabled=buttonsEnabled) if cLocHolder: def locationCallback(location): aLocHolder.countLocation = location assignedValue() locationButton = row.addEnumButton(st(673), LOCATION_OPTIONS, cLocHolder.countLocation, dLocHolder.countLocation, LOCATION_COLUMN, changeCallback=locationCallback, saveCallback=onSave, customLabels=LOCATION_LABELS, returnValue=True, alignment=pyxbmct.ALIGN_LEFT, columnspan=LOCATION_COLUMN_SPAN, padX=LOCATION_COLUMN_PAD, enabled=buttonsEnabled) else: locationButton = None if showOptions: setButtonsState(assignedTS.show) self.rows.append(row)
def __init__(self, file, cover=False, load_rows=True, intro_courses=1, method_courses=1): definition = configparser.ConfigParser() definition.optionxform = str # Don't want keys to be lower cased definition.read(file) self.name = definition.get('INFO', 'name') self.bells = definition.getint('INFO', 'bells') self.frame_length = definition.getint('INFO', 'frame_length', fallback=self.bells * 2) self.cover = cover if cover: self.bells = self.bells + 1 self.rows = definition.getint('INFO', 'rows') self.rows = [] if load_rows: # Build the intro courses for ndx in range(intro_courses): for r in range( 2): # Handstroke and backstroke in a course of rounds row = Row('I' + str(ndx * 2 + r + 1), self.frame_length) for b in range(self.bells): row.add_bell(b + 1) self.rows.append(row) # Add 'Go method' to the final round of the intro self.rows[len(self.rows) - 1].call_go = True # Load the method rows for ndx in range(method_courses): for r in definition.items('ROWS'): row = Row(r[0], self.frame_length) items = r[1].split() for i in items: if i == '(G)': row.call_go = True elif i == '(A)': row.call_thats_all = True elif i == '(B)': row.call_bob = True elif i == '(S)': row.call_single = True elif i == '(N)': row.call_stand = True else: bell = int(i) row.add_bell(bell) if cover: row.add_bell(self.bells) self.rows.append(row) # Add 'Thats all' to the second to last row of the method self.rows[len(self.rows) - 2].call_thats_all = True # Build the extro courses for r in range( 2): # Handstroke and backstroke in a course of rounds row = Row('E' + str(ndx * 2 + r + 1), self.frame_length) for b in range(self.bells): row.add_bell(b + 1) self.rows.append(row) # Add 'Stand next' to the second to last row of the extro self.rows[len(self.rows) - 2].call_stand = True
search = 'BT010111_position.xls' workbook = xlrd.open_workbook(search) worksheet = workbook.sheet_by_name('Sheet1') num_rows = worksheet.nrows - 1 num_cells = worksheet.ncols - 1 list_data = [] #testing purpose curr_row = 1 #start at 1 num_rows = 99 #end at 99 while curr_row < num_rows: curr_row += 1 row = worksheet.row(curr_row) # print 'Row:', curr_row curr_cell = -1 row_data = Row(curr_row, "name_tinh", "name_tram", 13, 23, 33, 43,"file_name", 0, 0, 0 , 0 , 0) while curr_cell < num_cells: curr_cell += 1 # Cell Types: 0=Empty, 1=Text, 2=Number, 3=Date, 4=Boolean, 5=Error, 6=Blank cell_type = worksheet.cell_type(curr_row, curr_cell) cell_value = worksheet.cell_value(curr_row, curr_cell) # print ' ', curr_cell, ':', cell_type, ':', cell_value if curr_cell == 0 : row_data.id = cell_value if curr_cell == 1 : if cell_type == 0: row_data.name_tinh = list_data[-1].name_tinh else: row_data.name_tinh = cell_value if curr_cell == 2 : row_data.name_tram = cell_value
def addNextPage(self, nextPage): if self.navRow is None: self.navRow = Row() self.navRow.addButton(addon.string(604), 9, lambda: self.window.showPage(nextPage), columnspan=1, bold=False)
def importOneFolder(expression): index = 0 #for line in fileinput.input(glob.glob("data/*.xls")): for line in fileinput.input(glob.glob(expression)): search = '.xls' #Tim tung thang cho nay//BT010111 if fileinput.filename().find(search) != -1: print '-Start for-' else: continue name = fileinput.filename() print name shirf = 19#for 2005-2014 shirf = 19#for 2005-2014 ngay = name[shirf +0] +name[shirf +1] thang = name[shirf +2] + name[shirf +3] nam = '20' + name[shirf +4] + name[shirf +5] print ngay, thang, nam if fileinput.isfirstline(): # first in a file? sys.stderr.write("-- reading %s --\n" % fileinput.filename()) workbook = xlrd.open_workbook(fileinput.filename()) #worksheet = workbook.sheet_by_name('Sheet1') worksheet = workbook.sheet_by_index(0) num_rows = worksheet.nrows - 1 num_cells = worksheet.ncols - 1 list_data = [] #testing purpose curr_row = 1 #start at 1 num_rows = 99 #end at 99 while curr_row < num_rows: curr_row += 1 row = worksheet.row(curr_row) #print 'Row:', curr_row curr_cell = -1 row_data = Row(curr_row, "name_tinh", "name_tram", 13, 23, 33, 43,"file_name", 0, 0, 0) while curr_cell < num_cells: curr_cell += 1 # Cell Types: 0=Empty, 1=Text, 2=Number, 3=Date, 4=Boolean, 5=Error, 6=Blank cell_type = worksheet.cell_type(curr_row, curr_cell) cell_value = worksheet.cell_value(curr_row, curr_cell) # print ' ', curr_cell, ':', cell_type, ':', cell_value if curr_cell == 0 : row_data.id = cell_value if curr_cell == 1 : if cell_type == 0: row_data.name_tinh = list_data[-1].name_tinh else: row_data.name_tinh = cell_value if curr_cell == 2 : row_data.name_tram = cell_value if curr_cell == 3 : cell_value = str(cell_value).replace(" ", "").replace("/","") if cell_value == empty_string or cell_value == ' ' or cell_value =='' or str(cell_value).find(empty_string) != -1 : row_data.temp_13 = 0 else: row_data.temp_13 = cell_value if cell_type == 0: row_data.temp_13 = 0 if curr_cell == 4 : cell_value = str(cell_value).replace(" ", "").replace("/","") if cell_value == empty_string or cell_value == ' ' or cell_value =='' or str(cell_value).find(empty_string) != -1 : row_data.humid_13 = 0 else: row_data.humid_13 = cell_value if cell_type == 0: row_data.humid_13 = 0 if curr_cell == 5 : cell_value = str(cell_value).replace(" ", "").replace("/","") if cell_value == empty_string or cell_value == ' ' or cell_value =='' or str(cell_value).find(empty_string) != -1 : row_data.rain_13 = 0 else: row_data.rain_13 = cell_value if cell_type == 0: row_data.rain_13 = 0 if curr_cell == 6 : cell_value = str(cell_value).replace(" ", "").replace("/","") if cell_value == empty_string or cell_value == ' ' or cell_value =='' or str(cell_value).find(empty_string) != -1 : row_data.rain_24 = 0 else: row_data.rain_24 = cell_value if cell_type == 0: row_data.rain24 = 0 if curr_cell == 7 : row_data.file_name = cell_value list_data.append(row_data) # for item in list_data: # pprint (vars(item)) list_root.append(list_data) f.write(fileinput.filename()+ str(index) +'\n') print index for item in list_data: index = index + 1 if item.rain_24 == '': item.rain_24 = 0 #print str(item.temp_13), str(item.humid_13), str(item.rain_13), str(item.rain_24), item.id list_.append((ngay+ '-'+thang+ '-'+nam, float(str(item.temp_13).replace(',','.')), float(str(item.humid_13).replace(',','.')), float(str(item.rain_13).replace(',','.')), float(str(item.rain_24).replace(',','.')), item.id))
class ListItemTable(object): def __init__(self): self.rows = [] #self.exampleRows = [] headingRow = Row() headingRow.addLabel( st(670), COLOR_COLUMN, columnspan=2, bold=True) headingRow.addLabel( st(671), BOLD_COLUMN, columnspan=2, bold=True, padX=23) headingRow.addLabel( st(672), ITALIC_COLUMN, columnspan=3, bold=True, padX=23) #headingRow.addLabel( st(653), LOCATION_COLUMN,columnspan=2, bold=True, padX=LOCATION_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) #headingRow.addLabel( st(653), LOCATION_COLUMN,columnspan=2, bold=True, padX=LOCATION_COLUMN_PAD+23, alignment=pyxbmct.ALIGN_LEFT) self.rows.append(headingRow) self.exampleRow = Row() #self.examplesTB = self.exampleRow.addTextBox(SETTING_COLUMN, columnspan=7, padX=SETTING_COLUMN_PAD, rowspan=5) self.exampleList = None self.examples = [] self._assignedValue = False def updateExamples(self): examplesToShow = [] for example in self.examples: if example.visible: examplesToShow.append(example.text) if self.exampleList: self.exampleList.control.reset() for example in examplesToShow: self.exampleList.control.addItem(example) else: self.exampleList = self.exampleRow.addList(examplesToShow, SETTING_COLUMN, space=0, columnspan=7, rowspan=9) #examplesText = '\n'.join(examplesToShow) #self.examplesTB.setText(examplesText) def addCustomItem(self, label, currentTS, defaultTS, saveCallback, showOptions=False, radioPadX=0): assignedTS = TextSettings.fromOther(currentTS) #exampleRow = Row() #example = exampleRow.addLabel(exampleText(), SETTING_COLUMN, columnspan=7, padX=SETTING_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) example = Example(assignedTS.apply(label), self, assignedTS.show) self.examples.append(example) def exampleUpdate(): exampleText = assignedTS.apply(label) example.update(exampleText, assignedTS.show) #example.setLabel(exampleText()) self.addItemRow(label, currentTS, defaultTS, assignedTS, exampleUpdate, showOptions, saveCallback=saveCallback, radioPadX=radioPadX) #self.exampleRows.append(exampleRow) def addFullItem(self, currentFTS, defaultFTS, saveCallback, titleExample, sourceExample=None, countlessTitleExample=None, countlessSourceExample=None): assignedFTS = FullTextSettings.fromOther(currentFTS) _saved = [False] def onSave(assignedTS): #this function prevents saveCallback to be called more than once by the other TSes if not _saved[0]: saveCallback(assignedFTS) _saved[0] = True count = '14hr' count2 = '562k' maxChars = 4 maxChars2 = 4 #textIfNone =' '*11 textIfNone2 =' '*12 def exampleText(): return assignedFTS.fullText(titleExample, sourceExample, count, maxChars, countNumber2=count2, maxChars2=maxChars2) def countlessExampleText(): return assignedFTS.fullText(countlessTitleExample, countlessSourceExample, count, maxChars, textIfNone2=textIfNone2) # countTS = assignedFTS.countTS # assignedFTS.countTS = None # text = assignedFTS.fullText(countlessTitleExample, countlessSourceExample) # # assignedFTS.countTS = countTS # return text example = Example(exampleText(), self) countlessExample = Example(countlessExampleText(), self) self.examples.append(example) self.examples.append(countlessExample) def exampleUpdate(): example.update(exampleText()) countlessExample.update(countlessExampleText()) radioPadX = 0 #radioPadX = -14 self.addItemRow(st(680), currentFTS.countTS, defaultFTS.countTS, assignedFTS.countTS, exampleUpdate, saveCallback=onSave, showOptions=True, radioPadX=radioPadX, cLocHolder=currentFTS, dLocHolder=defaultFTS, aLocHolder=assignedFTS) self.addItemRow(st(681), currentFTS.count2TS, defaultFTS.count2TS, assignedFTS.count2TS, exampleUpdate, saveCallback=onSave, showOptions=False, radioPadX=radioPadX) radioPadX = 0 #radioPadX = -14 self.addItemRow(st(682), currentFTS.sourceTS, defaultFTS.sourceTS, assignedFTS.sourceTS, exampleUpdate, saveCallback=onSave, showOptions=True, radioPadX=radioPadX) self.addItemRow(st(683), currentFTS.titleTS, defaultFTS.titleTS, assignedFTS.titleTS, exampleUpdate, saveCallback=onSave) #exampleRow = Row() #countlessExampleRow = Row() #example = exampleRow .addLabel(exampleText(), SETTING_COLUMN, columnspan=7, padX=SETTING_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) #countlessExample = countlessExampleRow .addLabel(countlessExampleText(), SETTING_COLUMN, columnspan=7, padX=SETTING_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) #def exampleUpdate(): #example.setLabel(exampleText()) #countlessExample.setLabel(countlessExampleText()) #pass #self.exampleRows.append(exampleRow) #self.exampleRows.append(countlessExampleRow) def addItemRow(self, label, currentTS, defaultTS, assignedTS, exampleUpdate, showOptions=False, saveCallback=None, radioPadX=0, cLocHolder=None, dLocHolder=None, aLocHolder=None): _assignedValue = [False] def assignedValue(): exampleUpdate() _assignedValue[0] = True def colorCallback(color): assignedTS.color = color assignedValue() def boldCallback(state): assignedTS.bold = state assignedValue() def italicCallback(state): assignedTS.italic = state assignedValue() def onSave(value): if _assignedValue[0] and saveCallback: saveCallback(assignedTS) _assignedValue[0] = None #so saveCallback doesn't get called again and again from the other controls row = Row() if showOptions: def setButtonsState(state): colorButton.setEnabled(state) boldButton.setEnabled(state) italicButton.setEnabled(state) if locationButton: locationButton.setEnabled(state) def showCallback(state): assignedTS.show = state setButtonsState(state) assignedValue() radioMove = 30 + radioPadX padX = SETTING_COLUMN_PAD - radioMove textOffsetX = radioMove row.addRadioButton(SETTING_COLUMN, assignedTS.show, defaultTS.show, label=label, changeCallback=showCallback, saveCallback=onSave, columnspan=1, padX=padX, textOffsetX=textOffsetX, alignment=pyxbmct.ALIGN_LEFT) #row.addRadioButton(LOCATION_COLUMN, assignedTS.show, defaultTS.show, changeCallback=showCallback, saveCallback=onSave, columnspan=LOCATION_COLUMN_SPAN, padX=LOCATION_COLUMN_PAD) buttonsEnabled = assignedTS.show else: row.addLabel(label, SETTING_COLUMN, columnspan=3, padX=SETTING_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) buttonsEnabled = True colorButton = row.addEnumButton(st(650), colors.loweredColors, currentTS.color, defaultTS.color, COLOR_COLUMN, customLabels=colors.coloredColors, alignment=pyxbmct.ALIGN_LEFT, columnspan=1, changeCallback=colorCallback, saveCallback=onSave, returnValue=True, mode=EnumMode.SELECT, enabled=buttonsEnabled) boldButton = row.addRadioButton(BOLD_COLUMN, currentTS.bold, defaultTS.bold, changeCallback=boldCallback, saveCallback=onSave, enabled=buttonsEnabled) italicButton = row.addRadioButton(ITALIC_COLUMN, currentTS.italic, defaultTS.italic, changeCallback=italicCallback, saveCallback=onSave, enabled=buttonsEnabled) if cLocHolder: def locationCallback(location): aLocHolder.countLocation = location assignedValue() locationButton = row.addEnumButton(st(673), LOCATION_OPTIONS, cLocHolder.countLocation, dLocHolder.countLocation, LOCATION_COLUMN, changeCallback=locationCallback, saveCallback=onSave, customLabels=LOCATION_LABELS, returnValue=True, alignment=pyxbmct.ALIGN_LEFT, columnspan=LOCATION_COLUMN_SPAN, padX=LOCATION_COLUMN_PAD, enabled=buttonsEnabled) else: locationButton = None if showOptions: setButtonsState(assignedTS.show) self.rows.append(row) def addExamples(self): #self.rows.extend(self.exampleRows) self.updateExamples() self.rows.append(self.exampleRow) def addEmptyRow(self): row = Row() self.rows.append(row)
def addItemRow(self, label, currentTS, defaultTS, assignedTS, exampleUpdate, showOptions=False, saveCallback=None, radioPadX=0, cLocHolder=None, dLocHolder=None, aLocHolder=None): _assignedValue = [False] def assignedValue(): exampleUpdate() _assignedValue[0] = True def colorCallback(color): assignedTS.color = color assignedValue() def boldCallback(state): assignedTS.bold = state assignedValue() def italicCallback(state): assignedTS.italic = state assignedValue() def onSave(value): if _assignedValue[0] and saveCallback: saveCallback(assignedTS) _assignedValue[0] = None #so saveCallback doesn't get called again and again from the other controls row = Row() if showOptions: def setButtonsState(state): colorButton.setEnabled(state) boldButton.setEnabled(state) italicButton.setEnabled(state) if locationButton: locationButton.setEnabled(state) def showCallback(state): assignedTS.show = state setButtonsState(state) assignedValue() radioMove = 30 + radioPadX padX = SETTING_COLUMN_PAD - radioMove textOffsetX = radioMove row.addRadioButton(SETTING_COLUMN, assignedTS.show, defaultTS.show, label=label, changeCallback=showCallback, saveCallback=onSave, columnspan=1, padX=padX, textOffsetX=textOffsetX, alignment=pyxbmct.ALIGN_LEFT) #row.addRadioButton(LOCATION_COLUMN, assignedTS.show, defaultTS.show, changeCallback=showCallback, saveCallback=onSave, columnspan=LOCATION_COLUMN_SPAN, padX=LOCATION_COLUMN_PAD) buttonsEnabled = assignedTS.show else: row.addLabel(label, SETTING_COLUMN, columnspan=3, padX=SETTING_COLUMN_PAD, alignment=pyxbmct.ALIGN_LEFT) buttonsEnabled = True colorButton = row.addEnumButton(st(650), colors.loweredColors, currentTS.color, defaultTS.color, COLOR_COLUMN, customLabels=colors.coloredColors, alignment=pyxbmct.ALIGN_LEFT, columnspan=1, changeCallback=colorCallback, saveCallback=onSave, returnValue=True, mode=EnumMode.SELECT, enabled=buttonsEnabled) boldButton = row.addRadioButton(BOLD_COLUMN, currentTS.bold, defaultTS.bold, changeCallback=boldCallback, saveCallback=onSave, enabled=buttonsEnabled) italicButton = row.addRadioButton(ITALIC_COLUMN, currentTS.italic, defaultTS.italic, changeCallback=italicCallback, saveCallback=onSave, enabled=buttonsEnabled) if cLocHolder: def locationCallback(location): aLocHolder.countLocation = location assignedValue() locationButton = row.addEnumButton(st(673), LOCATION_OPTIONS, cLocHolder.countLocation, dLocHolder.countLocation, LOCATION_COLUMN, changeCallback=locationCallback, saveCallback=onSave, customLabels=LOCATION_LABELS, returnValue=True, alignment=pyxbmct.ALIGN_LEFT, columnspan=LOCATION_COLUMN_SPAN, padX=LOCATION_COLUMN_PAD, enabled=buttonsEnabled) else: locationButton = None if showOptions: setButtonsState(assignedTS.show) self.rows.append(row)
num_rows = worksheet.nrows - 1 num_cells = worksheet.ncols - 1 curr_row = -1 list_data = [] empty_string = '-' #testing purpose curr_row = 1 #start at 1 num_rows = 4 #end at 99 while curr_row < num_rows: curr_row += 1 row = worksheet.row(curr_row) #print 'Row:', curr_row curr_cell = -1 row_data = Row(curr_row, "name_tinh", "name_tram", 13, 23, 33, 43,"file_name") while curr_cell < num_cells: curr_cell += 1 # Cell Types: 0=Empty, 1=Text, 2=Number, 3=Date, 4=Boolean, 5=Error, 6=Blank cell_type = worksheet.cell_type(curr_row, curr_cell) cell_value = worksheet.cell_value(curr_row, curr_cell) #print ' ', curr_cell, ':', cell_type, ':', cell_value if curr_cell == 0 : row_data.id = cell_value if curr_cell == 1 : row_data.name_tinh = cell_value if curr_cell == 2 : row_data.name_tram = cell_value if curr_cell == 3 : if cell_value == empty_string: row_data.temp_13 = 0
class SettingsWindow(object): def __init__(self, title, width=800, height=500, saveCallback=None, hideTabs=False, showButtons=True): self.title = title self.width = width self.height = height self.saveCallback = saveCallback self.hideTabs = hideTabs self.window = pyxbmct.AddonDialogWindow(title) self.window.setGeometry(width, height, 14, 10) if showButtons: self.createButtons() else: self.buttonRow = None self.tabs = [] self.onSaveCallbacks = [] self.currentPage = None def createButtons(self): buttonRow = Row() def defaultsActions(): for onDefaultCallback in self.currentPage.tab.onDefaultCallbacks: onDefaultCallback() def okAction(): for onSaveCallback in self.onSaveCallbacks: onSaveCallback() if self.saveCallback: self.saveCallback() self.window.close() def cancelAction(): self.window.close() buttonRow.addButton( addon.string(600), 2, okAction, columnspan=2, bold=True) buttonRow.addButton( addon.string(601), 4, cancelAction, columnspan=2, bold=True) buttonRow.addButton( addon.string(602), 6, defaultsActions, columnspan=2, bold=True) self._placeRow(buttonRow, BUTTON_ROW, forceLocation=True) self.buttonRow = buttonRow def addCustomButton(self, label, column, onClick): if self.buttonRow is None: self.buttonRow = Row() button = self.buttonRow.addButton(label, column, onClick, columnspan=2, bold=True) return button def placeCustomButtons(self): self._placeRow(self.buttonRow, BUTTON_ROW, forceLocation=True) def _placeRow(self, row, rowNum, onDefaultCallbacks=None, forceLocation=False): for rowControl in row.rowControls: column = rowControl.column columnspan = rowControl.columnspan if self.hideTabs and column == SETTING_COLUMN and not forceLocation: column -= 2 columnspan += 2 #column +=1 self.window.placeControl(rowControl.control, rowNum, column, columnspan=columnspan, pad_x=rowControl.padX, rowspan=rowControl.rowspan) if rowControl.action: self.window.connect(rowControl.control, rowControl.action) if rowControl.onDefault: onDefaultCallbacks.append(rowControl.onDefault) if rowControl.onSave: self.onSaveCallbacks.append(rowControl.onSave) if rowControl.init: rowControl.init() def addTabs(self, tabs, bold=False, space=10, padX=-10, textXOffset=0): listC = pyxbmct.List(_space=space, _itemTextXOffset=textXOffset) if not self.hideTabs: self.window.placeControl(listC, 0, 0, 10, 2, pad_x=padX) index = 0 for tab in tabs: title = tab.title title = ts.color(TABS_COLOR, title) if bold: title = ts.bold(title) listC.addItem(title) tab.num = index self.tabs.append(tab) self.window.setGeometry(self.width, self.height, tab.numRows, tab.numColumns) self.placeTab(tab) index += 1 self.tabsListC = listC self.showTab(0) self.window.connect(listC, self.tabAction) def tabAction(self): tabIndex = self.tabsListC.getSelectedPosition() self.showTab(tabIndex) def showPage(self, page): if self.currentPage == page: return if self.currentPage is not None: self.currentPage.hide() currentTab = self.currentPage.tab if currentTab.useGlobalButton: currentTab.ugbRow.hide() page.unHide() self.currentPage = page tab = page.tab if tab.useGlobalButton: tab.ugbRow.unHide() def showTab(self, tabIndex, pageNum=0): tab = self.tabs[tabIndex] page = tab.pages[pageNum] self.showPage(page) def placeTab(self, tab): pages = [] onDefaultCallbacks = [] currentPage = TabPage(0, tab, self) pages.append(currentPage) for row in tab.rows: #if currentPage.rowsFilled == MAX_PAGE_ROWS: if currentPage.rowsFilled == tab.numRows - 2: lastPage = currentPage currentPage = TabPage(lastPage.num + 1, tab, self, prevPage=lastPage) lastPage.addNextPage(currentPage) pages.append(currentPage) self._placeRow(row, currentPage.rowsFilled, onDefaultCallbacks) currentPage.addRow(row) for page in pages: page.placeNavRowIfExists() page.hide() tab.onDefaultCallbacks = onDefaultCallbacks tab.pages = pages if tab.useGlobalButton: ugbRow = Row() ugb = tab.useGlobalButton label = ts.italic( addon.string(605) ) ugbRow.addRadioButton(7, ugb.current, ugb.default, saveCallback=ugb.saveCallback, label=label, columnspan=2, changeCallback=lambda state: tab.setGlobalEnabled(not state)) self.window.setGeometry(self.width, self.height, 14, 10) self._placeRow(ugbRow, 12, onDefaultCallbacks) ugbRow.hide() tab.ugbRow = ugbRow if ugb.current is True: tab.globalDisable() def show(self): self.window.doModal() def close(self): self.window.close() def delete(self): del self.window
def addEmptyRow(self): row = Row() self.rows.append(row)
def addCustomButton(self, label, column, onClick): if self.buttonRow is None: self.buttonRow = Row() button = self.buttonRow.addButton(label, column, onClick, columnspan=2, bold=True) return button