コード例 #1
0
 def __init__(self, parent, context):
     super().__init__(parent)
     self._context = context
     layout = QHBoxLayout()
     tabs = QTabWidget()
     tabs.insertTab(0, self._init_about_tab(), "About")
     tabs.insertTab(1, self._init_keyboard_shortcuts_tab(),
                    "Keyboard Shortcuts")
     layout.addWidget(tabs)
     self.setLayout(layout)
     self.setWindowTitle(" ")
コード例 #2
0
ファイル: sheetAid.py プロジェクト: agrazela14/SeniorProject
class sheetAid(QMainWindow):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        #Documentation says no parents for tab objects
        self.tabs = QTabWidget(self)
        self.baseTab = baseTab(self, self.tabs)
        self.ndx = 1
        self.tabs.insertTab(0, self.baseTab, "Add Sheets")
        self.tabs.resize(600, 700)
        self.size = QSize(600, 700)
        self.resize(self.size)
        self.setWindowTitle('DnD 5e character sheet aid')
        self.sheets = []
        self.show()

    def openSheet(self):
        #use pickle.load for this
        typeSet = {0}
        flagSet = {0}
        fileName = QFileDialog.getOpenFileName(self, 'Open Sheet',
                                               '../characters')
        print(fileName)
        fo = open(fileName[0], "rb+")
        sheet = CharacterSheet(fileName[0], fo, False, self.tabs)
        self.sheets.append(sheet)
        self.tabs.addTab(sheet, fileName[0])

    def addNewSheet(self, name):
        #make a new characterData and pickle.dump in the end to save it
        fo = open("../characters/" + name, "wb+")
        sheet = CharacterSheet(name, fo, True, self.tabs)
        self.sheets.append(sheet)
        self.tabs.addTab(sheet, name)

    def closeEvent(self, event):
        print('Close Event Triggered for: MainWindow')
        for char in self.sheets:
            char.writeData()

        event.accept()
コード例 #3
0
class mainWindow(QWidget):
    def __init__(self):
        super().__init__()
        
        self.initUI()
        
        
    def initUI(self):      
        
        #self.tabBar = QTabBar(self)
        self.sheetList = [CharacterSheet(self)]
        self.sheetList.append(CharacterSheet(self))

        self.tabs = QTabWidget(self)
        self.tabs.insertTab(0, self.sheetList[0], "Sheet1")
        self.tabs.insertTab(1, self.sheetList[1], "Sheet2")
        self.size = QSize(1000, 1000)
        self.resize(self.size)
        self.setWindowTitle('DnD 5e character sheet aid')
        self.show()
コード例 #4
0
class finder(QDialog):
    def __init__(self, parent, i=0):
        super().__init__(parent)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.parent = parent
        self.i = i
        grid = QGridLayout()
        self.setLayout(grid)
        self.page1 = Page1(self.parent)
        self.page2 = Page2(self.parent)

        self.tab = QTabWidget()
        self.tab.insertTab(0, self.page1, 'FIND')
        self.tab.insertTab(1, self.page2, 'REPLACE')

        grid.addWidget(self.tab)

        self.tab.setCurrentIndex(i)

        self.setGeometry(800, 300, 600, 100)
コード例 #5
0
class SettingsFrame(QDialog):
    download_dir_changed = pyqtSignal(str)
    desktop_lyric_style_changed = pyqtSignal()
    close_button_act_changed = pyqtSignal(int)
    window_lyric_style_changed = pyqtSignal()
    def __init__(self, parent = None):
        super(SettingsFrame, self).__init__(parent)
