Ejemplo n.º 1
0
 def __init__( self, parent: QW.QWidget, service_key: bytes, accounts: typing.Collection[ HydrusNetwork.Account ] ):
     
     ClientGUIScrolledPanels.ReviewPanel.__init__( self, parent )
     
     self._service_key = service_key
     self._service = HG.client_controller.services_manager.GetService( self._service_key )
     self._accounts = accounts
     
     self._accounts_box = ClientGUICommon.StaticBox( self, 'accounts' )
     
     self._account_list = ClientGUIListBoxes.BetterQListWidget( self._accounts_box )
     self._account_list.setSelectionMode( QW.QListWidget.ExtendedSelection )
     
     ( min_width, min_height ) = ClientGUIFunctions.ConvertTextToPixels( self._account_list, ( 74, 16 ) )
     
     self._account_list.setMinimumSize( min_width, min_height )
     
     modify_button = ClientGUICommon.BetterButton( self._accounts_box, 'modify selected', self._ModifyAccounts )
     
     #
     
     my_admin_account_key = self._service.GetAccount().GetAccountKey()
     
     accounts.sort( key = lambda a: ( a.GetAccountType().GetTitle(), a.GetAccountKey().hex() ) )
     
     for account in accounts:
         
         item = QW.QListWidgetItem()
         
         account_key = account.GetAccountKey()
         
         text = account.GetSingleLineTitle()
         
         if account_key == my_admin_account_key:
             
             text = 'THIS IS YOU: {}'.format( text )
             
         
         item.setText( text )
         
         item.setData( QC.Qt.UserRole, account )
         
         self._account_list.addItem( item )
         
     
     #
     
     self._accounts_box.Add( self._account_list, CC.FLAGS_EXPAND_BOTH_WAYS )
     
     vbox = QP.VBoxLayout()
     
     QP.AddToLayout( vbox, self._accounts_box, CC.FLAGS_EXPAND_BOTH_WAYS )
     QP.AddToLayout( vbox, modify_button, CC.FLAGS_EXPAND_PERPENDICULAR )
     
     self.widget().setLayout( vbox )
     
     #
     
     self._account_list.itemDoubleClicked.connect( self._ModifyAccounts )
 def __init__( self, parent, service_key, tags, expand_parents = True, message = '', show_sibling_text = False ):
     
     Dialog.__init__( self, parent, 'input tags' )
     
     self._service_key = service_key
     
     self._tags = ClientGUIListBoxes.ListBoxTagsStringsAddRemove( self, service_key = service_key, show_sibling_text = show_sibling_text )
     
     self._expand_parents = expand_parents
     
     self._tag_autocomplete = ClientGUIACDropdown.AutoCompleteDropdownTagsWrite( self, self.EnterTags, self._expand_parents, CC.LOCAL_FILE_SERVICE_KEY, service_key, null_entry_callable = self.OK, show_paste_button = True )
     
     self._ok = ClientGUICommon.BetterButton( self, 'OK', self.done, QW.QDialog.Accepted )
     self._ok.setObjectName( 'HydrusAccept' )
     
     self._cancel = QW.QPushButton( 'Cancel', self )
     self._cancel.clicked.connect( self.reject )
     self._cancel.setObjectName( 'HydrusCancel' )
     
     #
     
     self._tags.SetTags( tags )
     
     #
     
     b_box = QP.HBoxLayout()
     
     QP.AddToLayout( b_box, self._ok, CC.FLAGS_CENTER_PERPENDICULAR )
     QP.AddToLayout( b_box, self._cancel, CC.FLAGS_CENTER_PERPENDICULAR )
     
     vbox = QP.VBoxLayout()
     
     if message != '':
         
         st = ClientGUICommon.BetterStaticText( self, message )
         
         st.setWordWrap( True )
         
         QP.AddToLayout( vbox, st, CC.FLAGS_EXPAND_PERPENDICULAR )
         
     
     QP.AddToLayout( vbox, self._tags, CC.FLAGS_EXPAND_BOTH_WAYS )
     QP.AddToLayout( vbox, self._tag_autocomplete )
     QP.AddToLayout( vbox, b_box, CC.FLAGS_ON_RIGHT )
     
     self.setLayout( vbox )
     
     size_hint = self.sizeHint()
     
     size_hint.setWidth( max( size_hint.width(), 300 ) )
     
     QP.SetInitialSize( self, size_hint )
     
     HG.client_controller.CallAfterQtSafe( self._tag_autocomplete, self._tag_autocomplete.setFocus, QC.Qt.OtherFocusReason)
