Skip to content

Instantly share code, notes, and snippets.

View SAW4's full-sized avatar

Sawa SAW4

  • Hong Kong
View GitHub Profile
@SAW4
SAW4 / revealer_example.lua
Created July 2, 2017 03:07
Lua GTK+ example ( using lgi )
--[[ Gtk.Revealer widget hiding animation with Lua & lgi
intro: revealer use to hide and show widgets with different transitions
demo: create a toolbar, hide/show by using a button(named:testbutton)
--]]
-- Import the module that you need
local lgi = require ('lgi')
local Gtk = lgi.Gtk
@SAW4
SAW4 / REMARK.md
Last active June 18, 2017 17:59
Understanding metaclass and Singleton in Python

How to use metaclass to implement Singleton in Python

First, you need to know that instance of metaclass is class,
just like : an instance of class is object, they have similar idea

Then you need to change the rule of metaclass of your class, to let it only allow create the instance once only.
If the class instance is not None (instance is existed), then return the instance, else create new instance of class.

One more important thing, metaclass is type
class is the instance of type (metaclass)
the origin of class is type (I may say that)

@SAW4
SAW4 / qaction_and_qmenu.py
Last active June 17, 2017 22:50
How to get QAction from QMenu + easy QSetting
# Create a new Qmenu
self.sqlcfg_menu = QtWidgets.QMenu(self)
# First item here, index 0
icon = QIcon(os.path.join(self.path, "image/File.png"))
self.sqlcfg_menu.addAction(icon, 'my.cnf', lambda: self.sqlConfMan('my.cnf'))
# Second item, index 1
self.sqlcfg_menu.addSeparator()
@SAW4
SAW4 / One_more_example.py
Created June 16, 2017 20:22
Reusable Exception Handling in Python (implement with decorator wrapper)
from functools import wraps
...
...
class MainInterface(QMainWindow):
...
...
# Reusble Exception checking funciton (For file manager, open file)
def fm_handle_stripe(f):
def wrapper(*args, **kwargs):
try:
@SAW4
SAW4 / fading_example.cpp
Created June 11, 2017 19:40
Qt Fading animation : Py vs C++
void MainInterface::ShowPathToCurr() {
TreeNodeButton* NodeButton = qobject_cast<TreeNodeButton*>(sender());
QPropertyAnimation *a;
int i = 1;
for (Node* curr = NodeButton->get_localref(); !curr->activated; curr=curr->prev,++i){
QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
a= new QPropertyAnimation(eff, "opacity");
curr->Widgetptr->setGraphicsEffect(eff);
curr->Widgetptr->setGraphicsEffect(eff);
a->setDuration(1000+i*500);