示例#1
0
    def copyCellColors(self):
        # Colour indexes ----- Pink: 45    Yellow: 43
        col = 1

        # Iterate over every cell, col first, row second.
        for i in range(5, 30, 2):
            for row in range(2, self.numEmployees[0] + 2):
                # Extracting style information to obtain background colour of cell.
                xf_left = self.new_sheet.cell_xf_index(row, i)
                xf_next_left = self.read_schedule.xf_list[xf_left]
                colour_index_left = xf_next_left.background.pattern_colour_index

                xf_right = self.new_sheet.cell_xf_index(row, i + 1)
                xf_next_right = self.read_schedule.xf_list[xf_right]
                colour_index_right = xf_next_right.background.pattern_colour_index

                if (self.new_sheet.cell(row, i).value == 'L'):
                    cell_item = QTableWidgetItem('L')
                    cell_item.setTextAlignment(1)
                    self.original_lunch_indexes[row + 1] = col
                elif (self.new_sheet.cell(row, i + 1).value == 'L'):
                    cell_item = QTableWidgetItem('L')
                    cell_item.setTextAlignment(2)
                    self.original_lunch_indexes[row + 1] = col
                else:
                    cell_item = QTableWidgetItem('')

                cell_item.setSizeHint(QSize(2, 2))

                # Set the table cell the same color as the excel cell.
                if colour_index_left == colour_index_right:
                    if colour_index_left == 45:
                        cell_item.setBackground(
                            QColor(self.pink[0], self.pink[1], self.pink[2]))
                        if cell_item.text() != 'L':
                            self.numberOfPT[col - 1] += 1
                    elif colour_index_left == 43:
                        cell_item.setBackground(
                            QColor(self.yellow[0], self.yellow[1],
                                   self.yellow[2]))
                        self.numberOfCE[col - 1] += 1
                    elif colour_index_left == 22:
                        cell_item.setBackground(
                            QColor(self.grey[0], self.grey[1], self.grey[2]))
                    self.tableWidget.setItem(row + 1, col, cell_item)
                else:
                    cell_item.setBackground(
                        QColor(self.grey[0], self.grey[1], self.grey[2]))
                    self.tableWidget.setItem(row + 1, col, cell_item)
                '''

                else:
                    cell_item.setBackground(QColor(self.grey[0], self.grey[1], self.grey[2]))
                    self.tableWidget.setItem(row, col, cell_item)
                '''

            col += 1
示例#2
0
 def add_song(self, song_title, song_artist, song_path):
     title = QTableWidgetItem(song_title)
     title.setData(Qt.UserRole, song_path)
     title.setSizeHint(QSize(0, 30))
     artist = QTableWidgetItem(song_artist)
     row = self.ui.fileWidget.rowCount()
     self.ui.fileWidget.insertRow(row)
     self.ui.fileWidget.setItem(row, 0, title)
     self.ui.fileWidget.setItem(row, 1, artist)
示例#3
0
    def onChanged(self,text):
        self.mataches_list = list()
        if text != '':
            try:
                self.matches_list = self.find_matches(text, self.applications_items)
            except:
                pass

        nmatches = len(self.matches_list)
        wsize = 40 + 49
        if nmatches == 0 or text.startswith('='):
            result_str = ""
            if(text.startswith('=')): text = text[1:]
            try:
                result_str = eval(text)
            except:
                pass
            if(result_str != ""):
                self.tableSearch.setRowCount(1)
                self.tableSearch.setColumnCount(1)
                self.setGeometry(self.centerPoint.x() - self.w / 2,25,self.w,wsize)
                trow = QTableWidgetItem("=%s"%(str(result_str)))
                trow.setSizeHint(QSize(400,40))
                trow.setBackground(QColor(255,255,255,255))
                self.tableSearch.setItem(0,0,trow)  
        else:
            wsize = 40 + nmatches*49
            if nmatches >= 9 : nmatches = 9
            self.tableSearch.setRowCount(nmatches)
            self.tableSearch.setColumnCount(1)
            self.setGeometry(self.centerPoint.x() - self.w / 2,25,self.w,wsize)
            nn = 0
            for m in self.matches_list:
                str_tmp = '%s' % (entry_name(m.DesktopEntry))
                trow = QTableWidgetItem(str_tmp)
                trow.setSizeHint(QSize(400,40))
                trow.setBackground(QColor(255,255,255,255))
                self.tableSearch.setItem(nn,0,trow)  
                nn +=1
                if nn == 9 : break
            self.tableSearch.selectRow(0)