Ejemplo n.º 3
0
    def __init__(self,
                 parent,
                 service_key,
                 tag_display_type,
                 tags,
                 message=''):

        Dialog.__init__(self, parent, 'input tags')

        self._service_key = service_key

        self._tags = ClientGUIListBoxes.ListBoxTagsStringsAddRemove(
            self, service_key, tag_display_type)

        default_location_context = HG.client_controller.new_options.GetDefaultLocalLocationContext(
        )

        self._tag_autocomplete = ClientGUIACDropdown.AutoCompleteDropdownTagsWrite(
            self,
            self.EnterTags,
            default_location_context,
            service_key,
            show_paste_button=True)

        self._tag_autocomplete.nullEntered.connect(self.OK)

        self._ok = ClientGUICommon.BetterButton(self, 'OK', self.done,
                                                QW.QDialog.Accepted)
        self._ok.setObjectName('HydrusAccept')

        self._cancel = QW.QPushButton('Cancel', self)
        self._cancel.clicked.connect(self.reject)
        self._cancel.setObjectName('HydrusCancel')

        #

        self._tags.SetTags(tags)

        #

        b_box = QP.HBoxLayout()

        QP.AddToLayout(b_box, self._ok, CC.FLAGS_CENTER_PERPENDICULAR)
        QP.AddToLayout(b_box, self._cancel, CC.FLAGS_CENTER_PERPENDICULAR)

        vbox = QP.VBoxLayout()

        if message != '':

            st = ClientGUICommon.BetterStaticText(self, message)

            st.setWordWrap(True)

            QP.AddToLayout(vbox, st, CC.FLAGS_EXPAND_PERPENDICULAR)

        QP.AddToLayout(vbox, self._tags, CC.FLAGS_EXPAND_BOTH_WAYS)
        QP.AddToLayout(vbox, self._tag_autocomplete)
        QP.AddToLayout(vbox, b_box, CC.FLAGS_ON_RIGHT)

        self.setLayout(vbox)

        size_hint = self.sizeHint()

        size_hint.setWidth(max(size_hint.width(), 300))

        QP.SetInitialSize(self, size_hint)

        ClientGUIFunctions.SetFocusLater(self._tag_autocomplete)
