Skip to content

Commit

Permalink
app doesn't exit if no device is connected, shows informational label…
Browse files Browse the repository at this point in the history
… instead. Initial support for update devices button
  • Loading branch information
GabMus committed Sep 27, 2016
1 parent da4d36d commit 2137c3c
Show file tree
Hide file tree
Showing 3 changed files with 748 additions and 685 deletions.
1 change: 1 addition & 0 deletions device.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def _hex2rgb(self, mhex):
return tuple(int(mhex[i:i+2], 16) for i in (0, 2 ,4))

def assignMacro(self, key, command):

script_macro=self.device.macro.create_script_macro_item(command)
self.device.macro.add_macro(key, script_macro)

Expand Down
45 changes: 38 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

universalApplyButton = builder.get_object('universalApplyButton')

refreshDevicesButton=builder.get_object('refreshDevicesButton')

universalApplyButton.modify_bg(
Gtk.StateFlags.NORMAL,
Gdk.Color.parse('#4884cb').color)
Expand All @@ -32,12 +34,18 @@

devicesList = []

mainBox=builder.get_object('mainBox')
noDevicesLabel=builder.get_object('noDevicesLabel')

def initDevices():
for dev in device.devlist:
newdev = device.Device(dev)
devicesList.append(newdev)

def emptyDevicesList():
for devindex in range(len(devicesList)):
popoverDevicesListBox.remove(popoverDevicesListBox.get_row_at_index(0))
del devicesList[0]

def fillDevicesList():
if len(devicesList) > 0:
Expand All @@ -58,12 +66,25 @@ def fillDevicesList():
currentDeviceLabel.set_text(
popoverDevicesListBox.get_row_at_index(0).value.name
)
else:
currentDeviceLabel.set_text('No devices')

def updateDevicesConnected():
if len(devicesList)>0:
mainBox.show_all()
noDevicesLabel.hide()
else:
print("no devices")
exit(1)
mainBox.hide()
noDevicesLabel.show()

initDevices()
fillDevicesList()
def refreshDevices():
emptyDevicesList()
initDevices()
fillDevicesList()
updateDevicesConnected()

refreshDevices()

settings = Gtk.Settings.get_default()
settings.set_property("gtk-application-prefer-dark-theme", True)
Expand Down Expand Up @@ -138,14 +159,18 @@ def activateCb(self, app):
app.set_app_menu(appMenu)
window.show_all()
keyboardBox.hide()
updateDevicesConnected()

def on_about_activate(self, *agrs):
builder.get_object("aboutdialog").show()

def on_quit_activate(self, *args):
self.quit()

myrazerkb = devicesList[0]
if len(devicesList)>0:
myrazerkb = devicesList[0]
else:
myrazerkb = None


gameModeIcon = builder.get_object("gameModeIcon")
Expand All @@ -158,6 +183,8 @@ def on_quit_activate(self, *args):
mainStackSwitcherButtons=builder.get_object('mainStackSwitcherButtons')

def refreshFxList():
if not myrazerkb:
return
# empty list before (re)filling it
while True:
row = fxListBox.get_row_at_index(0)
Expand Down Expand Up @@ -197,10 +224,11 @@ def refreshFxList():
gameModeIcon.hide()
gameModeSwitch.hide()

if myrazerkb.device.type != 'tartarus':
mainStackSwitcherButtons.hide()
else:
# macro functionalities temporarely limited to tartarus
if myrazerkb.device.has('macro_logic') and myrazerkb.device.type=='tartarus':
mainStackSwitcherButtons.show()
else:
mainStackSwitcherButtons.hide()

refreshFxList()

Expand Down Expand Up @@ -448,6 +476,9 @@ class Handler:
def onDeleteWindow(self, *args):
Gtk.main_quit(*args)

def on_refreshDevicesButton_clicked(self, button):
refreshDevices()

def on_tartarusKeyList_row_activated(self, list, row):
# TODO: set shortcut entry to already existing shortcut
tartarusShortcutDialogKeyNumber.set_text(str(row.value))
Expand Down
Loading

0 comments on commit 2137c3c

Please sign in to comment.