示例#4
0
def main(argv):
    options = optparse.OptionParser()
    options.add_option('-f', '--file', dest='file', help='file', default=None)
    options.add_option('-p', '--pid', dest='pid', help='file', default=None)
    opts, args = options.parse_args(argv)
    print('opts:%s' % (opts))
    print('args:%s' % (args))
    if len(args):
        options.print_help()
        return

    if not opts.file:
        options.print_help()
        return

    app = QApplication(argv)
    list_widget = QListWidget()
    database = image_parse.image_database()

    #for index in range(0, 7):
    #for index in range(0, 4 * 3 * 2 * 1 * 4 * 3 * 2 * 1):
    for index in [24]:
        #if index == 6:
        #if index == 12:
        #    table_column = 132
        #else:
        #    table_column = 132 / 4
        table_column = 132

        s = ''
        #for i1, i2 in database.gen_pixel_bytes(opts.file, opts.pid, index):
        pos = 0
        for i1, i2, i3, i4 in database.gen_pixel_bytes(opts.file, opts.pid,
                                                       index):
            #xor = 0xff
            #v1 = database.conf.items('%d' %(pos + 1))
            #v2 = database.conf.items('%d' %(pos + 2))
            #v3 = database.conf.items('%d' %(pos + 3))
            #v4 = database.conf.items('%d' %(pos + 4))
            #if len(v1):
            #    v1 = int(v1[0][0], 16) ^ xor
            #    i1 = chr(ord(i1) ^ v1)
            #if len(v2):
            #    v2 = int(v2[0][0], 16) ^ xor
            #    i2 = chr(ord(i2) ^ v2)
            #if len(v3):
            #    v3 = int(v3[0][0], 16) ^ xor
            #    i3 = chr(ord(i3) ^ v3)
            #if len(v4):
            #    v4 = int(v4[0][0], 16) ^ xor
            #    i4 = chr(ord(i4) ^ v4)

            s += i1 + i2 + i3 + i4
            pos += 4

        #print('len(s):%s' %(len(s)))

        if len(s) != 14784:
            continue

        #valid = True
        #pos_limit = (112 * 2 / 5) * 132
        #for row in range(112):
        #    for col in range(132):
        #        pos = row * 132 + col
        #        if pos < pos_limit:
        #            print('update %s:%s' %(pos, ord(s[pos])))
        #            database.update_conf_setction_item(pos + 1, ord(s[pos]))
        #    #if row == 0 or row == 111:
        #    #    for col in range(132):
        #    #        pos = 132 * row + col
        #    #        if s[pos] != chr(0x00):
        #    #            valid = False
        #    #            break

        #    #pos_s = 132 * row + 0
        #    #pos_e = 132 * row + 131
        #    #if s[pos_s] != chr(0x00) or s[pos_e] != chr(0x00):
        #    #    valid = False
        #    #    break
        #    pos_s = 132 * row + 0
        #    if s[pos_s] != chr(0x00):
        #        valid = False
        #        break
        database.save()
        #if not valid:
        #    continue

        print('index:%s' % (index))

        table = QTableWidget(112, table_column)
        font = QFont()
        font.setFamily("Calibri")
        font.setPointSize(6)
        table.setFont(font)

        table.setEditTriggers(QTableWidget.NoEditTriggers)
        table.verticalHeader().setVisible(False)
        table.horizontalHeader().setVisible(False)

        #widget = QWidget()
        #vlayout = QVBoxLayout()
        f = io.BytesIO(s)
        ##bf = open('%s.csv' %(opts.pid), 'wb+')
        for h in range(0, 112):
            #    #hlayout = QHBoxLayout()
            #    #bf_line = ''
            for w in range(0, table_column):
                c = f.read(1)
                #        #if index == 6:
                #        if index == 12:
                #            c = f.read(1)
                #        else:
                #            c = f.read(1)
                #            c = f.read(1)
                #            c = f.read(1)
                #            c = f.read(1)
                item = QTableWidgetItem()
                item.setText('%02x' % (ord(c)))
                #        if index == 12:
                #            item.setText('%02x' %(ord(c)))
                #        else:
                #            if index % 2 == 0:
                #                item.setText('%02x' %((ord(c) & 0xf0) >> 4))
                #            else:
                #                item.setText('%02x' %((ord(c) & 0xf0)))

                #        #item.setSizeHint(QSize(25, 25));
                item.setBackground(QBrush(QColor(ord(c), ord(c), ord(c))))
                table.setItem(h, w, item)

        #        #item = QLabel()
        #        #item.setText('%02x' %(ord(c)))
        #        #pe = QPalette()
        #        #pe.setColor(QPalette.Background, QColor(ord(c), ord(c), ord(c)))
        #        #item.setPalette(pe)
        #        #item.setAutoFillBackground(True)
        #        #hlayout.addWidget(item)

        #        #bf_line += hex(ord(c)) + ','

        #    #vlayout.addItem(hlayout)

        #    #bf_line += '\n'
        #    #bf.write(bf_line)

        #widget.setLayout(vlayout)
        #widget.show()

        #bf.close()
        for c in range(0, table_column):
            table.setColumnWidth(c, 18)

        for r in range(0, 112):
            table.setRowHeight(r, 18)

        #table.resizeColumnsToContents()
        #table.resizeRowsToContents()
        #table.show()
        item = QListWidgetItem(list_widget)
        item.setSizeHint(table.sizeHint())
        list_widget.setItemWidget(item, table)

        #item = QListWidgetItem(list_widget)
        #image = QImage(s, 112, 132, QImage.Format_Grayscale8)
        #widget = QWidget()
        #layout = QVBoxLayout()
        #label = QLabel()
        #label.setPixmap(QPixmap.fromImage(image))
        #layout.addWidget(label)
        #widget.setLayout(layout)
        #item.setSizeHint(widget.sizeHint());
        #list_widget.setItemWidget(item, widget);

        item = QListWidgetItem(list_widget)
        image = QImage(s, 132, 112, QImage.Format_Grayscale8)
        pixmap = QPixmap.fromImage(image)
        #pixmap.save('%d.bmp' %(index))
        img = image_file.image_file(132, 112)
        img.write_bmp('%s-%s-%s' % (opts.file, opts.pid, index), s)
        widget = QWidget()
        layout = QVBoxLayout()
        label = QLabel()
        label.setText(str(index))
        layout.addWidget(label)
        label = QLabel()
        label.setPixmap(pixmap)
        layout.addWidget(label)
        widget.setLayout(layout)
        item.setSizeHint(widget.sizeHint())
        list_widget.setItemWidget(item, widget)

    list_widget.show()
    app.exec_()
