Exemple #1
0
	def run(self):
		app = QApplication(sys.argv)
		w = QMainWindow()
		w.resize(700, 700)
		w.move(400, 0)
		w.setWindowTitle('Simple')
		w.show()
		w.isDrawMode = self.isDrawMode
		
		w.fileMenu = w.menuBar().addMenu("&File")
		w.fileSaveMenuItem = SfAction("&Save", w, shortcut="CTRL+S", tip="Save current scenario")
		w.fileSaveMenuItem.triggered.connect(self.fileSave)
		w.fileMenu.addAction(w.fileSaveMenuItem)
		w.fileMenu.addAction(SfAction("&Quit", w, slot=self.fileQuit(), shortcut="ALT+F4", 
									  tip="Quit SimFrames"))
		
		w.toolbar = w.addToolBar("Activities Toolbar")
		w.toolbar.setObjectName("ActivitiesToolbar")
		playActionsGroup = QActionGroup(w)
		w.toolbar.addAction(SfAction("&Play", w, "play.png", self.play, "CTRL+P", 
									 "Start the project", True, actionGroup=playActionsGroup ))
		w.toolbar.addAction(SfAction("&Stop", w, "stop.png", self.stop, "CTRL+F", 
								     "Stop executing", True, actionGroup=playActionsGroup, checked=True ))
		w.toolbar.addAction(SfSeparator(w))
		
		self.mouseModeGroup = QActionGroup(w)
		w.toolbar.addAction(SfAction("&Move", self.mouseModeGroup, "moveMode.png", shortcut="CTRL+M", 
									 tip="Turn on mode to move components around canvas", checkable=True,
									 checked=True))
		self.drawAction = SfAction("&Draw", self.mouseModeGroup, "connectMode.png", shortcut="CTRL+D", 
									 tip="Turn on mode to connect components in canvas", checkable=True)
		w.toolbar.addAction(self.drawAction)
		w.toolbar.addAction(SfSeparator(w))
		
		w.accordion = SfAccordion()
		functions = SfAccordionSection("Functions")
		functions.addComponents([SfComponent("add.png",), 
								 SfComponent("minus.png"),
								 SfComponent("multiplication.png")])
		inputSection = SfAccordionSection("Input")
		inputSection.addComponents([SfComponent("scale.png", ), 
								    SfComponent("square.png"),
								    SfComponent("constant.png" )])
		outputSection = SfAccordionSection("Output")
		outputSection.addComponents([SfComponent("txt.png", ), SfComponent("graph.png", )])
		w.accordion.addSections([functions, inputSection, outputSection])
		
		scene = SfGraphicsScene(w)
		self.canvas = SfGraphicsView(scene)
		scene.sceneRectChanged.connect(self.canvas.updateSceneRect)
		
		centralWidget = QWidget()
		mainLayout = QBoxLayout(QBoxLayout.LeftToRight, centralWidget)
		mainLayout.addWidget(w.accordion)
		mainLayout.addWidget(self.canvas)
		centralWidget.setLayout(mainLayout)
		w.setCentralWidget(centralWidget)
		w.quitAction = SfAction("&Quit", w, slot=self.fileQuit(), shortcut="ALT+F4", tip="Quit SimFrames")	
		app.exec_()
