./contents/
./contents/code/
./contents/code/main.py
./metadata.desktop
[Desktop Entry]
Encoding=UTF-8
Name=BWC Balance
Name[ru]= BWC
Type=Service
ServiceTypes=Plasma/Applet
Icon=phone
X-Plasma-API=python
X-Plasma-MainScript=code/main.py
X-KDE-PluginInfo-Author=SvartalF
X-KDE-PluginInfo-Email=self@svartalf.info
X-KDE-PluginInfo-Name=bwc-balance
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=http://bitbucket.org/svartalf/bwc-balance-plasmoid/
X-KDE-PluginInfo-Category=Online Services
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Copy Source | Copy HTML
- from PyQt4.QtCore import *
- from PyQt4.QtGui import *
- from PyKDE4.kio import *
- from PyKDE4.kdeui import *
- from PyKDE4.kdecore import *
- from PyKDE4.plasma import Plasma
- from PyKDE4 import plasmascript
- from PyKDE4.solid import Solid
Copy Source | Copy HTML
- class BWCBalancePlasmoid (plasmascript.Applet):
- def __init__ (self, parent, args = None):
- plasmascript.Applet. __init__ (self, parent)
- def init (self):
- "" "Initialization of settings" ""
- # Plasmoid has user settings
- self .setHasConfigurationInterface (True)
- self .setAspectRatioMode (Plasma.IgnoreAspectRatio)
- self .theme = Plasma.Svg (self)
- self .theme.setImagePath ( "widgets / background" )
- self .setBackgroundHints (Plasma.Applet.DefaultBackground)
- # Location of the elements of the plasmoid
- self .layout = QGraphicsLinearLayout (Qt.Horizontal, self .applet)
- # Label for output
- self .label = Plasma.Label ( self .applet)
- self .label.setText ( "0.0" ) # Initially, let it be 0
- # Add Label to Layout
- self .layout.addItem ( self .label)
- self .applet.setLayout ( self .layout)
- # And we change the size of the plasmoid
- self .resize ( 50 , 50 )
Copy Source | Copy HTML
- def CreateApplet (parent):
- return BWCBalancePlasmoid (parent)
Copy Source | Copy HTML
- class SettingsDialog (QWidget, Ui_SettingsDialog):
- def __init__ (self, parent = None):
- QWidget. __init__ (self)
- self .parent = parent
- self .setupUi (self)
- # Open local “wallet”
- self .wallet = KWallet.Wallet.openWallet (KWallet.Wallet.LocalWallet (), 0 )
- if self .wallet:
- # Choose our “folder” for storing passwords
- self .wallet.setFolder ( "bwc-balance-plasmoid" )
- if not self .wallet.entryList (). isEmpty ():
- phone = str ( self .wallet.entryList (). first ())
- password = QString ()
- # Read the password for the phone number
- self .wallet.readPassword (phone, password)
- # And fill this field with dialogue data
- self .textPhone.setText (phone)
- self .textPassword.setText ( str (password))
- def get_settings (self):
- return { "phone" : str ( self .textPhone.text ()), "password" : str ( self .textPassword.text ())}
Copy Source | Copy HTML
- # The settings dialog object will be stored here.
- self .settings_dialog = None
- # And this is the settings themselves
- self .settings = { "phone" : None, "password" : None}
- # When loading the plasmoid we open the wallet in asynchronous mode
- # So the user will immediately see the plasmoid and the offer to allow access
- this wallet app
- self .wallet = KWallet.Wallet.openWallet (KWallet.Wallet.LocalWallet (), 0 , 1 )
- if self .wallet:
- self .connect ( self .wallet, SIGNAL ( "walletOpened (bool)" ), self .walletOpened)
Copy Source | Copy HTML
- def showConfigurationInterface (self):
- # Create an object of our dialogue
- self .settings_dialog = SettingsDialog (self)
- # We embed it in a standard dialogue form
- dialog = KPageDialog ()
- dialog.setFaceType (KPageDialog.Plain)
- dialog.setButtons (KDialog.ButtonCode (KDialog.Ok | KDialog.Cancel))
- page = dialog.addPage ( self .settings_dialog, u "CCIS Settings" )
- # Connect slots with signals
- self .connect (dialog, SIGNAL ( "okClicked ()" ), self .configAccepted)
- self .connect (dialog, SIGNAL ( "cancelClicked ()" ), self .configDenied)
- dialog.resize ( 350 , 200 )
- # Show dialogue
- dialog.exec_ ()
Copy Source | Copy HTML
- def configAccepted (self):
- # Update data in the program
- self .settings = self .settings_dialog.get_settings ()
- # And save them in wallet
- wallet = KWallet.Wallet.openWallet (KWallet.Wallet.LocalWallet (), 0 )
- if wallet:
- if not wallet.hasFolder ( "bwc-balance-plasmoid" ):
- wallet.createFolder ( "bwc-balance-plasmoid" )
- wallet.setFolder ( "bwc-balance-plasmoid" )
- for e in wallet.entryList ():
- wallet.removeEntry (e)
- wallet.writePassword ( self .settings [ "phone" ], self .settings [ "password" ])
Copy Source | Copy HTML
- self .timer = QTimer ()
- self .connect ( self .timer, SIGNAL ( "timeout (bool)" ), self .loadBalance
Copy Source | Copy HTML
- self .timer.start ( 1000 * 60 * 60 ) # The time is specified in milliseconds
Copy Source | Copy HTML
- self .job = KIO.storedGet (KUrl ( "http://example.com/account" ), KIO.Reload, KIO.HideProgressInfo)
- self .job.addMetaData ( "User-Agent" , "User-Agent: bwc-balance-plasmoid" )
- self .connect ( self .job, SIGNAL ( "result (KJob *)" ), self ._get_result)
Copy Source | Copy HTML
- self .job = KIO.storedHttpPost (QByteArray (urlencode ({ 'phone' : self .settings.get ( "phone" ), 'password' : self .settings.get ( "password" )})), \
- KUrl ( "</ code> <code> http://example.com/ </ code> <code> login" ), KIO.HideProgressInfo)
- self .job.addMetaData ( "Content-type" , "Content-Type: application / x-www-form-urlencoded" )
- self .job.addMetaData ( "Accept" , "Accept: text / plain" )
- self .job.addMetaData ( "User-Agent" , "User-Agent: bwc-balance-plasmoid" )
- self .connect ( self .job, SIGNAL ( "result (KJob *)" ), self ._get_result)
Copy Source | Copy HTML
- def self ._get_result ( self , job):
- print job.data () # Just do something with the response received
Source: https://habr.com/ru/post/76548/
All Articles