示例#5
0
            continue

        pixmap = pixmap.scaled(ICON_WIDTH, ICON_WIDTH, Qt.KeepAspectRatio,
                               Qt.SmoothTransformation)
        base_file_name = Path(file_name).name

        item = QListWidgetItem(QIcon(pixmap), base_file_name)
        item.setTextAlignment(Qt.AlignHCenter | Qt.AlignBottom)
        item.setSizeHint(QSize(ICON_WIDTH, ICON_HEIGHT + 20))
        list_widget.addItem(item)

        table_widget.setRowCount(table_widget.rowCount() + 1)
        table_widget.setRowHeight(row, ICON_HEIGHT)
        item_img = QTableWidgetItem()
        item_img.setData(Qt.DecorationRole, pixmap)
        item_img.setSizeHint(QSize(ICON_WIDTH, ICON_HEIGHT))
        table_widget.setItem(row, 0, item_img)
        table_widget.setItem(row, 1, QTableWidgetItem(base_file_name))
        table_widget.setItem(row, 2,
                             QTableWidgetItem(str(Path(file_name).parent)))
        row += 1

        QApplication.processEvents()

    list_widget.setWindowTitle(list_widget.windowTitle() + '. Elapsed: ' +
                               str(DT.datetime.now() -
                                   start_time).split('.')[0])
    table_widget.setWindowTitle(table_widget.windowTitle() + '. Elapsed: ' +
                                str(DT.datetime.now() -
                                    start_time).split('.')[0])
示例#6
0
def main(argv):
    options = optparse.OptionParser()
    options.add_option('-l',
                       '--list_file',
                       dest='list_file',
                       help='list_file',
                       default=None)
    opts, args = options.parse_args(argv)
    print('opts:%s' % (opts))
    print('args:%s' % (args))
    if len(args):
        options.print_help()
        return
    if not opts.list_file:
        options.print_help()
        return

    list_file = []
    f = open(opts.list_file, 'r')
    for i in f:
        filepath = i.strip()
        if filepath:
            list_file.append(filepath)
    f.close()

    app = QApplication(argv)
    list_widget = QListWidget()

    for filepath in list_file:
        if not os.path.exists(filepath):
            continue

        bmp = get_image_data(filepath)
        data = bmp.data

        table = QTableWidget(bmp.height, bmp.width)
        font = QFont()
        font.setFamily("Calibri")
        font.setPointSize(6)
        table.setFont(font)

        table.setEditTriggers(QTableWidget.NoEditTriggers)
        table.verticalHeader().setVisible(False)
        table.horizontalHeader().setVisible(False)

        f = io.BytesIO(data)
        for h in range(0, bmp.height):
            for w in range(0, bmp.width):
                c = f.read(1)

                item = QTableWidgetItem()
                item.setText('%02x' % (ord(c)))
                item.setBackground(QBrush(QColor(ord(c), ord(c), ord(c))))
                table.setItem(h, w, item)
        f.close()

        for c in range(0, bmp.width):
            table.setColumnWidth(c, 18)

        for r in range(0, bmp.height):
            table.setRowHeight(r, 18)

        item = QListWidgetItem(list_widget)
        item.setSizeHint(table.sizeHint())
        list_widget.setItemWidget(item, table)

        item = QListWidgetItem(list_widget)
        image = QImage(data, bmp.width, bmp.height, QImage.Format_Grayscale8)
        pixmap = QPixmap.fromImage(image)
        widget = QWidget()
        layout = QVBoxLayout()

        label = QLabel()
        label.setText(filepath)
        layout.addWidget(label)

        label = QLabel()
        label.setPixmap(pixmap)
        layout.addWidget(label)
        widget.setLayout(layout)
        item.setSizeHint(widget.sizeHint())
        list_widget.setItemWidget(item, widget)

    list_widget.show()
    app.exec_()