#        self.setStyleSheet("QPushButton{font-family:'微软雅黑';font-size:14px;}")
        self.initial_basic_tab()
        self.initial_download_tab()
        self.initial_lyric_tab()
        self.initial_main_ui()
        self.create_connections()
        self.initial_parames()
    
    def create_connections(self):
        self.tabWidget.currentChanged.connect(self.tab_switched)
        self.pathSelectPanel.download_dir_changed.connect(self.change_download_dir)
        self.fontPanel.font_style_changed.connect(self.set_new_desktoplyric_font_style)
        self.colorsPanel.color_changed.connect(self.set_new_colors)
        self.closeActionsBox.close_act_changed.connect(self.check_close_button_act)
        self.lyricPanelsBox.parameters_changed.connect(self.set_new_windowlyric_font_style)
    
    def initial_parames(self):
        self.modifiedDict = {}
        self.modifiedDictsGroup = {}
        self.tabWidget.setCurrentIndex(0)
        self.currentIndex = self.tabWidget.currentIndex()
        for k in range(self.tabWidget.count()):
            self.modifiedDictsGroup[self.tabWidget.tabText(k)] = {}
    
    def tab_switched(self, index):
        self.modifiedDictsGroup[self.tabWidget.tabText(self.currentIndex)] = self.modifiedDict.copy()
        self.currentIndex = index
        self.modifiedDict = self.modifiedDictsGroup[self.tabWidget.tabText(self.currentIndex)].copy()
        self.check_control_buttons_state()
    
    def initial_basic_tab(self):
        self.basicTab = QWidget()
        self.closeActionsBox = CloseActionsBox()
        self.lyricPanelsBox = LyricPanelsBox()
        self.basic_tab_revert_parameters()
        mainLayout = QVBoxLayout(self.basicTab)
        mainLayout.addWidget(self.closeActionsBox)
        mainLayout.addStretch()
        mainLayout.addWidget(self.lyricPanelsBox)
        mainLayout.addStretch()
    
    def initial_download_tab(self):
        self.downloadTab = QWidget()
        self.pathSelectPanel = PathSelectPanel()
        self.download_tab_revert_parameters()
        downloadTabLayout = QVBoxLayout(self.downloadTab)
        downloadTabLayout.addWidget(self.pathSelectPanel)
        downloadTabLayout.addStretch()
    
    def initial_lyric_tab(self):
        self.lyricTab = QWidget()
        self.previewLabel = desktop_lyric.DesktopLyricBasic()
        self.previewLabel.setFixedHeight(80)
        self.previewLabel.set_color(globalSettings.DesktoplyricColors)
        label1 = QLabel('颜色:', self.lyricTab)
        label1.setFixedWidth(50)
        label2 = QLabel('预览:', self.lyricTab)
        self.fontPanel = FontPanel()
        self.colorsPanel = ColorsPanel()
        self.desktoplyric_tab_revert_parameters()
        lyricColorLayout = QHBoxLayout()
        lyricColorLayout.addWidget(label1)
        lyricColorLayout.addWidget(self.colorsPanel)
        lyricTabLayout = QVBoxLayout(self.lyricTab)
        lyricTabLayout.setSpacing(6)
        lyricTabLayout.addWidget(self.fontPanel)
        lyricTabLayout.addLayout(lyricColorLayout)
        lyricTabLayout.addStretch()
        lyricTabLayout.addWidget(label2)
        lyricTabLayout.addWidget(self.previewLabel)
    
    def initial_main_ui(self):
        self.defaultButton = QPushButton("恢复本页默认配置", clicked = self.default)
        self.defaultButton.setFocusPolicy(Qt.NoFocus)
        self.okButton = QPushButton("应用", clicked = self.confirm)
        self.okButton.setFocusPolicy(Qt.NoFocus)
        self.okButton.setEnabled(False)
        self.cancelButton = QPushButton("取消", clicked = self.cancel)
        self.cancelButton.setFocusPolicy(Qt.NoFocus)
        self.cancelButton.setEnabled(False)
        self.tabWidget = QTabWidget()
        self.tabWidget.insertTab(0, self.basicTab, Configures.SettingsBasicTab)
        self.tabWidget.insertTab(1, self.downloadTab, Configures.SettingsDownloadTab)
        self.tabWidget.insertTab(2, self.lyricTab, Configures.SettingsDesktopLyricTab)
        
        buttonsLayout = QHBoxLayout()
        buttonsLayout.addWidget(self.defaultButton)
        buttonsLayout.addStretch()
        buttonsLayout.addWidget(self.okButton)
        buttonsLayout.addWidget(self.cancelButton)
        
        mainLayout = QVBoxLayout(self)
        mainLayout.addWidget(self.tabWidget)
        mainLayout.addLayout(buttonsLayout)
        mainLayout.setContentsMargins(4, 4, 4, 4)

    def check_control_buttons_state(self):
        self.okButton.setEnabled(bool(len(self.modifiedDict)))
        self.cancelButton.setEnabled(bool(len(self.modifiedDict)))

    def check_and_change_edit_state(self, option, default, new):
        if new != default:
            self.modifiedDict[option] = new
        else:
            if option in self.modifiedDict:
                del self.modifiedDict[option]
        self.check_control_buttons_state()

    def make_modified_global_settings_valid(self):
        for key, value in self.modifiedDict.items():
            if key == globalSettings.optionsHub.DownloadfilesPath:
                if not os.path.isdir(value):
                    QMessageBox.critical(self, '错误', '您输入的不是一个文件夹!')
                    return False
            globalSettings.__setattr__(key, value)
        self.modifiedDict.clear()
        self.check_control_buttons_state()
        return True

    def confirm(self):
        if not self.make_modified_global_settings_valid() :
            return
        if self.tabWidget.tabText(self.currentIndex) == Configures.SettingsBasicTab:
            self.basic_tab_confirm()
        elif self.tabWidget.tabText(self.currentIndex) == Configures.SettingsDownloadTab:
            self.download_tab_confirm()
        elif self.tabWidget.tabText(self.currentIndex) == Configures.SettingsDesktopLyricTab:
            self.desktoplyric_tab_confirm()

    def cancel(self):
        if self.tabWidget.tabText(self.currentIndex) == Configures.SettingsBasicTab:
            self.basic_tab_revert_parameters()
        elif self.tabWidget.tabText(self.currentIndex) == Configures.SettingsDownloadTab:
            self.download_tab_revert_parameters()
        elif self.tabWidget.tabText(self.currentIndex) == Configures.SettingsDesktopLyricTab:
            self.desktoplyric_tab_revert_parameters()

    def default(self):
        ok = QMessageBox.question(self, 'xyplayer选项管理', '确认恢复本页默认配置?',QMessageBox.Cancel|QMessageBox.Ok, QMessageBox.Cancel )
        if ok == QMessageBox.Ok:
            if self.tabWidget.tabText(self.currentIndex) == Configures.SettingsBasicTab:
                self.basic_tab_default()
            elif self.tabWidget.tabText(self.currentIndex) == Configures.SettingsDownloadTab:
                self.download_tab_default()
            elif self.tabWidget.tabText(self.currentIndex) == Configures.SettingsDesktopLyricTab:
                self.desktoplyric_tab_default()

    def basic_tab_confirm(self):
        self.close_button_act_changed.emit(globalSettings.CloseButtonAct)
        self.window_lyric_style_changed.emit()
    
    def basic_tab_revert_parameters(self):
        self.closeActionsBox.set_close_act(globalSettings.CloseButtonAct)
        self.lyricPanelsBox.set_box_parameters(
            globalSettings.WindowlyricRunFontSize, 
            globalSettings.WindowlyricRunFontColor, 
            globalSettings.WindowlyricReadyFontSize, 
            globalSettings.WindowlyricReadyFontColor)
        
    def basic_tab_default(self):
        self.closeActionsBox.restore_default_close_act()
        self.lyricPanelsBox.restore_default_font_style()

    def download_tab_confirm(self):
        self.download_dir_changed.emit(globalSettings.DownloadfilesPath)

    def download_tab_revert_parameters(self):
        self.pathSelectPanel.lineEdit.setText(globalSettings.DownloadfilesPath)
    
    def download_tab_default(self):
        self.pathSelectPanel.restore_default_download_dir()
    
    def desktoplyric_tab_confirm(self):
        self.desktop_lyric_style_changed.emit()
    
    def desktoplyric_tab_revert_parameters(self):
        self.fontPanel.set_font_style(globalSettings.DesktoplyricFontFamily, 
            globalSettings.DesktoplyricFontSize, globalSettings.DesktoplyricFontForm)
        self.colorsPanel.set_colors(globalSettings.DesktoplyricColors)
            
    def desktoplyric_tab_default(self):
        self.fontPanel.restore_default_font_style()
        self.colorsPanel.restore_default_colors()
    
    def change_download_dir(self, text):
        self.check_and_change_edit_state(globalSettings.optionsHub.DownloadfilesPath, globalSettings.DownloadfilesPath, str(text))
    
    def get_download_dir(self):
        return globalSettings.DownloadfilesPath
    
    def check_close_button_act(self, act):
        self.check_and_change_edit_state(globalSettings.optionsHub.CloseButtonAct, globalSettings.CloseButtonAct, act)
    
    def set_new_desktoplyric_font_style(self, option, new):
        if option == globalSettings.optionsHub.DesktoplyricFontFamily:
            default = globalSettings.DesktoplyricFontFamily
        elif option == globalSettings.optionsHub.DesktoplyricFontSize:
            default = globalSettings.DesktoplyricFontSize
            new = int(new)
        elif option == globalSettings.optionsHub.DesktoplyricFontForm:
            default = globalSettings.DesktoplyricFontForm
        self.previewLabel.set_font_style(*self.get_lyric_font_styles())
        self.check_and_change_edit_state(option, default, new)
    
    def set_new_windowlyric_font_style(self, option, new):
        if option == globalSettings.optionsHub.WindowlyricRunFontSize:
            default = globalSettings.WindowlyricRunFontSize
            new = int(new)
        elif option == globalSettings.optionsHub.WindowlyricRunFontColor:
            default = globalSettings.WindowlyricRunFontColor
        elif option == globalSettings.optionsHub.WindowlyricReadyFontSize:
            default = globalSettings.WindowlyricReadyFontSize
            new = int(new)
        elif option == globalSettings.optionsHub.WindowlyricReadyFontColor:
            default = globalSettings.WindowlyricReadyFontColor
        self.check_and_change_edit_state(option, default, new)

    def set_new_colors(self):
        colors = self.get_lyric_colors()
        self.previewLabel.set_color(colors)
        self.check_and_change_edit_state(globalSettings.optionsHub.DesktoplyricColors, globalSettings.DesktoplyricColors, colors)
    
    def get_lyric_colors(self):
        return self.colorsPanel.get_colors()
        
    def get_lyric_font_styles(self):
        return self.fontPanel.get_font_style()
    
    def get_window_lyric_params(self):
        return (
            globalSettings.WindowlyricRunFontSize, 
            globalSettings.WindowlyricRunFontColor, 
            globalSettings.WindowlyricReadyFontSize, 
            globalSettings.WindowlyricReadyFontColor)