Ejemplo n.º 4
0
    def __init__(self, parent, flat_media, do_export_and_then_quit=False):

        ClientGUIScrolledPanels.ReviewPanel.__init__(self, parent)

        new_options = HG.client_controller.new_options

        self._media_to_paths = {}
        self._existing_filenames = set()
        self._last_phrase_used = ''
        self._last_dir_used = ''

        self._tags_box = ClientGUIListBoxes.StaticBoxSorterForListBoxTags(
            self, 'files\' tags')

        services_manager = HG.client_controller.services_manager

        self._neighbouring_txt_tag_service_keys = services_manager.FilterValidServiceKeys(
            new_options.GetKeyList(
                'default_neighbouring_txt_tag_service_keys'))

        t = ClientGUIListBoxes.ListBoxTagsMedia(self._tags_box,
                                                ClientTags.TAG_DISPLAY_ACTUAL,
                                                include_counts=True)

        self._tags_box.SetTagsBox(t)

        self._tags_box.setMinimumSize(QC.QSize(220, 300))

        self._paths = ClientGUIListCtrl.BetterListCtrl(
            self,
            CGLC.COLUMN_LIST_EXPORT_FILES.ID,
            24,
            self._ConvertDataToListCtrlTuples,
            use_simple_delete=True)

        self._paths.Sort()

        self._export_path_box = ClientGUICommon.StaticBox(self, 'export path')

        self._directory_picker = QP.DirPickerCtrl(self._export_path_box)
        self._directory_picker.dirPickerChanged.connect(self._RefreshPaths)

        self._open_location = QW.QPushButton('open this location',
                                             self._export_path_box)
        self._open_location.clicked.connect(self.EventOpenLocation)

        self._filenames_box = ClientGUICommon.StaticBox(self, 'filenames')

        self._pattern = QW.QLineEdit(self._filenames_box)

        self._update = QW.QPushButton('update', self._filenames_box)
        self._update.clicked.connect(self._RefreshPaths)

        self._examples = ClientGUICommon.ExportPatternButton(
            self._filenames_box)

        self._delete_files_after_export = QW.QCheckBox(
            'delete files from client after export?', self)
        self._delete_files_after_export.setObjectName('HydrusWarning')

        self._export_symlinks = QW.QCheckBox('EXPERIMENTAL: export symlinks',
                                             self)
        self._export_symlinks.setObjectName('HydrusWarning')

        text = 'This will export all the files\' tags, newline separated, into .txts beside the files themselves.'

        self._export_tag_txts_services_button = ClientGUICommon.BetterButton(
            self, 'set .txt services', self._SetTxtServices)

        self._export_tag_txts = QW.QCheckBox('export tags to .txt files?',
                                             self)
        self._export_tag_txts.setToolTip(text)
        self._export_tag_txts.clicked.connect(self.EventExportTagTxtsChanged)

        self._export = QW.QPushButton('export', self)
        self._export.clicked.connect(self._DoExport)

        #

        export_path = ClientExporting.GetExportPath()

        if export_path is not None:

            self._directory_picker.SetPath(export_path)

        phrase = new_options.GetString('export_phrase')

        self._pattern.setText(phrase)

        if len(self._neighbouring_txt_tag_service_keys) > 0:

            self._export_tag_txts.setChecked(True)

        self._paths.SetData(list(enumerate(flat_media)))

        self._delete_files_after_export.setChecked(
            HG.client_controller.new_options.GetBoolean(
                'delete_files_after_export'))
        self._delete_files_after_export.clicked.connect(
            self.EventDeleteFilesChanged)

        if not HG.client_controller.new_options.GetBoolean('advanced_mode'):

            self._export_symlinks.setVisible(False)

        #

        top_hbox = QP.HBoxLayout()

        QP.AddToLayout(top_hbox, self._tags_box, CC.FLAGS_EXPAND_PERPENDICULAR)
        QP.AddToLayout(top_hbox, self._paths, CC.FLAGS_EXPAND_BOTH_WAYS)

        hbox = QP.HBoxLayout()

        QP.AddToLayout(hbox, self._directory_picker, CC.FLAGS_EXPAND_BOTH_WAYS)
        QP.AddToLayout(hbox, self._open_location,
                       CC.FLAGS_CENTER_PERPENDICULAR)

        self._export_path_box.Add(hbox, CC.FLAGS_EXPAND_SIZER_PERPENDICULAR)

        hbox = QP.HBoxLayout()

        QP.AddToLayout(hbox, self._pattern, CC.FLAGS_EXPAND_BOTH_WAYS)
        QP.AddToLayout(hbox, self._update, CC.FLAGS_CENTER_PERPENDICULAR)
        QP.AddToLayout(hbox, self._examples, CC.FLAGS_CENTER_PERPENDICULAR)

        self._filenames_box.Add(hbox, CC.FLAGS_EXPAND_SIZER_PERPENDICULAR)

        txt_hbox = QP.HBoxLayout()

        QP.AddToLayout(txt_hbox, self._export_tag_txts_services_button,
                       CC.FLAGS_CENTER_PERPENDICULAR)
        QP.AddToLayout(txt_hbox, self._export_tag_txts,
                       CC.FLAGS_CENTER_PERPENDICULAR)

        vbox = QP.VBoxLayout()

        QP.AddToLayout(vbox, top_hbox, CC.FLAGS_EXPAND_SIZER_BOTH_WAYS)
        QP.AddToLayout(vbox, self._export_path_box,
                       CC.FLAGS_EXPAND_PERPENDICULAR)
        QP.AddToLayout(vbox, self._filenames_box,
                       CC.FLAGS_EXPAND_PERPENDICULAR)
        QP.AddToLayout(vbox, self._delete_files_after_export,
                       CC.FLAGS_ON_RIGHT)
        QP.AddToLayout(vbox, self._export_symlinks, CC.FLAGS_ON_RIGHT)
        QP.AddToLayout(vbox, txt_hbox, CC.FLAGS_ON_RIGHT)
        QP.AddToLayout(vbox, self._export, CC.FLAGS_ON_RIGHT)

        self.widget().setLayout(vbox)

        self._RefreshTags()

        self._UpdateTxtButton()

        ClientGUIFunctions.SetFocusLater(self._export)

        self._paths.itemSelectionChanged.connect(self._RefreshTags)

        if do_export_and_then_quit:

            HG.client_controller.CallAfterQtSafe(
                self, 'doing export before dialog quit', self._DoExport, True)
