56 def __init__(self, filenames=None, parent=None, name=None): |
56 def __init__(self, filenames=None, parent=None, name=None): |
57 """ |
57 """ |
58 Constructor |
58 Constructor |
59 |
59 |
60 @param filenames filenames of form and/or translation files to load |
60 @param filenames filenames of form and/or translation files to load |
61 @param parent parent widget of this window (QWidget) |
61 @type list of str |
62 @param name name of this window (string) |
62 @param parent parent widget of this window |
|
63 @type QWidget |
|
64 @param name name of this window |
|
65 @type str |
63 """ |
66 """ |
64 self.mainWidget = None |
67 self.mainWidget = None |
65 self.currentFile = QDir.currentPath() |
68 self.currentFile = QDir.currentPath() |
66 |
69 |
67 super().__init__(parent) |
70 super().__init__(parent) |
476 def __init__(self, selector, parent): |
480 def __init__(self, selector, parent): |
477 """ |
481 """ |
478 Constructor |
482 Constructor |
479 |
483 |
480 @param selector reference to the QComboBox used to show the |
484 @param selector reference to the QComboBox used to show the |
481 available languages (QComboBox) |
485 available languages |
482 @param parent parent widget (QWidget) |
486 @type QComboBox |
|
487 @param parent parent widget |
|
488 @type QWidget |
483 """ |
489 """ |
484 super().__init__(parent) |
490 super().__init__(parent) |
485 |
491 |
486 self.selector = selector |
492 self.selector = selector |
487 self.currentTranslator = None |
493 self.currentTranslator = None |
493 Public method to add a translation to the list. |
499 Public method to add a translation to the list. |
494 |
500 |
495 If the translation file (*.qm) has not been loaded yet, it will |
501 If the translation file (*.qm) has not been loaded yet, it will |
496 be loaded automatically. |
502 be loaded automatically. |
497 |
503 |
498 @param fileName name of the translation file to be added (string) |
504 @param fileName name of the translation file to be added |
|
505 @type str |
499 @param setTranslation flag indicating, if this should be set as |
506 @param setTranslation flag indicating, if this should be set as |
500 the active translation (boolean) |
507 the active translation |
|
508 @type bool |
501 """ |
509 """ |
502 if not self.__haveFileName(fileName): |
510 if not self.__haveFileName(fileName): |
503 ntr = Translation() |
511 ntr = Translation() |
504 ntr.fileName = fileName |
512 ntr.fileName = fileName |
505 ntr.name = self.__uniqueName(fileName) |
513 ntr.name = self.__uniqueName(fileName) |
590 |
599 |
591 def __findFileName(self, transFileName): |
600 def __findFileName(self, transFileName): |
592 """ |
601 """ |
593 Private method to find a translation by file name. |
602 Private method to find a translation by file name. |
594 |
603 |
595 @param transFileName file name of the translation file (string) |
604 @param transFileName file name of the translation file |
|
605 @type str |
596 @return reference to a translation object or None |
606 @return reference to a translation object or None |
|
607 @rtype QTranslator |
597 """ |
608 """ |
598 for trans in self.translations: |
609 for trans in self.translations: |
599 if trans.fileName == transFileName: |
610 if trans.fileName == transFileName: |
600 return trans |
611 return trans |
601 return None |
612 return None |
602 |
613 |
603 def __findName(self, name): |
614 def __findName(self, name): |
604 """ |
615 """ |
605 Private method to find a translation by name. |
616 Private method to find a translation by name. |
606 |
617 |
607 @param name name (language) of the translation (string) |
618 @param name name (language) of the translation |
|
619 @type str |
608 @return reference to a translation object or None |
620 @return reference to a translation object or None |
|
621 @rtype QTranslator |
609 """ |
622 """ |
610 for trans in self.translations: |
623 for trans in self.translations: |
611 if trans.name == name: |
624 if trans.name == name: |
612 return trans |
625 return trans |
613 return None |
626 return None |
614 |
627 |
615 def __haveFileName(self, transFileName): |
628 def __haveFileName(self, transFileName): |
616 """ |
629 """ |
617 Private method to check for the presence of a translation. |
630 Private method to check for the presence of a translation. |
618 |
631 |
619 @param transFileName file name of the translation file (string) |
632 @param transFileName file name of the translation file |
620 @return flag indicating the presence of the translation (boolean) |
633 @type str |
|
634 @return flag indicating the presence of the translation |
|
635 @rtype bool |
621 """ |
636 """ |
622 return self.__findFileName(transFileName) is not None |
637 return self.__findFileName(transFileName) is not None |
623 |
638 |
624 def __haveName(self, name): |
639 def __haveName(self, name): |
625 """ |
640 """ |
626 Private method to check for the presence of a named translation. |
641 Private method to check for the presence of a named translation. |
627 |
642 |
628 @param name name (language) of the translation (string) |
643 @param name name (language) of the translation |
629 @return flag indicating the presence of the translation (boolean) |
644 @type str |
|
645 @return flag indicating the presence of the translation |
|
646 @rtype bool |
630 """ |
647 """ |
631 return self.__findName(name) is not None |
648 return self.__findName(name) is not None |
632 |
649 |
633 def __uniqueName(self, transFileName): |
650 def __uniqueName(self, transFileName): |
634 """ |
651 """ |
635 Private method to generate a unique name. |
652 Private method to generate a unique name. |
636 |
653 |
637 @param transFileName file name of the translation file (string) |
654 @param transFileName file name of the translation file |
638 @return unique name (string or None) |
655 @type str |
|
656 @return unique name |
|
657 @rtype str |
639 """ |
658 """ |
640 name = os.path.basename(transFileName) |
659 name = os.path.basename(transFileName) |
641 if not name: |
660 if not name: |
642 return None |
661 return None |
643 |
662 |
705 |
728 |
706 def __init__(self, uiFileName, parent=None, name=None): |
729 def __init__(self, uiFileName, parent=None, name=None): |
707 """ |
730 """ |
708 Constructor |
731 Constructor |
709 |
732 |
710 @param uiFileName name of the UI file to load (string) |
733 @param uiFileName name of the UI file to load |
711 @param parent parent widget (QWidget) |
734 @type str |
712 @param name name of this widget (string) |
735 @param parent parent widget |
|
736 @type QWidget |
|
737 @param name name of this widget |
|
738 @type str |
713 """ |
739 """ |
714 super().__init__(parent) |
740 super().__init__(parent) |
715 if name: |
741 if name: |
716 self.setObjectName(name) |
742 self.setObjectName(name) |
717 self.setWindowTitle(name) |
743 self.setWindowTitle(name) |
726 |
752 |
727 def isValid(self): |
753 def isValid(self): |
728 """ |
754 """ |
729 Public method to return the validity of this widget view. |
755 Public method to return the validity of this widget view. |
730 |
756 |
731 @return flag indicating the validity (boolean) |
757 @return flag indicating the validity |
|
758 @rtype bool |
732 """ |
759 """ |
733 return self.__valid |
760 return self.__valid |
734 |
761 |
735 def uiFileName(self): |
762 def uiFileName(self): |
736 """ |
763 """ |
737 Public method to retrieve the name of the UI file. |
764 Public method to retrieve the name of the UI file. |
738 |
765 |
739 @return filename of the loaded UI file (string) |
766 @return filename of the loaded UI file |
|
767 @rtype str |
740 """ |
768 """ |
741 return self.__uiFileName |
769 return self.__uiFileName |
742 |
770 |
743 def buildWidget(self): |
771 def buildWidget(self): |
744 """ |
772 """ |
847 |
877 |
848 def eventFilter(self, obj, ev): |
878 def eventFilter(self, obj, ev): |
849 """ |
879 """ |
850 Public method called to filter an event. |
880 Public method called to filter an event. |
851 |
881 |
852 @param obj object, that generated the event (QObject) |
882 @param obj object, that generated the event |
853 @param ev the event, that was generated by object (QEvent) |
883 @type QObject |
|
884 @param ev the event, that was generated by object |
|
885 @type QEvent |
854 @return flag indicating if event was filtered out |
886 @return flag indicating if event was filtered out |
|
887 @rtype bool |
855 """ |
888 """ |
856 if obj in self.widgets and ev.type() == QEvent.Type.Close: |
889 if obj in self.widgets and ev.type() == QEvent.Type.Close: |
857 with contextlib.suppress(ValueError): |
890 with contextlib.suppress(ValueError): |
858 self.widgets.remove(obj) |
891 self.widgets.remove(obj) |
859 if len(self.widgets) == 0: |
892 if len(self.widgets) == 0: |
863 |
896 |
864 def __findWidget(self, uiFileName): |
897 def __findWidget(self, uiFileName): |
865 """ |
898 """ |
866 Private method to find a specific widget view. |
899 Private method to find a specific widget view. |
867 |
900 |
868 @param uiFileName filename of the loaded UI file (string) |
901 @param uiFileName filename of the loaded UI file |
869 @return reference to the widget (WidgetView) or None |
902 @type str |
|
903 @return reference to the widget or None |
|
904 @rtype WidgetView |
870 """ |
905 """ |
871 wviewList = self.findChildren(WidgetView) |
906 wviewList = self.findChildren(WidgetView) |
872 if wviewList is None: |
907 if wviewList is None: |
873 return None |
908 return None |
874 |
909 |
896 def showWindowMenu(self, windowMenu): |
931 def showWindowMenu(self, windowMenu): |
897 """ |
932 """ |
898 Public method to set up the widgets part of the Window menu. |
933 Public method to set up the widgets part of the Window menu. |
899 |
934 |
900 @param windowMenu reference to the window menu |
935 @param windowMenu reference to the window menu |
|
936 @type QMenu |
901 """ |
937 """ |
902 for idx, wid in enumerate(self.widgets): |
938 for idx, wid in enumerate(self.widgets): |
903 act = windowMenu.addAction(wid.windowTitle()) |
939 act = windowMenu.addAction(wid.windowTitle()) |
904 act.setData(idx) |
940 act.setData(idx) |
905 act.setCheckable(True) |
941 act.setCheckable(True) |
907 |
943 |
908 def toggleSelectedWidget(self, act): |
944 def toggleSelectedWidget(self, act): |
909 """ |
945 """ |
910 Public method to handle the toggle of a window. |
946 Public method to handle the toggle of a window. |
911 |
947 |
912 @param act reference to the action that triggered (QAction) |
948 @param act reference to the action that triggered |
|
949 @type QAction |
913 """ |
950 """ |
914 idx = act.data() |
951 idx = act.data() |
915 if idx is not None: |
952 if idx is not None: |
916 self.__toggleWidget(self.widgets[idx]) |
953 self.__toggleWidget(self.widgets[idx]) |
917 |
954 |
918 def __toggleWidget(self, w): |
955 def __toggleWidget(self, w): |
919 """ |
956 """ |
920 Private method to toggle a workspace window. |
957 Private method to toggle a workspace window. |
921 |
958 |
922 @param w window to be toggled |
959 @param w window to be toggled |
|
960 @type QWidget |
923 """ |
961 """ |
924 if w.isHidden(): |
962 if w.isHidden(): |
925 w.show() |
963 w.show() |
926 else: |
964 else: |
927 w.hide() |
965 w.hide() |
928 |
966 |
929 def hasWidgets(self): |
967 def hasWidgets(self): |
930 """ |
968 """ |
931 Public method to check for loaded widgets. |
969 Public method to check for loaded widgets. |
932 |
970 |
933 @return flag signaling if any widget was loaded (boolean) |
971 @return flag signaling if any widget was loaded |
|
972 @rtype bool |
934 """ |
973 """ |
935 return len(self.widgets) > 0 |
974 return len(self.widgets) > 0 |