Exemple #2
0
def main():
    qapp = QApplication(sys.argv)
    window = QMainWindow()
    view = QWebView()
    window.setWindowTitle('MUTE - Collaborative Text Editor')

    def file_save():
        name = QFileDialog.getSaveFileName(window, 'Save File')
        if len(name.strip()) > 0:
            print('SAVE|' + name)
            sys.stdout.flush()

    def file_open():
        name = QFileDialog.getOpenFileName(window, 'Open File')
        if len(name.strip()) > 0:
            print('OPEN|' + name)
            sys.stdout.flush()

    def dir_open():
        dir_name = QFileDialog.getExistingDirectory(window, 'Open Directory',
                                                    'C:\\',
                                                    QFileDialog.ShowDirsOnly)
        if len(name.strip()) > 0:
            print('DIR|' + dir_name)
            sys.stdout.flush()

    def set_console():
        name = QFileDialog.getOpenFileName(window, 'Set Console')
        if len(name.strip()) > 0:
            print('SCONSOLE|' + name)
            sys.stdout.flush()

    extractAction = QAction("&Exit", window)
    extractAction.setStatusTip('Leave The App')
    extractAction.triggered.connect(sys.exit)

    extractAction2 = QAction("&Open File", window)
    extractAction2.setStatusTip('Open a file')
    extractAction2.triggered.connect(file_open)

    extractAction4 = QAction("&Save File", window)
    extractAction4.setStatusTip('Save a file')
    extractAction4.triggered.connect(file_save)

    extractAction5 = QAction("&Set Console", window)
    extractAction5.triggered.connect(set_console)

    extractAction3 = QAction("&Open Project Directory", window)
    extractAction3.setStatusTip('Open a directory')
    extractAction3.triggered.connect(dir_open)

    mainMenu = window.menuBar()
    fileMenu = mainMenu.addMenu('&File')
    fileMenu.addAction(extractAction)
    fileMenu.addAction(extractAction2)
    fileMenu.addAction(extractAction4)
    fileMenu.addAction(extractAction3)
    fileMenu.addAction(extractAction5)

    def set_bold():
        print('SET_BOLD|', end='\n', file=sys.stdout, flush=True)
        # sys.stdout.flush()
    def set_italics():
        print('SET_ITALICS|')
        sys.stdout.flush()

    def set_html_tag():
        text, ok = QInputDialog.getText(window, 'Text Input Dialog',
                                        'Enter HTML Tag:')
        if ok:
            textArray = text.strip().split()
            name = textArray[0]
            attributes = ' '.join(textArray[1:])
            print('SET_HTML_TAG|' + str(name) + '|' + attributes)
            sys.stdout.flush()

    boldAction = QAction("&Set Bold", window)
    boldAction.triggered.connect(set_bold)
    italicsAction = QAction("&Set Italics", window)
    italicsAction.triggered.connect(set_italics)
    htmlTagAction = QAction("&Set Html Tag", window)
    htmlTagAction.triggered.connect(set_html_tag)

    editMenu = mainMenu.addMenu('&Edit')
    editMenu.addAction(boldAction)
    editMenu.addAction(italicsAction)
    editMenu.addAction(htmlTagAction)

    view.load(QUrl('http://127.0.0.1:8000/index.html'))
    #view.page().mainFrame().evaluateJavaScript('var IS_ADMIN = true;')
    # view.setHtml('<h1>hi</h1>')
    window.setCentralWidget(view)
    window.showMaximized()
    view.show()
    qapp.exec_()
Exemple #3
0
class Test(unittest.TestCase):
    """Base class for tests
    """
    app = QApplication(sys.argv)  # app crashes, if created more than once
    
    def setUp(self):
        self._window = QMainWindow()
        self.qpart = Qutepart()
        self._window.setCentralWidget(self.qpart)
        self._window.menuBar().addAction(self.qpart.invokeCompletionAction)
    
    def tearDown(self):
        del self.qpart

    def test_down_selects_first(self):
        self.qpart.text = 'aaaa\nbbbb\ncccX\ndddd\ncccY'
        
        while QApplication.hasPendingEvents():
            QApplication.processEvents()
        
        QTest.keyClicks(self.qpart, "ccc")
        QTest.keyClick(self.qpart, Qt.Key_Down)
        QTest.keyClick(self.qpart, Qt.Key_Enter)
        QTest.keyClick(self.qpart, Qt.Key_Enter)
        self.assertEqual(self.qpart.text, 'cccX\naaaa\nbbbb\ncccX\ndddd\ncccY')
        
    def test_down_selects_second(self):
        self.qpart.text = 'aaaa\nbbbb\ncccX\ndddd\ncccY'
        
        while QApplication.hasPendingEvents():
            QApplication.processEvents()
        
        QTest.keyClicks(self.qpart, "ccc")
        
        QTest.keyClick(self.qpart, Qt.Key_Down)
        QTest.keyClick(self.qpart, Qt.Key_Down)
        QTest.keyClick(self.qpart, Qt.Key_Enter)
        QTest.keyClick(self.qpart, Qt.Key_Enter)
        self.assertEqual(self.qpart.text, 'cccY\naaaa\nbbbb\ncccX\ndddd\ncccY')
    
    @unittest.skip("Crashes Qt 4.8.3")
    def test_click_selects_first(self):
        self.qpart.text = 'aaaa\nbbbb\ncccX\ndddd\ncccY'
                
        QTest.keyClicks(self.qpart, "ccc")
        QTest.mouseClick(self.qpart, Qt.LeftButton)
        QTest.keyClick(self.qpart, Qt.Key_Enter)
        self.assertEqual(self.qpart.text, 'cccY\naaaa\nbbbb\ncccX\ndddd\ncccY')
        
    def test_tab_completes(self):
        self.qpart.text = 'aaaaa\naaaaaXXXXX\n'
        
        while QApplication.hasPendingEvents():
            QApplication.processEvents()
        
        self.qpart.cursorPosition = (2, 0)
        QTest.keyClicks(self.qpart, "aaa")
        QTest.keyClick(self.qpart, Qt.Key_Tab)
        self.assertEqual(self.qpart.text, 'aaaaa\naaaaaXXXXX\naaaaa')
        QTest.keyClick(self.qpart, Qt.Key_Tab)
        self.assertEqual(self.qpart.text, 'aaaaa\naaaaaXXXXX\naaaaaXXXXX')

    def test_manual(self):
        self._window.show()
        
        self.qpart.text = 'aaaaa\naaaaaXXXXX\n'
        
        while QApplication.hasPendingEvents():
            QApplication.processEvents()
        
        self.qpart.cursorPosition = (2, 0)
        QTest.keyClicks(self.qpart, "a")
        
        QTest.keyPress(self.qpart, Qt.Key_Space, Qt.ControlModifier, 100)
        
        QTest.keyClicks(self.qpart, "a")
        QTest.keyClick(self.qpart, Qt.Key_Tab)
        self.assertEqual(self.qpart.text, 'aaaaa\naaaaaXXXXX\naaaaa')
