<commit_before># -*- coding: utf-8 -*-

import storj.exception as sjexc
import threading

from PyQt4 import QtCore, QtGui
from qt_interfaces.bucket_editing_ui import Ui_BucketEditing
from engine import StorjEngine


class BucketEditingUI(QtGui.QMainWindow):

    def __init__(self, parent=None, bucketid=None, action=None, dashboard_instance=None):
        QtGui.QWidget.__init__(self, parent)
        self.bucket_create_ui = Ui_BucketEditing()
        self.bucket_create_ui.setupUi(self)

        self.bucket_id = bucketid

        QtCore.QObject.connect(
            self.bucket_create_ui.cancel_bt, QtCore.SIGNAL('clicked()'),  self.close)

        self.connect(self, QtCore.SIGNAL('printBucketDetails'), self.set_bucket_details)
        self.connect(self, QtCore.SIGNAL('showBucketCreatingException'), self.show_bucket_creating_exception_dialog)
        self.connect(self, QtCore.SIGNAL('showBucketCreatedSuccessfully'), self.show_bucket_created_successfully)
        self.connect(self, QtCore.SIGNAL('showBucketDeletedSuccessfully'), self.show_bucket_deleted_successfully)
        self.connect(self, QtCore.SIGNAL('showBucketCreationMissingFields'),
            lambda: QtGui.QMessageBox.about(self, 'Warning', 'Please fill out all fields!'))
        self.dashboard_instance = dashboard_instance
        self.storj_engine = StorjEngine()

        if action == 'add':
            QtCore.QObject.connect(self.bucket_create_ui.create_edit_bucket_bt, QtCore.SIGNAL('clicked()'),
                                   self.createNewBucketCreateThread)  # create bucket action
            self.bucket_create_ui.create_edit_bucket_bt.setText('CREATE')
            self.bucket_create_ui.remove_bucket_bt.setVisible(False)
            self.setWindowTitle('Add bucket - Storj GUI')
        else:
            self.createBucketDetailsLoadThread()
            QtCore.QObject.connect(self.bucket_create_ui.create_edit_bucket_bt, QtCore.SIGNAL('clicked()'),
                                   lambda: self.createNewBucketEditThread(bucketid))  # create bucket action
            QtCore.QObject.connect(self.bucket_create_ui.remove_bucket_bt, QtCore.SIGNAL('clicked()'),
                                   self.createNewBucketRemoveThread)  # create bucket action
            self.bucket_create_ui.create_edit_bucket_bt.setText('SAVE')

    def set_bucket_details(self, bucket_name, bucket_transfer, bucket_storage):
        self.bucket_create_ui.bucket_name.setText(str(bucket_name))
        self.bucket_create_ui.bucket_transfer.setText(str(bucket_transfer))
        self.bucket_create_ui.bucket_size.setText(str(bucket_storage))

    def resolve_bucket_details(self):
        bucket_details = self.storj_engine.storj_client.bucket_get(str(self.bucket_id))
        self.emit(QtCore.SIGNAL('printBucketDetails'), bucket_details.name,
                  bucket_details.transfer, bucket_details.storage)  # update bucket details

    def show_bucket_creating_exception_dialog(self, exception):
        QtGui.QMessageBox.about(
            self,
            'Unhandled exception while creating bucket',
            'Exception: %s' % str(exception))

    def show_bucket_created_successfully(self, bucket_name):
        msgBox = QtGui.QMessageBox(
            QtGui.QMessageBox.Information,
            'Success',<commit_msg>comments before instruction. use single quotes.<commit_after># -*- coding: utf-8 -*-

import storj.exception as sjexc
import threading

from PyQt4 import QtCore, QtGui

from engine import StorjEngine
from qt_interfaces.bucket_editing_ui import Ui_BucketEditing


class BucketEditingUI(QtGui.QMainWindow):

    def __init__(self, parent=None, bucketid=None, action=None, dashboard_instance=None):
        QtGui.QWidget.__init__(self, parent)
        self.bucket_create_ui = Ui_BucketEditing()
        self.bucket_create_ui.setupUi(self)

        self.bucket_id = bucketid

        QtCore.QObject.connect(
            self.bucket_create_ui.cancel_bt, QtCore.SIGNAL('clicked()'),  self.close)

        self.connect(self, QtCore.SIGNAL('printBucketDetails'), self.set_bucket_details)
        self.connect(self, QtCore.SIGNAL('showBucketCreatingException'), self.show_bucket_creating_exception_dialog)
        self.connect(self, QtCore.SIGNAL('showBucketCreatedSuccessfully'), self.show_bucket_created_successfully)
        self.connect(self, QtCore.SIGNAL('showBucketDeletedSuccessfully'), self.show_bucket_deleted_successfully)
        self.connect(self, QtCore.SIGNAL('showBucketCreationMissingFields'),
            lambda: QtGui.QMessageBox.about(self, 'Warning', 'Please fill out all fields!'))
        self.dashboard_instance = dashboard_instance
        self.storj_engine = StorjEngine()

        if action == 'add':
            # create bucket action
            QtCore.QObject.connect(
                self.bucket_create_ui.create_edit_bucket_bt,
                QtCore.SIGNAL('clicked()'),
                self.createNewBucketCreateThread)
            self.bucket_create_ui.create_edit_bucket_bt.setText('CREATE')
            self.bucket_create_ui.remove_bucket_bt.setVisible(False)
            self.setWindowTitle('Add bucket - Storj GUI')
        else:
            self.createBucketDetailsLoadThread()

            # edit bucket action
            QtCore.QObject.connect(self.bucket_create_ui.create_edit_bucket_bt, QtCore.SIGNAL('clicked()'),
                                   lambda: self.createNewBucketEditThread(bucketid))
            # remove bucket action
            QtCore.QObject.connect(self.bucket_create_ui.remove_bucket_bt, QtCore.SIGNAL('clicked()'),
                                   self.createNewBucketRemoveThread)
            self.bucket_create_ui.create_edit_bucket_bt.setText('SAVE')

    def set_bucket_details(self, bucket_name, bucket_transfer, bucket_storage):
        self.bucket_create_ui.bucket_name.setText(str(bucket_name))
        self.bucket_create_ui.bucket_transfer.setText(str(bucket_transfer))
        self.bucket_create_ui.bucket_size.setText(str(bucket_storage))

    def resolve_bucket_details(self):
        # update bucket details
        bucket_details = self.storj_engine.storj_client.bucket_get(str(self.bucket_id))
        self.emit(QtCore.SIGNAL('printBucketDetails'), bucket_details.name,
                  bucket_details.transfer, bucket_details.storage)

    def show_bucket_creating_exception_dialog(self, exception):
        QtGui.QMessageBox.about(
            self,
            'Unhandled exception while creating bucket',
            'Exception: %s' % str(exception))

    def show_bucket_created_successfully(self, bucket_name):
        msgBox = QtGui.QMessageBox(
            QtGui.QMessageBox.Information,
            'Success',
{'fraction_non_alphanumeric': 0.09191286183228888, 'fraction_numerical': 0.000596836765144733, 'mean_word_length': 3.2803320561941254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6570993', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1900, 'n_words': 279}