mainWindow.py :  » Network » rwhois.py » releaseforge-0.5 » modules » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » rwhois.py 
rwhois.py » releaseforge 0.5 » modules » mainWindow.py
#!/usr/bin/env python

from qt import *
from mainWindowBA import mainWindowBA
from sf import SF
from sfcomm import SFComm
from login import Login
import os
from constants import *
import logging
from ProjectVO import ProjectVO
from PackageVO import PackageVO
from messageQueue import mainMessageQueue
import releaseWizard
#from releaseWizard import ReleaseWizard
from workerThread import WorkerThread
from help import Help
from aboutDialog import AboutDialog

debug = logging.getLogger("mainwindow").debug
error = logging.getLogger("mainwindow").error

COL_PROJ_NAME = 0
COL_PROJ_UNIX = 1
COL_PROJ_GROUP = 2

COL_PKG_NAME = 0
COL_PKG_ID = 1
COL_PKG_STATUS = 2
COL_PKG_FULLACCESS = 3

class mainWindow(mainWindowBA):
    def __init__(self, settings, *args):
        apply(mainWindowBA.__init__,(self,) + args)
        self.projects_dict = {} # maps group_id to set of projectVO's
        self.projects = None
        self.settings = settings
        self.timer = QTimer(self)
        self.connect(self.timer, SIGNAL("timeout()"),
                     self.getStatusMsg)
        self.timer.start(500, False)

        self.sf_comm = SFComm(settings['data_path'])
        self.sf = SF(settings['data_path'], self.sf_comm)
        self.connect(self, PYSIGNAL('projects_fetched()'), self.populateProjects)

        self.current_project_item = None
        self.current_projectVO = None
        self.current_package_item = None
        self.current_packageVO = None

        self.logged_in = False
        self.releaseWizards = []
        self.threads = []

        self.eventDict = {EVENT_REFRESH_PACKAGES: self.packageRefreshEvent,
                          EVENT_ADD_PACKAGE: self.projectNewPackageEvent}

