[Uludag-commits] r16244 - trunk/tasma/package-manager/src

uludag-commits at pardus.org.tr uludag-commits at pardus.org.tr
5 Ara 2007 Çar 12:05:24 EET


Author: gokcen.eraslan
Date: Wed Dec  5 12:05:24 2007
New Revision: 16244

Added:
   trunk/tasma/package-manager/src/Globals.py
Modified:
   trunk/tasma/package-manager/src/BasketDialog.py
   trunk/tasma/package-manager/src/CustomEventListener.py
   trunk/tasma/package-manager/src/HelpDialog.py
   trunk/tasma/package-manager/src/MainWidget.py
   trunk/tasma/package-manager/src/SpecialList.py
   trunk/tasma/package-manager/src/package-manager.py
Log:
Globals and SpecialList module created

Globals module is responsible from operations requires KApplication. SpecialList module is a new form of KHTMLPart used as a listview like widget on the right side of the package manager.


Modified: trunk/tasma/package-manager/src/BasketDialog.py
=================================================================
--- trunk/tasma/package-manager/src/BasketDialog.py	(original)
+++ trunk/tasma/package-manager/src/BasketDialog.py	Wed Dec  5 12:05:24 2007
@@ -15,7 +15,7 @@
 from sets import Set as set
 from qt import *
 from kdecore import *
-from kdeui import KCursor
+from kdeui import KCursor, KDialog
 from khtml import *
 
 import pisi

Modified: trunk/tasma/package-manager/src/CustomEventListener.py
=================================================================
--- trunk/tasma/package-manager/src/CustomEventListener.py	(original)
+++ trunk/tasma/package-manager/src/CustomEventListener.py	Wed Dec  5 12:05:24 2007
@@ -22,6 +22,7 @@
     def handleEvent(self,event):
         target = event.target().nodeName().string()
         try:
+            #if checkbox is clicked, add/remove package to/from basket
             if target == "INPUT":
                 inputElement = DOM.HTMLInputElement(event.target())
                 name = inputElement.name().string()

Modified: trunk/tasma/package-manager/src/HelpDialog.py
=================================================================
--- trunk/tasma/package-manager/src/HelpDialog.py	(original)
+++ trunk/tasma/package-manager/src/HelpDialog.py	Wed Dec  5 12:05:24 2007
@@ -13,6 +13,7 @@
 from qt import *
 from kdecore import locate, i18n, KURL
 from khtml import KHTMLPart
+from kdeui import KDialog
 from LocaleData import getKDELocale
 
 (MAINAPP, PREFERENCES) = (1, 2)

Modified: trunk/tasma/package-manager/src/MainWidget.py
=================================================================
Suppressed!
	Too long (more than 250 lines) diff output suppressed...