コード例 #6
0
class SettingsWidget(QWidget, MooseWidget):
    """
    A very simple widget to modify settings.
    This widget actually doesn't do anything, it just holds
    various tabs.
    Other widgets are responsible for creating their own settings
    widget and adding it here.
    """
    def __init__(self, **kwds):
        """
        Constructor.
        """
        super(SettingsWidget, self).__init__(**kwds)

        self.top_layout = WidgetUtils.addLayout(vertical=True)
        self.setLayout(self.top_layout)
        self.tabs = QTabWidget(parent=self)
        self.top_layout.addWidget(self.tabs)
        self.button_layout = WidgetUtils.addLayout()
        self.top_layout.addLayout(self.button_layout)
        self.save_button = WidgetUtils.addButton(self.button_layout, self, "&Save", self._save)
        self.cancel_button = WidgetUtils.addButton(self.button_layout, self, "&Cancel", self._cancel)
        self.setup()

    def addTab(self, name, widget, index=-1):
        """
        Add a new tab for settings.
        Input:
            name: name of the tab
            widget: widget of settings
            index: index of where to put the tab. Default is at the beginning.
        """
        self.removeTab(name)
        self.tabs.insertTab(index, widget, name)

    def removeTab(self, name):
        """
        Remove a tab with a given name.
        Input:
            name: name of the tab. If it doesn't exist, nothing happens.
        """
        for i in range(self.tabs.count()):
            if self.tabs.tabText(i) == name:
                self.tabs.removeTab(i)
                break

    def load(self):
        """
        Loads all the settings from the different widgets.
        """
        settings = QSettings()
        for i in range(self.tabs.count()):
            w = self.tabs.widget(i)
            w.load(settings)

    def _save(self):
        """
        Saves all the settings from the different widgets.
        """
        settings = QSettings()
        for i in range(self.tabs.count()):
            w = self.tabs.widget(i)
            w.save(settings)
        settings.sync()
        self.close()

    def _cancel(self):
        """
        They didn't want to save.
        """
        self.close()
