프로젝트

일반

사용자정보

개정판 36a2a92a

ID36a2a92ad41a62a56b2272c58f706aa87f395f8a
상위 056452e7
하위 21c5196e

백흠경이(가) 약 5년 전에 추가함

issue #1260: stream data 복사/붙여넣기 기능

Change-Id: Ica9becb53a84006e12fa14a18b728d95fb90d20a

차이점 보기:

HYTOS/HYTOS/MainWindow.py
398 398
        self.tableWidgetHMB.resizeColumnsToContents()
399 399
        self.tableWidgetHMB.resizeRowsToContents()
400 400

  
401
    def copy_selection(self, table_widget):
402
        """copy selected text to clipboard"""
403

  
404
        import io
405
        import csv
406

  
407
        selection = table_widget.selectedIndexes()
408
        if selection:
409
            rows = sorted(index.row() for index in selection)
410
            columns = sorted(index.column() for index in selection)
411
            rowcount = rows[-1] - rows[0] + 1
412
            colcount = columns[-1] - columns[0] + 1
413
            table = [[''] * colcount for _ in range(rowcount)]
414
            for index in selection:
415
                row = index.row() - rows[0]
416
                column = index.column() - columns[0]
417
                table[row][column] = index.data()
418
            stream = io.StringIO()
419
            csv.writer(stream, delimiter='\t').writerows(table)
420
            QApplication.clipboard().setText(stream.getvalue())
421

  
422
    def paste_selection(self, table_widget):
423
        """paste text of clipboard to table widget"""
424

  
425
        import io
426
        import csv
427

  
428
        selection = table_widget.selectedIndexes()
429
        if selection:
430
            model = table_widget.model()
431

  
432
            buffer = QApplication.clipboard().text()
433
            rows = sorted(index.row() for index in selection)
434
            columns = sorted(index.column() for index in selection)
435
            reader = csv.reader(io.StringIO(buffer), delimiter='\t')
436
            if len(rows) == 1 and len(columns) == 1:
437
                for i, line in enumerate(reader):
438
                    for j, cell in enumerate(line):
439
                        model.setData(model.index(rows[0] + i, columns[0] + j), cell)
440
            else:
441
                arr = [[cell for cell in row] for row in reader]
442
                for index in selection:
443
                    row = index.row() - rows[0]
444
                    column = index.column() - columns[0]
445
                    model.setData(model.index(index.row(), index.column()), arr[row][column])
446

  
447

  
401 448
    '''
402 449
        @brief      Drawing 속성의 Units 에서 Key값을 이용하여 Value를 찾음
403 450
        @author     yeonjin
......
1863 1910
                # checked = self.actionGroup.checkedAction()
1864 1911
                # if checked:
1865 1912
                #    checked.setChecked(False)
1866
                #    self.graphicsView.useDefaultCommand()                                                           
1913
                #    self.graphicsView.useDefaultCommand()
1914
            elif (event.key() == Qt.Key_C) and (event.modifiers() & Qt.ControlModifier):
1915
                if self.tableWidgetHMB.hasFocus():
1916
                    self.copy_selection(self.tableWidgetHMB)
1917
            elif (event.key() == Qt.Key_V) and (event.modifiers() & Qt.ControlModifier):
1918
                if self.tableWidgetHMB.hasFocus():
1919
                    self.paste_selection(self.tableWidgetHMB)
1867 1920

  
1868 1921
            QMainWindow.keyPressEvent(self, event)
1869 1922
        except Exception as ex:

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)