Exemple #4
0
class Test(unittest.TestCase):
    """Base class for tests
    """
    app = base.papp  # app crashes, if created more than once

    def setUp(self):
        self._window = QMainWindow()
        self.qpart = Qutepart()
        self._window.setCentralWidget(self.qpart)
        self._window.menuBar().addAction(self.qpart.invokeCompletionAction)

    def tearDown(self):
        del self.qpart

    def test_down_selects_first(self):
        self.qpart.text = 'aaaa\nbbbb\ncccX\ndddd\ncccY'

        while self.app.hasPendingEvents():
            self.app.processEvents()

        QTest.keyClicks(self.qpart, "ccc")
        QTest.keyClick(self.qpart, Qt.Key_Down)
        QTest.keyClick(self.qpart, Qt.Key_Enter)
        QTest.keyClick(self.qpart, Qt.Key_Enter)
        self.assertEqual(self.qpart.text, 'cccX\naaaa\nbbbb\ncccX\ndddd\ncccY')

    def test_down_selects_second(self):
        self.qpart.text = 'aaaa\nbbbb\ncccX\ndddd\ncccY'

        base._processPendingEvents(self.app)

        QTest.keyClicks(self.qpart, "ccc")

        QTest.keyClick(self.qpart, Qt.Key_Down)
        QTest.keyClick(self.qpart, Qt.Key_Down)
        QTest.keyClick(self.qpart, Qt.Key_Enter)
        QTest.keyClick(self.qpart, Qt.Key_Enter)
        self.assertEqual(self.qpart.text, 'cccY\naaaa\nbbbb\ncccX\ndddd\ncccY')

    @unittest.skip("Crashes Qt 4.8.3")
    def test_click_selects_first(self):
        self.qpart.text = 'aaaa\nbbbb\ncccX\ndddd\ncccY'

        QTest.keyClicks(self.qpart, "ccc")
        QTest.mouseClick(self.qpart, Qt.LeftButton)
        QTest.keyClick(self.qpart, Qt.Key_Enter)
        self.assertEqual(self.qpart.text, 'cccY\naaaa\nbbbb\ncccX\ndddd\ncccY')

    def test_tab_completes(self):
        self.qpart.text = 'aaaaa\naaaaaXXXXX\n'

        base._processPendingEvents(self.app)

        self.qpart.cursorPosition = (2, 0)
        QTest.keyClicks(self.qpart, "aaa")
        QTest.keyClick(self.qpart, Qt.Key_Tab)
        self.assertEqual(self.qpart.text, 'aaaaa\naaaaaXXXXX\naaaaa')
        QTest.keyClick(self.qpart, Qt.Key_Tab)
        self.assertEqual(self.qpart.text, 'aaaaa\naaaaaXXXXX\naaaaaXXXXX')

    def test_manual(self):
        self._window.show()

        self.qpart.text = 'aaaaa\naaaaaXXXXX\n'

        base._processPendingEvents(self.app)

        self.qpart.cursorPosition = (2, 0)
        QTest.keyClicks(self.qpart, "a")

        QTest.keyPress(self.qpart, Qt.Key_Space, Qt.ControlModifier, 100)

        QTest.keyClicks(self.qpart, "a")
        QTest.keyClick(self.qpart, Qt.Key_Tab)
        self.assertEqual(self.qpart.text, 'aaaaa\naaaaaXXXXX\naaaaa')

    @base.in_main_loop
    def test_too_long_list(self):
        self._window.show()

        self.qpart.text = '\n'.join(['asdf' + str(i) \
                                        for i in range(100)]) + '\n'
        base._processPendingEvents(self.app)
        self.qpart.cursorPosition = (100, 0)
        QTest.keyClicks(self.qpart, "asdf")
        self.assertIsNotNone(self.qpart._completer._widget)

        self.qpart.text = '\n'.join(['asdf' + str(i) \
                                        for i in range(1000)]) + '\n'
        base._processPendingEvents(self.app)
        self.qpart.cursorPosition = (1000, 0)
        QTest.keyClicks(self.qpart, "asdf")
        self.assertIsNone(self.qpart._completer._widget)

        QTest.keyPress(self.qpart, Qt.Key_Space, Qt.ControlModifier, 100)
        self.assertIsNotNone(self.qpart._completer._widget)