Modified: trunk/tasma/package-manager/src/SpecialList.py
=================================================================
--- trunk/tasma/package-manager/src/SpecialList.py	(original)
+++ trunk/tasma/package-manager/src/SpecialList.py	Wed Dec  5 12:05:24 2007
@@ -1,4 +1,174 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
+#qt import
+from qt import *
+
+#kde imports
+from kdecore import *
+from kdeui import *
+from khtml import *
+
+import pisi
+import re
+
+import Globals
+import CustomEventListener
+
+class SpecialList:
+    def __init__(self, parent):
+        self.parent = parent
+        self.part = KHTMLPart(self.parent)
+        self.part.view().setFocus()
+        
+        # Read javascript
+        js = file(str(locate("data","package-manager/animation.js"))).read()
+        js = re.sub("#3cBB39", KGlobalSettings.alternateBackgroundColor().name(), js)
+        js = re.sub("#3c8839", KGlobalSettings.baseColor().name(), js)
+        self.javascript = re.sub("#533359",KGlobalSettings.highlightColor().name(), js)
+
+        # Read Css
+        cssFile = file(str(locate("data","package-manager/layout.css"))).read()
+        self.css = cssFile
+
+        QObject.connect(self.part, SIGNAL("completed()"), self.registerEventListener)
+    
+    def registerEventListener(self):
+        self.eventListener = CustomEventListener.CustomEventListener(self)
+        node = self.part.document().getElementsByTagName(DOM.DOMString("body")).item(0)
+        node.addEventListener(DOM.DOMString("click"),self.eventListener,True)
+
+    def clear(self):
+        self.part.view().setContentsPos(0, 0)
+        self.part.begin()
+        self.part.write('''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+        <html>
+        <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+        </head>
+        <body/>
+        ''')
+        self.part.end()
+
+    def createList(self,packages,part=None):
+        head =  '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+        <html>
+        <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+        '''
+
+        if not part:
+            part = self.part
+
+        Globals.setWaitCursor()
+        part.view().setContentsPos(0, 0)
+        part.begin()
+        part.write(head)
+        part.write("<style type=\"text/css\">%s</style>" % self.css)
+        part.write("<script language=\"JavaScript\">%s</script>" % self.javascript)
+        part.write("</head><body>")
+
+        if set(packages) - set(self.basket.packages):
+            part.write('''<font size="-2"><a href="#selectall">'''+i18n("Select all packages in this category")+'''</a></font>''')
+        else:
+            part.write('''<font size="-2"><a href="#selectall">'''+i18n("Reverse package selections")+'''</a></font>''')
+
+        part.write(self.createListForPackages(packages))
+        part.end()
+        Globals.setNormalCursor()
+
+    def createListForPackages(self,packages):
+        result = ""
+        template ='''
+        <!-- package start -->
+        <div>
+        <!-- checkbox --> %s <!-- checkbox -->
+        <div class="package_title" style="%s" id="package_t%d" onclick="showHideContent(this)">
+        <img src="%s" style="float:left;" width="%dpx" height="%dpx">
+        <b>%s</b><br><span style="color:#303030">%s</span><br>
+        </div>
+        <div class="package_info" style="%s" id="package_i%d">
+        <div style="margin-left:25px;" class="package_info_content" id="package_ic%d">
+        <p><b>%s</b>
+        %s<br>
+        <b>%s</b>%s<br><b>%s</b>%s<br><b>%s</b>%s<br><b>%s</b><a href=\"%s\">%s</a>
+        </p>
+        </div>
+        </div>
+        </div>
+        <!-- package end -->
+        '''
+
+        index = 0
+        titleStyle = ""
+        style = ""
+        packages.sort(key=string.lower)
+        pdb = pisi.db.packagedb.PackageDB()
+
+        alternativeColor = KGlobalSettings.alternateBackgroundColor().name()
+        baseColor = KGlobalSettings.baseColor().name()
+
+        for app in packages:
+            if index % 2 == 0:
+                style = "background-color:%s" % alternativeColor
+            else:
+                style = "background-color:%s" % baseColor
+            titleStyle = style
+
+            size = 0L
+            if self.state == remove_state:
+                # first try to locate package information from repository databases
+                try:
+                    package, repo = pdb.get_package_repo(app)
+                #TODO: Handle "Repo item not found" type of exceptions only
+                except:
+                    # if it fails use provided information directly
+                    #package = pdb.get_package(app, pisi.itembyrepodb.installed)
+                    package = pisi.db.installdb.InstallDB().get_package(app)
+                    repo = i18n("N\A")
+                size = package.installedSize
+            else:
+                package, repo = pdb.get_package_repo(app)
+                size = package.packageSize
+
+            desc = package.description
+            summary = package.summary
+            version = package.version
+            iconPath = getIconPath(package.icon)
+
+            if package.source:
+                homepage = package.source.homepage
+            else:
+                homepage = i18n("N\A")
+
+            if size:
+                tpl = pisi.util.human_readable_size(size)
+                size = "%.0f %s" % (tpl[0], tpl[1])
+            else:
+                size = i18n("N\A")
+
+            if app in self.basket.packages:
+                titleStyle = "background-color:#678DB2"
+                checkState = "checked"
+            else:
+                checkState = ""
+
+            curindex = index + 1
+            if self.state == remove_state and app in unremovable_packages:
+                checkbox = """<div class="checkboks" style="%s" id="checkboks_t%d"><input type="checkbox" \
+                           disabled %s name="%s id="checkboks%d"></div>""" % (titleStyle,curindex,checkState,app,curindex)
+            else:
+                checkbox = """<div class="checkboks" style="%s" id="checkboks_t%d"><input type="checkbox" \
+                           %s onclick="changeBackgroundColor(this)" name="%s" id="checkboks%d"></div>""" % (titleStyle,curindex,checkState,app,curindex)
+
+            iconSize = getIconSize()
+            result += template % (checkbox, titleStyle,curindex,iconPath,iconSize,iconSize,app,summary,style,curindex,curindex,
+                                  i18n("Description: "), desc,
+                                  i18n("Version: "), version,
+                                  i18n("Repository: "), repo,
+                                  i18n("Package Size: "), size,
+                                  i18n("Homepage: "), homepage,homepage)
+            index += 1
+
+        return result
 

Modified: trunk/tasma/package-manager/src/package-manager.py
=================================================================
--- trunk/tasma/package-manager/src/package-manager.py	(original)
+++ trunk/tasma/package-manager/src/package-manager.py	Wed Dec  5 12:05:24 2007
@@ -19,9 +19,10 @@
 from kdeui import *
 from kio import *
 import kdedesigner
-import PmDcop
 
 # Local imports
+import PmDcop
+import Globals
 from MainWidget import *
 import Settings
 
@@ -57,7 +58,7 @@
         self.aboutus = KAboutApplication(self)
         self.helpWidget = None
 
-        self.mainwidget = MainApplicationWidget(self, application=kapp)
+        self.mainwidget = MainApplicationWidget(self)
         self.setCentralWidget(self.mainwidget)
 
         self.setupMenu()
@@ -146,6 +147,9 @@
 
     kapp = KUniqueApplication(True, True, True)
 
+    # pass reference to Globals module, so KApplication can be reached when needed
+    Globals.init(kapp)
+
     args = KCmdLineArgs.parsedArgs()
     if args.isSet("install"):
         packageToInstall = args.getOption("install")


Uludag-commits mesaj listesiyle ilgili daha fazla bilgi