def setupFirmwareTable(self): """setup the table of firmware with title/author, etc""" self.header = ["Title","Updated","Author","Summary"] self.feed_url = "http://www.bocolab.org/bopunks/feeds/firms.atom.xml" self.feed = FirmwareFeed(url=self.feed_url) # setup table self.tableModel = FirmwareTableModel(self.feed, self.header, self) table = self.firmwareTable table.setModel(self.tableModel) table.verticalHeader().hide() table.horizontalHeader().setStretchLastSection(True) table.horizontalHeader().setHighlightSections(False) table.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents) # set default selection table.selectRow(0) # fun hack! but ... still a hack # create an anonymous object with functions for row/column qmi = type('', (), {'row':lambda s: 0, 'column':lambda s: 0})() self.updateSelection(qmi,0) self.splitter.setStretchFactor(1,4)
class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self, parent = None): QMainWindow.__init__(self, parent) self.setupUi(self) # Variables # TODO: add persistent settings and configure # reference dialog box buttons by name std_button = QDialogButtonBox.StandardButton std_buttons = [ bt for bt in dir(QDialogButtonBox) if type(getattr(QDialogButtonBox, bt)) == std_button ] stdButtons = \ dict((getattr(QDialogButtonBox,v),v) for v in std_buttons) self._dynamicButtons = [] for b in self.buttonDialogVariables.buttons(): r = self.buttonDialogVariables.standardButton(b) attrname = "buttonDialog"+stdButtons[r] self._dynamicButtons.append(attrname) setattr(self,attrname, b) # Configure tabs self.setupTabs() # Setup and start Firmware List self.setupFirmwareProxy() self.setupFirmwareTable() # self.refreshFirmwareTable() # Connect slots/signals and actions self.setupConnections() def setupTabs(self): """configure generic settings of the firmware/downloads tabs""" # setup Main window self.statusBar().hide() self.progressLabel.setText("") self.progressBar.reset() self.descriptionText.setOpenExternalLinks(True) # cache for images/http descriptions self.cache_loc = tempfile.mkdtemp() self.cache = urlcache.build_opener(self.cache_loc) self.descriptionText.setResourceCache(self.cache) # cache for firmware downloads self.firmcache = FirmCache(self.set_progress, self.reset_progress) # DEBUG: tmp self.firmcache.clear() def setupFirmwareProxy(self): """Configures the firmware tab and interacts with FirmwareProxy""" self.device = FirmwareProxy(self) def setupFirmwareTable(self): """setup the table of firmware with title/author, etc""" self.header = ["Title","Updated","Author","Summary"] self.feed_url = "http://www.bocolab.org/bopunks/feeds/firms.atom.xml" self.feed = FirmwareFeed(url=self.feed_url) # setup table self.tableModel = FirmwareTableModel(self.feed, self.header, self) table = self.firmwareTable table.setModel(self.tableModel) table.verticalHeader().hide() table.horizontalHeader().setStretchLastSection(True) table.horizontalHeader().setHighlightSections(False) table.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents) # set default selection table.selectRow(0) # fun hack! but ... still a hack # create an anonymous object with functions for row/column qmi = type('', (), {'row':lambda s: 0, 'column':lambda s: 0})() self.updateSelection(qmi,0) self.splitter.setStretchFactor(1,4) def refreshFirmwareTable(self): """ Download and refresh RSS list of firmware and then parse and add the firmwares to the table model """ print "Running refreshFirmwareTable" self.descriptionText.setHtml("") self.tableModel.removeRows(0, len(self.feed)) self.feed.refresh() self.tableModel.insertRows(0, len(self.feed)) loc = self.cache_loc try: files = os.listdir(self.cache_loc) for file in files: os.remove(os.path.join(self.cache_loc,file)) except IOError, inst: print "ERROR refreshFirmwareTable:", inst