Exemple #5
0
def main():
    ns = _parseCommandLine()
    _fixSysPath(ns.binary)

    import qutepart  # after correct sys.path has been set

    with open(ns.file) as file:
        text = unicode(file.read(), 'utf8')

    if ns.debug:
        logging.getLogger('qutepart').setLevel(logging.DEBUG)

    app = QApplication(sys.argv)

    window = QMainWindow()

    qpart = qutepart.Qutepart()
    window.setCentralWidget(qpart)

    firstLine = text.splitlines()[0] if text else None
    qpart.detectSyntax(sourceFilePath=ns.file, firstLine=firstLine)

    qpart.lineLengthEdge = 20

    qpart.drawIncorrectIndentation = True
    qpart.drawAnyWhitespace = False

    qpart.indentUseTabs = False

    qpart.text = text

    qpart.setWindowTitle(ns.file)

    menu = {
        'File': ('printAction', ),
        'Bookmarks':
        ('toggleBookmarkAction', 'nextBookmarkAction', 'prevBookmarkAction'),
        'Navigation': (
            'scrollUpAction',
            'scrollDownAction',
            'selectAndScrollUpAction',
            'selectAndScrollDownAction',
        ),
        'Indentation': ('increaseIndentAction', 'decreaseIndentAction',
                        'autoIndentLineAction', 'indentWithSpaceAction',
                        'unIndentWithSpaceAction'),
        'Lines': ('moveLineUpAction', 'moveLineDownAction', 'deleteLineAction',
                  'copyLineAction', 'pasteLineAction', 'cutLineAction',
                  'duplicateLineAction'),
        'Edit': ('invokeCompletionAction', 'undoAction', 'redoAction')
    }
    for k, v in menu.items():
        menuObject = window.menuBar().addMenu(k)
        for actionName in v:
            menuObject.addAction(getattr(qpart, actionName))

    qpart.userWarning.connect(
        lambda text: window.statusBar().showMessage(text, 3000))

    window.resize(800, 600)
    window.show()

    from PyQt4.QtCore import QTimer
    if ns.quit:
        QTimer.singleShot(0, app.quit)

    return app.exec_()
Exemple #6
0
        super(EditableFormLayout, self).__init__(parent)


if __name__ == "__main__":
    app = QApplication(sys.argv)

    EditableForm.extendAvailableOptions(
        "datakey", list("ABCDEFHIJKLMNOPQRSTUVWXYZ1234567890"))

    col = IPETEvaluationColumn(origcolname="A",
                               name="name",
                               formatstr="%.2f",
                               transformfunc="sum",
                               constant=None,
                               alternative="2",
                               minval="0.5",
                               maxval="10.0",
                               comp="default",
                               translevel="1")

    mainwindow = QMainWindow()
    mainwindow.menuBar()
    ev = IPETEvaluation()
    fg = IPETFilterGroup(name="bla")
    f = IPETFilter("Bla", "expression2", "neq", "one")
    form = EditableForm(col)
    mainwindow.setCentralWidget(form)
    mainwindow.show()

    app.exec_()
