def initUI(self, tags): ############################################## ### From top to bottom: ############################################## ## header_label # self.header_edit ############################################## ## self.svg_edit ############################################## ## footer_label # self.footer ############################################## ## tags_label # self.tags_edit ############################################## ## deck_container ## ######################## ## # deckChooser # ## ######################## ############################################## # Header self.header_edit = QLineEdit() self.header_edit.setPlaceholderText("(optional)") header_label = QLabel("Header: ") header_hbox = QHBoxLayout() header_hbox.addWidget(header_label) header_hbox.addWidget(self.header_edit) # svg-edit self.svg_edit = webview.AnkiWebView() self.svg_edit.setCanFocus(True) # Footer self.footer_edit = QLineEdit() self.footer_edit.setPlaceholderText("(optional)") footer_label = QLabel("Footer: ") footer_hbox = QHBoxLayout() footer_hbox.addWidget(footer_label) footer_hbox.addWidget(self.footer_edit) # Tags self.tags_edit = tagedit.TagEdit(self) self.tags_edit.setText(" ".join(tags)) self.tags_edit.setCol(mw.col) tags_label = QLabel("Tags: ") tags_hbox = QHBoxLayout() tags_hbox.addWidget(tags_label) tags_hbox.addWidget(self.tags_edit) deck_container = QGroupBox("Deck") self.deckChooser = deckchooser.DeckChooser(mw, deck_container, label=False) vbox = QVBoxLayout() vbox.addLayout(header_hbox) vbox.addWidget(self.svg_edit, stretch=1) vbox.addLayout(footer_hbox) vbox.addLayout(tags_hbox) vbox.addWidget(deck_container) self.setLayout(vbox) self.setMinimumHeight(600) # Don't focus on the tags. # When the focus is on the tags an ugly autocomplete # list appears, taking away screen real estate for no reason. self.header_edit.setFocus() self.setWindowTitle('Image Occlusion Editor') self.show()
def setupUi(self): """Set up ImgOccEdit UI""" # Main widgets aside from fields self.svg_edit = webview.AnkiWebView() self.svg_edit.setCanFocus(True) # focus necessary for hotkeys self.tags_hbox = QHBoxLayout() self.tags_edit = tagedit.TagEdit(self) self.tags_label = QLabel("Tags") self.tags_label.setFixedWidth(70) self.deck_container = QWidget() self.deckChooser = deckchooser.DeckChooser(mw, self.deck_container, label=True) # workaround for tab focus order issue of the tags entry # (this particular section is only needed when the quick deck # buttons add-on is installed) if self.deck_container.layout().children(): # multiple deck buttons for i in range(self.deck_container.layout().children()[0].count()): item = self.deck_container.layout().children()[0].itemAt(i) # remove Tab focus manually: item.widget().setFocusPolicy(Qt.ClickFocus) # Button row widgets self.bottom_label = QLabel() button_box = QtGui.QDialogButtonBox(QtCore.Qt.Horizontal, self) button_box.setCenterButtons(False) image_btn = QPushButton("Change &Image", clicked=self.changeImage) image_btn.setIcon(QIcon(":/icons/new_occlusion.png")) image_btn.setIconSize(QSize(16, 16)) self.occl_tp_select = QComboBox() self.occl_tp_select.addItems([ "Don't Change", "Hide All, Reveal One", "Hide All, Reveal All", "Hide One, Reveal All" ]) self.edit_btn = button_box.addButton("&Edit Cards", QDialogButtonBox.ActionRole) self.new_btn = button_box.addButton("&Add New Cards", QDialogButtonBox.ActionRole) self.ao_btn = button_box.addButton(u"Hide &All, Reveal One", QDialogButtonBox.ActionRole) self.aa_btn = button_box.addButton(u"Hide All, &Reveal All", QDialogButtonBox.ActionRole) self.oa_btn = button_box.addButton(u"Hide &One, Reveal All", QDialogButtonBox.ActionRole) close_button = button_box.addButton("&Close", QDialogButtonBox.RejectRole) image_tt = "Switch to a different image while preserving all of \ the shapes and fields" dc_tt = "Preserve existing occlusion type" edit_tt = "Edit all cards using current mask shapes and field entries" new_tt = "Create new batch of cards without editing existing ones" ao_tt = ( "Generate cards with nonoverlapping information, where all<br>" "labels are hidden on the front and just one is revealed on the back" ) aa_tt = ( "Generate cards with partial overlapping information, where<br>" "all labels are hidden on the front and all are revealed on the back" ) oa_tt = ( "Generate cards with overlapping information, where just one<br>" "label is hidden on the front and all are revealed on the back") close_tt = "Close Image Occlusion Editor without generating cards" image_btn.setToolTip(image_tt) self.edit_btn.setToolTip(edit_tt) self.new_btn.setToolTip(new_tt) self.ao_btn.setToolTip(ao_tt) self.aa_btn.setToolTip(aa_tt) self.oa_btn.setToolTip(oa_tt) close_button.setToolTip(close_tt) self.occl_tp_select.setItemData(0, dc_tt, Qt.ToolTipRole) self.occl_tp_select.setItemData(1, ao_tt, Qt.ToolTipRole) self.occl_tp_select.setItemData(2, aa_tt, Qt.ToolTipRole) self.occl_tp_select.setItemData(3, oa_tt, Qt.ToolTipRole) self.connect(self.edit_btn, SIGNAL("clicked()"), self.edit_note) self.connect(self.new_btn, SIGNAL("clicked()"), self.new) self.connect(self.ao_btn, SIGNAL("clicked()"), self.addAO) self.connect(self.aa_btn, SIGNAL("clicked()"), self.addAA) self.connect(self.oa_btn, SIGNAL("clicked()"), self.addOA) self.connect(close_button, SIGNAL("clicked()"), self.close) # Set basic layout up ## Button row bottom_hbox = QHBoxLayout() bottom_hbox.addWidget(image_btn) bottom_hbox.insertStretch(1, stretch=1) bottom_hbox.addWidget(self.bottom_label) bottom_hbox.addWidget(self.occl_tp_select) bottom_hbox.addWidget(button_box) ## Tab 1 vbox1 = QVBoxLayout() vbox1.addWidget(self.svg_edit, stretch=1) ## Tab 2 self.vbox2 = QVBoxLayout() # vbox2 fields are variable and added by setupFields() at a later point ## Main Tab Widget tab1 = QWidget() self.tab2 = QWidget() tab1.setLayout(vbox1) self.tab2.setLayout(self.vbox2) self.tab_widget = QtGui.QTabWidget() self.tab_widget.addTab(tab1, "&Masks Editor") self.tab_widget.addTab(self.tab2, "&Fields") self.tab_widget.setTabToolTip( 1, "Include additional information (optional)") self.tab_widget.setTabToolTip( 0, "Create image occlusion masks (required)") ## Main Window vbox_main = QVBoxLayout() vbox_main.setMargin(5) vbox_main.addWidget(self.tab_widget) vbox_main.addLayout(bottom_hbox) self.setLayout(vbox_main) self.setMinimumWidth(640) self.tab_widget.setCurrentIndex(0) self.svg_edit.setFocus() # Define and connect key bindings ## Field focus hotkeys for i in range(1, 10): s = self.connect(QtGui.QShortcut(QtGui.QKeySequence("Ctrl+%i" % i), self), QtCore.SIGNAL('activated()'), lambda f=i - 1: self.focusField(f)) ## Other hotkeys self.connect(QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Return"), self), QtCore.SIGNAL('activated()'), lambda: self.defaultAction(True)) self.connect( QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Alt+Return"), self), QtCore.SIGNAL('activated()'), lambda: self.addAA(True)) self.connect( QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Shift+Return"), self), QtCore.SIGNAL('activated()'), lambda: self.addOA(True)) self.connect(QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Tab"), self), QtCore.SIGNAL('activated()'), self.switchTabs) self.connect(QtGui.QShortcut(QtGui.QKeySequence("Ctrl+r"), self), QtCore.SIGNAL('activated()'), self.resetMainFields) self.connect(QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Shift+r"), self), QtCore.SIGNAL('activated()'), self.resetAllFields) self.connect(QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Shift+t"), self), QtCore.SIGNAL('activated()'), lambda: self.focusField(self.tags_edit)) self.connect(QtGui.QShortcut(QtGui.QKeySequence("Ctrl+f"), self), QtCore.SIGNAL('activated()'), self.fitImageCanvas)
def initUI(self, tags): ############################################## ### From top to bottom: ############################################## ## header_label # self.header_edit ############################################## ## self.svg_edit ############################################## ## footer_label # self.footer ############################################## ## tags_label # self.tags_edit ############################################## ## deck_container ## ######################## ## # deckChooser # ## ######################## ############################################## # Header self.header_edit = QLineEdit() self.header_edit.setPlaceholderText("(optional)") header_label = QLabel("Header: ") header_hbox = QHBoxLayout() header_hbox.addWidget(header_label) header_hbox.addWidget(self.header_edit) # svg-edit self.svg_edit = webview.AnkiWebView() self.svg_edit.setCanFocus(True) # Footer self.footer_edit = QLineEdit() self.footer_edit.setPlaceholderText("(optional)") footer_label = QLabel("Footer: ") footer_hbox = QHBoxLayout() footer_hbox.addWidget(footer_label) footer_hbox.addWidget(self.footer_edit) # Tags self.tags_edit = tagedit.TagEdit(self) self.tags_edit.setText(" ".join(tags)) self.tags_edit.setCol(mw.col) tags_label = QLabel("Tags: ") tags_hbox = QHBoxLayout() tags_hbox.addWidget(tags_label) tags_hbox.addWidget(self.tags_edit) deck_container = QGroupBox("Deck") self.deckChooser = deckchooser.DeckChooser(mw, deck_container, label=False) vbox = QVBoxLayout() vbox.addStretch(1) vbox.addLayout(header_hbox) vbox.addWidget(self.svg_edit) vbox.addLayout(footer_hbox) vbox.addLayout(tags_hbox) vbox.addWidget(deck_container) self.setLayout(vbox) self.setMinimumHeight(600) # Don't focus on the tags. # When the focus is on the tags an ugly autocomplete # list appears, taking away screen real estate for no reason. self.header_edit.setFocus() # define and connect key bindings # CTRL+F - fit to canvas self.connect( QtGui.QShortcut(QtGui.QKeySequence(Qt.CTRL + Qt.Key_F), self), QtCore.SIGNAL('activated()'), self.fit_image_canvas) # CTRL+1 - focus header field self.connect( QtGui.QShortcut(QtGui.QKeySequence(Qt.CTRL + Qt.Key_1), self), QtCore.SIGNAL('activated()'), self.header_edit.setFocus) # CTRL+2 - focus footer field self.connect( QtGui.QShortcut(QtGui.QKeySequence(Qt.CTRL + Qt.Key_2), self), QtCore.SIGNAL('activated()'), self.footer_edit.setFocus) # CTRL+I - focus SVG-Edit self.connect( QtGui.QShortcut(QtGui.QKeySequence(Qt.CTRL + Qt.Key_I), self), QtCore.SIGNAL('activated()'), self.svg_edit.setFocus) # CTRL+T - focus tags field self.connect( QtGui.QShortcut(QtGui.QKeySequence(Qt.CTRL + Qt.Key_T), self), QtCore.SIGNAL('activated()'), self.tags_edit.setFocus) # CTRL+R - reset all fields self.connect( QtGui.QShortcut(QtGui.QKeySequence(Qt.CTRL + Qt.Key_R), self), QtCore.SIGNAL('activated()'), self.reset_all_fields) # CTRL + O - add overlapping note self.connect( QtGui.QShortcut(QtGui.QKeySequence(Qt.CTRL + Qt.Key_O), self), QtCore.SIGNAL('activated()'), self.add_overlapping) # CTRL + N - add non-overlapping note self.connect( QtGui.QShortcut(QtGui.QKeySequence(Qt.CTRL + Qt.Key_N), self), QtCore.SIGNAL('activated()'), self.add_nonoverlapping) # Escape - Close Image Occlusion window self.connect(QtGui.QShortcut(QtGui.QKeySequence(Qt.Key_Escape), self), QtCore.SIGNAL('activated()'), self.close) self.setWindowTitle('Image Occlusion Editor') self.show()