#!/usr/bin/env python

import wx
import subprocess


class Example(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)

        self.initui()

    def initui(self):

        menubar = wx.MenuBar()
        filemenu = wx.Menu()
        fileitem = filemenu.Append(wx.ID_EXIT, 'Quit', 'Quit application')
        menubar.Append(filemenu, '&File')
        self.SetMenuBar(menubar)

        self.Bind(wx.EVT_MENU, self.onquit, fileitem)

        self.SetSize((300, 200))
        self.SetTitle('OS Updater')
        self.Centre()

        pnl = wx.Panel(self)
        updateflatpakbutton = wx.Button(pnl, label='Update Flatpaks', pos=(20, 20))
        updateflatpakbutton.Bind(wx.EVT_BUTTON, self.onflatpakupdate)
        updaterpmbutton = wx.Button(pnl, label='Update RPMs', pos=(20, 60))
        updaterpmbutton.Bind(wx.EVT_BUTTON, self.onrpmupdate)

    def onflatpakupdate(self, e):
        subprocess.run(["flatpak", "update", "-y"])

    def onrpmupdate(self, e):
        subprocess.run(["sudo", "dnf", "update", "-y"])

    def onquit(self, e):
        self.Close()


def main():

    app = wx.App(0)
    ex = Example(None)
    ex.Show()
    app.MainLoop()


if __name__ == '__main__':
    main()