##        self.projectsListView.hideColumn(COL_PROJ_UNIX)
##        self.projectsListView.hideColumn(COL_PROJ_GROUP)
##        self.packagesListView.hideColumn(COL_PKG_ID)
##        self.packagesListView.hideColumn(COL_PKG_STATUS)
##        self.packagesListView.hideColumn(COL_PKG_FULLACCESS)
        
        self.show()
        self.loginPrompt()
        

    def __del__(self):
        for t in self.threads:
            running = t.running()
            t.stop()
            if not t.finished():
                t.wait()


    def customEvent(self, event):
        data = event.data()
        etype = event.type()
        event_action = self.eventDict.get(etype)
        if event_action: event_action(data)

    def closeEvent(self, ev):
        self.sf_comm.remove_cookie()
        ev.accept()



    def loginPrompt(self):
        if not self.logged_in:
            self.login = Login(self, self.settings['data_path'], self.sf)


        
    def getStatusMsg(self):
        # read the message queue.  If an item exists,
        # populate the status bar with it.
        msg = mainMessageQueue.get()
        if msg:
            self.statusBar().message(msg)


    def populateProjects(self, projects):
        self.projects = projects
        self.logged_in = True
        self.fileSourceforge_LoginAction.setEnabled(False)
        self.projectsListView.clear()
        self.current_project_item = None
        self.current_projectVO = None
        self.current_package_item = None
        self.current_packageVO = None
        if projects:
            for project in projects:
                proj_item = QListViewItem(self.projectsListView)
                proj_item.setText(COL_PROJ_NAME, project.getProjectName())
                proj_item.setText(COL_PROJ_UNIX, project.getUnixName())
                proj_item.setText(COL_PROJ_GROUP, project.getGroupId())
                self.projects_dict[project.getGroupId()] = project.getPackages()
            if len(projects) == 1:
                self.projectSelected(proj_item)


    def populatePackages(self, group_id):
        self.packagesListView.clear()
        packages = self.projects_dict.get(group_id)
        debug("packages: %s", packages)
        self.__initialize_package_fields()
        if packages:
            for package in packages:
                pkg_item = QListViewItem(self.packagesListView)
                pkg_item.setText(COL_PKG_NAME, package.getPackageName())
                pkg_item.setText(COL_PKG_ID, package.getPackageId())
                pkg_item.setText(COL_PKG_STATUS, package.getPackageStatus())
                pkg_item.setText(COL_PKG_FULLACCESS, package.getFullAccess())
            if len(packages) == 1:
                self.packagesListView.setSelected(pkg_item, True)
                #self.packageSelected(pkg_item)


    def __initialize_package_fields(self):
        self.current_package_item = None
        self.current_packageVO = None

        self.packageIdLineEdit.setText("")
        self.updatePackageLineEdit.setText("")
        self.newPackageLineEdit.setText("")

        # enable
        self.refreshPackagesPushButton.setEnabled(1)
        self.newPackageLineEdit.setEnabled(1)

        # disable
        self.AddPackagePushButton.setEnabled(0)
        self.newReleasePushButton.setEnabled(0)
        self.packageStatusComboBox.setEnabled(0)
        self.updatePackagePushButton.setEnabled(0)
        self.updatePackageLineEdit.setEnabled(0)
        self.newReleasePushButton.setEnabled(0)

        
    def projectSelected(self, item):
        self.current_project_item = item
        self.current_projectVO = self.__getProjectFromItem(item)
        group_id = self.current_projectVO.getGroupId()
        debug("projectSelected: %s", group_id)
        self.populatePackages(group_id)

        

    def newPackageEdited(self, val):
        if not val:
            self.AddPackagePushButton.setEnabled(0)
        else:
            self.AddPackagePushButton.setEnabled(1)

            
    def updatePackageEdited(self, val):
        if val:
            self.updatePackagePushButton.setEnabled(1)
        else:
            self.updatePackagePushButton.setEnabled(0)


    def updatePackage(self):
        package_name = str(self.updatePackageLineEdit.text())
        package_status = str(self.packageStatusComboBox.currentText())
        package_id = str(self.packageIdLineEdit.text())
        
        if self.sf_comm.update_package(self.current_projectVO.getGroupId(),
                                       package_id,
                                       package_name,
                                       package_status):
            self.statusBar().message("Package updated successfully.")

            self.packageRefresh()
            ##self.packageRefresh(PackageVO(package_name,
            ##                              package_id,
            ##                              package_status))
        else:
            self.statusBar().message("Could not update package")
            

    def __getPackageFromItem(self, item):
        return PackageVO(str(item.text(COL_PKG_NAME)),
                         str(item.text(COL_PKG_ID)),
                         str(item.text(COL_PKG_STATUS)),
                         str(item.text(COL_PKG_FULLACCESS)))

    def __getProjectFromItem(self, item):
        return ProjectVO(str(item.text(COL_PROJ_NAME)),
                         str(item.text(COL_PROJ_UNIX)),
                         str(item.text(COL_PROJ_GROUP)))


    def packageSelected(self, item):       
        self.current_package_item = item
        pkg = self.__getPackageFromItem(item)
        self.current_packageVO = pkg

        self.updatePackageLineEdit.setText(pkg.getPackageName())
        status = pkg.getPackageStatus()

        if status == 'Active':
            self.packageStatusComboBox.setCurrentItem(0)
        else:
            self.packageStatusComboBox.setCurrentItem(1)

        if pkg.getFullAccess() == "True":
            self.updatePackageLineEdit.setReadOnly(False)
        else:
            self.updatePackageLineEdit.setReadOnly(True)
            
        self.packageIdLineEdit.setText(pkg.getPackageId())

        #enable
        self.packageStatusComboBox.setEnabled(1)
        self.updatePackageLineEdit.setEnabled(1)
        self.newReleasePushButton.setEnabled(1)

        # disable
        self.updatePackagePushButton.setEnabled(0)
        

    def packageRefresh(self):
        project = self.current_projectVO        
        group_id = project.getGroupId()

        # disable
        self.projectsListView.setEnabled(0)
        
        self.setCursor(Qt.waitCursor)
        thread = WorkerThread(self,
                              EVENT_REFRESH_PACKAGES,
                              self.sf_comm.get_packages,
                              group_id)
        thread.start()
        self.threads.append(thread)                              


    def packageRefreshEvent(self, pkgs):
        selectedVO = self.current_packageVO       
        project = self.current_projectVO
        
        group_id = project.getGroupId()
        current_pkgs = self.projects_dict[group_id]
        if current_pkgs != pkgs:
            debug("Packages updated.  Adding %d packages", len(pkgs))

            # remove the current project from
            # the set: self.projects
            self.projects.remove(project)
            project.setPackages(pkgs)

            # re-add this project, with the
            # new pkgs to self.projects
            self.projects.add(project)

            # save them for future runs
            self.sf.save_projects()

            # update the hash & listview
            self.projects_dict[group_id] = pkgs
            self.populatePackages(group_id)
        else:
            debug("No new packages detected")

        if selectedVO:
            self.__set_package_selected(selectedVO)

        # disable
        self.updatePackagePushButton.setEnabled(0)

        # enable
        self.projectsListView.setEnabled(1)
        
        self.setCursor(Qt.arrowCursor)



    def __set_package_selected(self, selectedVO):
        pkg = self.packagesListView.firstChild()
        while pkg != None:
            pkgVO = self.__getPackageFromItem(pkg)
            if pkgVO.getPackageId() == selectedVO.getPackageId():
                self.packagesListView.setCurrentItem(pkg)
                break
            pkg = pkg.nextSibling()


    def projectNewPackage(self):
        name = str(self.newPackageLineEdit.text())
        if not name:
            QMessageBox.information(self, "Package Name",
                                 "Cannot create package..\n"
                                 "Package name is empty.")
            return
        
        debug("Creating package: %s", name)
        group_id = str(self.projectsListView.currentItem().text(2))

        self.setCursor(Qt.waitCursor)
        thread = WorkerThread(self,
                              EVENT_ADD_PACKAGE,
                              self.sf_comm.add_package,
                              group_id,
                              name)
        thread.start()
        self.threads.append(thread)                              


        

    def projectNewPackageEvent(self, result):
        self.setCursor(Qt.arrowCursor)
        debug("add package result: %d", result)
        if result:
            self.packageRefresh()


    def createNewRelease(self):
        debug("%s", self.current_packageVO)
        
        release_wizard = releaseWizard.ReleaseWizard(self,
                                                     self.settings,
                                                     self.sf_comm,
                                                     self.current_projectVO.copy(),
                                                     self.current_packageVO.copy())
        release_wizard.show()
        self.releaseWizards.append(release_wizard)
        

    def packageNewRelease(self):
        item = self.projectsListView.currentItem()
        package = PackageVO(str(item.text(0)), str(item.text(1)))
        debug("packageNewRelease(): %s", package)
        

    def help(self):
        self._help = Help(self, "mainwindow.html")
        

    def reloadWizard(self):
        reload(releaseWizard)
        
    def editCopy(self, *args):
        print "mainWindow.editCopy(): Not implemented yet"
    
    def editCut(self, *args):
        print "mainWindow.editCut(): Not implemented yet"
    
    def editFind(self, *args):
        print "mainWindow.editFind(): Not implemented yet"
    
    def editPaste(self, *args):
        print "mainWindow.editPaste(): Not implemented yet"
    
    def editRedo(self, *args):
        print "mainWindow.editRedo(): Not implemented yet"
    
    def editUndo(self, *args):
        print "mainWindow.editUndo(): Not implemented yet"

    def fileExit(self):
        self.close()
        
    
    def fileNew(self, *args):
        print "mainWindow.fileNew(): Not implemented yet"
    
    def fileOpen(self, *args):
        print "mainWindow.fileOpen(): Not implemented yet"
    
    def filePrint(self, *args):
        print "mainWindow.filePrint(): Not implemented yet"
    
    def fileSave(self, *args):
        print "mainWindow.fileSave(): Not implemented yet"
    
    def fileSaveAs(self, *args):
        print "mainWindow.fileSaveAs(): Not implemented yet"
    
    def helpAbout(self, *args):
        self.aboutWindow = AboutDialog(self)
        self.aboutWindow.show()
    
    
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.