Exemple #7
0
def main():
    ns = _parseCommandLine()
    _fixSysPath(ns.binary)

    import qutepart  # after correct sys.path has been set

    with open(ns.file) as file:
        text = unicode(file.read(), 'utf8')

    if ns.debug:
        logging.getLogger('qutepart').setLevel(logging.DEBUG)

    app = QApplication(sys.argv)

    window = QMainWindow()

    qpart = qutepart.Qutepart()
    window.setCentralWidget(qpart)

    firstLine = text.splitlines()[0] if text else None
    qpart.detectSyntax(sourceFilePath=ns.file, firstLine=firstLine)

    qpart.lineLengthEdge = 20

    qpart.drawIncorrectIndentation = True
    qpart.drawAnyWhitespace = False

    qpart.indentUseTabs = True

    qpart.text = text

    qpart.setWindowTitle(ns.file)

    menu = {'File':      ('printAction',),
            'Bookmarks': ('toggleBookmarkAction',
                          'nextBookmarkAction',
                          'prevBookmarkAction'),
            'Navigation':('scrollUpAction',
                          'scrollDownAction',
                          'selectAndScrollUpAction',
                          'selectAndScrollDownAction',
                          ),
            'Indentation':('increaseIndentAction',
                           'decreaseIndentAction',
                           'autoIndentLineAction',
                           'indentWithSpaceAction',
                           'unIndentWithSpaceAction'),
            'Lines':      ('moveLineUpAction',
                           'moveLineDownAction',
                           'deleteLineAction',
                           'copyLineAction',
                           'pasteLineAction',
                           'cutLineAction',
                           'duplicateLineAction'),
            'Edit'      : ('invokeCompletionAction',
                           'undoAction',
                           'redoAction'
                           )
    }
    for k, v in menu.items():
        menuObject = window.menuBar().addMenu(k)
        for actionName in v:
            menuObject.addAction(getattr(qpart, actionName))

    qpart.userWarning.connect(lambda text: window.statusBar().showMessage(text, 3000))

    window.resize(800, 600)
    window.show()

    from PyQt4.QtCore import QTimer
    if ns.quit:
        QTimer.singleShot(0, app.quit)

    return app.exec_()