コード例 #7
0
ファイル: students.py プロジェクト: jfisteus/eyegrade
class StudentGroupsTabs(QWidget):
    def __init__(self, parent, student_listings=None):
        super().__init__(parent)
        if student_listings is None:
            self.student_listings = students.StudentListings()
            inserted_group = students.StudentGroup(0, 'INSERTED')
            self.student_listings.create_listing(inserted_group)
        else:
            self.student_listings = student_listings
        layout = QVBoxLayout(self)
        self.setLayout(layout)
        self.tabs = QTabWidget(self)
        # Special tab for creating a new group:
        self.tabs.addTab(QWidget(), '  +  ')
        # Group 0 is special: don't show it
        for listing in self.student_listings[1:]:
            self._add_group_tab(listing)
        # At least one normal group needs to be present:
        if len(self.student_listings) == 1:
            self._create_default_group()
        button_load = QPushButton(_('Add students from file'), parent=self)
        button_new_student = QPushButton(
            QIcon(utils.resource_path('new_id.svg')),
            _('New student'),
            parent=self)
        button_remove = QPushButton(
            QIcon(utils.resource_path('discard.svg')),
            _('Remove group'),
            parent=self)
        layout.addWidget(self.tabs)
        layout.addWidget(button_load)
        layout.addWidget(button_new_student)
        layout.addWidget(button_remove)
        layout.setAlignment(button_load, Qt.AlignHCenter)
        layout.setAlignment(button_new_student, Qt.AlignHCenter)
        layout.setAlignment(button_remove, Qt.AlignHCenter)
        self.tabs.setCurrentIndex(0)
        self._active_tab = 0
        self.tabs.currentChanged.connect(self._tab_changed)
        self.tabs.tabBarDoubleClicked.connect(self._rename_group)
        button_load.clicked.connect(self._load_students)
        button_new_student.clicked.connect(self._new_student)
        button_remove.clicked.connect(self._remove_group)

    def _load_students(self):
        index = self.tabs.currentIndex()
        file_name, __ = QFileDialog.getOpenFileName(
            self,
            _('Select the student list file'),
            '',
            FileNameFilters.student_list,
            None,
            QFileDialog.DontUseNativeDialog)
        try:
            if file_name:
                with students.StudentReader.create(file_name) as reader:
                    student_list = list(reader.students())
                # Flag duplicate student ids:
                warn_duplicates = False
                for s in self.student_listings.find_duplicates(student_list):
                    s.is_duplicate = True
                    warn_duplicates = True
                if warn_duplicates:
                    QMessageBox.warning(
                        self,
                        _('Importing a student list'),
                        _('Some student ids are already in the list. '
                          'Remove them or cancel the import operation.'))
                column_map = reader.column_map.normalize()
                preview_dialog = DialogPreviewStudents(
                    self, student_list, column_map)
                result = preview_dialog.exec_()
                if result == QMessageBox.Accepted:
                    self.tabs.widget(index).add_students(student_list)
        except Exception as e:
            QMessageBox.critical(
                self,
                _('Error in student list'),
                file_name + '\n\n' + str(e))

    def _new_student(self):
        index = self.tabs.currentIndex()
        dialog = NewStudentDialog(
            self.student_listings,
            group_index=index,
            parent=self)
        student = dialog.exec_()
        if student is not None:
            self.tabs.widget(index).listing_updated()

    def _remove_group(self):
        index = self.tabs.currentIndex()
        if len(self.student_listings[index + 1]) > 0:
            result = QMessageBox.warning(
                self,
                _('Warning'),
                _('This group and its students will be removed. '
                  'Are you sure you want to continue?'),
                QMessageBox.Yes | QMessageBox.No,
                QMessageBox.No)
            remove = (result == QMessageBox.Yes)
        else:
            remove = True
        if remove:
            try:
                self.student_listings.remove_at(index + 1)
                if len(self.student_listings) > 1:
                    if index == self.tabs.count() - 2:
                        self.tabs.setCurrentIndex(index - 1)
                    else:
                        self.tabs.setCurrentIndex(index + 1)
                else:
                    self._create_default_group()
                    self.tabs.setCurrentIndex(1)
                self.tabs.removeTab(index)
            except students.CantRemoveGroupException:
                QMessageBox.critical(
                    self,
                    _('Error'),
                    _('This group cannot be removed because '
                      'exams have been graded for some of its students.'))

    def _add_group_tab(self, listing, show=False):
        self.tabs.insertTab(
            self.tabs.count() - 1,
            GroupWidget(listing, self),
            listing.group.name
        )
        if show:
            self.tabs.setCurrentIndex(self.tabs.count() - 2)

    def _new_group(self):
        group_name = GroupNameDialog(parent=self).exec_()
        if group_name is not None:
            group = students.StudentGroup(None, group_name)
            listing = self.student_listings.create_listing(group)
            self._add_group_tab(listing, show=True)
        else:
            self.tabs.setCurrentIndex(self._active_tab)

    def _create_default_group(self):
        group = students.StudentGroup(None, _('Students'))
        listing = self.student_listings.create_listing(group)
        self._add_group_tab(listing, show=True)

    def _rename_group(self, index):
        name = self.student_listings[index + 1].group.name
        new_name = GroupNameDialog(group_name=name, parent=self).exec_()
        if new_name is not None and new_name != name:
            self.student_listings[index + 1].rename(new_name)
            self.tabs.setTabText(index, new_name)

    def _tab_changed(self, index):
        if index == self.tabs.count() - 1:
            # The last (special) tab has been activated: create a new group
            self._new_group()
        self._active_tab = self.tabs.currentIndex()