Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python

# Distribution / packaging
build/
dist/
*.egg-info/

# Virtual environments
venv/
env/
ENV/

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db
43 changes: 37 additions & 6 deletions globalPlugins/wordpressmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@
}
config.conf.spec["wordpressManager"] = confSpec

class WordPressSettingsDialog(gui.SettingsDialog):
"""Settings dialog for WordPress Manager configuration."""
title = _("WordPress Manager Settings")

def makeSettings(self, settingsSizer):
sHelper = gui.guiHelper.BoxSizerHelper(self, sizer=settingsSizer)

self.siteUrlCtrl = sHelper.addLabeledControl(_("Site &URL:"), wx.TextCtrl)
self.siteUrlCtrl.Value = config.conf["wordpressManager"]["siteUrl"]

self.usernameCtrl = sHelper.addLabeledControl(_("&Username:"), wx.TextCtrl)
self.usernameCtrl.Value = config.conf["wordpressManager"]["username"]

self.appPasswordCtrl = sHelper.addLabeledControl(_("&Application Password:"), wx.TextCtrl, style=wx.TE_PASSWORD)
self.appPasswordCtrl.Value = config.conf["wordpressManager"]["appPassword"]

def onOk(self, event):
config.conf["wordpressManager"]["siteUrl"] = self.siteUrlCtrl.Value
config.conf["wordpressManager"]["username"] = self.usernameCtrl.Value
config.conf["wordpressManager"]["appPassword"] = self.appPasswordCtrl.Value
super(WordPressSettingsDialog, self).onOk(event)

class CreateContentDialog(gui.SettingsDialog):
"""Ultimate dialog for creating Posts, Pages and selecting Categories."""
title = _("WordPress: Create New Content")
Expand All @@ -60,6 +82,9 @@ def makeSettings(self, settingsSizer):
threading.Thread(target=self.fetchCategories).start()

def fetchCategories(self):
if requests is None:
wx.CallAfter(ui.message, _("Requests library not available. Please install it."))
return
url = config.conf["wordpressManager"]["siteUrl"]
auth = (config.conf["wordpressManager"]["username"], config.conf["wordpressManager"]["appPassword"])
try:
Expand Down Expand Up @@ -115,6 +140,9 @@ def makeSettings(self, settingsSizer):
threading.Thread(target=self.loadComments).start()

def loadComments(self):
if requests is None:
wx.CallAfter(ui.message, _("Requests library not available. Please install it."))
return
url = config.conf["wordpressManager"]["siteUrl"]
auth = (config.conf["wordpressManager"]["username"], config.conf["wordpressManager"]["appPassword"])
try:
Expand Down Expand Up @@ -142,15 +170,15 @@ def createMenu(self):
self.menu = gui.mainFrame.sysTrayIcon.menu
self.wp_menu = wx.Menu()

self.wp_menu.Append(wx.ID_ANY, _("New Content...")).SetItemLabel(_("New Content..."))
gui.mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.onNew, self.wp_menu.FindItemByPosition(0))
newContentItem = self.wp_menu.Append(wx.ID_ANY, _("New Content..."))
gui.mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.onNew, newContentItem)

self.wp_menu.Append(wx.ID_ANY, _("Manage Comments..."))
gui.mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.onComments, self.wp_menu.FindItemByPosition(1))
commentsItem = self.wp_menu.Append(wx.ID_ANY, _("Manage Comments..."))
gui.mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.onComments, commentsItem)

self.wp_menu.AppendSeparator()
self.wp_menu.Append(wx.ID_ANY, _("Settings..."))
gui.mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.onSettings, self.wp_menu.FindItemByPosition(3))
settingsItem = self.wp_menu.Append(wx.ID_ANY, _("Settings..."))
gui.mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.onSettings, settingsItem)

self.main_item = self.menu.AppendSubMenu(self.wp_menu, _("WordPress Manager"))

Expand All @@ -168,6 +196,9 @@ def onSettings(self, evt):
WordPressSettingsDialog(gui.mainFrame).Show()

def api_call(self, method, endpoint, data=None):
if requests is None:
wx.CallAfter(ui.message, _("Requests library not available. Please install it."))
return
url = f"{config.conf['wordpressManager']['siteUrl']}/wp-json/wp/v2/{endpoint}"
auth = (config.conf['wordpressManager']['username'], config.conf['wordpressManager']['appPassword'])
try:
Expand Down