Ejemplo n.º 5
0
        def qt_code():

            frame = TestController.TestFrame()

            try:

                initial_namespace_colours = {
                    'series': (153, 101, 21),
                    '': (0, 111, 250),
                    None: (114, 160, 193),
                    'creator': (170, 0, 0)
                }

                panel = ClientGUIListBoxes.ListBoxTagsColourOptions(
                    frame, initial_namespace_colours)

                frame.SetPanel(panel)

                self.assertEqual(panel.GetNamespaceColours(),
                                 initial_namespace_colours)

                #

                new_namespace_colours = dict(initial_namespace_colours)
                new_namespace_colours['character'] = (0, 170, 0)

                colour = QG.QColor(0, 170, 0)

                panel.SetNamespaceColour('character', colour)

                self.assertEqual(panel.GetNamespaceColours(),
                                 new_namespace_colours)

                #

                terms = set(panel._terms_to_logical_indices.keys())
                ordered_terms = list(panel._ordered_terms)

                self.assertEqual(len(terms), len(ordered_terms))

                #

                all_clickable_indices = GetAllClickableIndices(panel)

                self.assertEqual(len(list(all_clickable_indices.keys())),
                                 len(terms))
                self.assertEqual(
                    set(all_clickable_indices.keys()),
                    set(range(len(list(all_clickable_indices.keys())))))

                #

                for (index, y) in list(all_clickable_indices.items()):

                    click = GenerateClick(panel, QC.QPointF(10, y),
                                          QC.QEvent.MouseButtonPress,
                                          QC.Qt.LeftButton, QC.Qt.NoModifier)

                    DoClick(click, panel)

                    self.assertEqual(
                        panel.GetSelectedNamespaceColours(),
                        dict([ordered_terms[index].GetNamespaceAndColour()]))

                #

                current_y = 5

                click = QG.QMouseEvent(QC.QEvent.MouseButtonPress,
                                       QC.QPointF(10,
                                                  current_y), QC.Qt.LeftButton,
                                       QC.Qt.LeftButton, QC.Qt.NoModifier)

                while panel._GetLogicalIndexUnderMouse(click) is not None:

                    current_y += 5

                    click = GenerateClick(panel, QC.QPointF(10, current_y),
                                          QC.QEvent.MouseButtonPress,
                                          QC.Qt.LeftButton, QC.Qt.NoModifier)

                DoClick(click, panel)

                self.assertEqual(panel.GetSelectedNamespaceColours(), {})

                #

                if len(list(all_clickable_indices.keys())) > 2:

                    indices = random.sample(
                        list(all_clickable_indices.keys()),
                        len(list(all_clickable_indices.keys())) - 1)

                    for index in indices:

                        click = GenerateClick(
                            panel, QC.QPointF(10,
                                              all_clickable_indices[index]),
                            QC.QEvent.MouseButtonPress, QC.Qt.LeftButton,
                            QC.Qt.ControlModifier)

                        DoClick(click, panel)

                    expected_selected_namespaces_and_colours = [
                        ordered_terms[index].GetNamespaceAndColour()
                        for index in indices
                    ]

                    self.assertEqual(
                        panel.GetSelectedNamespaceColours(),
                        dict(expected_selected_namespaces_and_colours))

                #

                random_index = random.choice(list(
                    all_clickable_indices.keys()))

                while ordered_terms[random_index].GetNamespaceAndColour(
                )[0] in panel.PROTECTED_TERMS:

                    random_index = random.choice(
                        list(all_clickable_indices.keys()))

                del new_namespace_colours[
                    ordered_terms[random_index].GetNamespaceAndColour()[0]]

                # select nothing

                current_y = 5

                click = GenerateClick(panel, QC.QPointF(10, current_y),
                                      QC.QEvent.MouseButtonPress,
                                      QC.Qt.LeftButton, QC.Qt.NoModifier)

                while panel._GetLogicalIndexUnderMouse(click) is not None:

                    current_y += 5

                    click = GenerateClick(panel, QC.QPointF(10, current_y),
                                          QC.QEvent.MouseButtonPress,
                                          QC.Qt.LeftButton, QC.Qt.NoModifier)

                DoClick(click, panel)

                # select the random index

                click = GenerateClick(
                    panel, QC.QPointF(10, all_clickable_indices[random_index]),
                    QC.QEvent.MouseButtonPress, QC.Qt.LeftButton,
                    QC.Qt.NoModifier)

                DoClick(click, panel)

            finally:

                frame.deleteLater()