Exemple #8
0
class QMPCApp(QObject):
    __images__ = {
        'background':           "images/background.png",
    }
    
    __icons__  = {
        'homeButton':           "general_backspace",
        'volumeButton':         "general_speaker",
        'settingsButton':       "keyboard_menu",
        'prevButton':           "/etc/hildon/theme/mediaplayer/Back.png",
        'prevButtonPressed':    "/etc/hildon/theme/mediaplayer/BackPressed.png",
        'playButton':           "/etc/hildon/theme/mediaplayer/Play.png",
        'pauseButton':          "/etc/hildon/theme/mediaplayer/Pause.png",
        'stopButton':           "/etc/hildon/theme/mediaplayer/Stop.png",
        'stopButtonPressed':    "/etc/hildon/theme/mediaplayer/StopPressed.png",
        'nextButton':           "/etc/hildon/theme/mediaplayer/Forward.png",
        'nextButtonPressed':    "/etc/hildon/theme/mediaplayer/ForwardPressed.png",
        'repeatButton':         "/etc/hildon/theme/mediaplayer/Repeat.png",
        'repeatButtonPressed':  "/etc/hildon/theme/mediaplayer/RepeatPressed.png",
        'shuffleButton':        "/etc/hildon/theme/mediaplayer/Shuffle.png",
        'shuffleButtonPressed': "/etc/hildon/theme/mediaplayer/ShufflePressed.png",
    }

    def __init__(self):
        super(QMPCApp,self).__init__()
        self.mw = None
        self.initData()
        self.initMPD()
        self.initActions()
        self.initGUI()
        QTimer.singleShot(100,self.deferredStart)

    def deferredStart(self):
        if self.data.autoconnect: self.connectMPD()

    def initData(self):
        self.selectedServerName = None
        self.data = DataModel()
        self.data.loadSettings()
        self.imagehelper = ImageHelper(images=self.__images__,
                                       icons=self.__icons__)
        QApplication.instance().aboutToQuit.connect(self.data.saveSettings)

    def initActions(self):
        self.actionPlayer = QAction("Player", self)
        self.actionPlayer.triggered.connect(
            lambda: self.showWidget(self.player))
        self.actionPlaylist = QAction("Playlist",self)
        self.actionPlaylist.triggered.connect(
            lambda: self.showWidget(self.playlist))
        self.actionBrowser = QAction("Browser",self)
        self.actionBrowser.triggered.connect(
            lambda: self.showWidget(self.browser))

        self.actionOutputs = QAction("Outputs",self)
        self.actionOutputs.triggered.connect(self.showOutputs)
        self.actionStats = QAction("Statistics",self)
        self.actionStats.triggered.connect(self.showStats)
        self.actionPrefs = QAction("Preferences",self)
        self.actionPrefs.triggered.connect(self.showPrefs)
        self.actionConnect = QAction("Connect",self)
        self.actionConnect.triggered.connect(self.connectActivated)

    def initGUI(self):
        self.initStartScreen()
        self.initWidgets()
        
        if not have_maemo:
            self.mw     = QMainWindow()
            menu        = self.mw.menuBar()
            menufile    = menu.addMenu("&File")
            menuwindows = menu.addMenu("&Windows")
            self.mw.statusBar()
            menuwindows.addAction(self.actionPlayer)
            menuwindows.addAction(self.actionPlaylist)
            menuwindows.addAction(self.actionBrowser)
            menuwindows.addAction(self.actionOutputs)
            menuwindows.addAction(self.actionStats)
            menufile.addAction(self.actionConnect)
            menufile.addAction(self.actionPrefs)
            menufile.addSeparator()
            menufile.addAction("&Quit", QApplication.quit)
       
        self.setConnectionState(False)

    def initStartScreen(self):
        self.startscreen = StartScreen(self)
        self.startscreen.clicked.connect(self.connectActivated)
        if have_maemo:
            menu = QMenuBar(self.startscreen)
            menu.addAction(self.actionConnect)
            menu.addAction(self.actionPrefs)
            
    def initWidgets(self):
        # create subwidgets
        self.player   = Player(self)
        self.playlist = Playlist(self)
        self.browser  = Browser(self)
        if have_maemo:
            # build Maemo stack hierarchy
            self.playlist.setParent(self.player)
            self.browser.setParent(self.player)
            for w in [ self.player, self.playlist, self.browser ]:
                w.setAttribute( Qt.WA_Maemo5StackedWindow)
                w.setWindowFlags( w.windowFlags() | Qt.Window)

            # add menu bar
            menu = QMenuBar(self.player)
            menu.addAction(self.actionPlaylist)
            menu.addAction(self.actionBrowser)
            menu.addAction(self.actionStats)
            menu.addAction(self.actionOutputs)
            menu.addAction(self.actionPrefs)
            menu.addAction(self.actionConnect)
        else:
            self.stack = QStackedWidget()
            for w in [ self.player, self.playlist, self.browser ]:
                w.setParent(self.stack)
                self.stack.addWidget(w)

    def switchView(self, connected):
        if have_maemo:
            if connected:
                self.player.show()
                self.startscreen.hide()
            else:
                self.startscreen.show()
        else:
            cw = self.mw.centralWidget()
            if cw:
                cw.setParent(None)
                cw.hide()
            if connected:
                self.mw.setCentralWidget(self.stack)
                self.stack.show()
                self.showWidget(self.player)
            else:
                self.mw.setCentralWidget(self.startscreen)
                self.startscreen.show()
            self.mw.show()

    def showWidget(self,widget):
        if not have_maemo:
            self.stack.setCurrentWidget(widget)
        widget.show()

    def connectActivated(self):
        if self.actionConnect.text() == "Connect":
            self.connectMPD()
        else:
            self.disconnectMPD()

    def initMPD(self):
        self.mpd = MPDWrapper()
        self.mpdtimer = None
    
    def connectMPD(self,reconnect=False):
        selected = self.data.selectedServer()
        if not len(selected):
            InformationBox.information( self.mw, "Select server to connect")
            self.showPrefs()

        selected = self.data.selectedServer()
        if len(selected):
            name, address, port = selected
            try:
                if not reconnect:
                    InformationBox.information(
                        self.mw, "Connecting to <b>%s</b>" % name)
                    QApplication.processEvents()
                self.mpd.timeout = 10
                self.mpd.connect( str(address), int(port))
                if not reconnect:
                    InformationBox.information(
                        self.mw, "Connected to <b>%s</b>" % name)
                    QApplication.processEvents()
                    self.setConnectionState(True)
                    self.selectedServerName = name
                self.mpdtimer = self.startTimer(5000)
            except socket.timeout, e:
                self.setConnectionState(False)
                InformationBox.information( self.mw, "%s: %s" %(name,e))
                QApplication.processEvents()
            except socket.gaierror, e:
                self.setConnectionState(False)
                InformationBox.information( self.mw, "%s: %s" %(name,e[1]))
                QApplication.processEvents()
            except socket.error, e:
                self.setConnectionState(False)
                InformationBox.information( self.mw, "%s: %s" %(name,e[1]))
                QApplication.processEvents()