# -*- coding: utf-8 -*-
import pluginsystem, configsystem, hmsystem, utils
from threading import Thread
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from QTextArea import QTextArea
class QConsole(QWidget):
def __init__(self):
QWidget.__init__(self)
self.hms = hmsystem.HMSystem(self)
self.hms.initHM()
pluginsystem.load_plugins()
pluginsystem.trigger_event("init", obj=self)
self.watcher = QFileSystemWatcher(self)
self.watcher.addPath(configsystem.get_jake_config_path() + "config")
self.loadGconfig(self)
self.setAttribute(Qt.WA_TranslucentBackground)
self.setObjectName("mainWidget")
self.addTabButton = QPushButton("+")
self.addTabButton.setObjectName("addTabButton")
self.removeTabButton = QPushButton("-")
self.removeTabButton.setObjectName("removeTabButton")
self.tabwidget = QTabWidget(self)
#self.tabwidget = QCustomTabWidget(self) ###TODO Fix that annoying bug!
#self.tabwidget.setTabBar(QCustomTabBar(self.tabwidget)) ###TODO And use someday...
self.tabwidget.setObjectName("mainTabWidget")
self.tabwidget.setMovable(True)
self.tabwidget.setTabsClosable(True)
self.tabwidget.tabBar().setSelectionBehaviorOnRemove(QTabBar.SelectPreviousTab)
self.tabwidget.tabBar().setObjectName("mainTabBarWidget")
self.tabwidget.setCornerWidget(self.addTabButton, Qt.TopRightCorner)
self.tabwidget.setCornerWidget(self.removeTabButton, Qt.TopLeftCorner)
self.tabwidget.insertTab(self.tabwidget.count(), QTextArea(self), "jake" + str(self.tabwidget.count()+1))
self.giveFocus()
self.mainLayout = QVBoxLayout(self)
self.mainLayout.setObjectName("mainLayout")
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.mainLayout.addWidget(self.tabwidget)
self.connect(self.tabwidget, QtCore.SIGNAL("tabCloseRequested(int)"), self.tabRemoveRequested)
self.connect(self.addTabButton, QtCore.SIGNAL("clicked()"), self.tabAddRequested)
self.connect(self.removeTabButton, QtCore.SIGNAL("clicked()"), self.tabRemoveRequested)
self.connect(self, QtCore.SIGNAL("toggle_visibility(PyQt_PyObject)"), self.toggleVisibility)
self.connect(self.watcher, QtCore.SIGNAL("fileChanged(QString)"), self.loadGconfig)
self.connect(self, QtCore.SIGNAL("giveFocus()"), self.giveFocus)
self.show()
def loadGconfig(self, config):
tmpconfig = []
pluginsystem.trigger_event("get_config", config=tmpconfig, plugin="jake")
self.gconfig = tmpconfig[0]
self.gconfig_others = tmpconfig[1]
if configsystem.value(self.gconfig, 'alwaysontop'):
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
else:
self.setWindowFlags(Qt.FramelessWindowHint)
qscreen = QDesktopWidget()
screen = qscreen.screenGeometry()
self.gsizew = screen.width() * (configsystem.value(self.gconfig, 'appwidth') / 100.0)
self.gsizeh = screen.height() * (configsystem.value(self.gconfig, 'appheight') / 100.0)
self.resize(self.gsizew, self.gsizeh)
self.move(((screen.width() - self.geometry().width()) / 2) + (configsystem.value(self.gconfig, 'screen') * screen.width()) , 0)
self.setWindowTitle(self.gconfig_others[0] + " " + self.gconfig_others[1])
self.prompt = configsystem.value(self.gconfig, 'prompt')
self.lastChar = "_"
styleData = QFile(configsystem.get_skin_path(utils.get_skins()[configsystem.value(self.gconfig, 'skin')]))
styleReader = QTextStream(styleData)
if styleData.open(QIODevice.ReadOnly | QIODevice.Text):
self.setStyleSheet(styleReader.readAll())
styleData.close()
class fakeEvent():
Key = 0
e = fakeEvent()
e.Key = "F8"
self.toggleVisibility(e)
def tabAddRequested(self):
self.tabwidget.insertTab(self.tabwidget.count(), QTextArea(self), "jake" + str(self.tabwidget.count()+1))
def tabRemoveRequested(self, i=None):
if self.tabwidget.count() > 1:
if i == None:
self.tabwidget.currentWidget().close()
else:
self.tabwidget.widget(i).close()
if self.tabwidget.count() == 1:
self.tabwidget.setTabText(0, "jake" + str(self.tabwidget.count()))
def toggleVisibility(self, e):
if e.Key == "F8":
self.setVisible(self.isHidden())
if self.hms.mustFocus() and self.isVisible():
thread = Thread(target=self.hms.focus)
thread.start()
def giveFocus(self):
self.tabwidget.currentWidget().setFocus(Qt.OtherFocusReason)