def __init__(self): QtGui.QMainWindow.__init__(self,None,QtCore.Qt.WindowStaysOnTopHint|QtCore.Qt.FramelessWindowHint) self.setAttribute(QtCore.Qt.WA_TranslucentBackground,True) self.setAttribute(QtCore.Qt.WA_X11NetWmWindowTypeDock,True) self.setWindowTitle("ducklauncher!!")#recognisable by wnck self.activateWindow() #screen size d = QtGui.QDesktopWidget() self.top_pos=0 self.s_width = d.availableGeometry().width() self.s_height =d.availableGeometry().height() self.top_pos= d.availableGeometry().y() #Config values conf=Config.get() self.conf=conf self.HALF_OPEN_POS=int(conf['size']) self.ICO_TOP=self.HALF_OPEN_POS-5 self.OPEN_STATE_TOP=self.ICO_TOP*4+5 self.SIZE = 14 #Geometry self.setGeometry(0,self.top_pos,self.HALF_OPEN_POS+9,self.s_height) #Values self.ICON_SIZE=int(conf['icon-size']) self.apps_per_row = math.trunc(((self.s_width/3)-50)/ int(self.conf["icon-size"])) self.apps_per_col = math.trunc(((self.s_height)-90)/ int(self.conf["icon-size"])) self.apps_per_page=self.apps_per_col*self.apps_per_row self.app_page_state=0 self.appRect=None self.drawAppRect=False self.pos_x=self.HALF_OPEN_POS-2 self.move=False self.current_state="half_open" self.activity="apps" self.dock_apps = Apps.find_info(self.conf['dock-apps']) self.current_text='' self.allApps=Apps.info(self.current_text) self.plugin=False self.pl_rect_pos=0 self.pl_logo=None self.fg_color=(int(self.conf['r']),int(self.conf['g']),int(self.conf['b'])) self.font_color=(int(self.conf['font-r']),int(self.conf['font-g']),int(self.conf['font-b'])) ##Windows #Enables the server which gets open windows self.op_thread=Window.openWindowsThread() self.op_thread.start() self.connect(self.op_thread,QtCore.SIGNAL("new-window"),self.addOpenWindow) self.connect(self.op_thread,QtCore.SIGNAL("remove-window"),self.updateOpenWindows) self.open_windows=Window.get_open_windows() self.ow_in_dock=[] #Dock Apps Options Window self.dock_options_win=DockAppsOptions.Window(parent=self) #Webview (for plugins, files, and settings view) self.webview=Widgets.pluginView(self) self.webview.setGeometry(2,60,self.s_width/3-20,self.s_height-60) #System window self.sys_win=System.Window() #Fake window, required to capture keyboard events self.fakewin = Fakewin(10,10, self) self.fakewin.show() XlibStuff.fix_window(self.winId(),self.HALF_OPEN_POS+3,0,0,0)
def paintEvent(self,e): qp= QtGui.QPainter() qp.begin(self) qp.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) qp.setPen(QtGui.QColor(int(self.r),int(self.g),int(self.b))) qp.setBrush(QtGui.QColor(int(self.r),int(self.g),int(self.b))) qp.drawRoundedRect(QtCore.QRectF(10,0,self.size*self.win_len*1.3+10,self.size*1.6),4,4) qp.setPen(QtGui.QColor(250,250,250)) qp.setBrush(QtGui.QColor(250,250,250)) qp.drawRect(9,0,5,self.size*1.6) half_height=self.size*0.9 icon=QtGui.QIcon("/usr/share/duck-launcher/icons/win.svg") icon.paint(qp, -10,half_height-10, 20,20) for i,w in enumerate(self.windows): ico = Apps.ico_from_app(w['icon']) if ico==None: ico = Apps.ico_from_app(w["title"]) if ico==None: home = os.path.expanduser("~")+"/.duck" try: os.stat(home) except: os.mkdir(home) if os.path.isfile("{0}/{1}.png".format(home,w["icon"])): ico = QtGui.QIcon("{0}/{1}.png".format(home,w["icon"])) else: ico = QtGui.QIcon("/usr/share/duck-launcher/apps.svg") ico.paint(qp,20+self.size*i*1.3, 10, self.size*1.1, self.size*1.1)
def keyPressEvent(self, e): if e.key()==QtCore.Qt.Key_Backspace: self.parent.current_text=self.parent.current_text[:-1] self.parent.app_page_state=0 elif e.key()==QtCore.Qt.Key_Return: if len(self.parent.allApps)==1: a=self.parent.allApps[0] print("Launching '{0}' with '{1}'".format(a["name"], a["exec"]) ) thread = Launch(parent=self.parent) thread.app=a["exec"] thread.start() self.parent.close_it() self.parent.current_text='' self.parent.allApps=Apps.find_info('') elif e.key()==16777216: self.parent.current_text="" self.parent.app_page_state=0 elif e.key() == QtGui.QKeySequence.Quit: print("Quit") elif e.key()==16777249: if e.text()=='q': print("Quiting") sys.exit() elif e.text()!='': self.parent.current_text+=e.text() self.parent.app_page_state=0 else: if e.key()==16777250: if self.parent.current_state=="half_open": self.parent.activity="apps" self.parent.open_it() elif self.parent.current_state=="open": self.parent.close_it() elif e.key()==16777236: if self.parent.activity=="apps": max_pages=math.trunc(len(self.parent.allApps)/self.parent.apps_per_page) if max_pages>self.parent.app_page_state: self.parent.app_page_state+=1 if self.parent.activity=="files": max_pages=math.trunc(len(self.parent.Files.all())/self.parent.apps_per_page) if max_pages>self.parent.files_page_state: self.parent.files_page_state+=1 elif e.key()==16777234: if self.parent.activity=="apps": max_pages=math.trunc(len(self.parent.allApps)/self.parent.apps_per_page) if self.parent.app_page_state>0: self.parent.app_page_state-=1 if self.parent.activity=="files": max_pages=math.trunc(len(self.parent.Files.all())/self.parent.apps_per_page) if self.parent.files_page_state>0: self.parent.files_page_state-=1 self.parent.allApps=Apps.info(self.parent.current_text) self.parent.update()
def update_all(self,conf): self.conf=conf if self.HALF_OPEN_POS!=int(conf["size"]): self.HALF_OPEN_POS=int(conf['size']) self.current_state="half_open" self.pos_x=int(conf["size"]) self.setGeometry(0,self.top_pos,self.HALF_OPEN_POS+6,self.s_height) self.ICO_TOP=self.HALF_OPEN_POS-5 self.OPEN_STATE_TOP=self.ICO_TOP*4+5 elif self.ICON_SIZE!=int(conf['icon-size']): self.ICON_SIZE=int(conf['icon-size']) self.apps_per_row = math.trunc(((self.s_width/3)-30)/self.ICON_SIZE) self.apps_per_col = math.trunc(((self.s_height)-30)/self.ICON_SIZE) self.apps_per_page=self.apps_per_col*self.apps_per_row if self.conf["blocks"]==None: self.conf["blocks"]=[] if self.conf["dock-apps"]==None: self.conf["dock-apps"]=[] self.dock_apps = Apps.find_info(self.conf['dock-apps']) self.sys_win.update_all(conf) self.dock_options_win.update_all(conf) self.update() QtGui.QApplication.processEvents()
def open_it(self): Window.activateFakewin(self.fakewin.winId()) self.plugin=False self.sys_win.close() self.open_win.close() self.dock_options_win.close() while self.pos_x<self.s_width/3-5: self.current_state='nothing' if self.pos_x<self.s_width/7: self.pos_x=self.s_width/7 else: self.pos_x+=float(self.conf["animation-speed"]) self.setGeometry(0,self.top_pos,self.s_width/3+5,self.s_height) self.update() QtGui.QApplication.processEvents() if self.pos_x!=self.s_width/3-2 : self.pos_x=self.s_width/3-2 self.current_state="open" if self.activity=="apps": self.allApps=Apps.info(self.current_text) self.setAttribute(QtCore.Qt.WA_X11NetWmWindowTypeDock,False) self.windowActivationChange(True) self.resetInputContext() self.webview.setEnabled(True) self.webview.setFocus(True) self.webview.resetInputContext() self.update() self.windowActivationChange(True) QtGui.QApplication.processEvents()
def update_all(self): #All values to update import Config conf=Config.get() self.conf=conf if self.HALF_OPEN_POS!=int(conf["size"]): self.HALF_OPEN_POS=int(conf['size']) self.current_state="half_open" self.pos_x=int(conf["size"]) self.setGeometry(0,self.top_pos,self.HALF_OPEN_POS+4,self.s_height) self.fakewin.setGeometry(0,self.top_pos,self.HALF_OPEN_POS+4,self.s_height) XlibStuff.fix_window(self.fakewin.winId(),self.HALF_OPEN_POS+5,0,0,0) self.ICO_TOP=self.HALF_OPEN_POS-5 self.OPEN_STATE_TOP=self.ICO_TOP*4+5 elif self.R!=int(conf['r']) or self.G!=int(conf['g']) or self.B!=int(conf['b']): self.R=int(conf['r']) self.G=int(conf['g']) self.B=int(conf['b']) elif self.ICON_SIZE!=int(conf['icon-size']): self.ICON_SIZE=int(conf['icon-size']) self.apps_per_row = math.trunc(((self.s_width/3)-30)/self.ICON_SIZE) self.apps_per_col = math.trunc(((self.s_height)-30)/self.ICON_SIZE) self.apps_per_page=self.apps_per_col*self.apps_per_row self.dock_apps = Apps.find_info(conf['dock-apps']) self.open_win.update_all() self.sys_win.update_all() self.update() QtGui.QApplication.processEvents()
def keyPressEvent(self, e): if e.key()==QtCore.Qt.Key_Backspace: if self.parent.plugin==False: self.parent.current_text=self.parent.current_text[:-1] self.parent.allApps=Apps.info(str(self.parent.current_text)) self.parent.webview.page().mainFrame().evaluateJavaScript("setNewApps({})".format(self.parent.allApps)) self.parent.update() elif e.key()==QtCore.Qt.Key_Return: if len(self.parent.allApps)==1: a=self.parent.allApps[0] print("[Duck Launcher] Launching '{0}' with '{1}'".format(a["name"], a["exec"]) ) thread = Launch(parent=self.parent) thread.app=a["exec"] thread.start() self.parent.close_it() self.parent.current_text='' self.parent.allApps=Apps.find_info('') html= Plugins.get(str(self.parent.current_text),color=(self.parent.conf["r"],self.parent.conf["g"],self.parent.conf["b"]),font=self.parent.conf["font"]) if html!=None: self.parent.webview.load(QtCore.QUrl(html)) self.parent.webview.show() self.parent.plugin=True self.parent.webview.page().mainFrame().setFocus() self.parent.webview.setFocus() self.update() elif e.key()==16777216: #ESC self.parent.current_text="" self.parent.allApps=Apps.info(str(self.parent.current_text)) self.parent.webview.page().mainFrame().evaluateJavaScript("setNewApps({})".format(self.parent.allApps)) self.parent.initApps() elif e.text()!='': self.parent.current_text+=e.text() self.parent.allApps=Apps.info(str(self.parent.current_text)) self.parent.webview.page().mainFrame().evaluateJavaScript("setNewApps({})".format(self.parent.allApps)) self.parent.update() else: if e.key()==16777250: if self.parent.current_state=="half_open": self.parent.activity="apps" self.parent.current_text='' self.parent.allApps=Apps.info('') self.parent.initApps() self.parent.open_it() elif self.parent.current_state=="open": self.parent.close_it() self.parent.update()
def paintEvent(self,e): qp=QtGui.QPainter() qp.begin(self) qp.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) qp.setPen(QtGui.QColor(int(self.r),int(self.g),int(self.b))) qp.setBrush(QtGui.QColor(int(self.r),int(self.g),int(self.b))) qp.drawRoundedRect(QtCore.QRectF(10,0,self.width-10,self.height),2,2) qp.setPen(QtGui.QColor(255,255,255,255)) qp.setBrush(QtGui.QColor(255,255,255,255)) qp.drawRect(9,0,5,self.height) icon=QtGui.QIcon("/usr/share/duck-launcher/default-theme/win.svg") icon.paint(qp, -10,self.size/2-10, 20,20) # qp.setFont(QtGui.QFont(Config.get()["font"],12)) t_rect=QtCore.QRectF(10,0,self.width-10,30) t_rect2=QtCore.QRectF(11,1,self.width-10,30) qp.setPen(QtGui.QColor(40,40,40,80)) qp.drawText(t_rect2,QtCore.Qt.AlignCenter,self.app["name"]) qp.setPen(QtGui.QColor(255,255,255,255)) qp.drawText(t_rect,QtCore.Qt.AlignCenter,self.app["name"]) qp.drawLine(26,30,self.width-20,30) if self.drawButtonRect==True and self.buttonRect!=None: qp.setPen(QtGui.QColor(0,0,0,0)) qp.setBrush(QtGui.QColor(255,255,255,40)) qp.drawRect(self.buttonRect) if self.state=="normal": qp.setFont(QtGui.QFont(Config.get()["font"],10)) o_rect=QtCore.QRectF(50,30,self.width-10,30) qp.setPen(QtGui.QColor(255,255,255,255)) qp.drawText(o_rect,QtCore.Qt.AlignVCenter,"Open") removeIcon=QtGui.QIcon("/usr/share/duck-launcher/default-theme/open.svg") removeIcon.paint(qp, 25,34,20,20) #move r_rect=QtCore.QRectF(50,60,self.width-10,30) qp.drawText(r_rect, QtCore.Qt.AlignVCenter,"Move") removeIcon=QtGui.QIcon("/usr/share/duck-launcher/default-theme/move.svg") removeIcon.paint(qp, 25,64,20,20) #remove r_rect=QtCore.QRectF(50,90,self.width-10,30) qp.drawText(r_rect, QtCore.Qt.AlignVCenter,"Remove") removeIcon=QtGui.QIcon("/usr/share/duck-launcher/default-theme/remove.svg") removeIcon.paint(qp, 25,94,20,20) elif self.state=="moving": if self.width<150: self.width=150 self.resize(150,self.height) icon=QtGui.QIcon(Apps.ico_from_name(self.app["icon"])) if icon!=None: w = self.width/2-40 icon.paint(qp,w,40,70,70) upicon=QtGui.QIcon("/usr/share/duck-launcher/default-theme/up.svg") upicon.paint(qp, self.width/2+35,35,40,40) downicon=QtGui.QIcon("/usr/share/duck-launcher/default-theme/down.svg") downicon.paint(qp, self.width/2+35,self.height-45,40,40)
def get_open_windows(): gtk.main_iteration_do(False) screen = wnck.screen_get_default() screen.force_update() win = screen.get_windows_stacked() windows=[] for w in win: if 'NORMAL' in str(w.get_window_type()): if "ducklauncher!!!"==w.get_name(): pass elif w.is_sticky()!=True and "ducklauncher!!"!=w.get_name(): window={} window['id']=w.get_xid() window['title'] =w.get_name() window['app']=w.get_application().get_name() #print w.get_class_group().get_name() ico = Apps.ico_from_app(w.get_application().get_icon_name()) if ico==None: ico = Apps.ico_from_app(w.get_application().get_name()) if ico==None: pix=w.get_icon() pix= pix.scale_simple(128,128,gtk.gdk.INTERP_HYPER) ico_data= pix.get_pixels_array() img = Image.fromarray(ico_data, 'RGBA') home = os.path.expanduser("~")+"/.duck" try: os.stat(home) except: os.mkdir(home) #print window img_name=str(window["title"]).replace(" ","").replace(".","").lower() img_path="{0}/{1}.png".format(home,img_name) img.save(img_path) ico=img_path window['icon']=ico windows.append(window) return windows
def get_open_windows(): gtk.main_iteration_do(False) screen = wnck.screen_get_default() screen.force_update() win = screen.get_windows_stacked() windows = [] for w in win: if 'NORMAL' in str(w.get_window_type()): if "ducklauncher!!!" == w.get_name(): pass elif w.is_sticky() != True and "ducklauncher!!" != w.get_name(): window = {} window['id'] = w.get_xid() window['title'] = w.get_name() window['app'] = w.get_application().get_name() #print w.get_class_group().get_name() ico = Apps.ico_from_app(w.get_application().get_icon_name()) if ico == None: ico = Apps.ico_from_app(w.get_application().get_name()) if ico == None: pix = w.get_icon() pix = pix.scale_simple(128, 128, gtk.gdk.INTERP_HYPER) ico_data = pix.get_pixels_array() img = Image.fromarray(ico_data, 'RGBA') home = os.path.expanduser("~") + "/.duck" try: os.stat(home) except: os.mkdir(home) #print window img_name = str(window["title"]).replace(" ", "").replace( ".", "").lower() img_path = "{0}/{1}.png".format(home, img_name) img.save(img_path) ico = img_path window['icon'] = ico windows.append(window) return windows
def __init__(self): QtGui.QMainWindow.__init__(self, None,QtCore.Qt.WindowStaysOnTopHint|QtCore.Qt.FramelessWindowHint)#| QtCore.Qt.X11BypassWindowManagerHint) self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setWindowTitle("ducklauncher")#recognisable by wnck #screen size d = QtGui.QDesktopWidget() self.top_pos=0 self.s_width = d.availableGeometry().width() self.s_height =d.availableGeometry().height() d.resized.connect(self.updateSize) #Config conf=Config.get() self.conf=conf self.HALF_OPEN_POS=int(conf['size']) self.ICO_TOP=self.HALF_OPEN_POS-5 self.OPEN_STATE_TOP=self.ICO_TOP*4+5 self.SIZE = 15 self.R=int(conf['r']) self.G=int(conf['g']) self.B=int(conf['b']) self.ICON_SIZE=int(conf['icon-size']) #Geometry self.setGeometry(0,0,self.HALF_OPEN_POS+4,self.s_height) #reserve wndow space #self.activateWindow() xwin = XlibStuff.fix_window(self.winId(),self.HALF_OPEN_POS+5,0,0,0) # #Values self.apps_per_row = math.trunc(((self.s_width/3)-30)/self.ICON_SIZE) self.apps_per_col = math.trunc(((self.s_height)-30)/self.ICON_SIZE) self.apps_per_page=self.apps_per_col*self.apps_per_row self.app_page_state=0 self.files_page_state=0 self.Files = Files.getFiles() self.pos_x=self.HALF_OPEN_POS self.move=False self.current_state="half_open" self.activity="apps" self.dock_apps = Apps.find_info(self.conf['dock-apps']) self.current_text='' #Update open windows self.timer=QtCore.QTimer() self.timer.setInterval(2000) self.timer.start() self.timer.timeout.connect(self.updateOpenWindows) # self.open_windows=window.get_open_windows() self.open_win = window.open_windows() self.open_state=False # self.settings_win = Settings.Window(self)
def open_it(self): Window.activateFakewin(self.fakewin.winId()) self.sys_win.close() self.open_win.close() while self.pos_x<self.s_width/3: self.current_state='nothing' if self.pos_x<self.s_width/7: self.pos_x=self.s_width/7 else: self.pos_x+=1.5 self.setGeometry(0,self.top_pos,self.s_width/3+5,self.s_height) self.update() QtGui.QApplication.processEvents() self.current_state="open" if self.activity=="apps": self.allApps=Apps.info(self.current_text) self.update()
def __init__(self): QtGui.QDialog.__init__(self, None) self.parent=None vbox=QtGui.QVBoxLayout() self.list=QtGui.QListView() self.model = QtGui.QStandardItemModel() for app in Apps.info(''): a = QtGui.QStandardItem(app["name"]) a.setAccessibleText(app["name"]) self.model.appendRow(a) self.model.itemChanged.connect(self.change_app) self.list.setModel(self.model) vbox.addWidget(self.list) self.list.clicked.connect(self.change_app) self.setLayout(vbox) self.setGeometry(300, 300, 600, 300) self.setWindowTitle('Choose your application')
def __init__(self, *args, **kwargs): super(AddAppList, self).__init__(*args, **kwargs) the_apps = [a["name"] for a in APPS.info('')] args_converter = lambda row_index, obj: {'text': obj, 'size_hint_y': None, 'height': 20, 'font_size':14, 'deselected_color':[0,0,0,0], 'selected_color':[.86,.46,.26,1], 'background_normal':"images/button.png", 'background_down':"images/buton.png", 'color':[.8,.8,.8,1]} self.adapter=ListAdapter(data = the_apps, selection_mode = 'single', args_converter=args_converter, allow_empty_selection = True, cls = ListItemButton, sorted_keys=[])
def wheelEvent(self,e): if self.activity == 'apps': value= int(e.delta()/120) max_pages=math.trunc(len(Apps.info(self.current_text))/self.apps_per_page) if value<0 and self.app_page_state>0: self.app_page_state-=1 if value>0 and self.app_page_state<max_pages: self.app_page_state+=1 self.update() QtGui.QApplication.processEvents() if self.activity == 'files': value= int(e.delta()/120) max_pages=math.trunc(len(self.Files.all())/self.apps_per_page) if value<0 and self.app_page_state>0: self.app_page_state-=1 if value>0 and self.app_page_state<max_pages: self.files_page_state+=1 self.update() QtGui.QApplication.processEvents()
def __init__(self, *args, **kwargs): super(AddAppList, self).__init__(*args, **kwargs) the_apps = [a["name"] for a in APPS.info('')] args_converter = lambda row_index, obj: { 'text': obj, 'size_hint_y': None, 'height': 20, 'font_size': 14, 'deselected_color': [0, 0, 0, 0], 'selected_color': [.86, .46, .26, 1], 'background_normal': "images/button.png", 'background_down': "images/buton.png", 'color': [.8, .8, .8, 1] } self.adapter = ListAdapter(data=the_apps, selection_mode='single', args_converter=args_converter, allow_empty_selection=True, cls=ListItemButton, sorted_keys=[])
def open_it(self): Window.activateFakewin(self.fakewin.winId()) self.plugin=False self.sys_win.close() self.dock_options_win.close() self.setGeometry(0,self.top_pos,self.s_width/3+8,self.s_height) while self.pos_x<self.s_width/3-4.5: self.current_state='nothing' if self.pos_x<self.s_width/7: self.pos_x=self.s_width/7 else: self.pos_x+=float(self.conf["animation-speed"]) self.repaint() QtGui.QApplication.processEvents() if self.pos_x!=self.s_width/3-4 : self.pos_x=self.s_width/3-4 self.current_state="open" if self.activity=="apps": self.allApps=Apps.info(self.current_text) self.setAttribute(QtCore.Qt.WA_X11NetWmWindowTypeDock,False) self.update() QtGui.QApplication.processEvents()
def __init__(self, *args, **kwargs): super(DockAppsList, self).__init__(*args, **kwargs) the_apps = [DataItem(text=a["name"]) for a in APPS.info('')] args_converter = lambda row_index, obj: {'text': obj.text, 'is_selected':obj.is_selected, 'size_hint_y': None, 'height': 20, 'font_size':14, 'deselected_color':[0,0,0,0], 'selected_color':[.96,.56,.36,1], 'background_normal':"images/button.png", 'background_down':"images/buton.png", 'color':[.2,.2,.2,1]} self.adapter=ListAdapter(data = the_apps, selection_mode = 'multiple', args_converter=args_converter, allow_empty_selection = True, propagate_selection_to_data=True, cls = ListItemButton, sorted_keys=[]) #self.adapter.select_list(self.adapter.data,extend=False) self.adapter.bind(on_selection_change=self.on_select)
def paintEvent(self, e): qp = QtGui.QPainter() qp.begin(self) qp.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) qp.setPen(QtGui.QColor(int(self.r), int(self.g), int(self.b))) qp.setBrush(QtGui.QColor(int(self.r), int(self.g), int(self.b))) qp.drawRoundedRect( QtCore.QRectF(10, 0, self.size * self.win_len * 1.3 + 10, self.size * 1.6), 2, 2) qp.setPen(QtGui.QColor(250, 250, 250)) qp.setBrush(QtGui.QColor(250, 250, 250)) qp.drawRect(9, 0, 5, self.size * 1.6) half_height = self.size * 0.9 icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/win.svg") icon.paint(qp, -10, half_height - 10, 20, 20) if self.drawButtonRect == True and self.buttonRect != None: qp.setPen(QtGui.QColor(0, 0, 0, 0)) qp.setBrush(QtGui.QColor(254, 254, 255, 50)) qp.drawRect(self.buttonRect) for i, w in enumerate(self.windows): ico = Apps.ico_from_app(w['icon']) if ico == None: home = os.path.expanduser("~") + "/.duck" try: os.stat(home) except: os.mkdir(home) if os.path.isfile("{0}/{1}.png".format( home, binascii.hexlify(w["icon"]))): ico = QtGui.QIcon("{0}/{1}.png".format( home, binascii.hexlify(w["icon"]))) else: ico = QtGui.QIcon( "/usr/share/duck-launcher/default-theme/apps.svg") ico.paint(qp, 20 + self.size * i * 1.3, 10, self.size * 1.1, self.size * 1.1)
def update_all(self,conf): if self.HALF_OPEN_POS!=int(conf["size"]): self.HALF_OPEN_POS=int(conf['size']) self.webview.hide() self.current_state="half_open" self.pos_x=int(conf["size"])-2 self.setGeometry(0,self.top_pos,self.HALF_OPEN_POS+6,self.s_height) self.ICO_TOP=self.HALF_OPEN_POS-5 self.OPEN_STATE_TOP=self.ICO_TOP*4+5 if self.activity=="apps" and self.plugin==False and int(self.conf["icon-size"])!=int(conf["icon-size"]): self.webview.page().mainFrame().evaluateJavaScript("changeIconSize({});".format(int(self.conf['icon-size']))) self.conf=conf if self.conf["blocks"]==None: self.conf["blocks"]=[] if self.conf["dock-apps"]==None: self.conf["dock-apps"]=[] self.dock_apps = Apps.find_info(self.conf['dock-apps']) self.open_win.update_all(conf) self.sys_win.update_all(conf) self.dock_options_win.update_all(conf) self.update() QtGui.QApplication.processEvents()
def update_all(self): #All values to update import Config conf=Config.get() self.conf=conf self.HALF_OPEN_POS=int(conf['size']) self.ICO_TOP=self.HALF_OPEN_POS-5 self.OPEN_STATE_TOP=self.ICO_TOP*4+5 self.SIZE = 15 self.R=int(conf['r']) self.G=int(conf['g']) self.B=int(conf['b']) self.ICON_SIZE=int(conf['icon-size']) self.apps_per_row = math.trunc(((self.s_width/3)-30)/self.ICON_SIZE) self.apps_per_col = math.trunc(((self.s_height)-30)/self.ICON_SIZE) self.apps_per_page=self.apps_per_col*self.apps_per_row self.dock_apps = Apps.find_info(conf['dock-apps']) self.pos_x=self.HALF_OPEN_POS self.current_state='half_open' self.setGeometry(0,self.top_pos,self.pos_x+self.SIZE/2,self.s_height) self.open_win.update_all() self.update() QtGui.QApplication.processEvents()
def __init__(self, *args, **kwargs): super(DockAppsList, self).__init__(*args, **kwargs) the_apps = [DataItem(text=a["name"]) for a in APPS.info('')] args_converter = lambda row_index, obj: { 'text': obj.text, 'is_selected': obj.is_selected, 'size_hint_y': None, 'height': 20, 'font_size': 14, 'deselected_color': [0, 0, 0, 0], 'selected_color': [.96, .56, .36, 1], 'background_normal': "images/button.png", 'background_down': "images/buton.png", 'color': [.2, .2, .2, 1] } self.adapter = ListAdapter(data=the_apps, selection_mode='multiple', args_converter=args_converter, allow_empty_selection=True, propagate_selection_to_data=True, cls=ListItemButton, sorted_keys=[]) #self.adapter.select_list(self.adapter.data,extend=False) self.adapter.bind(on_selection_change=self.on_select)
def setDockApps(self,v): self.conf["dock-apps"]=v self.parent.conf=self.conf self.parent.dock_apps=Apps.find_info(self.conf['dock-apps']) self.parent.update()
def paintEvent(self,e): qp=QtGui.QPainter() qp.begin(self) qp.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) ####DRAW qp.setBrush(QtGui.QColor(int(self.conf['r2']),int(self.conf['g2']),int(self.conf['b2']),int(self.conf["alpha"]))) qp.drawRect(0,0,self.pos_x+self.SIZE/2,self.s_height) pen = QtGui.QPen(QtGui.QColor(self.R,self.G,self.B), 6, QtCore.Qt.SolidLine) qp.setPen(pen) qp.drawLine(self.pos_x+self.SIZE/2-2,0,self.pos_x+self.SIZE/2-2,self.s_height) if self.current_state!="half_open": qp.setPen(QtGui.QPen(QtGui.QColor(self.R,self.G,self.B,100), 2, QtCore.Qt.SolidLine)) qp.drawLine(self.pos_x-self.SIZE,0,self.pos_x-self.SIZE,self.s_height) qp.setPen(QtGui.QPen(QtGui.QColor(self.R,self.G,self.B), 4, QtCore.Qt.SolidLine)) r_s=3 a=4 r = QtCore.QRectF(self.pos_x-self.SIZE/2,self.s_height/2,r_s,r_s) qp.drawEllipse(r) r = QtCore.QRectF(self.pos_x-self.SIZE/2,self.s_height/2-r_s*3,r_s,r_s) qp.drawEllipse(r) r = QtCore.QRectF(self.pos_x-self.SIZE/2,self.s_height/2+r_s*3,r_s,r_s) qp.drawEllipse(r) ## #Draw rect under clicked app if self.drawAppRect==True and self.appRect!=None: qp.setPen(QtGui.QColor(0,0,0,0)) qp.setBrush(QtGui.QColor(249,249,251,80)) qp.drawRect(self.appRect) ### if self.current_state == "half_open": qp.setBrush(QtGui.QColor(self.R,self.G,self.B)) qp.drawRect(0,0,self.pos_x+self.SIZE/2,self.OPEN_STATE_TOP) rect = QtCore.QRectF(50,0,150,50) ####DRAW BUTTONS ###Apps ICO_TOP=self.ICO_TOP icon = QtGui.QIcon("/usr/share/duck-launcher/icons/apps.svg") icon.paint(qp,7,ICO_TOP*0+5,ICO_TOP-5,ICO_TOP-5) #Files icon = QtGui.QIcon("/usr/share/duck-launcher/icons/file.svg") ##temp_file icon.paint(qp,7,ICO_TOP*1+5,ICO_TOP-5,ICO_TOP-5) #Settings icon = QtGui.QIcon("/usr/share/duck-launcher/icons/settings.svg") icon.paint(qp,7,ICO_TOP*2+5,ICO_TOP-5,ICO_TOP-5) #Star icon = QtGui.QIcon("/usr/share/duck-launcher/icons/star.svg") icon.paint(qp,7,ICO_TOP*3+5,ICO_TOP-5,ICO_TOP-5) ##### #Dock Apps for i,a in enumerate(self.dock_apps): try: ####OFF WE GOOO! ico = Apps.ico_from_name(str(a['icon'])) if ico!=None: ico.paint(qp,6,self.OPEN_STATE_TOP+ICO_TOP*i+10,ICO_TOP-5,ICO_TOP-5) except KeyError: print("Error: Some apps could not be found ") #Open Windows Button qp.setPen(QtGui.QPen(QtGui.QColor(250,250,250), 2, QtCore.Qt.SolidLine)) icon = QtGui.QIcon("/usr/share/duck-launcher/icons/open-apps.svg") icon.paint(qp,10,self.s_height-ICO_TOP*2-10,ICO_TOP-10,ICO_TOP-10) rect = QtCore.QRectF(10,self.s_height-ICO_TOP*2-10,ICO_TOP-10,ICO_TOP-10) qp.setFont(QtGui.QFont(self.conf["font"],self.HALF_OPEN_POS/3)) qp.drawText(rect, QtCore.Qt.AlignCenter, str(len(self.open_windows))) #System button icon = QtGui.QIcon("/usr/share/duck-launcher/icons/sys.svg") icon.paint(qp,10,self.s_height-ICO_TOP,ICO_TOP-10,ICO_TOP-10) ## ## if self.current_state=="open": close=QtGui.QIcon("/usr/share/duck-launcher/icons/close.svg") close.paint(qp,self.pos_x-13,self.s_height-13,13,13) if self.activity=="apps": ###page_buttons #Current Text qp.setPen(QtGui.QPen(QtGui.QColor(250,250,250), 2, QtCore.Qt.SolidLine)) qp.setFont(QtGui.QFont(self.conf["font"],10)) t_rect=QtCore.QRectF(10,10,self.s_width/8,30) if self.current_text=='': qp.drawText(t_rect, QtCore.Qt.AlignCenter, "Type to search..") else: qp.drawText(t_rect, QtCore.Qt.AlignCenter, "Searching: "+self.current_text) max_apps= math.trunc((len(self.allApps)-1)/self.apps_per_page)+1 #Page for i in range(0, max_apps): btn_size = 20 x_pos = self.s_width/6-btn_size+(btn_size*i) rect = QtCore.QRectF(x_pos,2,btn_size,btn_size) if self.app_page_state==i: qp.setBrush(QtGui.QColor(self.R,self.G,self.B)) else: qp.setBrush(QtGui.QColor(100,100,100,60)) qp.setPen(QtGui.QPen(QtGui.QColor(self.R,self.G,self.B,100), 2, QtCore.Qt.SolidLine)) qp.drawRect(rect) qp.setPen(QtGui.QPen(QtGui.QColor(250,250,250), 2, QtCore.Qt.SolidLine)) qp.drawText(rect,QtCore.Qt.AlignCenter,str(i+1)) ###app_buttons for i, app in enumerate(self.allApps): app_page = math.trunc(i/self.apps_per_page) if app_page==self.app_page_state: qp.setBrush(QtGui.QColor(self.R,self.G,self.B)) row_pos = math.trunc(i/self.apps_per_row) x_pos = self.ICON_SIZE*(i-(row_pos*self.apps_per_row))+30 y_pos = row_pos*self.ICON_SIZE+30-(app_page*(self.ICON_SIZE*self.apps_per_col)) try: ico=Apps.ico_from_name(app["icon"]) if ico!=None: Apps.ico_from_name(app["icon"]).paint(qp,x_pos+20,y_pos+20,self.ICON_SIZE-40,self.ICON_SIZE-40) else: i = QtGui.QIcon('/usr/share/duck-launcher/icons/apps.svg') i.paint(qp,x_pos+20,y_pos+20,self.ICON_SIZE-40,self.ICON_SIZE-40) except KeyError: i = QtGui.QIcon('/usr/share/duck-launcher/icons/apps.svg') i.paint(qp,x_pos+20,y_pos+20,self.ICON_SIZE-40,self.ICON_SIZE-40) qp.setPen(QtGui.QColor(250,250,250)) text_rect = QtCore.QRectF(x_pos+5,y_pos+self.ICON_SIZE-10,self.ICON_SIZE-10,60) #qp.drawRect(text_rect) qp.setFont(QtGui.QFont(self.conf["font"],8)) qp.drawText(text_rect,QtCore.Qt.TextWordWrap |QtCore.Qt.AlignHCenter,self.tr(app["name"]).replace(u"Â", "")) ### if self.activity=="files": #Buttons b1_rect=QtCore.QRectF(10,10,30,30) ico = QtGui.QIcon("/usr/share/duck-launcher/icons/home.svg") ico.paint(qp,self.s_width/3-40-self.SIZE,10,25,25) ico2 = QtGui.QIcon("/usr/share/duck-launcher/icons/back.svg") ico2.paint(qp,self.s_width/3-80-self.SIZE,10,25,25) max_files= math.trunc(len(self.Files.all())/self.apps_per_page)+1 for i in range(0, max_files): btn_size = 20 x_pos = self.s_width/6-btn_size+(btn_size*i) rect = QtCore.QRectF(x_pos,2,btn_size,btn_size) if self.files_page_state==i: qp.setBrush(QtGui.QColor(self.R,self.G,self.B)) else: qp.setBrush(QtGui.QColor(100,100,100,100)) qp.setPen(QtGui.QPen(QtGui.QColor(self.R,self.G,self.B,100), 2, QtCore.Qt.SolidLine)) qp.drawRect(rect) qp.setPen(QtGui.QPen(QtGui.QColor(250,250,250), 2, QtCore.Qt.SolidLine)) qp.setFont(QtGui.QFont(self.conf["font"],10)) qp.drawText(rect,QtCore.Qt.TextWordWrap |QtCore.Qt.AlignHCenter,str(i+1)) #Text t_rect=QtCore.QRectF(10,10,self.s_width/8,30) qp.drawText(t_rect,QtCore.Qt.AlignRight,self.Files.directory.replace(u"Â", "")) ###app_buttons for i, f in enumerate(self.Files.all()): app_page = math.trunc(i/self.apps_per_page) if app_page==self.files_page_state: qp.setBrush(QtGui.QColor(self.R,self.G,self.B)) row_pos = math.trunc(i/self.apps_per_row) x_pos = self.ICON_SIZE*(i-(row_pos*self.apps_per_row))+30 y_pos = row_pos*self.ICON_SIZE+30-(app_page*(self.ICON_SIZE*self.apps_per_col)) try: if f["type"]=="directory": da_icon=QtGui.QIcon("/usr/share/duck-launcher/icons/folder.svg") da_icon.paint(qp,x_pos+20,y_pos+20,self.ICON_SIZE-40,self.ICON_SIZE-40) if f["type"]=="file": da_icon=Files.getFileIcon(f["whole_path"]) da_icon.paint(qp,x_pos+20,y_pos+20,self.ICON_SIZE-40,self.ICON_SIZE-40) except KeyError: i = QtGui.QImage('images/apps.png') rect= QtCore.QRectF(x_pos+20,y_pos+20,self.ICON_SIZE-40,self.ICON_SIZE-40) qp.drawImage(rect,i) qp.setPen(QtGui.QColor(250,250,250)) text_rect = QtCore.QRectF(x_pos-5,y_pos+self.ICON_SIZE-20,self.ICON_SIZE,30) qp.setFont(QtGui.QFont(self.conf["font"],8)) qp.drawText(text_rect,QtCore.Qt.AlignCenter,f["name"].replace(u"Â", "")) if self.activity=="star": qp.setPen(QtGui.QPen(QtGui.QColor(250,250,250), 3, QtCore.Qt.SolidLine)) all_rows=0 for i,b in enumerate(self.conf['blocks']): all_stuff = Config.get_from_block(b) if len(all_stuff)!=self.apps_per_row: row_num = math.trunc(len(all_stuff)/self.apps_per_row)+1 else: row_num = math.trunc(len(all_stuff)/self.apps_per_row) h=self.ICON_SIZE*all_rows+i*50 all_rows+=row_num qp.setFont(QtGui.QFont(self.conf["font"],8)) for j, thing in enumerate(all_stuff): #same thing as for the apps row_pos = math.trunc(j/self.apps_per_row) x_pos = self.ICON_SIZE*(j-(row_pos*self.apps_per_row))+40 y_pos = (row_pos*self.ICON_SIZE+20)+h+30 if thing['type']=='app': icon = Apps.ico_from_app(thing['value']) to_write=thing['value'] elif thing['type']=='directory': icon = QtGui.QIcon('/usr/share/duck-launcher/icons/folder.svg') splitted = thing['value'].split('/') to_write = splitted[-1] elif thing['type']=='file': icon = QtGui.QIcon('/usr/share/duck-launcher/icons/file.svg') splitted = thing['value'].split('/') to_write = splitted[-1] if icon!=None: icon.paint(qp, x_pos+15,y_pos+15, self.ICON_SIZE-50,self.ICON_SIZE-50) rect = QtCore.QRectF(x_pos-10, y_pos+self.ICON_SIZE-30, self.ICON_SIZE, 30) txt = qp.drawText(rect,QtCore.Qt.TextWordWrap |QtCore.Qt.AlignHCenter,to_write) #Title qp.setPen(QtGui.QColor(0,0,0,0)) qp.setBrush(QtGui.QColor(self.R,self.G,self.B)) qp.drawRect(18, h+40,self.s_width/6,2) qp.setPen(QtGui.QColor(250,250,250)) qp.setFont(QtGui.QFont(self.conf["font"],16)) qp.drawText(QtCore.QRectF(20, h+10,self.s_width/3,200),b['name'])
def __init__(self): QtGui.QMainWindow.__init__(self,None,QtCore.Qt.WindowStaysOnTopHint|QtCore.Qt.FramelessWindowHint) self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setAttribute(QtCore.Qt.WA_X11NetWmWindowTypeDock) self.setWindowTitle("ducklauncher!!")#recognisable by wnck self.activateWindow() #screen size d = QtGui.QDesktopWidget() self.top_pos=0 self.s_width = d.availableGeometry().width() self.s_height =d.availableGeometry().height() self.top_pos= d.availableGeometry().y() #bg_width #Config conf=Config.get() self.conf=conf self.HALF_OPEN_POS=int(conf['size']) self.ICO_TOP=self.HALF_OPEN_POS-5 self.OPEN_STATE_TOP=self.ICO_TOP*4+5 self.SIZE = 14 #self.R=int(conf['r']) #self.G=int(conf['g']) #self.B=int(conf['b']) #self.ICON_SIZE=int(conf['icon-size']) #Geometry self.setGeometry(0,self.top_pos,self.HALF_OPEN_POS+6,self.s_height) #Values self.appRect=None self.drawAppRect=False self.pos_x=self.HALF_OPEN_POS-2 self.move=False self.current_state="half_open" self.activity="apps" self.dock_apps = Apps.find_info(self.conf['dock-apps']) self.current_text='' self.allApps=Apps.info(self.current_text) self.appHtmlSource="/usr/share/duck-launcher/default-theme/apps.html" self.appHtmlString=Template(open(self.appHtmlSource,"r").read()).render(color=(int(self.conf["r"]),int(self.conf["g"]),int(self.conf["b"])),font=str(self.conf["font"]), icon_size=int(self.conf["icon-size"])) self.plugin=False #Open windows window self.open_windows=Window.get_open_windows() self.open_win = Window.open_windows() #Dock Apps Options Window self.dock_options_win=DockAppsOptions.Window(parent=self) #Webview for plugins self.webview=QtWebKit.QWebView(self) palette = self.webview.palette() palette.setBrush(QtGui.QPalette.Base, QtCore.Qt.transparent) self.webview.page().setPalette(palette) self.webview.setAttribute(QtCore.Qt.WA_OpaquePaintEvent, False) self.webview.setContextMenuPolicy(QtCore.Qt.NoContextMenu) self.webview.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks) self.webview.connect(self.webview, QtCore.SIGNAL("linkClicked(const QUrl&)"), self.web_linkClicked) self.webview.page().mainFrame().javaScriptWindowObjectCleared.connect(self.web_populateJavaScriptWindowObject) self.webview.setHtml("<body style='background:rgb(230,100,80);'><input type='text' placehodler='aaa'></input></body>") self.webview.setGeometry(2,50,self.s_width/3-20,self.s_height-50) self.webview.activateWindow() self.webview.hide() #System window self.sys_win=System.Window() #Fake window self.fakewin = Fakewin(10,10, self) self.fakewin.show() XlibStuff.fix_window(self.winId(),self.HALF_OPEN_POS+5,0,0,0)
def mouseReleaseEvent(self,e): x_m,y_m = e.x(),e.y() self.drawAppRect=False Window.activateFakewin(self.fakewin.winId()) #While moving if self.current_state=="nothing": self.move=False ###sets position to right one pos_list = [self.HALF_OPEN_POS, self.s_width/3] closest = min(pos_list, key=lambda x: abs(x-self.pos_x)) if closest<self.pos_x: while closest<self.pos_x: self.pos_x-=5 self.setGeometry(0,self.top_pos,self.pos_x+self.SIZE/2,self.s_height) QtGui.QApplication.processEvents() self.update() self.pos_x=closest QtGui.QApplication.processEvents() self.update() elif closest>self.pos_x: while closest>self.pos_x: self.pos_x+=5 self.setGeometry(0,self.top_pos,self.pos_x+self.SIZE/2,self.s_height) QtGui.QApplication.processEvents() self.update() self.pos_x=closest QtGui.QApplication.processEvents() self.update() ##set the current state if self.pos_x==self.HALF_OPEN_POS: self.current_state="half_open" self.update_all() elif self.pos_x==self.s_width/3: self.current_state="open" else: self.current_state="nothing" #Events # elif self.current_state=="open": if self.pos_x-self.SIZE<x_m<self.pos_x and self.move==False and e.button()==QtCore.Qt.LeftButton: self.close_it() if y_m>self.s_height-13: print("Quiting") sys.exit() ###app events if self.activity == "apps": max_apps= math.trunc((len(self.allApps)-1)/self.apps_per_page)+1 ##Change Page for i in range(0,max_apps): btn_size = 20 x_pos = self.s_width/6-btn_size+(btn_size*i) if x_pos<x_m<x_pos+btn_size and 2<y_m<2+btn_size: self.app_page_state=i self.update() QtGui.QApplication.processEvents() ## launch apps for i, app in enumerate(self.allApps): app_page = math.trunc(i/self.apps_per_page) if app_page==self.app_page_state: row_pos = math.trunc(i/self.apps_per_row) x_pos = self.ICON_SIZE*(i-(row_pos*self.apps_per_row))+30 y_pos = row_pos*self.ICON_SIZE+30-(app_page*(self.ICON_SIZE*self.apps_per_col)) if x_pos<x_m<(x_pos+self.ICON_SIZE) and y_pos<y_m<(y_pos+self.ICON_SIZE) and x_m<self.pos_x-self.SIZE-3: if e.button()==QtCore.Qt.LeftButton: print("Launching '{0}' with '{1}'".format(app["name"],app["exec"]) ) thread = Launch(parent=self) thread.app=app["exec"] thread.start() self.close_it() if self.activity == "files": if self.s_width/3-80-self.SIZE<x_m<self.s_width/3-50-self.SIZE and 10<y_m<30: l= self.Files.directory.split("/")[:-1][1:] new_dir='' for a in l: new_dir+='/' new_dir+=a if new_dir=='':new_dir='/' self.files_page_state=0 self.Files.directory=new_dir self.update() if self.s_width/3-40-self.SIZE<x_m<self.s_width/3-self.SIZE and 10<y_m<30: self.Files.directory = self.Files.default self.files_page_state=0 self.update() max_files= math.trunc(len(self.Files.all())/self.apps_per_page)+1 ##Change Page for i in range(0,max_files): btn_size = 20 x_pos = self.s_width/6-btn_size+(btn_size*i) if x_pos<x_m<x_pos+btn_size and 2<y_m<2+btn_size: self.files_page_state=i self.update() QtGui.QApplication.processEvents() ## launch apps for i, f in enumerate(self.Files.all()): app_page = math.trunc(i/self.apps_per_page) if app_page==self.files_page_state: row_pos = math.trunc(i/self.apps_per_row) x_pos = self.ICON_SIZE*(i-(row_pos*self.apps_per_row))+30 y_pos = row_pos*self.ICON_SIZE+30-(app_page*(self.ICON_SIZE*self.apps_per_col)) if x_pos<x_m<(x_pos+self.ICON_SIZE) and y_pos<y_m<(y_pos+self.ICON_SIZE) and x_m<self.pos_x-self.SIZE-3: if e.button()==QtCore.Qt.LeftButton: if f["type"]=="file": import webbrowser webbrowser.open(f["whole_path"]) elif f["type"]=="directory": self.Files.directory=f["whole_path"] self.update() QtGui.QApplication.processEvents() if self.activity=="star": blocks=self.conf['blocks'] all_rows=0 for i,b in enumerate(blocks): all_stuff = Config.get_from_block(b) if len(all_stuff)!=self.apps_per_row: row_num = math.trunc(len(all_stuff)/self.apps_per_row)+1 else: row_num = math.trunc(len(all_stuff)/self.apps_per_row) h=self.ICON_SIZE*all_rows+i*50 all_rows+=row_num for j, thing in enumerate(all_stuff): row_pos = math.trunc(j/self.apps_per_row) x_pos = self.ICON_SIZE*(j-(row_pos*self.apps_per_row))+40 y_pos = (row_pos*self.ICON_SIZE+20)+h+30 if x_pos+15<x_m<x_pos+15+self.ICON_SIZE and y_pos<y_m<y_pos+self.ICON_SIZE and x_m<self.pos_x-self.SIZE-3: if e.button()==QtCore.Qt.LeftButton: if thing['type']=='app': the_exec="" for a in Apps.info(''): if thing['value'] in a['name']: the_exec=a['exec'] thread = Launch(parent=self) thread.app=the_exec thread.start() print("Launching '{0}' with '{1}'".format(thing["value"], the_exec) ) else: import webbrowser webbrowser.open(thing['value']) elif self.current_state=="half_open": ##buttons if self.pos_x-self.SIZE<x_m<self.pos_x and self.move==False and self.s_height/2-20<y_m<self.s_height/2+20: self.activity="apps" self.open_it() if 0<x_m<self.HALF_OPEN_POS: if e.button()==QtCore.Qt.LeftButton: if 0<y_m<self.ICO_TOP: self.activity="apps" self.current_text='' self.open_it() if self.ICO_TOP<y_m<self.ICO_TOP*2: self.activity="files" self.Files.directory=self.Files.default self.files_page_state=0 self.open_it() if self.ICO_TOP*2<y_m<self.ICO_TOP*3: self.activity="settings" Settings(parent=self).start() if self.ICO_TOP*3<y_m<self.ICO_TOP*4: self.activity="star" self.open_it() try: for i,a in enumerate(self.dock_apps): if self.OPEN_STATE_TOP+self.ICO_TOP*i+10<y_m<self.OPEN_STATE_TOP+self.ICO_TOP*(i+1)+10: if e.button()==QtCore.Qt.LeftButton: print("Launching '{0}' with '{1}'".format(a["name"], a["exec"]) ) thread = Launch(parent=self) thread.app=a["exec"] thread.start() self.close_it() except KeyError: pass if self.s_height-self.ICO_TOP*2-20<y_m<self.s_height-self.ICO_TOP-20: ##open windows self.sys_win.close() if self.open_win.isHidden(): if len(self.open_windows)>0: self.open_win.updateApps() self.open_win.show() else:pass elif self.open_win.isHidden()==False: self.open_win.close() if self.s_height-self.ICO_TOP<y_m<self.s_height: if self.sys_win.isHidden(): self.open_win.close() self.sys_win.show() elif self.sys_win.isHidden()==False: self.sys_win.close() self.update()
def _appsGetAll(self): if self.activity=="apps" and self.plugin==False: self.allApps=Apps.info(self.current_text) self.webview.page().mainFrame().evaluateJavaScript("setNewApps({})".format(self.allApps))
def __init__(self): QtGui.QMainWindow.__init__(self, None,QtCore.Qt.WindowStaysOnTopHint|QtCore.Qt.FramelessWindowHint) self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setAttribute(QtCore.Qt.WA_X11NetWmWindowTypeDock) self.setWindowTitle("ducklauncher!!")#recognisable by wnck self.activateWindow() #screen size d = QtGui.QDesktopWidget() self.top_pos=0 self.s_width = d.availableGeometry().width() self.s_height =d.availableGeometry().height() import Xlib screen = Xlib.display.Display().screen().root.get_geometry() self.top_pos= screen.height-self.s_height #bg_width #Config conf=Config.get() self.conf=conf self.HALF_OPEN_POS=int(conf['size']) self.ICO_TOP=self.HALF_OPEN_POS-5 self.OPEN_STATE_TOP=self.ICO_TOP*4+5 self.SIZE = 14 self.R=int(conf['r']) self.G=int(conf['g']) self.B=int(conf['b']) self.ICON_SIZE=int(conf['icon-size']) #Geometry self.setGeometry(0,self.top_pos,self.HALF_OPEN_POS+4,self.s_height) #Values self.apps_per_row = math.trunc(((self.s_width/3)-30)/self.ICON_SIZE) self.apps_per_col = math.trunc(((self.s_height)-30)/self.ICON_SIZE) self.apps_per_page=self.apps_per_col*self.apps_per_row self.app_page_state=0 self.appRect=None self.drawAppRect=False self.files_page_state=0 self.Files = Files.getFiles() self.pos_x=self.HALF_OPEN_POS self.move=False self.current_state="half_open" self.activity="apps" self.dock_apps = Apps.find_info(self.conf['dock-apps']) self.current_text='' self.allApps=Apps.info(self.current_text) #Update open windows ''' self.timer=QtCore.QTimer() self.timer.setInterval(1000) self.timer.start() self.timer.timeout.connect(self.updateOpenWindows) ''' #Open windows window self.open_windows=Window.get_open_windows() self.open_win = Window.open_windows() #Settings window #self.settings_win = Settings.Window(self) #System window self.sys_win=System.Window() #Fake window self.fakewin = Fakewin(self.HALF_OPEN_POS,self.s_height, self) self.fakewin.show() XlibStuff.fix_window(self.fakewin.winId(),self.HALF_OPEN_POS+5,0,0,0)
def mousePressEvent(self,e): x_m,y_m = e.x(),e.y() self.open_windows=window.get_open_windows() self.update() QtGui.QApplication.processEvents() if self.current_state=="open": if self.pos_x-self.SIZE<x_m<self.pos_x and self.move==False: self.close_it() ###app events if self.activity == "apps": max_apps= math.trunc(len(Apps.info(self.current_text))/self.apps_per_page)+1 ##Change Page for i in range(0,max_apps): btn_size = 20 x_pos = self.s_width/6-btn_size+(btn_size*i) if x_pos<x_m<x_pos+btn_size and 2<y_m<2+btn_size: self.app_page_state=i self.update() QtGui.QApplication.processEvents() ## launch apps for i, app in enumerate(Apps.info(self.current_text)): app_page = math.trunc(i/self.apps_per_page) if app_page==self.app_page_state: row_pos = math.trunc(i/self.apps_per_row) x_pos = self.ICON_SIZE*(i-(row_pos*self.apps_per_row))+30 y_pos = row_pos*self.ICON_SIZE+30-(app_page*(self.ICON_SIZE*self.apps_per_col)) if x_pos<x_m<(x_pos+self.ICON_SIZE) and y_pos<y_m<(y_pos+self.ICON_SIZE): print "It should launch: " + app["name"] + " with " + app["exec"] thread = Launch(parent=self) thread.app=app["exec"] thread.start() self.close_it() if self.activity == "files": if 10<x_m<40 and 10<y_m<40: l= self.Files.directory.split("/")[:-1][1:] new_dir='' for a in l: new_dir+='/' new_dir+=a if new_dir=='':new_dir='/' self.Files.directory=new_dir self.update() max_files= math.trunc(len(self.Files.all())/self.apps_per_page)+1 ##Change Page for i in range(0,max_files): btn_size = 20 x_pos = self.s_width/6-btn_size+(btn_size*i) if x_pos<x_m<x_pos+btn_size and 2<y_m<2+btn_size: self.files_page_state=i self.update() QtGui.QApplication.processEvents() ## launch apps for i, f in enumerate(self.Files.all()): app_page = math.trunc(i/self.apps_per_page) if app_page==self.files_page_state: row_pos = math.trunc(i/self.apps_per_row) x_pos = self.ICON_SIZE*(i-(row_pos*self.apps_per_row))+30 y_pos = row_pos*self.ICON_SIZE+30-(app_page*(self.ICON_SIZE*self.apps_per_col)) if x_pos<x_m<(x_pos+self.ICON_SIZE) and y_pos<y_m<(y_pos+self.ICON_SIZE): if f["type"]=="file": import webbrowser webbrowser.open(f["whole_path"]) elif f["type"]=="directory": self.Files.directory=f["whole_path"] self.update() QtGui.QApplication.processEvents() if self.activity=="star": blocks=self.conf['blocks'] all_rows=0 for i,b in enumerate(blocks): all_stuff = Config.get_from_block(b) row_num = math.trunc(len(all_stuff)/self.apps_per_row)+1 h=self.ICON_SIZE*all_rows+20 all_rows+=row_num for j, thing in enumerate(all_stuff): row_pos = math.trunc(j/self.apps_per_row) x_pos = self.ICON_SIZE*(j-(row_pos*self.apps_per_row))+40 y_pos = (row_pos*self.ICON_SIZE+20)+h if x_pos+15<x_m<x_pos+15+self.ICON_SIZE and y_pos+15<y_m<y_pos+15+self.ICON_SIZE: if thing['type']=='app': the_exec="" for a in Apps.info(''): if thing['value'] in a['name']: print "a" the_exec=a['exec'] thread = Launch(parent=self) thread.app=the_exec thread.start() print "Launching " , thing['value'], "with :",the_exec else: import webbrowser webbrowser.open(thing['value']) if self.current_state=="half_open": ##buttons if 0<x_m<self.HALF_OPEN_POS: if 0<y_m<self.ICO_TOP: self.activity="apps" self.current_text='' self.open_it() if self.ICO_TOP<y_m<self.ICO_TOP*2: self.activity="files" self.Files.directory=self.Files.default self.open_it() if self.ICO_TOP*2<y_m<self.ICO_TOP*3: self.activity="settings" self.settings_win.show() if self.ICO_TOP*3<y_m<self.ICO_TOP*4: self.activity="star" self.open_it() try: ####OFF WE GOOO! for i,a in enumerate(self.dock_apps): if self.OPEN_STATE_TOP+self.ICO_TOP*i+10<y_m<self.OPEN_STATE_TOP+self.ICO_TOP*(i+1)+10: print "It should launch: " + a["name"] + " with " + a["exec"] thread = Launch(parent=self) thread.app=a["exec"] thread.start() self.close_it() except KeyError: pass if self.s_height-self.ICO_TOP*2-20<y_m<self.s_height-self.ICO_TOP-20: ##open windows if self.open_state==False: if len(self.open_windows)>0: self.open_win.update_apps() self.open_win.show() self.open_state=True else:pass elif self.open_state==True: self.open_win.close() self.open_state=False if self.s_height-self.ICO_TOP*2-20>y_m<self.s_height-self.ICO_TOP-20: self.open_win.close() if self.s_height-self.ICO_TOP<y_m<self.s_height: sys.exit()
import Geo import Direct import Post import Token import UserActivity import RobConfig import UrlShortener import Contacts if __name__ == '__main__': conf = { '/': { 'tools.sessions.on': True, 'tools.staticdir.root': os.path.abspath(os.getcwd()) }, '/assets': { 'tools.staticdir.on': True, 'tools.staticdir.dir': './assets' } } cherrypy.tree.mount(Token.StringGeneratorToken(), '/thirdpartyrats/twitter/tokens', conf) cherrypy.tree.mount(Direct.StringGeneratorDirect(), '/thirdpartyrats/twitter/directMessage', conf) cherrypy.tree.mount(Post.StringGeneratorPost(), '/thirdpartyrats/twitter/postTweet', conf) cherrypy.tree.mount(Contacts.StringGeneratorContacts(), '/thirdpartyrats/twitter/getContacts', conf) cherrypy.tree.mount(UserActivity.StringGeneratorActivity(), '/thirdpartyrats/twitter/userActivity', conf) cherrypy.tree.mount(Geo.StringGeneratorGeo(), '/thirdpartyrats/twitter/geoTagging', conf) cherrypy.tree.mount(Apps.StringGeneratorApps(), '/thirdpartyrats/twitter/apps', conf) cherrypy.tree.mount(UrlShortener.StringGeneratorUrl(), '/thirdpartyrats/twitter/urlShortener', conf) cherrypy.engine.start() cherrypy.engine.block()
def keyPressEvent(self, e): QtCore.QCoreApplication.sendEvent(self.parent, e) if e.key()==QtCore.Qt.Key_Backspace: self.parent.current_text=self.parent.current_text[:-1] if self.plugin==False: self.parent.allApps=Apps.info(str(self.parent.current_text)) self.parent.update() elif e.key()==QtCore.Qt.Key_Return: if len(self.parent.allApps)==1: a=self.parent.allApps[0] print("[Duck Launcher] Launching '{0}' with '{1}'".format(a["name"], a["exec"]) ) thread = Launch(parent=self.parent) thread.app=a["exec"] thread.start() self.parent.close_it() self.parent.current_text='' self.parent.allApps=Apps.find_info('') pl= Plugins.get(str(self.parent.current_text)) #html = pl.html(color=(self.parent.conf["r"],self.parent.conf["g"],self.parent.conf["b"]),font=self.parent.conf["font"]) if pl.isAlright(): self.parent.fg_color=pl.getColor("background") self.parent.font_color=pl.getColor("foreground") self.parent.pl_logo=pl.getLogo() if self.parent.plugin==False: self.parent.plugin=True self.parent.open_pl_rect() html = pl.html(color=(self.parent.conf["r"],self.parent.conf["g"],self.parent.conf["b"]),font=self.parent.conf["font"]) if html !=None: self.parent.webview.setHtml(html) else:print("ummm, error") self.parent.setAttribute(QtCore.Qt.WA_X11NetWmWindowTypeDock,False) self.update() self.parent.update() self.parent.webview.show() self.parent.webview.page().mainFrame().setFocus() self.parent.webview.setFocus() self.parent.webview.update() elif e.key()==16777216: #ESC if self.parent.plugin==False: self.parent.current_text="" self.parent.allApps=Apps.info('') self.parent.app_page_state=0 if self.parent.plugin==True: self.parent.close_it() self.parent.update() #QtGui.QApplication.processEvents() elif e.text()!='': self.parent.current_text+=e.text() self.parent.app_page_state=0 self.parent.allApps=Apps.info(str(self.parent.current_text)) #self.parent.webview.page().mainFrame().evaluateJavaScript("setNewApps({})".format(self.parent.allApps)) self.parent.update() else: if e.key()==16777250: if self.parent.current_state=="half_open": self.parent.activity="apps" self.parent.current_text='' self.parent.allApps=Apps.info('') self.parent.open_it() elif self.parent.current_state=="open": self.parent.webview.hide() self.parent.close_pl_rect() self.parent.fg_color=(int(self.parent.conf['r']),int(self.parent.conf['g']),int(self.parent.conf['b'])) self.parent.close_it() self.parent.update()
def setDockApps(self,v): self.conf["dock-apps"]=v self.parent.conf=self.conf self.parent.dock_apps=Apps.find_info(self.conf['dock-apps']) self.parent.update_all(self.conf)
new_l.pop(index) new_l.insert(index-1,app_name) return new_l def moveDownList(app_name, dock_apps): new_l=None dock_apps=[str(a) for a in dock_apps] if dock_apps.index(app_name) < len(dock_apps) and app_name in dock_apps: index=None for i, d in enumerate(dock_apps): if str(d)==str(app_name): index=i break if index!=None: new_l=dock_apps new_l.pop(index) new_l.insert(index+1,app_name) return new_l if __name__=="__main__": app = QApplication(sys.argv) w = Container() cfg = getConfig() apps = Apps.info('') fonts= [ str(a) for a in QFontDatabase().families()] f=open("/usr/lib/duck_settings/template.html","r") t=Template(f.read()) f.close() w.setHtml(t.render(cfg=cfg,fonts=fonts,apps=apps,static_url="file:///usr/share/duck-launcher/default-theme/")) w.show() sys.exit(app.exec_())
def paintEvent(self,e): qp=QtGui.QPainter(self) qp.fillRect(e.rect(), QtCore.Qt.transparent) qp.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) ####DRAW qp.setPen(QtCore.Qt.NoPen) qp.setBrush(QtGui.QColor(int(self.conf['r2']),int(self.conf['g2']),int(self.conf['b2']),int(self.conf["alpha"]))) qp.drawRect(0,0,self.pos_x+7,self.s_height) ## if self.current_state == "half_open": qp.setPen(QtCore.Qt.NoPen) qp.setBrush(QtGui.QColor(self.fg_color[0],self.fg_color[1],self.fg_color[2])) qp.drawRect(0,0,self.pos_x+7,self.OPEN_STATE_TOP) rect = QtCore.QRectF(50,0,150,50) ####DRAW BUTTONS ###Apps ICO_TOP=self.HALF_OPEN_POS-5 icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/apps.svg") icon.paint(qp,5,ICO_TOP*0+5,ICO_TOP,ICO_TOP-6) #Files icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/file.svg") ##temp_file icon.paint(qp,5,ICO_TOP*1+5,ICO_TOP,ICO_TOP-6) #Settings icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/settings.svg") icon.paint(qp,5,ICO_TOP*2+5,ICO_TOP,ICO_TOP-6) #Star icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/star.svg") icon.paint(qp,5,ICO_TOP*3+5,ICO_TOP,ICO_TOP-6) ##### #Dock Apps for i,a in enumerate(self.dock_apps): try: if a["name"] in [e["name"] for e in self.ow_in_dock]: qp.setBrush(QtGui.QColor(self.fg_color[0],self.fg_color[1],self.fg_color[2],100)) qp.drawRect(0,self.OPEN_STATE_TOP+ICO_TOP*i+8,self.HALF_OPEN_POS+3,ICO_TOP-1) qp.setBrush(QtGui.QColor(self.fg_color[0],self.fg_color[1],self.fg_color[2])) r_s=6 c = QtCore.QRectF(-r_s/2,self.OPEN_STATE_TOP+ICO_TOP*i+8+ICO_TOP/2-r_s/2,r_s,r_s) qp.drawEllipse(c) QtGui.QIcon(Apps.ico_from_name(a['icon'])).paint(qp,4,self.OPEN_STATE_TOP+ICO_TOP*i+10,ICO_TOP,ICO_TOP-5) except KeyError: print("[Duck Launcher] Error: Some apps could not be found ") qp.setBrush(QtGui.QColor(self.fg_color[0],self.fg_color[1],self.fg_color[2])) if len(self.open_windows)>0: after_dapps = self.OPEN_STATE_TOP+len(self.dock_apps)*ICO_TOP+30 all_wins=[e["info"]["id"] for e in self.ow_in_dock] ow_list=[o for o in self.open_windows if o["id"] not in all_wins] if len(ow_list)>0: qp.drawRect(4, after_dapps-15, self.HALF_OPEN_POS-6,1) for i,w in enumerate(ow_list): y_pos=i*ICO_TOP+after_dapps r_s=6 c = QtCore.QRectF(-r_s/2,y_pos+ICO_TOP/2-r_s,r_s,r_s) qp.drawEllipse(c) QtGui.QIcon(w["icon"]).paint(qp, 4, y_pos,ICO_TOP,ICO_TOP-5) qp.setPen(QtCore.Qt.NoPen) qp.setBrush(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2])) print self.pos_x+7 if self.pos_x+7>=70: s=12 elif 55<self.pos_x+7<70: s=8 elif 40<self.pos_x+7<=55: s=6 elif self.pos_x+7<=40: s=4 top_r=self.s_height-self.HALF_OPEN_POS/2-s/2 qp.drawRect((self.pos_x+7)/2-2*s,top_r,s,s) qp.drawRect((self.pos_x+7)/2-s/2,top_r,s,s) qp.drawRect((self.pos_x+7)/2+s,top_r,s,s) #icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/sys.svg") #icon.paint(qp,10,self.s_height-self.HALF_OPEN_POS+8,self.HALF_OPEN_POS-15,self.HALF_OPEN_POS-15) ## ## if self.current_state=="open": #close=QtGui.QIcon("/usr/share/duck-launcher/default-theme/remove.svg") #close.paint(qp,self.pos_x-10,self.s_height-13,13,13) if self.activity=="apps": max_apps= math.trunc((len(self.allApps)-1)/self.apps_per_page)+1 if self.plugin==False: ##pages btn_size = 15 minus = math.trunc(len(self.allApps)/self.apps_per_page)*15/2 for i in range(0, max_apps): x_pos = self.s_width/6-btn_size+(btn_size*i)-minus qp.setPen(QtCore.Qt.NoPen) qp.setBrush(QtGui.QColor(int(self.font_color[0]),int(self.font_color[1]),int(self.font_color[2]))) rect = QtCore.QRectF(x_pos,2,btn_size,btn_size) if self.app_page_state==i: rect = QtCore.QRectF(x_pos+2,15,btn_size-1,btn_size-1) else: rect = QtCore.QRectF(x_pos+btn_size/4,15+btn_size/4,btn_size-btn_size/2,btn_size-btn_size/2) qp.drawEllipse(rect) ###app_buttons for i, app in enumerate(self.allApps): app_page = math.trunc(i/self.apps_per_page) if app_page==self.app_page_state: qp.setBrush(QtGui.QColor(int(self.conf['r2']),int(self.conf['g2']),int(self.conf['b2']))) row_pos = math.trunc(i/self.apps_per_row) page_row_pos=row_pos-(self.apps_per_page/self.apps_per_row*app_page) col_pos=(i-(row_pos*self.apps_per_row)) #pr,app["name"] x_pos = self.ICON_SIZE*col_pos+30+col_pos*10 y_pos = page_row_pos*self.ICON_SIZE+30+page_row_pos*10 try: if self.ICON_SIZE-60>20: rect=QtCore.QRect(x_pos+30,y_pos+30,self.ICON_SIZE-60,self.ICON_SIZE-60) elif self.ICON_SIZE-30>20: rect=QtCore.QRect(x_pos+15,y_pos+15,self.ICON_SIZE-30,self.ICON_SIZE-30) else: rect=QtCore.QRect(x_pos,y_pos,self.ICON_SIZE,self.ICON_SIZE) ico=Apps.ico_from_name(app["icon"]) if ico!=None: QtGui.QIcon(Apps.ico_from_name(app["icon"])).paint(qp,rect) else: i = QtGui.QIcon('/usr/share/duck-launcher/default-theme/apps.svg') i.paint(qp,rect) except KeyError: i = QtGui.QIcon('/usr/share/duck-launcher/default-theme/apps.svg') i.paint(qp,x_pos+20,y_pos+20,self.ICON_SIZE-40,self.ICON_SIZE-40) qp.setPen(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2])) text_rect = QtCore.QRectF(x_pos+5,y_pos+self.ICON_SIZE-10,self.ICON_SIZE-10,60) #font font = QtGui.QFont(self.conf["font"],9) font.setLetterSpacing(QtGui.QFont.PercentageSpacing,116) font.setWeight(QtGui.QFont.Normal) font.setHintingPreference(QtGui.QFont.PreferDefaultHinting) qp.setFont(font) qp.drawText(text_rect,QtCore.Qt.TextWordWrap |QtCore.Qt.AlignHCenter,self.tr(app["name"]).replace(u"Â", "")) elif self.plugin==True: qp.setPen(QtCore.Qt.NoPen) qp.setBrush(QtGui.QColor(self.fg_color[0],self.fg_color[1],self.fg_color[2])) pl_rect=QtCore.QRect(0,0,self.pl_rect_pos,self.s_height) qp.drawRect(pl_rect) #Current Text qp.setPen(QtCore.Qt.NoPen) font = QtGui.QFont(self.conf["font"],10) font.setWeight(QtGui.QFont.Bold) qp.setFont(font) t_rect=QtCore.QRectF(20,18,self.s_width-36,20) t_rect_pl=QtCore.QRectF(70,18,self.s_width-36,20) if self.current_text=='': font = QtGui.QFont(self.conf["font"],10) font.setWeight(QtGui.QFont.Light) font.setStyle(QtGui.QFont.StyleItalic) qp.setFont(font) self.plugin=False qp.setPen(QtGui.QPen(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2],160), 1, QtCore.Qt.SolidLine)) qp.drawText(t_rect, QtCore.Qt.AlignLeft, "Type to search") else: font = QtGui.QFont(self.conf["font"],10) #font.setWeight(QtGui.QFont.Light) qp.setFont(font) if "#" in self.current_text.split(" ")[0]: plugins_list=[] for p in Plugins.get_plugin_names(): if str(self.current_text.split(" ")[0]).lower().replace("#","") in p: plugins_list.append(p) if plugins_list: what_in_text=str(self.current_text.split(" ")[0].replace("#","")).lower() query_name=plugins_list[0] font =QtGui.QFont(self.conf["font"],10) fm=QtGui.QFontMetrics(QtGui.QFont(self.conf["font"],10)) whole_width=0 for i,s in enumerate("#{}".format(query_name)): w = int(fm.charWidth("#{}".format(query_name),i)) whole_width+=w if query_name==what_in_text: if self.plugin==False: qp.setBrush(QtGui.QColor(self.fg_color[0],self.fg_color[1],self.fg_color[2],255)) qp.drawRect(19,37,whole_width+4,3) qp.setPen(QtGui.QPen(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2]),1, QtCore.Qt.SolidLine)) qp.drawText(t_rect, QtCore.Qt.AlignLeft,self.current_text) else: qp.setBrush(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2],255)) qp.drawRect(69,37,whole_width+4,3) qp.setPen(QtGui.QPen(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2]),1, QtCore.Qt.SolidLine)) qp.drawText(t_rect_pl, QtCore.Qt.AlignLeft,self.current_text) if self.pl_logo!=None: ico = QtGui.QIcon(self.pl_logo) ico.paint(qp,15,10,40,40) else: qp.setPen(QtGui.QPen(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2]),1, QtCore.Qt.SolidLine)) qp.drawText(t_rect, QtCore.Qt.AlignLeft,self.current_text) else: qp.setPen(QtGui.QPen(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2]), 2, QtCore.Qt.SolidLine)) qp.drawText(t_rect, QtCore.Qt.AlignLeft,self.current_text) else: self.plugin=False qp.setPen(QtGui.QPen(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2]), 2, QtCore.Qt.SolidLine)) qp.drawText(t_rect, QtCore.Qt.AlignLeft, self.current_text) ### if self.activity=="star" : qp.setPen(QtGui.QPen(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2]), 3, QtCore.Qt.SolidLine)) all_rows=0 blocks_l=pickle.loads(Config.get()["blocks"]) for i,b in enumerate(blocks_l): all_stuff = Config.get_from_block(b) apps_per_row = math.trunc(((self.s_width/3)-30)/int(self.conf["icon-size"])) if len(all_stuff)!=apps_per_row: row_num = math.trunc(len(all_stuff)/apps_per_row)+1 else: row_num = math.trunc(len(all_stuff)/apps_per_row) h=int(self.conf["icon-size"])*all_rows+i*50 all_rows+=row_num qp.setFont(QtGui.QFont(self.conf["font"],8)) for j, thing in enumerate(all_stuff): #same thing as for the apps row_pos = math.trunc(j/apps_per_row) x_pos = int(self.conf["icon-size"])*(j-(row_pos*apps_per_row))+40 y_pos = (row_pos*int(self.conf["icon-size"])+20)+h+30 if thing['type']=='app': icon = QtGui.QIcon(Apps.ico_from_app(str(thing['value']))) to_write=str(thing['value']) elif thing['type']=='directory': print "a" icon = QtGui.QIcon(Apps.ico_from_name("folder")) splitted = thing['value'].split('/') to_write = splitted[-1] elif thing['type']=='file': icon = QtGui.QIcon(Apps.ico_from_name("text-plain")) splitted = thing['value'].split('/') to_write = splitted[-1] if icon!=None: icon.paint(qp, x_pos+15,y_pos+15, int(self.conf["icon-size"])-50,int(self.conf["icon-size"])-50) rect = QtCore.QRectF(x_pos-10, y_pos+int(self.conf["icon-size"])-30, int(self.conf["icon-size"]), 30) qp.drawText(rect,QtCore.Qt.TextWordWrap |QtCore.Qt.AlignHCenter,to_write) #Title qp.setPen(QtCore.Qt.NoPen) qp.setBrush(QtGui.QColor(self.fg_color[0],self.fg_color[1],self.fg_color[2])) qp.drawRect(18, h+40,self.s_width/6,2) qp.setPen(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2])) qp.setFont(QtGui.QFont(self.conf["font"],16)) if isinstance(b["name"],list): b["name"]="".join(b["name"]) qp.drawText(QtCore.QRectF(20, h+10,self.s_width/3,200),b['name']) qp.setPen(QtCore.Qt.NoPen) qp.setBrush(QtGui.QColor(self.fg_color[0],self.fg_color[1],self.fg_color[2])) ''' if self.plugin==False: qp.setBrush(QtGui.QColor(self.fg_color[0],self.fg_color[1],self.fg_color[2])) else: qp.setBrush(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2],255)) ''' qp.drawRect(self.pos_x+5,0,2,self.s_height) qp.setBrush(QtGui.QColor(0,0,0,20)) qp.drawRect(self.pos_x+7,0,3,self.s_height) qp.setBrush(QtGui.QColor(0,0,0,30)) qp.drawRect(self.pos_x+7,0,2,self.s_height) qp.setBrush(QtGui.QColor(0,0,0,50)) qp.drawRect(self.pos_x+7,0,1,self.s_height) if self.current_state!="half_open": qp.setPen(QtCore.Qt.NoPen) qp.setBrush(QtGui.QColor(self.fg_color[0],self.fg_color[1],self.fg_color[2],18)) qp.drawRect(self.pos_x-14,0,20,self.s_height) if self.plugin==False: qp.setBrush(QtGui.QColor(self.fg_color[0],self.fg_color[1],self.fg_color[2],255)) else: qp.setBrush(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2],255)) r_s=5 a=10 r = QtCore.QRectF(self.pos_x-7,self.s_height/2-r_s/2,r_s,r_s) qp.drawEllipse(r) r = QtCore.QRectF(self.pos_x-7,self.s_height/2-a-r_s/2,r_s,r_s) qp.drawEllipse(r) r = QtCore.QRectF(self.pos_x-7,self.s_height/2+a-r_s/2,r_s,r_s) qp.drawEllipse(r) #Draw rect under clicked app if self.drawAppRect==True and self.appRect!=None: qp.setPen(QtCore.Qt.NoPen) qp.setBrush(QtGui.QColor(self.font_color[0],self.font_color[1],self.font_color[2],30)) qp.drawRect(self.appRect)
def paintEvent(self,e): qp=QtGui.QPainter() qp.begin(self) qp.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) ####DRAW qp.setBrush(QtGui.QColor(40,40,40,200)) qp.drawRect(0,0,self.pos_x+self.SIZE/2,self.s_height) #qp.setBrush(QtGui.QColor(200,20,20)) pen = QtGui.QPen(QtGui.QColor(self.R,self.G,self.B), 8, QtCore.Qt.SolidLine) qp.setPen(pen) qp.drawLine(self.pos_x+self.SIZE/2-2,0,self.pos_x+self.SIZE/2-2,self.s_height) qp.setPen(QtGui.QPen(QtGui.QColor(self.R,self.G,self.B), 4, QtCore.Qt.SolidLine)) r_s=3 a=3 r = QtCore.QRectF(self.pos_x-self.SIZE/2-a,self.s_height/2,r_s,r_s) qp.drawEllipse(r) r = QtCore.QRectF(self.pos_x-self.SIZE/2-a,self.s_height/2-r_s*3,r_s,r_s) qp.drawEllipse(r) r = QtCore.QRectF(self.pos_x-self.SIZE/2-a,self.s_height/2+r_s*3,r_s,r_s) qp.drawEllipse(r) ## ### if self.current_state == "half_open": qp.setBrush(QtGui.QColor(self.R,self.G,self.B)) qp.drawRect(0,0,self.pos_x+self.SIZE/2,self.OPEN_STATE_TOP) rect = QtCore.QRectF(50,0,150,50) qp.setPen(QtGui.QPen(QtGui.QColor(250,250,250), 3, QtCore.Qt.SolidLine)) ####DRAW BUTTONS qp.setBrush(QtGui.QColor(250,250,250,100)) qp.setPen(QtGui.QPen(QtGui.QColor(250,250,250), 2, QtCore.Qt.SolidLine)) ###Apps ICO_TOP=self.ICO_TOP icon = QtGui.QIcon("/usr/share/duck-launcher/icons/apps.svg") icon.paint(qp,7,ICO_TOP*0+5,ICO_TOP-5,ICO_TOP-5) #Files icon = QtGui.QIcon("/usr/share/duck-launcher/icons/file.svg") ##temp_file icon.paint(qp,7,ICO_TOP*1+5,ICO_TOP-5,ICO_TOP-5) #Settings icon = QtGui.QIcon("/usr/share/duck-launcher/icons/settings.svg") icon.paint(qp,7,ICO_TOP*2+5,ICO_TOP-5,ICO_TOP-5) #Star icon = QtGui.QIcon("/usr/share/duck-launcher/icons/star.svg") icon.paint(qp,7,ICO_TOP*3+5,ICO_TOP-5,ICO_TOP-5) ##### #Dock Apps try: ####OFF WE GOOO! for i,a in enumerate(self.dock_apps): ico = Apps.ico_from_name(str(a['icon'])) if ico!=None: ico.paint(qp,6,self.OPEN_STATE_TOP+ICO_TOP*i+10,ICO_TOP-5,ICO_TOP-5) except KeyError: print 'No Dock apps' #Open Windows Button icon = QtGui.QIcon("/usr/share/duck-launcher/icons/open-apps.svg") icon.paint(qp,10,self.s_height-ICO_TOP*2-10,ICO_TOP-10,ICO_TOP-10) rect = QtCore.QRectF(10,self.s_height-ICO_TOP*2-10,ICO_TOP-10,ICO_TOP-10) qp.setFont(QtGui.QFont('Hermeneus One',14)) qp.drawText(rect, QtCore.Qt.AlignCenter, str(len(self.open_windows))) #Quit Button icon = QtGui.QIcon("/usr/share/duck-launcher/icons/close.svg") icon.paint(qp,10,self.s_height-ICO_TOP,ICO_TOP-10,ICO_TOP-10) ## ## if self.current_state=="open": if self.activity=="apps": ###page_buttons #Current Text t_rect=QtCore.QRectF(10,10,self.s_width/8,30) if self.current_text=='': qp.drawText(t_rect, QtCore.Qt.AlignCenter, "Type to search..") else: qp.drawText(t_rect, QtCore.Qt.AlignCenter, "Searching: "+self.current_text) max_apps= math.trunc(len(Apps.info(self.current_text))/self.apps_per_page)+1 for i in range(0, max_apps): btn_size = 20 x_pos = self.s_width/6-btn_size+(btn_size*i) rect = QtCore.QRectF(x_pos,2,btn_size,btn_size) qp.drawRect(rect) qp.drawText(rect,QtCore.Qt.AlignCenter,str(i+1)) ###app_buttons for i, app in enumerate(Apps.info(self.current_text)): app_page = math.trunc(i/self.apps_per_page) if app_page==self.app_page_state: qp.setBrush(QtGui.QColor(self.R,self.G,self.B)) row_pos = math.trunc(i/self.apps_per_row) x_pos = self.ICON_SIZE*(i-(row_pos*self.apps_per_row))+30 y_pos = row_pos*self.ICON_SIZE+30-(app_page*(self.ICON_SIZE*self.apps_per_col)) try: da_icon=Apps.ico_from_name(app["icon"]) if da_icon!=None: da_icon.paint(qp,x_pos+10,y_pos+10,self.ICON_SIZE-30,self.ICON_SIZE-30) r1 =QtCore.QRect(x_pos+10,y_pos+10,self.ICON_SIZE-30,self.ICON_SIZE-30) except KeyError: i = QtGui.QImage('images/apps.png') rect= QtCore.QRectF(x_pos+10,y_pos+10,self.ICON_SIZE-30,self.ICON_SIZE-30) qp.drawImage(rect,i) qp.setPen(QtGui.QColor(250,250,250)) text_rect = QtCore.QRectF(x_pos-5,y_pos+self.ICON_SIZE-20,self.ICON_SIZE,30) qp.setFont(QtGui.QFont('Hermeneus One',8)) qp.drawText(text_rect,QtCore.Qt.AlignCenter,self.tr(app["name"]).replace(u"Â", "")) ### if self.activity=="files": #Buttons b1_rect=QtCore.QRectF(10,10,30,30) qp.drawRect(b1_rect)#temporarily ico = QtGui.QIcon("/usr/share/duck-launcher/icons/back.svg") max_files= math.trunc(len(self.Files.all())/self.apps_per_page)+1 for i in range(0, max_files): btn_size = 20 x_pos = self.s_width/6-btn_size+(btn_size*i) rect = QtCore.QRectF(x_pos,2,btn_size,btn_size) qp.drawRect(rect) qp.drawText(rect,QtCore.Qt.AlignCenter,str(i+1)) ###app_buttons for i, f in enumerate(self.Files.all()): app_page = math.trunc(i/self.apps_per_page) if app_page==self.files_page_state: qp.setBrush(QtGui.QColor(self.R,self.G,self.B)) row_pos = math.trunc(i/self.apps_per_row) x_pos = self.ICON_SIZE*(i-(row_pos*self.apps_per_row))+30 y_pos = row_pos*self.ICON_SIZE+30-(app_page*(self.ICON_SIZE*self.apps_per_col)) print Files.getFileIcon(f["whole_path"]) try: if f["type"]=="directory": da_icon=QtGui.QIcon("/usr/share/duck-launcher/icons/folder.svg") da_icon.paint(qp,x_pos+10,y_pos+10,self.ICON_SIZE-30,self.ICON_SIZE-30) if f["type"]=="file": da_icon=QtGui.QIcon("/usr/share/duck-launcher/icons/file.svg") da_icon.paint(qp,x_pos+10,y_pos+10,self.ICON_SIZE-30,self.ICON_SIZE-30) except KeyError: i = QtGui.QImage('images/apps.png') rect= QtCore.QRectF(x_pos+10,y_pos+10,self.ICON_SIZE-30,self.ICON_SIZE-30) qp.drawImage(rect,i) qp.setPen(QtGui.QColor(250,250,250)) text_rect = QtCore.QRectF(x_pos-5,y_pos+self.ICON_SIZE-20,self.ICON_SIZE,30) qp.setFont(QtGui.QFont('Hermeneus One',8)) qp.drawText(text_rect,QtCore.Qt.AlignCenter,f["name"].replace(u"Â", "")) if self.activity=="star": qp.setPen(QtGui.QPen(QtGui.QColor(250,250,250), 3, QtCore.Qt.SolidLine)) all_rows=0 for i,b in enumerate(self.conf['blocks']): all_stuff = Config.get_from_block(b) row_num = math.trunc(len(all_stuff)/self.apps_per_row)+1 h=self.ICON_SIZE*all_rows+20 all_rows+=row_num qp.setFont(QtGui.QFont('Hermeneus One',16)) qp.drawText(QtCore.QRectF(20, h+10,self.s_width/3,200),b['name']) qp.setFont(QtGui.QFont('Hermeneus One',10)) for j, thing in enumerate(all_stuff): #same thing as for the apps row_pos = math.trunc(j/self.apps_per_row) x_pos = self.ICON_SIZE*(j-(row_pos*self.apps_per_row))+40 y_pos = (row_pos*self.ICON_SIZE+20)+h if thing['type']=='app': icon = Apps.ico_from_app(thing['value']) to_write=thing['value'] elif thing['type']=='directory': icon = QtGui.QIcon('/usr/share/duck-launcher/icons/folder.svg') splitted = thing['value'].split('/') to_write = splitted[-1] elif thing['type']=='file': icon = QtGui.QIcon('/usr/share/duck-launcher/icons/file.svg') splitted = thing['value'].split('/') to_write = splitted[-1] icon.paint(qp, x_pos+15,y_pos+15, self.ICON_SIZE-50,self.ICON_SIZE-50) rect = QtCore.QRectF(x_pos+10, y_pos+self.ICON_SIZE-30, self.ICON_SIZE, 30) txt = qp.drawText(rect, to_write)
def appConfigSave(data): s = Apps.Applications(data["app_name"], data["max_size"], data["max_time"]) Apps.Applications.all_apps.append(s) cronJobs.start()
def paintEvent(self, e): qp = QtGui.QPainter() qp.begin(self) qp.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) qp.setPen(QtGui.QColor(int(self.r), int(self.g), int(self.b))) qp.setBrush(QtGui.QColor(int(self.r), int(self.g), int(self.b))) qp.drawRoundedRect(QtCore.QRectF(10, 0, self.width - 10, self.height), 2, 2) qp.setPen(QtGui.QColor(255, 255, 255, 255)) qp.setBrush(QtGui.QColor(255, 255, 255, 255)) qp.drawRect(9, 0, 5, self.height) icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/win.svg") icon.paint(qp, -10, self.size / 2 - 10, 20, 20) # qp.setFont(QtGui.QFont(Config.get()["font"], 12)) t_rect = QtCore.QRectF(10, 0, self.width - 10, 30) t_rect2 = QtCore.QRectF(11, 1, self.width - 10, 30) qp.setPen(QtGui.QColor(40, 40, 40, 80)) qp.drawText(t_rect2, QtCore.Qt.AlignCenter, self.app["name"]) qp.setPen(QtGui.QColor(255, 255, 255, 255)) qp.drawText(t_rect, QtCore.Qt.AlignCenter, self.app["name"]) qp.drawLine(26, 30, self.width - 20, 30) if self.drawButtonRect == True and self.buttonRect != None: qp.setPen(QtGui.QColor(0, 0, 0, 0)) qp.setBrush(QtGui.QColor(255, 255, 255, 40)) qp.drawRect(self.buttonRect) if self.state == "normal": qp.setFont(QtGui.QFont(Config.get()["font"], 10)) o_rect = QtCore.QRectF(50, 30, self.width - 10, 30) qp.setPen(QtGui.QColor(255, 255, 255, 255)) qp.drawText(o_rect, QtCore.Qt.AlignVCenter, "Open") removeIcon = QtGui.QIcon( "/usr/share/duck-launcher/default-theme/open.svg") removeIcon.paint(qp, 25, 34, 20, 20) #move r_rect = QtCore.QRectF(50, 60, self.width - 10, 30) qp.drawText(r_rect, QtCore.Qt.AlignVCenter, "Move") removeIcon = QtGui.QIcon( "/usr/share/duck-launcher/default-theme/move.svg") removeIcon.paint(qp, 25, 64, 20, 20) #remove r_rect = QtCore.QRectF(50, 90, self.width - 10, 30) qp.drawText(r_rect, QtCore.Qt.AlignVCenter, "Remove") removeIcon = QtGui.QIcon( "/usr/share/duck-launcher/default-theme/remove.svg") removeIcon.paint(qp, 25, 94, 20, 20) elif self.state == "moving": if self.width < 150: self.width = 150 self.resize(150, self.height) icon = QtGui.QIcon(Apps.ico_from_name(self.app["icon"])) if icon != None: w = self.width / 2 - 40 icon.paint(qp, w, 40, 70, 70) upicon = QtGui.QIcon( "/usr/share/duck-launcher/default-theme/up.svg") upicon.paint(qp, self.width / 2 + 35, 35, 40, 40) downicon = QtGui.QIcon( "/usr/share/duck-launcher/default-theme/down.svg") downicon.paint(qp, self.width / 2 + 35, self.height - 45, 40, 40)
def __init__(self, parent): QtGui.QDialog.__init__(self, None) # self.parent=parent self.conf=Config.get() self.current_selection="" self.current_block = "" self.current_item="" self.block_win=AddBlock() self.block_win.parent=self self.add_block_win=AddToBlock() self.add_block_win.parent=self # self.setWindowTitle('Duck Launcher Settings') self.resize(650,500) vbox=QtGui.QVBoxLayout() tabs = QtGui.QTabWidget() ##################### tab1 = QtGui.QWidget() hbox=QtGui.QVBoxLayout(tab1) l1 = QtGui.QLabel('Color:') l1.move(10,10) hbox.addWidget(l1) #Red l_R = QtGui.QLabel(' red: ') hbox.addWidget(l_R) value = int(self.conf['r']) percent = value*100/255 slider1=QtGui.QSlider(QtCore.Qt.Horizontal) slider1.setValue(percent) slider1.valueChanged[int].connect(self.change_red) hbox.addWidget(slider1) #Green l_G = QtGui.QLabel(' green: ') hbox.addWidget(l_G) value = int(self.conf['g']) percent = value*100/255 slider2=QtGui.QSlider(QtCore.Qt.Horizontal) slider2.setValue(percent) slider2.valueChanged[int].connect(self.change_green) hbox.addWidget(slider2) #Blue l_B = QtGui.QLabel(' blue: ') hbox.addWidget(l_B) value = int(self.conf['b']) percent = value*100/255 slider3=QtGui.QSlider(QtCore.Qt.Horizontal) slider3.setValue(percent) slider3.valueChanged[int].connect(self.change_blue) hbox.addWidget(slider3) #Color2 l2 = QtGui.QLabel('Second Color:') hbox.addWidget(l2) #Red2 l_R = QtGui.QLabel(' red: ') hbox.addWidget(l_R) value = int(self.conf['r2']) percent = value*100/255 slider1=QtGui.QSlider(QtCore.Qt.Horizontal) slider1.setValue(percent) slider1.valueChanged[int].connect(self.change_red2) hbox.addWidget(slider1) #Green2 l_G = QtGui.QLabel(' green: ') hbox.addWidget(l_G) value = int(self.conf['g2']) percent = value*100/255 slider2=QtGui.QSlider(QtCore.Qt.Horizontal) slider2.setValue(percent) slider2.valueChanged[int].connect(self.change_green2) hbox.addWidget(slider2) #Blue2 l_B = QtGui.QLabel(' blue: ') hbox.addWidget(l_B) value = int(self.conf['b2']) percent = value*100/255 slider3=QtGui.QSlider(QtCore.Qt.Horizontal) slider3.setValue(percent) slider3.valueChanged[int].connect(self.change_blue2) hbox.addWidget(slider3) #Alpha l_B = QtGui.QLabel('Transparency: ') hbox.addWidget(l_B) value = int(self.conf['alpha']) percent = value*100/255 slider3=QtGui.QSlider(QtCore.Qt.Horizontal) slider3.setValue(percent) slider3.valueChanged[int].connect(self.change_alpha) hbox.addWidget(slider3) #Canvas sep = QtGui.QLabel('__________________________') hbox.addWidget(sep) l_s = QtGui.QLabel('Canvas Width:') hbox.addWidget(l_s) value = int(self.conf['size']) slider4=QtGui.QSlider(QtCore.Qt.Horizontal) slider4.setValue(value) slider4.valueChanged[int].connect(self.change_size) hbox.addWidget(slider4) tabs.addTab(tab1,"Basic") #Tab 2 #################### tab2 = QtGui.QWidget() hbox=QtGui.QVBoxLayout(tab2) ico_label=QtGui.QLabel('Icon size: ') hbox.addWidget(ico_label) slider=QtGui.QSlider(QtCore.Qt.Horizontal) slider.setValue(int(self.conf["icon-size"])-50) slider.valueChanged[int].connect(self.change_icon_size) hbox.addWidget(slider) sep = QtGui.QLabel('__________________________') hbox.addWidget(sep) dock_label=QtGui.QLabel('Dock apps: ') hbox.addWidget(dock_label) list=QtGui.QListView() model = QtGui.QStandardItemModel(list) for app in Apps.info(''): a = QtGui.QStandardItem(app["name"]) a.setAccessibleText(app["name"]) a.setCheckable(True) if app['name'] in self.conf['dock-apps']: a.setCheckState(QtCore.Qt.Checked) model.appendRow(a) model.itemChanged.connect(self.change_dock_apps) list.setModel(model) hbox.addWidget(list) tabs.addTab(tab2,"Apps") #TAB 3 ###################### tab3 = QtGui.QWidget() hbox=QtGui.QVBoxLayout(tab3) self.tree=QtGui.QTreeView() self.model = QtGui.QStandardItemModel() self.updateBlocks() self.tree.clicked.connect(self.block_clicked) hbox.addWidget(self.tree) button_line = QtGui.QHBoxLayout() btn = QtGui.QPushButton("Add Block") btn.clicked.connect(self.addBlock) button_line.addWidget(btn) btn = QtGui.QPushButton("Delete block") btn.clicked.connect(self.deleteBlock) button_line.addWidget(btn) btn = QtGui.QPushButton("Add to block") btn.clicked.connect(self.addToBlock) button_line.addWidget(btn) btn = QtGui.QPushButton("Delete from block") btn.clicked.connect(self.removeFromBlock) button_line.addWidget(btn) hbox.addLayout(button_line) tabs.addTab(tab3,"Star") # tabs.show() vbox.addWidget(tabs) close = QtGui.QPushButton("Save settings and close") close.clicked.connect(self.close) vbox.addWidget(close) self.setLayout(vbox)
def paintEvent(self,e): qp=QtGui.QPainter(self) qp.fillRect(e.rect(), QtCore.Qt.transparent) qp.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) ####DRAW qp.setPen(QtCore.Qt.NoPen) qp.setBrush(QtGui.QColor(int(self.conf['r2']),int(self.conf['g2']),int(self.conf['b2']),int(self.conf["alpha"]))) qp.drawRect(0,0,self.pos_x+7,self.s_height) qp.setPen(QtGui.QPen(QtGui.QColor(int(self.conf['r']),int(self.conf['g']),int(self.conf['b'])), 3, QtCore.Qt.SolidLine)) qp.drawRect(self.pos_x+5,0,2,self.s_height) if self.current_state!="half_open": qp.setPen(QtGui.QPen(QtGui.QColor(int(self.conf['r']),int(self.conf['g']),int(self.conf['b']),30), 2, QtCore.Qt.SolidLine)) qp.drawLine(self.pos_x-14,0,self.pos_x-14,self.s_height) qp.setPen(QtGui.QPen(QtGui.QColor(int(self.conf['r']),int(self.conf['g']),int(self.conf['b'])), 4, QtCore.Qt.SolidLine)) qp.setBrush(QtGui.QBrush(QtGui.QColor(int(self.conf['r']),int(self.conf['g']),int(self.conf['b'])))) r_s=2 a=10 r = QtCore.QRectF(self.pos_x-7,self.s_height/2-r_s/2,r_s,r_s) qp.drawEllipse(r) r = QtCore.QRectF(self.pos_x-7,self.s_height/2-a-r_s/2,r_s,r_s) qp.drawEllipse(r) r = QtCore.QRectF(self.pos_x-7,self.s_height/2+a-r_s/2,r_s,r_s) qp.drawEllipse(r) ## ### if self.current_state == "half_open": qp.setPen(QtGui.QPen(QtGui.QColor(0,0,0,0),1,QtCore.Qt.SolidLine)) qp.setBrush(QtGui.QColor(int(self.conf['r']),int(self.conf['g']),int(self.conf['b']))) qp.drawRect(0,0,self.pos_x+7,self.OPEN_STATE_TOP) rect = QtCore.QRectF(50,0,150,50) ####DRAW BUTTONS ###Apps ICO_TOP=self.HALF_OPEN_POS-5 icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/apps.svg") icon.paint(qp,5,ICO_TOP*0+5,ICO_TOP,ICO_TOP-6) #Files icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/file.svg") ##temp_file icon.paint(qp,5,ICO_TOP*1+5,ICO_TOP,ICO_TOP-6) #Settings icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/settings.svg") icon.paint(qp,5,ICO_TOP*2+5,ICO_TOP,ICO_TOP-6) #Star icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/star.svg") icon.paint(qp,5,ICO_TOP*3+5,ICO_TOP,ICO_TOP-6) ##### #Dock Apps for i,a in enumerate(self.dock_apps): try: QtGui.QIcon(a['icon']).paint(qp,6,self.OPEN_STATE_TOP+ICO_TOP*i+10,ICO_TOP-5,ICO_TOP-5) except KeyError: print("[Duck Launcher] Error: Some apps could not be found ") #Open Windows Button qp.setPen(QtGui.QPen(QtGui.QColor(250,250,250), 2, QtCore.Qt.SolidLine)) icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/open-apps.svg") #icon = QtGui.QIcon("test-1.svg") icon.paint(qp,10,self.s_height-ICO_TOP*2-10,ICO_TOP-10,ICO_TOP-10) #rect = QtCore.QRectF(10,self.s_height-ICO_TOP*2-10,ICO_TOP-10,ICO_TOP-10) #qp.setFont(QtGui.QFont(self.conf["font"],self.HALF_OPEN_POS/3)) #qp.drawText(rect, QtCore.Qt.AlignCenter, str(len(self.open_windows))) #System button icon = QtGui.QIcon("/usr/share/duck-launcher/default-theme/sys.svg") icon.paint(qp,10,self.s_height-self.HALF_OPEN_POS+8,self.HALF_OPEN_POS-15,self.HALF_OPEN_POS-15) ## ## if self.current_state=="open": close=QtGui.QIcon("/usr/share/duck-launcher/default-theme/remove.svg") close.paint(qp,self.pos_x-13,self.s_height-13,13,13) if self.activity=="apps": #Current Text qp.setPen(QtCore.Qt.NoPen) qp.setFont(QtGui.QFont(self.conf["font"],10)) t_rect=QtCore.QRectF(20,20,self.s_width-36,20) if self.current_text=='': self.plugin=False qp.setPen(QtGui.QPen(QtGui.QColor(250,250,250), 2, QtCore.Qt.SolidLine)) qp.drawText(t_rect, QtCore.Qt.AlignLeft, "Type to search") else: if "#" in self.current_text.split(" ")[0]: plugins_list=[] for p in Plugins.get_plugin_names(): if str(self.current_text.split(" ")[0]).lower().replace("#","") in p: plugins_list.append(p) if plugins_list: what_in_text=str(self.current_text.split(" ")[0].replace("#","")).lower() query_name=plugins_list[0] fm=QtGui.QFontMetrics(QtGui.QFont(self.conf["font"],10)) whole_width=0 for i,s in enumerate("#{}".format(query_name)): w = int(fm.charWidth("#{}".format(query_name),i)) whole_width+=w if query_name==what_in_text: qp.setBrush(QtGui.QColor(int(self.conf["r"]),int(self.conf["g"]),int(self.conf["b"]),150)) qp.drawRoundedRect(QtCore.QRectF(19,18,whole_width+4,20), 2,2) else:pass qp.setPen(QtGui.QPen(QtGui.QColor(255,255,255), 2, QtCore.Qt.SolidLine)) qp.drawText(t_rect, QtCore.Qt.AlignLeft,self.current_text) else: qp.setPen(QtGui.QPen(QtGui.QColor(255,255,255), 2, QtCore.Qt.SolidLine)) qp.drawText(t_rect, QtCore.Qt.AlignLeft,self.current_text) else: self.plugin=False qp.setPen(QtGui.QPen(QtGui.QColor(250,250,250), 2, QtCore.Qt.SolidLine)) qp.drawText(t_rect, QtCore.Qt.AlignLeft, self.current_text) #Page if self.plugin==False: pass ### if self.activity=="files": pass if self.activity=="star" : qp.setPen(QtGui.QPen(QtGui.QColor(250,250,250), 3, QtCore.Qt.SolidLine)) all_rows=0 blocks_l=pickle.loads(Config.get()["blocks"]) for i,b in enumerate(blocks_l): all_stuff = Config.get_from_block(b) apps_per_row = math.trunc(((self.s_width/3)-30)/int(self.conf["icon-size"])) if len(all_stuff)!=apps_per_row: row_num = math.trunc(len(all_stuff)/apps_per_row)+1 else: row_num = math.trunc(len(all_stuff)/apps_per_row) h=int(self.conf["icon-size"])*all_rows+i*50 all_rows+=row_num qp.setFont(QtGui.QFont(self.conf["font"],8)) for j, thing in enumerate(all_stuff): #same thing as for the apps row_pos = math.trunc(j/apps_per_row) x_pos = int(self.conf["icon-size"])*(j-(row_pos*apps_per_row))+40 y_pos = (row_pos*int(self.conf["icon-size"])+20)+h+30 if thing['type']=='app': icon = Apps.ico_from_app(str(thing['value'])) to_write=str(thing['value']) elif thing['type']=='directory': print "a" icon = QtGui.QIcon(Apps.ico_from_name("folder")) splitted = thing['value'].split('/') to_write = splitted[-1] elif thing['type']=='file': icon = QtGui.QIcon(Apps.ico_from_name("text-plain")) splitted = thing['value'].split('/') to_write = splitted[-1] if icon!=None: icon.paint(qp, x_pos+15,y_pos+15, int(self.conf["icon-size"])-50,int(self.conf["icon-size"])-50) rect = QtCore.QRectF(x_pos-10, y_pos+int(self.conf["icon-size"])-30, int(self.conf["icon-size"]), 30) qp.drawText(rect,QtCore.Qt.TextWordWrap |QtCore.Qt.AlignHCenter,to_write) #Title qp.setPen(QtGui.QColor(0,0,0,0)) qp.setBrush(QtGui.QColor(int(self.conf['r']),int(self.conf['g']),int(self.conf['b']))) qp.drawRect(18, h+40,self.s_width/6,2) qp.setPen(QtGui.QColor(250,250,250)) qp.setFont(QtGui.QFont(self.conf["font"],16)) if isinstance(b["name"],list): b["name"]="".join(b["name"]) qp.drawText(QtCore.QRectF(20, h+10,self.s_width/3,200),b['name']) #Draw rect under clicked app if self.drawAppRect==True and self.appRect!=None: qp.setPen(QtGui.QPen(QtGui.QColor(0,0,0,0),1,QtCore.Qt.SolidLine)) qp.setBrush(QtGui.QColor(252,252,255,40)) qp.drawRoundedRect(self.appRect,2,2)
def mouseReleaseEvent(self,e): x_m,y_m = e.x(),e.y() self.drawAppRect=False Window.activateFakewin(self.fakewin.winId()) #While moving if self.current_state=="nothing": if self.plugin==False: self.webview.hide() self.move=False ###sets position to right one pos_list = [self.HALF_OPEN_POS, self.s_width/3] closest = min(pos_list, key=lambda x: abs(x-self.pos_x)) if closest<self.pos_x: while closest<self.pos_x: self.pos_x-=5 self.setGeometry(0,self.top_pos,self.pos_x+7,self.s_height) QtGui.QApplication.processEvents() self.update() self.pos_x=closest QtGui.QApplication.processEvents() self.update() elif closest>self.pos_x: while closest>self.pos_x: self.pos_x+=5 self.setGeometry(0,self.top_pos,self.pos_x+7,self.s_height) QtGui.QApplication.processEvents() self.update() self.pos_x=closest QtGui.QApplication.processEvents() self.update() ##set the current state if self.pos_x==self.HALF_OPEN_POS: self.pos_x-=3 self.dock_apps = Apps.find_info(self.conf['dock-apps']) self.current_state="half_open" elif self.pos_x==self.s_width/3: self.pos_x-=3 self.current_state="open" else: self.current_state="nothing" if self.plugin==True and self.current_state=='open' and self.activity=='apps': self.webview.show() if self.plugin==False and self.current_state=='open' and self.activity=='apps': self.current_text="" self.initApps() #Events # elif self.current_state=="open": if self.pos_x-14<x_m<self.pos_x and self.move==False and e.button()==QtCore.Qt.LeftButton: self.close_it() if y_m>self.s_height-13: print("[Duck Launcher] Saving configuration.") Config.check_dict(self.conf) QtGui.QApplication.processEvents() print("[Duck Launcher] Quitting, Good Bye!") QtGui.qApp.quit() ###app events elif self.activity==False and self.plugin==True: self.webview.show() elif self.activity == "files": pass elif self.activity=="star": blocks=pickle.loads(Config.get()["blocks"]) all_rows=0 apps_per_row = math.trunc(((self.s_width/3)-30)/int(self.conf["icon-size"])) for i,b in enumerate(blocks): all_stuff = Config.get_from_block(b) if len(all_stuff)!=apps_per_row: row_num = math.trunc(len(all_stuff)/apps_per_row)+1 else: row_num = math.trunc(len(all_stuff)/apps_per_row) h=int(self.conf["icon-size"])*all_rows+i*50 all_rows+=row_num for j, thing in enumerate(all_stuff): row_pos = math.trunc(j/apps_per_row) x_pos = int(self.conf["icon-size"])*(j-(row_pos*apps_per_row))+40 y_pos = (row_pos*int(self.conf["icon-size"])+20)+h+30 if x_pos-10<x_m<x_pos-10+int(self.conf["icon-size"]) and y_pos<y_m<y_pos+int(self.conf["icon-size"]) and x_m<self.pos_x-self.SIZE-3: if e.button()==QtCore.Qt.LeftButton: if thing['type']=='app': the_exec="" for a in Apps.info(''): if thing['value'] in a['name']: the_exec=a['exec'] thread = Launch(parent=self) thread.app=the_exec thread.start() print("[Duck Launcher] Launching '{0}' with '{1}'".format(thing["value"], the_exec) ) else: import webbrowser webbrowser.open(thing['value']) elif self.current_state=="half_open": ##buttons if self.pos_x-self.SIZE<x_m<self.pos_x and self.move==False and self.s_height/2-20<y_m<self.s_height/2+20: self.activity="apps" self.current_text="" self.open_it() self.initApps() if 0<x_m<self.HALF_OPEN_POS: if e.button()==QtCore.Qt.LeftButton: if y_m<self.ICO_TOP: self.activity="apps" self.current_text='' self.open_it() #self.allApps=Apps.info(self.current_text) self.initApps() if self.ICO_TOP<y_m<self.ICO_TOP*2: HOME=os.path.expanduser("~") self.activity="apps" self.current_text="#Files " html= Plugins.get(str(self.current_text),color=(self.conf["r"],self.conf["g"],self.conf["b"]),font=self.conf["font"]) if html!=None: self.open_it() self.webview.load(QtCore.QUrl(html)) self.webview.show() self.plugin=True self.webview.page().mainFrame().setFocus() self.webview.setFocus() self.update() if self.ICO_TOP*2<y_m<self.ICO_TOP*3: self.activity="settings" Settings(parent=self).start() if self.ICO_TOP*3<y_m<self.ICO_TOP*4: self.activity="star" self.open_it() if self.s_height-self.HALF_OPEN_POS*2<y_m<self.s_height-self.HALF_OPEN_POS-5: ##open windows if self.open_win.isHidden(): if len(self.open_windows)>0: #self.open_win.updateApps() self.open_win.show() self.sys_win.close() else:pass elif self.open_win.isHidden()==False: self.open_win.close() if self.s_height-self.HALF_OPEN_POS-5<y_m: if self.sys_win.isHidden(): self.open_win.close() self.sys_win.show() elif self.sys_win.isHidden()==False: self.sys_win.close() try: for i,a in enumerate(self.dock_apps): if self.OPEN_STATE_TOP+self.ICO_TOP*i+10<y_m<self.OPEN_STATE_TOP+self.ICO_TOP*(i+1)+10: if e.button()==QtCore.Qt.LeftButton: print("[Duck Launcher] Launching '{0}' with '{1}'".format(a["name"], a["exec"]) ) thread = Launch(parent=self) thread.app=a["exec"] thread.start() self.dock_options_win.close() elif e.button()==QtCore.Qt.RightButton: #LaunchOption(y_pos, app_dict if self.dock_options_win.isHidden() or self.dock_options_win.app["name"]!=a["name"]: self.dock_options_win.update_all(self.conf) self.dock_options_win.setTopPosition(self.OPEN_STATE_TOP+self.ICO_TOP*i+10) self.dock_options_win.setApp(a) self.dock_options_win.updateWidth() self.dock_options_win.show() else: self.dock_options_win.close() except KeyError: pass self.update()
======= qp.drawRoundedRect(QtCore.QRectF(10,0,self.size*self.win_len*1.3+10,self.size*1.6),4,4) >>>>>>> 86af556d16439afcb5d5a16d03cf98ebf6a5d387 qp.setPen(QtGui.QColor(250,250,250)) qp.setBrush(QtGui.QColor(250,250,250)) qp.drawRect(9,0,5,self.size*1.6) half_height=self.size*0.9 icon=QtGui.QIcon("/usr/share/duck-launcher/icons/win.svg") icon.paint(qp, -10,half_height-10, 20,20) if self.drawButtonRect==True and self.buttonRect!=None: qp.setPen(QtGui.QColor(0,0,0,0)) qp.setBrush(QtGui.QColor(254,254,255,50)) qp.drawRect(self.buttonRect) for i,w in enumerate(self.windows): ico = Apps.ico_from_app(w['icon']) if ico==None: ico = Apps.ico_from_app(w["title"]) if ico==None: home = os.path.expanduser("~")+"/.duck" try: os.stat(home) except: os.mkdir(home) <<<<<<< HEAD if os.path.isfile("{0}/{1}.png".format(home,binascii.hexlify(w["icon"]))): ico = QtGui.QIcon("{0}/{1}.png".format(home,binascii.hexlify(w["icon"]))) ======= if os.path.isfile("{0}/{1}.png".format(home,binascii.hexlify(window["icon"]))): ico = QtGui.QIcon("{0}/{1}.png".format(home,binascii.hexlify(window["icon"]))) >>>>>>> 86af556d16439afcb5d5a16d03cf98ebf6a5d387
def mouseReleaseEvent(self,e): x_m,y_m = e.x(),e.y() self.drawAppRect=False Window.activateFakewin(self.fakewin.winId()) #While moving '''' if self.current_state=="nothing": if self.plugin==False: self.webview.hide() self.move=False ###sets position to right one pos_list = [self.HALF_OPEN_POS, self.s_width/3] closest = min(pos_list, key=lambda x: abs(x-self.pos_x)) if closest<self.pos_x: while closest<self.pos_x: self.pos_x-=5 self.setGeometry(0,self.top_pos,self.pos_x+9,self.s_height) QtGui.QApplication.processEvents() self.update() self.pos_x=closest QtGui.QApplication.processEvents() self.update() elif closest>self.pos_x: while closest>self.pos_x: self.pos_x+=5 self.setGeometry(0,self.top_pos,self.pos_x+9,self.s_height) QtGui.QApplication.processEvents() self.update() self.pos_x=closest QtGui.QApplication.processEvents() self.update() ##set the current state if self.pos_x==self.HALF_OPEN_POS: self.pos_x-=3 #self.dock_apps = Apps.find_info(self.conf['dock-apps']) self.current_state="half_open" elif self.pos_x==self.s_width/3: self.pos_x-=3 self.current_state="open" else: self.current_state="nothing" if self.plugin==True and self.current_state=='open' and self.activity=='apps': self.webview.show() if self.plugin==False and self.current_state=='open' and self.activity=='apps': self.current_text="" #self.initApps() ''' #Events # if self.current_state=="open": if self.pos_x-14<x_m<self.pos_x and self.move==False and e.button()==QtCore.Qt.LeftButton: self.close_it() if y_m>self.s_height-13: print("[Duck Launcher] Saving configuration.") c = Config.check_dict(self.conf) QtGui.QApplication.processEvents() print("[Duck Launcher] Quitting, Good Bye!") QtGui.qApp.quit() ###app events if self.activity == "apps" and self.plugin==False: max_apps= math.trunc((len(self.allApps)-1)/self.apps_per_page)+1 minus = math.trunc(len(self.allApps)/self.apps_per_page)*15/2 ##Change Page for i in range(0,max_apps): btn_size = 15 x_pos = self.s_width/6-btn_size+(btn_size*i)-minus if x_pos<x_m<x_pos+btn_size and 12<y_m<btn_size+12: self.app_page_state=i self.update() QtGui.QApplication.processEvents() for i, app in enumerate(self.allApps): app_page = math.trunc(i/self.apps_per_page) if app_page==self.app_page_state: row_pos = math.trunc(i/self.apps_per_row) page_row_pos=row_pos-(self.apps_per_page/self.apps_per_row*app_page) col_pos=(i-(row_pos*self.apps_per_row)) x_pos = self.ICON_SIZE*col_pos+30+col_pos*10 y_pos = page_row_pos*self.ICON_SIZE+45+page_row_pos*10 if x_pos<x_m<x_pos+int(self.conf["icon-size"]) and y_pos<y_m<y_pos+int(self.conf["icon-size"]): if e.button()==QtCore.Qt.LeftButton: print("[Duck Launcher] Launching '{0}' with '{1}'".format(app["name"],app["exec"]) ) thread = Widgets.Launch(parent=self) thread.app=app["exec"] thread.start() self.close_it() elif self.activity=="star": blocks=pickle.loads(Config.get()["blocks"]) all_rows=0 apps_per_row = math.trunc(((self.s_width/3)-30)/int(self.conf["icon-size"])) for i,b in enumerate(blocks): all_stuff = Config.get_from_block(b) if len(all_stuff)!=apps_per_row: row_num = math.trunc(len(all_stuff)/apps_per_row)+1 else: row_num = math.trunc(len(all_stuff)/apps_per_row) h=int(self.conf["icon-size"])*all_rows+i*50 all_rows+=row_num for j, thing in enumerate(all_stuff): row_pos = math.trunc(j/apps_per_row) x_pos = int(self.conf["icon-size"])*(j-(row_pos*apps_per_row))+40 y_pos = (row_pos*int(self.conf["icon-size"])+20)+h+30 if x_pos-10<x_m<x_pos-10+int(self.conf["icon-size"]) and y_pos<y_m<y_pos+int(self.conf["icon-size"]) and x_m<self.pos_x-self.SIZE-3: if e.button()==QtCore.Qt.LeftButton: if thing['type']=='app': the_exec="" for a in Apps.info(''): if thing['value'] in a['name']: the_exec=a['exec'] thread = Widgets.Launch(parent=self) thread.app=the_exec thread.start() print("[Duck Launcher] Launching '{0}' with '{1}'".format(thing["value"], the_exec) ) else: import webbrowser webbrowser.open(thing['value']) elif self.current_state=="half_open": ##buttonsszd if 0<x_m<self.HALF_OPEN_POS: if e.button()==QtCore.Qt.LeftButton: if y_m<self.ICO_TOP: self.activity="apps" self.current_text='' self.open_it() #self.allApps=Apps.info(self.current_text) if self.ICO_TOP<y_m<self.ICO_TOP*2: HOME=os.path.expanduser("~") self.activity="apps" self.current_text="#Files " pl= Plugins.get(str(self.current_text)) html=pl.html(color=(self.conf["r"],self.conf["g"],self.conf["b"]),font=self.conf["font"]) if html!=None: self.open_it() self.plugin=True self.pl_logo="/usr/share/duck-launcher/default-theme/file.svg" self.fg_color=(40,40,40) self.font_color=(255,255,255) self.open_pl_rect() self.webview.setHtml(html) self.webview.show() #self.webview.page().mainFrame().setFocus() #self.webview.setFocus() self.update() if self.ICO_TOP*2<y_m<self.ICO_TOP*3: self.activity="settings" Settings(parent=self).start() if self.ICO_TOP*3<y_m<self.ICO_TOP*4: self.activity="star" self.open_it() if self.s_height-self.HALF_OPEN_POS-5<y_m: if self.sys_win.isHidden(): #self.open_win.close() self.sys_win.show() elif self.sys_win.isHidden()==False: self.sys_win.close() for i,a in enumerate(self.dock_apps): if self.OPEN_STATE_TOP+self.ICO_TOP*i+10<y_m<self.OPEN_STATE_TOP+self.ICO_TOP*(i+1)+10: if e.button()==QtCore.Qt.LeftButton: if a["name"] in [e["name"] for e in self.ow_in_dock]: l=[e for e in self.ow_in_dock if e["name"]==a["name"]] for k in l: c = Window.changeWindowState(parent=self,win_info=k["info"]) c.start() else: print("[Duck Launcher] Launching '{0}' with '{1}'".format(a["name"], a["exec"]) ) thread = Widgets.Launch(parent=self) thread.app=a["exec"] thread.start() self.dock_options_win.close() elif e.button()==QtCore.Qt.RightButton: #LaunchOption(y_pos, app_dict if self.dock_options_win.isHidden() or self.dock_options_win.app["name"]!=a["name"]: self.dock_options_win.update_all(self.conf) self.dock_options_win.setTopPosition(self.OPEN_STATE_TOP+self.ICO_TOP*i+10) self.dock_options_win.setApp(a) self.dock_options_win.updateWidth() self.dock_options_win.show() else: self.dock_options_win.close() if len(self.open_windows)>0: after_dapps = self.OPEN_STATE_TOP+len(self.dock_apps)*self.ICO_TOP+30 all_wins=[e["info"]["id"] for e in self.ow_in_dock] ow_list=[o for o in self.open_windows if o["id"] not in all_wins] for i,w in enumerate(ow_list): y_pos=i*self.ICO_TOP+after_dapps-3 if y_pos<y_m<y_pos+self.ICO_TOP: c = Window.changeWindowState(parent=self,win_info=w) c.start() self.update()